示例#1
0
  @Override
  public void update(float delta) {
    super.updatePeriodicSprite();
    planePhysics.update(delta);
    Log.debug("Plane update " + planePhysics.getPosition());

    long now = new Date().getTime();

    if (shooting) {
      // on tire!
      if (now - lastBulletShootTime > SHOOTING_PERIOD_TIME) {
        lastBulletShootTime = now;
        shoot();
      }

      // pas d'ennemis, on va peut-être arrêter de tirer...
      if (now - shootingstartTime > MIN_SHOOTING_TIME && !checkEnemiesAround()) {
        shooting = false;
      }
    } else {
      // on n'est pas en train de tirer
      if (checkEnemiesAround()) {
        shooting = true;
        shootingstartTime = new Date().getTime();
      }
    }
  }
示例#2
0
  /** @param alpha */
  public void paint(float alpha) {

    if (planePhysics.getPosition() == null
        || planePhysics.getPreviousPosition() == null
        || cameraPosition.getPosition() == null
        || cameraPosition.getPreviousPosition() == null) {
      return;
    }
    float x = planePhysics.getPosition().x() - cameraPosition.getPosition().x();
    float y = planePhysics.getPosition().y() - cameraPosition.getPosition().y();
    positionInScreen = new Point(x, y);

    float thex = (x);
    float they = (y);

    Log.debug("paint plane " + thex + " " + they);

    groupImageLayer.setTranslation(thex, they);
    double angle = planePhysics.getAngle();

    groupImageLayer.setRotation((float) angle);
    if (planePhysics.getAngleDegrees() > 90
        && planePhysics.getAngleDegrees() < 270
        && !flyingUpsideDown) {
      flyingUpsideDown = true;
      imageLayer.setScaleY(-1);
    } else if ((270 < planePhysics.getAngleDegrees() || planePhysics.getAngleDegrees() < 90)
        && flyingUpsideDown) {
      flyingUpsideDown = false;
      imageLayer.setScaleY(1);
    }
  }
示例#3
0
 @Override
 public boolean testHit(EnemyShoot enemyShoot) {
   Point p =
       Layer.Util.screenToLayer(
           groupLayer, enemyShoot.getPositionInScreen().x, enemyShoot.getPositionInScreen().y);
   if (groupLayer.hitTest(p) != null) {
     Log.info("plane hit " + new Date().getTime());
     return true;
   }
   return false;
 }
示例#4
0
 /** on regardesi il y ades ennemis sur qui tirer */
 private boolean checkEnemiesAround() {
   Iterator<Enemy> itEnemy = enemyManager.getEnemyList().iterator();
   while (itEnemy.hasNext()) {
     Enemy enemy = itEnemy.next();
     //
     // premier tri
     //
     if (Math.abs(enemy.getPosition().x - planePhysics.getPosition().x) < 1000) {
       Point enemyInScreen = enemy.getPositionInScreen();
       Point enemyInTestZone =
           Util.screenToLayer(enemyDetectionLayer, enemyInScreen.x, enemyInScreen.y);
       if (enemyDetectionLayer.hitTest(enemyInTestZone) != null) {
         Log.debug("checkEnemiesAround true " + new Date().getTime());
         return true;
       }
     }
   }
   return false;
 }