Esempio n. 1
1
  /**
   * 描画処理
   *
   * @param 描画オブジェクト
   */
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // 背景を黒で塗りつぶす
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, getWidth(), getHeight());

    // X方向のオフセットを計算
    int offsetX = MainPanel.WIDTH / 2 - (int) player.getX();
    // マップの端ではスクロールしないようにする
    offsetX = Math.min(offsetX, 0);
    offsetX = Math.max(offsetX, MainPanel.WIDTH - map.getWidth());

    // Y方向のオフセットを計算
    int offsetY = MainPanel.HEIGHT / 2 - (int) player.getY();
    // マップの端ではスクロールしないようにする
    offsetY = Math.min(offsetY, 0);
    offsetY = Math.max(offsetY, MainPanel.HEIGHT - map.getHeight());

    // マップを描画
    map.draw(g, offsetX, offsetY);

    // プレイヤーを描画
    player.draw(g, offsetX, offsetY);

    // スプライトを描画
    // マップにいるスプライトを取得
    LinkedList sprites = map.getSprites();
    Iterator iterator = sprites.iterator();
    while (iterator.hasNext()) {
      Sprite sprite = (Sprite) iterator.next();
      sprite.draw(g, offsetX, offsetY);
    }
  }
Esempio n. 2
1
  public void render(GameContainer container, Graphics g) throws SlickException {
    int xOffset = -(int) player.getX() + WIDTH / 2;
    int yOffset = -(int) player.getY() + HEIGHT / 2;

    tileMap.render(xOffset, yOffset);
    player.draw(WIDTH, HEIGHT);
    entity.draw(xOffset, yOffset);
    for (int i = 0; i < projectiles.size(); i++) {
      projectiles.get(i).draw(xOffset, yOffset);
    }
    this.drawHealthBar(g, player, xOffset, yOffset);
    this.drawHealthBar(g, entity, xOffset, yOffset);
  }
Esempio n. 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());
  }
  public boolean distanceRobotBall() {

    boolean isCurrentRobotMostCloseToBall = true;

    double distanceCurrentRobotToBall =
        Math.sqrt(
            Math.pow(this.player.getX() - this.world.getBall().getX(), 2)
                + Math.pow(this.player.getY() - this.world.getBall().getY(), 2));
    double distanceOtherRobotToBall;
    if (isCurrentRobotMostCloseToBall) {
      for (Player bluePlayer : this.world.getBlueTeam().getPlayers()) {
        distanceOtherRobotToBall =
            Math.sqrt(
                Math.pow(bluePlayer.getX() - this.world.getBall().getX(), 2)
                    + Math.pow(bluePlayer.getY() - this.world.getBall().getY(), 2));
        if (distanceOtherRobotToBall < distanceCurrentRobotToBall) {
          isCurrentRobotMostCloseToBall = false;
          break;
        }
      }
    }
    if (isCurrentRobotMostCloseToBall) {
      for (Player yellowPlayer : this.world.getYellowTeam().getPlayers()) {
        distanceOtherRobotToBall =
            Math.sqrt(
                Math.pow(yellowPlayer.getX() - this.world.getBall().getX(), 2)
                    + Math.pow(yellowPlayer.getY() - this.world.getBall().getY(), 2));
        if (distanceOtherRobotToBall < distanceCurrentRobotToBall) {
          isCurrentRobotMostCloseToBall = false;
          break;
        }
      }
    }
    return isCurrentRobotMostCloseToBall;
  }
Esempio n. 5
0
 public void moveLayerThree(Graphics g) {
   backy += (int) (player1.getVelocity() * 0.1);
   midy += (int) (player1.getVelocity() * 0.5);
   drawEnemy(g);
   drawCoin(g);
   drawBox(g);
   drawPoof(g);
   drawStar(g);
   drawJumper(g);
   drawSpike(g);
   drawPup(g);
   if (backy <= dieHeight) {
     // System.out.println(die);
     g.drawImage(player1.move(2), player1.getX(), player1.getY(), this);
     if (player1.animationComplete()) {
       die = true;
     }
   } else {
     if (backy <= dieHeight) {
       player1.resetCounter();
     }
     if (keys[KeyEvent.VK_RIGHT]) {
       g.drawImage(player1.move(1), player1.getX(), player1.getY(), this);
     } else if (keys[KeyEvent.VK_LEFT]) {
       g.drawImage(player1.move(-1), player1.getX(), player1.getY(), this);
     } else {
       g.drawImage(player1.move(0), player1.getX(), player1.getY(), this);
     }
   }
 }
