# Getting my asteroids videogame to work

**URL:** <https://discourse.processing.org/t/getting-my-asteroids-videogame-to-work/17945>\
**Category:** Coding Questions\
**Created:** [February 20, 2020, 1:39am UTC](https://discourse.processing.org/t/getting-my-asteroids-videogame-to-work/17945 "2020-02-20T01:39:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![The-Coder](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the-coder/32/8127_2.png) [@The-Coder](https://discourse.processing.org/u/The-Coder)\
**Post date:** [February 20, 2020, 1:39am UTC](https://discourse.processing.org/t/getting-my-asteroids-videogame-to-work/17945/1 "2020-02-20T01:39:35Z")

</div>

I am try to make a sideways meteor dodging game where you are a spaceship that avoids asteroids that fly towards you from the left. My problem is that I have not been able to make a larger than 1 pixel hit box for the asteroids. Currently the player is 1 pixel and the asteroids are 1 pixel and my code only ends the game if they touch exactly. I would like help writing code so if the player is within 10 pixels of an asteroid on any side the game ends. Under here is my code, sorry if it’s a bit long.

```auto
void setup() {
  size(800, 400);
  noLoop(); // draw() will not loop
  //start text
  print ("press the mouse to start the game the up arrow moves your spaceship up and the down arrow moves it down");
}
// x for player
float x = 50 ;
// y for player
float y = 50;

// game end, triggered when you hit a meteor
float GameOver = 0;

//player score counter
float playerScore = 0;

// x’s for meteors
float A= 100;
float B= 100;
float C= 100;
float D= 100;
float E= 100;
float F = 100;
float G =100;
float H= 100;
float I=100;
float J = 100;
float K = 100;
float L= 100;

// Y’s for meteors
float AA= 50;
float BB = 60;
float CC = 90;
float DD =70;
float EE = 10;
float FF = 50;
float GG = 60;
float HH = 65;
float II = 80;
float JJ= 15;
float KK= 40;
float LL = 70;

void draw() {
  background(200, 200, 200);
  strokeWeight(1);

  //score varaible
  playerScore = playerScore + .6;
  if (GameOver == 1) {
    playerScore = playerScore - 0;
  }

  ///code to move meteors across screen and reset them when they hit the left edge

  A= A- .25;
  if (A > width) {
    A = 100;
  }
  B =B - .25;
  if (B > width) {
    B = 100;
  }
  C=C- .25;
  if (C> width) {
    C= 100;
  }
  D= D - .25;
  if (D > width) {
    D= 100;
  }
  E=E - .25;
  if (E > width) {
    E = 100;
  }
  F = F- .25;
  if (F > width) {
    F = 100;
  }
  G = G - .25;
  if (G > width) {
    G = 100;
  }
  H =H - .25;
  if (H > width) {
    H = 100;
  }
  I = I - .25;
  if (I > width) {
    I = 100;
  }
  J = J - .25;
  if (J > width) {
    J = 100;
  }
  K =K- .25;
  if (K > width) {
    K= 100;
  }
  L = L - .25;

  if (L > width) {
    L= 100;
  }

  // meteors

  stroke (255);
  // player
  point(x, y);

  stroke (0);

  //meteors
  point(A, AA);
  point(B, BB);
  point(C, CC);
  point(D, DD);
  point(E, EE);
  point(F, FF );
  point(G, GG);
  point(H, HH);
  point(I, II);
  point(J, JJ);
  point(K, KK);
  point(L, LL);

  // meteorcrash detector

  while (X == A && Y == AA) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == B && Y == BB) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == C && Y == CC) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == D && Y == DD) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == E && Y == EE) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == F && Y == FF) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == G && Y == GG) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == H && Y == HH) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == I && Y == II ) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X == J && Y == JJ ) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X ==K && Y == KK ) {
    print ("gameOver");
    GameOver = 1;
  }

  while (X ==L && Y == LL) {
    print ("gameOver");
    GameOver = 1;
  }
}

//player movement using arrow keys

void keyPressed() {
  if (key == CODED) {
    if (keyCode == UP) {
      y=y-1.5 ;
    } else if (keyCode == DOWN) {
      y=y+1.5;
    } else if (keyCode == RIGHT) {
      x=x+1.5 ;
    } else if (keyCode == LEFT) {
      x=x-1.5;
    }
  }
}

void mousePressed() {
  loop();
}
void mouseReleased() {
  loop();
}

```

---

<div class="post-metadata">

**Author:** ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)\
**Post date:** [February 23, 2020, 8:30am UTC](https://discourse.processing.org/t/getting-my-asteroids-videogame-to-work/17945/2 "2020-02-23T08:30:06Z")

</div>

i think you are looking for circle collision  
look at this:  
[https://forum.processing.org/one/topic/simple-collision-detection.html](https://forum.processing.org/one/topic/simple-collision-detection.html)

---

<div class="post-metadata">

**Author:** ![The-Coder](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the-coder/32/8127_2.png) [@The-Coder](https://discourse.processing.org/u/The-Coder)\
**Post date:** [February 25, 2020, 3:42am UTC](https://discourse.processing.org/t/getting-my-asteroids-videogame-to-work/17945/3 "2020-02-25T03:42:50Z")

</div>

Ok thanks, that was really helpful

---

<div class="post-metadata">

**Author:** ![markcosmic](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@markcosmic](https://discourse.processing.org/u/markcosmic)\
**Post date:** [February 29, 2020, 10:02pm UTC](https://discourse.processing.org/t/getting-my-asteroids-videogame-to-work/17945/4 "2020-02-29T22:02:46Z")

</div>

Also I add; the use of a PVector() array for your meteors would make them more manageable. You might check out what Daniel Shiffman has to say about PVectors on YouTube
