@Override public void update(GameContainer container, int delta) throws SlickException { Projectile proj; playerNextPos = inputHandler.playerInput(player, container.getInput(), delta, sound); entity.update(delta, sound); if (!isBlocked(playerNextPos, player.getWidth(), player.getHeight())) { player.setCoord(playerNextPos); } player.logic(); for (int i = 0; i < projectiles.size(); i++) { proj = projectiles.get(i); proj.update(delta); if (isBlocked(proj.pos, proj.getWidth(), proj.getHeight())) { projectiles.remove(i); sound.playSound(collisionSound); } else if (proj.collidesWith(entity) && proj.getOwner() == player) { proj.damage(entity); projectiles.remove(i); } else if (proj.collidesWith(player) && proj.getOwner() == entity) { proj.damage(player); projectiles.remove(i); } } }
// 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)); } } }
/** Tests for getWidth. */ @Test public void testgetWidth() { Player bob = PlayerTestHelper.createPlayer("bob"); assertThat(bob.getWidth(), is(1.0)); assertThat(bob.get("width"), is("1")); assertThat(bob.getHeight(), is(1.0)); assertThat(bob.get("height"), is("1")); Player george = Player.createZeroLevelPlayer("george2", null); assertThat(george.getWidth(), is(1.0)); assertThat(george.get("width"), is("1")); assertThat(george.getHeight(), is(1.0)); assertThat(george.get("height"), is("1")); }
public void render(ShaderHandler sh, DisplaySetup d, DataUtils util) { for (int i = 0; i < size(); i++) { pellet.changePos(get(i).getPos().x - currentpos.x, get(i).getPos().y - currentpos.y); pellet.changeTexture(get(i).getTexid()); if (get(i).getAnimationWait() > 3) { if (get(i).getTexid() < 11) { get(i).changeTexid(1); } else { get(i).setTexid(0); } get(i).resetWait(); } else { get(i).animationWait(); } currentpos = new Vector2f(get(i).getPos().x, get(i).getPos().y); pellet.render(sh, util, 0); if (get(i) .contains( player.getPos(), (float) player.getWidth() / Display.getWidth(), (float) player.getHeight() / Display.getHeight(), d)) { parent.score(get(i).getScore()); remove(i); } } }
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("")) { } }
public float getHeight() { return player.getHeight(); }
private void drawActors(Graphics2D g2d) { g2d.setColor(Color.GREEN); for (Player actor : actors) { g2d.drawRect(actor.getX(), actor.getY(), actor.getWidth(), actor.getHeight()); } }