Esempio n. 6
0
 /**
  * determines whether a projectile hits a player
  *
  * @param aPlayer - player the projectile hits
  * @return - true if player gets hit, false otherwise
  */
 public boolean hitPlayer(Player aPlayer) {
   if (myX >= aPlayer.getX() - 1 && myX <= aPlayer.getX() + 1) {
     if (myY <= aPlayer.getY() + 1 && myY >= aPlayer.getY() - 1) {
       return true;
     }
   }
   return false;
 }
Esempio n. 7
0
  // Sets the location for NPCs to move towards
  public void NPCTarget(Stage s, ArrayList<NPC> npc, Player p) {

    int playerx = p.getX();
    int playery = p.getY();
    int viewrange = 100;
    int npcx;
    int npcy;

    int randnext = 0;

    // For each npc
    for (NPC n : npc) {

      // Get X/Y
      npcx = n.getX();
      npcy = n.getY();
      randnext = rand.nextInt(10);

      // If npc has nowhere to go
      if (n.getMoveticks() == 0 || (n.getGotox() == n.getX() && n.getGotoy() == n.getY())) {

        // Set random amount of movements
        n.setMoveticks(rand.nextInt(150));
        // Set a direction
        n.setDirection(rand.nextInt(4));

        n.setGotox(0);
        n.setGotoy(0);
      }

      // check if the player is within view range and move
      if ((playery >= npcy && playery <= npcy + viewrange
              || playery <= npcy && playery >= npcy - viewrange)
          && playerx > (npcx + n.getWidth())
          && playerx <= (npcx + viewrange)) {

        n.setGotox(p.getX() + (p.getWidth() / 2));
        n.setGotoy(p.getY() + (p.getHeight() / 2));
      }

      if ((playery >= npcy && playery <= npcy + viewrange
              || playery <= npcy && playery >= npcy - viewrange)
          && (playerx + p.getWidth()) < npcx
          && playerx > (npcx - viewrange)) {

        n.setGotox(p.getX() + (p.getWidth() / 2));
        n.setGotoy(p.getY() + (p.getHeight() / 2));
      }
    }
  }
Esempio n. 8
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());
  }
Esempio n. 9
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(Color.GREEN);

    if (player != null) {
      g2d.fillOval(player.getX(), player.getY(), 5, 5);
    }
    /*
    if(trees != null)
    {
     for(Circle tree: trees)
     {
     	g2d.fillOval((int) tree.x, (int) tree.y,(int) tree.RADIUS,(int) tree.RADIUS);
     }
    }
    if(bigHerbivores != null)
    {
    	for(BigHerbivore c: bigHerbivores)
    	{
    		int rad = Math.round(c.RADIUS/2);

    		g2d.setColor(Color.RED);
    		g2d.fillOval((int) c.x - rad,(int) c.y - rad,(int) c.RADIUS,(int) c.RADIUS);
    		g2d.drawLine((int) c.x,(int) c.y,(int) c.destX,(int) c.destY);
    	}
    }
    */
  }
