Example #1
0
  @Override
  public void renderImages(Graphics g) {

    g.drawImage(Resources.background, -300, bgp, null);

    for (int i = 0; i < ArrayB.size(); i++) {
      for (int j = 0; j < ArrayE.size(); j++) ArrayB.get(i).onCollideWith(ArrayE.get(j));
    }
    g.drawImage(Resources.flight, mc.getX(), mc.getY(), null);

    // if(ArrayB.size() > 0){
    for (int i1 = 0; i1 < ArrayB.size(); i1++) {
      g.drawImage(Resources.bullet, ArrayB.get(i1).getX(), ArrayB.get(i1).getY(), null);
    }
    // }
    if (count > 10000) {
      count = 0;
    }
    count++;
    if (count % 25 == 0) {
      int x = (int) (Math.random() * GameMain.GAME_WIDTH);
      ArrayE.add(new Enemy(x, 0, 200, 100));
    }
    for (int i1 = 0; i1 < ArrayE.size(); i1++) {
      g.drawImage(Resources.enemies, ArrayE.get(i1).getX(), ArrayE.get(i1).getY(), null);
    }
  }
Example #2
0
 @Override
 public void onRelease(KeyEvent k) {
   if (k.getKeyCode() == KeyEvent.VK_UP
       || k.getKeyCode() == KeyEvent.VK_DOWN
       || k.getKeyCode() == KeyEvent.VK_LEFT
       || k.getKeyCode() == KeyEvent.VK_RIGHT
       || k.getKeyCode() == KeyEvent.VK_W
       || k.getKeyCode() == KeyEvent.VK_X
       || k.getKeyCode() == KeyEvent.VK_A
       || k.getKeyCode() == KeyEvent.VK_D) {
     mc.stop();
   }
 }
Example #3
0
 @Override
 public void updateState() {
   mc.update();
   for (int i = 0; i < ArrayB.size(); i++) {
     if (ArrayB.get(i).isDead) ArrayB.remove(ArrayB.get(i));
   }
   for (int i = 0; i < ArrayE.size(); i++) {
     if (ArrayE.get(i).isDead) ArrayE.remove(ArrayE.get(i));
   }
   for (int i = 0; i < ArrayB.size(); i++) {
     ArrayB.get(i).update();
   }
   for (int i = 0; i < ArrayE.size(); i++) {
     ArrayE.get(i).update();
   }
   if (bgp >= 0) bgp = -1200 + GameMain.GAME_HEIGHT;
   bgp++;
 }
Example #4
0
 @Override
 public void onPress(KeyEvent k) {
   if (k.getKeyCode() == KeyEvent.VK_UP || k.getKeyCode() == KeyEvent.VK_W) {
     mc.accelUp();
   } else if (k.getKeyCode() == KeyEvent.VK_DOWN || k.getKeyCode() == KeyEvent.VK_S) {
     mc.accelDown();
   } else if (k.getKeyCode() == KeyEvent.VK_LEFT || k.getKeyCode() == KeyEvent.VK_A) {
     mc.accelLeft();
   } else if (k.getKeyCode() == KeyEvent.VK_RIGHT || k.getKeyCode() == KeyEvent.VK_D) {
     mc.accelRight();
   } else if (k.getKeyCode() == KeyEvent.VK_Z || k.getKeyCode() == KeyEvent.VK_H) {
     mc.shoot();
   } else if (k.getKeyCode() == KeyEvent.VK_X || k.getKeyCode() == KeyEvent.VK_J) {
     mc.bomb();
   } else if (k.getKeyCode() == KeyEvent.VK_F1) {
     setCurrentState(new MenuState());
   } else if (k.getKeyCode() == KeyEvent.VK_F2) {
     if (mc.powerup == true) {
       mc.powerup = false;
     } else {
       mc.powerup = true;
     }
   }
 }