示例#1
1
  public void tick() {

    // update mobs and if they are using AI, check to see if the player is visible to them

    for (Mob e : mobList) {
      e.tick();
    }

    Point2D p = Globals.getIsoCoords(player.getX(), player.getY());
    Camera.moveTo((int) p.getX(), (int) p.getY());
  }
示例#2
0
  @Test
  public void picksFuel() {
    // jogador apanha um bonus de combustivel
    Player p = new Player(true);

    int fuel = p.getFuel();

    // cria objeto que da a vida ao player
    Fuel f = new Fuel(p.getX(), p.getY(), true);

    // verifica se apanha
    assertTrue(f.colide(p));
    f.caught(p, true);

    // nao ganha fuel, pois esta cheio
    assertFalse(fuel < p.getFuel());

    // retirar fuel
    p.addFuel(-100);
    assertTrue(fuel > p.getFuel());

    // ganha fuel
    int fuel1 = p.getFuel();
    f.caught(p, true);
    assertTrue(fuel1 < p.getFuel());
  }
示例#3
0
  @Test
  public void picksHealth() {
    // jogador apanha um bonus de vida (ganha vida)
    Player p = new Player(true);

    int life = p.getLifepoints();

    // cria objeto que da a vida ao player
    Health h = new Health(p.getX(), p.getY(), true);

    Obstacle ob = new Obstacle((int) p.getX(), (int) p.getY(), 20, true);

    // verifica se apanha
    assertTrue(h.colide(p));
    h.caught(p, true);

    // verifica se nao ganha vida, pois tem a vida cheia
    assertEquals(life, p.getLifepoints());

    // perde vida
    ob.damage(p);
    int life1 = p.getLifepoints();
    assertTrue(life > life1);

    // ganha vida
    h.caught(p, true);
    assertTrue(life1 < p.getLifepoints());
  }
示例#4
0
  @Test
  public void colidesWithMine() {
    // jogador fica com os controlos trocados
    Player p = new Player(true);
    Skymine s = new Skymine(p.getX(), p.getY(), true);

    assertFalse(p.isMalfunctioning());
    assertTrue(s.colide(p));
    s.caught(p, true);

    assertTrue(p.isMalfunctioning());
  }
示例#5
0
  public void render(Graphics g) {
    // points used for render culling
    // long starter = System.currentTimeMillis();

    Point origin =
        Globals.findTile(
            (int) player.getX() - Camera.width / 2, (int) player.getY() - Camera.height);
    Point bottomRight =
        Globals.findTile((int) player.getX() + Camera.width, (int) player.getY() + Camera.height);

    if (origin.x < 0) origin.setLocation(0, origin.y);
    if (origin.y < 0) origin.setLocation(origin.x, 0);

    if (bottomRight.x >= xLength) bottomRight.setLocation(xLength - 1, bottomRight.y);
    if (bottomRight.y >= yHeight) bottomRight.setLocation(bottomRight.x, yHeight - 1);

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

    for (Entity e : mobList) {
      sortList.add(e);
    }

    // render loop
    for (int x = origin.x; x < bottomRight.x; x++) {
      for (int y = bottomRight.y; y >= origin.y; y--) {
        try {
          if (tileMap[x][y] != null) {
            //	renderct++;
            tileMap[x][y].render(g);
          }
          if (walls[x][y] != null) sortList.add(walls[x][y]);
        } catch (Exception e) {
          System.out.println("EXCEPTION IN WORLD RENDER LOOP");
          e.printStackTrace();
        }
        ;
      }
    }

    Collections.sort(sortList, spriteSorter);
    if (player.target != null)
      player.selection.render(
          g,
          (int) ((Mob) player.target).getAttbox().getX() - 10,
          (int) ((Mob) player.target).getAttbox().getY() + 130);
    for (Entity e : sortList) {
      //	renderct++;
      e.render(g);
    }
  }
示例#6
0
  @Test
  public void colidesWithObstacle() {
    // jogador colide com um obstaculo (perde vida)
    Player p = new Player(true);

    int life = p.getLifepoints();

    Obstacle ob = new Obstacle((int) p.getX(), (int) p.getY(), life, true);

    // verifica se colide
    assertTrue(ob.colide(p));

    ob.damage(p);

    // verifica se perde vida
    assertTrue(life > p.getLifepoints());
  }
示例#7
0
  @Test
  public void picksInvulnerableBonus() {
    // jogador fica invulnerável durante x tempo
    Player p = new Player(true);

    int life = p.getLifepoints();

    Invulnerability ob = new Invulnerability();

    Obstacle obj = new Obstacle((int) p.getX(), (int) p.getY(), life, true);

    // verifica se apanha
    assertTrue(ob.colide(p));
    ob.caught(p, true);

    // colide com objeto que danifica
    obj.damage(p);

    // verifica se nao perde vida
    assertEquals(life, p.getLifepoints());
  }
示例#8
0
  public World(Sprite t) {

    tileHeight = (Camera.scale * t.getHeight());
    tileWidth = (Camera.scale * t.getWidth() / 2); // same as tileHeight (square/flatspace)

    Globals.tileHeight = (Camera.scale * t.getHeight());
    Globals.tileWidth = (Camera.scale * t.getWidth() / 2); // same as tileHeight (square/flatspace)

    tile = t;

    InventoryMenu i = new InventoryMenu();
    mobList = new ArrayList<Mob>();
    player = new Player(39, 3, i);
    player.init(this);
    OverlayManager.init(player);
    // player.addPathFinder(this);
    mobList.add(player);
    Point2D p = Globals.getIsoCoords(player.getX(), player.getY());
    Camera.moveTo((int) p.getX(), (int) p.getY());
    loadEnviro(9);
  }
示例#9
0
  // GAMEPLAY
  @Test
  public void gameOver() {
    // jogador fica sem vida
    Player p = new Player(true);

    int life = p.getLifepoints();

    // cria obstaculo que tira a vida toda ao player
    Obstacle ob = new Obstacle((int) p.getX(), (int) p.getY(), life, true);

    // verifica se colide
    assertTrue(ob.colide(p));

    ob.damage(p);

    // verifica se perde vida toda
    assertTrue(life > p.getLifepoints());
    assertEquals(p.getLifepoints(), 0);
  }