Esempio n. 10
0
  public boolean saveGame(String map) {
    Player p = m_game.getPlayer();
    GameConfig cfg = new GameConfig();
    cfg.put("tag", "GameSaveFile");
    cfg.put("x", (int) p.getX());
    cfg.put("y", (int) p.getY());
    cfg.put("name", p.getName());
    cfg.put("map", map);
    cfg.put("hp", p.HP);
    cfg.put("face", p.getFace());
    cfg.put("playtime", (int) m_game.getPlayTime());
    cfg.put("cansword", p.items[Player.ITEM_SWORD] != null);
    cfg.put("canshoot", p.items[Player.ITEM_RING] != null);
    cfg.put("canbomb", p.items[Player.ITEM_BOMB] != null);
    if (p.canShoot()) cfg.put("ring.num", p.items[Player.ITEM_RING].getCount());
    if (p.canBomb()) cfg.put("bomb.num", p.items[Player.ITEM_BOMB].getCount());
    if (p.curItem == p.items[Player.ITEM_SWORD]) cfg.put("curitem", "sword");
    else if (p.curItem == p.items[Player.ITEM_RING]) cfg.put("curitem", "ring");
    else if (p.curItem == p.items[Player.ITEM_BOMB]) cfg.put("curitem", "bomb");

    for (int i = 0; i < 256; i++) {
      if (p.hasKey[i]) cfg.put("key" + i, p.hasKey[i]);
      if (p.openedDoor[i]) cfg.put("door" + i, p.openedDoor[i]);
    }
    if (cfg.save(m_name + FILEDIR) == false) return false;
    cfg.reset();
    java.util.Map<String, String> vars = AbstractScript.getVars();
    Object[] keys = (vars.keySet().toArray());
    for (int i = 0; i < keys.length; i++) {
      cfg.put((String) keys[i], vars.get(keys[i]));
    }
    return cfg.save(m_name + FILEVARSDIR);
  }
Esempio n. 11
0
  private void move() {
    xa = 0;
    ya = 0;

    List<Player> players = level.getPlayers(this, 300);
    if (players.size() > 0) {
      Player player = players.get(0);

      if (isSlowed((int) xa, (int) ya)) speed = 0.35;
      else speed = 0.5;
      if (x + 30 < player.getX()) xa += speed;
      if (x - 30 > player.getX()) xa -= speed;
      if (y + 30 < player.getY()) ya += speed;
      if (y - 30 > player.getY()) ya -= speed;
    } else {
      time++; // /n time % 60 = 0; == once per second
      if (time % (random.nextInt(60) + 40) == 0) {
        xa = random.nextInt(3) - 1;
        ya = random.nextInt(3) - 1;
        if (random.nextInt(3) == 0) { // or if (time % 60 == 0)
          xa = 0;
          ya = 0;
        }
      }
    }

    if (xa != 0 || ya != 0) {
      move(xa, ya);
      walking = true;
    } else {
      walking = false;
    }
  }
Esempio n. 12
0
  public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    g2d.drawImage(img, 0, 0, null);
    g2d.drawImage(p.getImage(), p.getX(), p.getY(), null);
  }
Esempio n. 13
0
  @Override
  public Move getMove(Gameboard gameboard, Opponent opponent, Player player)
      throws NoItemException, MapOutOfBoundsException {
    // System.out.format("Turn NUm:%d\n", gameboard.getCurrentTurnNumber());
    // Turret t = gameboard.getTurrets().get(2);
    // System.out.format("Turret: cool:%d fire:%d
    // isFiringNextTurn:%b\n",t.getCooldownTime(),t.getFireTime(),t.isFiringNextTurn());
    buildBoardValue(gameboard, player, opponent);
    int maxVal = highestValueTile(gameboard);
    // System.out.format("maxVal:%d\n", maxVal);
    Move myMove =
        bfs(
            gameboard,
            player,
            opponent,
            player.getX(),
            player.getY(),
            player.getDirection(),
            maxVal);
    return myMove;
    // }

    // System.out.println("x:"+player.getX()+" y:"+player.getY()+" safe:
    // "+bulletSafe(gameboard,player.getX(),player.getY()));

  }
