Exemple #1
0
  /**
   * Update each entity with the proper screen size (conserving ratios)
   *
   * @param screen
   */
  public void screenModified(Rect screen) {
    screen_width = screen.width();
    screen_height = screen.height();

    ArrayList<Entity> TMPentities = new ArrayList<Entity>();

    int playerWidth = (int) (screen_width * GameModel.playerWidthRatio);
    int playerHeight = (int) (screen_height * GameModel.playerHeightRatio);

    for (Entity e : entities) {
      if (e instanceof Player) {
        if (e == user) {
          user =
              new Player(
                  playerWidth,
                  playerHeight,
                  screen_width - 2 * playerWidth,
                  (screen_height / 2) - playerHeight,
                  0,
                  0,
                  GameView.playerP);
          TMPentities.add(user);
        } else {
          TMPentities.add(
              new Player(
                  playerWidth,
                  playerHeight,
                  playerWidth,
                  (screen_height / 2) - playerHeight,
                  0,
                  0,
                  GameView.playerP));
        }
      } else {
        TMPentities.add(e);
      }
    }

    entities = TMPentities;

    for (Entity e : entities) {
      e.setScreen(screen_width, screen_height);
    }
  }
Exemple #2
0
  /** Update position and check for collision through entities */
  public void update() {
    if (!GameActivity.bpause) {
      for (Entity e : entities) {
        if (e.getClass() == Ball.class) {
          for (Entity d : entities) {
            if (d != e)
              if (((Ball) e).checkCollision(d)) {
                ((Player) d).randomDecalageIA =
                    new Random().nextFloat() * d.height / 2 - d.height / 2;
              }
          }
        }
      }

      for (Entity e : entities) {
        if (e instanceof Player) {
          if (e == user) e.update(user_y);
          else {
            e.update(enemy_y);
          }
        } else {
          if (!isIA && !ServerUDP.server) {
            e.update();
            e.dx = ball_dx;
            e.dy = ball_dy;
            e.pos_x = ball_x;
            e.pos_y = ball_y;
          }

          if (isIA) {
            Random rnd = new Random();
            enemy_y = e.pos_y + 100 - rnd.nextInt(200);
            e.update();
          }

          if (!isIA && ServerUDP.server) {
            e.update();
            ball_x = e.pos_x;
            ball_y = e.pos_y;
            ball_dx = e.dx;
            ball_dy = e.dy;
          }
        }
      }
    }
  }
Exemple #3
0
 /** @param canvas */
 public void draw(Canvas canvas) {
   for (Entity e : entities) {
     e.draw(canvas);
   }
 }