# Ship fly through the gate (asteroids game)

**URL:** <https://discourse.processing.org/t/ship-fly-through-the-gate-asteroids-game/4647>\
**Category:** Coding Questions\
**Created:** [October 19, 2018, 4:48pm UTC](https://discourse.processing.org/t/ship-fly-through-the-gate-asteroids-game/4647 "2018-10-19T16:48:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nhghi](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@nhghi](https://discourse.processing.org/u/nhghi)\
**Post date:** [October 19, 2018, 4:48pm UTC](https://discourse.processing.org/t/ship-fly-through-the-gate-asteroids-game/4647/1 "2018-10-19T16:48:22Z")

</div>

hi, guys, I’m trying to make a small game look like asteroids game but I this time I just need my ship to fly through the gate ( make from 2 direct that the ship can fly in) if it hit the gate the ship should stop at where it hit and when ship touch the area inside the gate it will start at a new point with the new gate  
this is my code

```auto
float ship_Pos_X=250, 
  ship_Pos_Y=250, 
  angle_of_the_Ship=0, 
  d1=55, 
  d2=30, 
  angle_of_wing=0.7;
float x=0, 
  y=0, 
  x1=0, 
  y1=0, 
  x3=0, 
  y3=0;
float ship_Pos_X1=ship_Pos_X, 
  ship_Pos_Y1=ship_Pos_Y, 
  angle_both_first=0, 
  angle_both_second=0;
boolean turningleft=false, 
  turningright=false, 
  go_ahead=false;
color demension=color(random(255), random(255), random(255));
void setup()
{
  size(1000, 1000);
}
void draw()
{
  newDimension();
  calcPoints();
  drawSHIP();

  Move_Ship();
}

void calcPoints()
{

  x =cos(angle_of_the_Ship)*d1;
  y =sin(angle_of_the_Ship)*d1;
  angle_both_first=angle_of_the_Ship+angle_of_wing;
  angle_both_second=angle_of_the_Ship-angle_of_wing;
  x1=cos(angle_both_first)*d2;
  y1=sin(angle_both_first)*d2;
  x3=cos(angle_both_second)*d2;
  y3=sin(angle_both_second)*d2;
}

void drawSHIP()
{
  fill(#FF4A08);
  quad(ship_Pos_X1, ship_Pos_Y1, ship_Pos_X1-x1, ship_Pos_Y1-y1, ship_Pos_X1+x, ship_Pos_Y1+y, ship_Pos_X1-x3, ship_Pos_Y1-y3);
  if (key=='d'||key=='l'&& turningleft==true) {
    angle_of_the_Ship+=0.01;
  }
  if (key=='a'||key=='j'&& turningright==true) {
    angle_of_the_Ship-=0.01;
  }
  if (key=='s' ||key=='k'&&go_ahead==true) {
  }
}

void Move_Ship()

{

  ship_Pos_X1=ship_Pos_X1+cos(angle_of_the_Ship)*2;
  ship_Pos_Y1=ship_Pos_Y1+sin(angle_of_the_Ship)*2;
 if (ship_Pos_X1 < 0){
      ship_Pos_X1 = width;
    }
    if (ship_Pos_Y1 < 0) {
      ship_Pos_Y1 = height;
    }
    if (ship_Pos_X1 > width) {
      ship_Pos_X1 = 0;
    }
    if (ship_Pos_Y1 > height){
      ship_Pos_Y1 = 0;
    ship_Pos_Y1=-ship_Pos_Y;
  }
}

void newDimension()
{
  background(demension);
}

void keyPressed()
{
  if (key=='d'||key=='l') {
    turningleft=true;
  }
  if (key=='a'||key=='j') {   
    turningright=true;
  }
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [October 19, 2018, 6:01pm UTC](https://discourse.processing.org/t/ship-fly-through-the-gate-asteroids-game/4647/2 "2018-10-19T18:01:39Z")

</div>

Edit your post. Select your code. Hit the FORMAT THIS LIKE CODE button, which looks like this: \</\>

You - and others too - have been asking questions about this asteroid ship code for like three days. So you have been here long enough to get this right. I am sick of having to fix the single quotes every time I try to run this.

Why didn’t you mention the gates before? Also, you have not attempted to put in any gates yourself! Please attempt to do your work before asking us to do it.

If this is for an assignment, please also post the whole, exact text of what you are trying to do.

---

<div class="post-metadata">

**Author:** ![Quertz](https://avatars.discourse-cdn.com/v4/letter/q/cc9497/32.png) [@Quertz](https://discourse.processing.org/u/Quertz)\
**Post date:** [October 20, 2018, 9:05am UTC](https://discourse.processing.org/t/ship-fly-through-the-gate-asteroids-game/4647/3 "2018-10-20T09:05:11Z")

</div>

Hi Thomas, this is jens from germany. Your are doing an awesome job here in explaining and helping! I have sent you a facebook-request. Cheers, Jens

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [October 21, 2018, 12:09am UTC](https://discourse.processing.org/t/ship-fly-through-the-gate-asteroids-game/4647/4 "2018-10-21T00:09:20Z")

</div>

@nhghi Please follow this link that gives tips on asking questions. - [Guidelines—Tips on Asking Questions](https://discourse.processing.org/t/guidelines-tips-on-asking-questions/2147) And, make sure to break your problem into smaller steps. - [http://happycoding.io/tutorials/how-to/program](http://happycoding.io/tutorials/how-to/program) Programming is a trial and error process. Which part of your code do you think needs to be adjusted in order to get the ship to stop?