Esempio n. 14
0
 @SuppressWarnings("unchecked")
 @Override
 public int loop() {
   synchronized (lock) {
     try {
       if (!ui.isVisible()) handler.stopMod(getName());
       World world = minecraft.getWorld();
       JTable list = ui.getList();
       DefaultTableModel model = (DefaultTableModel) list.getModel();
       TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) list.getRowSorter();
       if (world != null) {
         Player currentPlayer = minecraft.getPlayer();
         int playerX = (int) java.lang.Math.round(currentPlayer.getX());
         int playerY = (int) java.lang.Math.round(currentPlayer.getY());
         int playerZ = (int) java.lang.Math.round(currentPlayer.getZ());
         ArrayList<Block> blocks = new ArrayList<Block>();
         for (int x = playerX - radius; x < playerX + radius; x++)
           for (int y = playerY - radius; y < playerY + radius; y++)
             for (int z = playerZ - radius; z < playerZ + radius; z++)
               if (world.getBlockIDAt(x, y, z) == blockID) blocks.add(new Block(x, y, z));
         label:
         for (int row = 0; row < model.getRowCount(); row++) {
           int x = (Integer) model.getValueAt(row, 1);
           int y = (Integer) model.getValueAt(row, 2);
           int z = (Integer) model.getValueAt(row, 3);
           for (Block block : blocks) {
             if (x == block.getX() && y == block.getY() && z == block.getZ()) {
               model.setValueAt(getDistanceTo(x, y, z, currentPlayer), row, 0);
               continue label;
             }
           }
           model.removeRow(row);
         }
         label:
         for (Block block : blocks) {
           for (int row = 0; row < model.getRowCount(); row++) {
             int x = (Integer) model.getValueAt(row, 1);
             int y = (Integer) model.getValueAt(row, 2);
             int z = (Integer) model.getValueAt(row, 3);
             if (x == block.getX() && y == block.getY() && z == block.getZ()) continue label;
           }
           model.addRow(
               new Object[] {
                 getDistanceTo(block.getX(), block.getY(), block.getZ(), minecraft.getPlayer()),
                 block.getX(),
                 block.getY(),
                 block.getZ()
               });
         }
         sorter.sort();
         list.repaint();
       } else {
         for (int i = model.getRowCount() - 1; i >= 0; i--) model.removeRow(i);
       }
     } catch (Exception exception) {
     }
   }
   return 500;
 }
Esempio n. 15
0
 public void update(Player player, float delta) {
   //
   // body.getPosition().set(body.getPosition().x+(body.getPosition().x-player.getX())*delta,body.getPosition().y);
   if (player.getX() < body.getPosition().x) body.applyForceToCenter(new Vector2(-10, 0), true);
   else {
     body.applyForceToCenter(new Vector2(10, 0), true);
   }
 }
Esempio n. 16
0
 private double getDistanceTo(double x, double y, double z, Player player) {
   double x2 = player.getX();
   double y2 = player.getY();
   double z2 = player.getZ();
   double xResult = java.lang.Math.pow(java.lang.Math.max(x, x2) - java.lang.Math.min(x, x2), 2);
   double yResult = java.lang.Math.pow(java.lang.Math.max(y, y2) - java.lang.Math.min(y, y2), 2);
   double zResult = java.lang.Math.pow(java.lang.Math.max(z, z2) - java.lang.Math.min(z, z2), 2);
   return java.lang.Math.sqrt(xResult + yResult + zResult);
 }
Esempio n. 17
0
 public void tick(GameControls gc, GameTimer time) {
   dt = time.GetDeltaTime();
   boolean hasMoved =
       player.move(
           level, (int) (player.getX() + gc.GetAxis(0)), (int) (player.getY() - gc.GetAxis(1)));
   if (hasMoved) {
     level.tick();
   }
 }
Esempio n. 18
0
 private void tickLeft(Player z, Element x, ArrayList<Element> d) {
   if ((z.getX() - (x.getX() + 15)) < 0
       && (z.getX() - (x.getX() + 15)) > -15
       && (z.getY() - x.getY()) < 10
       && (z.getY() - x.getY()) > -5) {
     if (z.getCol().equals(x.getCol())) {
       d.add(x);
     } else if (x.getCol().equals(BLUE)) {
       if (meta.equals(NO)) {
         meta = WINNERS;
       } else {
         d.add(x);
       }
     } else {
       z.setX(z.getX() + ((x.getX() + 15) - z.getX()));
     }
   }
 }
 public void set(Player p) {
   m_x = p.getX();
   m_y = p.getY();
   m_svrX = p.getServerX();
   m_svrY = p.getServerY();
   m_sprite = p.getSprite();
   m_direction = p.getDirection();
   m_username = p.getUsername();
   m_id = p.getId();
   m_ours = p.isOurPlayer();
 }
Esempio n. 20
0
  @Override
  public void spawn() {
    MainGame mainGame = MainGame.getInstance();
    double x, y;

    x = -10;
    y = 80;
    this.setPosition(x, y);
    this.setVelocity(0.1, 0.1);
    Player p = mainGame.getPlayer();
    double angle = Math.atan((getY() - p.getY()) / (p.getX() - getX()));
    if (p.getX() < getX()) angle -= Math.PI;
    this.setAngle(angle);
    this.setRv(0.0);
    // this.activateProjectiles();
    this.setNextShot(mainGame.getCurrentTime() + 300);
    mainGame.setNextEnemy3Delay(mainGame.getCurrentTime() + 300);

    this.setState(new ActiveShooter());
  }
Esempio n. 21
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());
  }
Esempio n. 22
0
  /**
   * Move a player in the world given a 3D vector.
   *
   * @param username - username of player to be moved
   * @param x - player's x coordinate (Tile x, Renderer x)
   * @param y - player's y coordinate (Tile y, Renderer z)
   * @param z - player's z coordinate (Tile z, Renderer y)
   * @param rot - rotation around (z axis -> Tile, y axis -> Renderer)
   */
  public void movePlayer(String username, double x, double y, double z, double rot) {
    Player p = getPlayer(username);

    // Check if the player is moving
    if (p.getX() != x || p.getY() != y || p.getRotation() != rot) p.setMoving(true);
    else p.setMoving(false);

    p.setX(x);
    p.setY(y);
    p.setZ(z);
    p.setRot(rot);
  }
Esempio n. 23
0
 public void playerMove(String command) {
   char direction = command.charAt(0);
   Entity enemy = collision.collisionCheck(player.getX(), player.getY(), direction, entities);
   if (enemy != null) {
     collision.combat(player, enemy);
     // 4 testing
     System.out.println("COMBAT");
   } else {
     player.move(direction);
     // 4 testing
     System.out.println("MOVEMENT");
   }
 }
Esempio n. 24
0
 public Shoot(Player owner) {
   this.owner = owner;
   clientId = owner.getClientId();
   setScaleX(2);
   setScaleY(5);
   setWidth(texture.getWidth() * getScaleX());
   setHeight(texture.getHeight() * getScaleY());
   setColor(0.93f, 0.93f, 0, 1);
   setRotation(owner.getRotation());
   setOrigin(Align.bottom);
   setX(owner.getX() + 20 * (float) Math.cos(Math.toRadians(getRotation() + 90)));
   setY(owner.getY() + 20 * (float) Math.sin(Math.toRadians(getRotation() + 90)));
 }
Esempio n. 25
0
 public void drawPowerUpEffect(Graphics g) {
   if (player1.getPower().equals("Magnet")) {
     Image magpic = magnetList.get((int) count % 6);
     g.drawImage(
         magpic,
         player1.getX() - ((magpic.getWidth(null) - player1.getWidth()) / 2),
         player1.getY() - ((magpic.getHeight(null) - player1.getHeight()) / 2),
         magpic.getWidth(null),
         magpic.getHeight(null),
         this);
     count += 0.1;
   } else if (player1.getPower().equals("Ball")) {
     g.drawImage(
         ballPower,
         player1.getX() - ballPower.getWidth(null) / 2 + 17,
         player1.getY() + player1.getHeight() - 20,
         ballPower.getWidth(null),
         ballPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("Sheild")) {
     g.drawImage(
         sheildPower,
         player1.getX() - ((sheildPower.getWidth(null) - player1.getWidth()) / 2),
         player1.getY() - ((sheildPower.getHeight(null) - player1.getHeight()) / 2),
         sheildPower.getWidth(null),
         sheildPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("Umbrella")) {
     g.drawImage(
         umbrellaPower,
         player1.getX() - (umbrellaPower.getWidth(null) / 2) + 20,
         player1.getY() - umbrellaPower.getHeight(null) + 40,
         umbrellaPower.getWidth(null),
         umbrellaPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("")) {
   }
 }
Esempio n. 26
0
 public void loseCoins() {
   int x = player1.getX();
   int y = player1.getY();
   double losePercentage = 0.1;
   for (int i = 0;
       i < (int) coins * losePercentage;
       i++) { // makes the user lose 10 percent of the coin and draws them in a circle
     // System.out.println(i);
     int xPos = x + (int) (100 * Math.cos(Math.toRadians((360 / (coins * losePercentage)) * i)));
     int yPos = y - (int) (100 * Math.sin(Math.toRadians((360 / (coins * losePercentage)) * i)));
     coinList.add(new Coin(xPos, yPos, 3));
   }
   coins -= (int) (coins * losePercentage);
 }
Esempio n. 27
0
 public boolean playerQuantityCloseToBall() {
   double distanceOtherRobotToBall;
   int robotCloseToBall = 0;
   for (Player bluePlayer : this.world.getBlueTeam().getPlayers()) {
     distanceOtherRobotToBall =
         Math.sqrt(
             Math.pow(bluePlayer.getX() - this.world.getBall().getX(), 2)
                 + Math.pow(bluePlayer.getY() - this.world.getBall().getY(), 2));
     if (distanceOtherRobotToBall < 600) {
       robotCloseToBall++;
     }
   }
   return robotCloseToBall > 0;
 }
Esempio n. 28
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());
  }
Esempio n. 29
0
 /**
  * Inefficient implementation of a naive pathfinding algorithm starts from the position of the
  * player and "grows" out finding the number of steps to the player They player is one step away
  * from itself its neighbors are two etc. The only squares 0 steps away are walls. This allows the
  * zombies to find their way to the player
  */
 public static void doPathFinding() {
   pathFind = new int[map.length][map[0].length];
   pathFind[p.getX()][p.getY()] = 1;
   int timesRun =
       map.length * map.length * 3 / 5; // approximately the biggest distance between any two tiles
   int worstCase = timesRun + 1; // worst case path
   int bestDecision = worstCase; // best neighboring tile to go to next
   for (int a = 0; a < timesRun; a++) {
     for (int i = 0; i < pathFind.length; i++) {
       for (int j = 0; j < pathFind[0].length; j++) {
         if (pathFind[i][j] == 0 && map[i][j] != 'w') {
           try {
             if (pathFind[i + 1][j] < bestDecision && pathFind[i + 1][j] != 0) {
               bestDecision = pathFind[i + 1][j];
               pathFind[i][j] = bestDecision + 1;
             }
           } catch (Exception e) {
           }
           try {
             if (pathFind[i - 1][j] < bestDecision && pathFind[i - 1][j] != 0) {
               bestDecision = pathFind[i - 1][j];
               pathFind[i][j] = bestDecision + 1;
             }
           } catch (Exception e) {
           }
           try {
             if (pathFind[i][j - 1] < bestDecision && pathFind[i][j - 1] != 0) {
               bestDecision = pathFind[i][j - 1];
               pathFind[i][j] = bestDecision + 1;
             }
           } catch (Exception e) {
           }
           try {
             if (pathFind[i][j + 1] < bestDecision && pathFind[i][j + 1] != 0) {
               bestDecision = pathFind[i][j + 1];
               pathFind[i][j] = bestDecision + 1;
             }
           } catch (Exception e) {
           }
           bestDecision = worstCase;
         }
       }
     }
   }
 }
Esempio n. 30
0
  public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_RIGHT) {
      p.setVelX(5);
    } else if (key == KeyEvent.VK_LEFT) {
      p.setVelX(-5);
    } else if (key == KeyEvent.VK_DOWN) {
      p.setVelY(5);
    } else if (key == KeyEvent.VK_UP) {
      p.setVelY(-5);
    }

    if (key == KeyEvent.VK_SPACE && !is_shooting) {
      c.addEntity(new Bullet(p.getX(), p.getY(), tex, this));
      is_shooting = true;
    }
  }