public Droid(Bitmap[] bitmap, float x, float y, float speed, Game game, boolean isAlive) { super(bitmap, x, y, speed, game.getLevel().getGrid(), game, isAlive); mGame = game; }
/** * check if the human interacts with ghost, key, door or wall * * @param game * @throws java.lang.InterruptedException * @throws java.io.IOException */ public void checkInteract(Game game) throws InterruptedException, IOException { DirectionType doorDisplacement = game.getLevel().getDoorDirection(); Point2D door = new Point2D.Double( game.getLevel().getDoorLocation().getX(), game.getLevel().getDoorLocation().getY()); switch (doorDisplacement) { case UP: door.setLocation(door.getX(), door.getY() - 100); break; case RIGHT: door.setLocation(door.getX() + 100, door.getY()); break; case LEFT: door.setLocation(door.getX() - 100, door.getY()); break; case DOWN: door.setLocation(door.getX(), door.getY() + 100); break; } Point2D key = game.getLevel().getKeyLocation(); // door collision if ((checkHitboxCollision( new Point2D.Double(this.getPosition().getX() + 10, this.getPosition().getY() + 10), 80, 80, new Point2D.Double(door.getX() - 5, door.getY() - 5), 110, 110) && this.hasKey)) // key collision { this.enterDoor(game); } // key collision if (checkHitboxCollision(this.getPosition(), 80, 80, key, 80, 80)) { this.pickUpKey(); } // flashlight and ghost collision if (this.checkGhostCollision(game) != null) { this.checkGhostCollision(game).possess(game); } setFlashlight(); game.getGhosts() .stream() .forEach( (g) -> { if (g.isVulnerable() && !g.getRip() && !g.getDead()) { boolean hit = false; for (Point2D p : g.getHitboxPoints()) { if (flashlightCollision(p)) { hit = true; break; } } if (hit) { g.setTimeOfDeath(); g.vanish(game); } } }); }
public void render() { Shader shader = Game.getLevel().getShader(); shader.updateUniforms( transform.getTransformation(), transform.getProjectedTransformation(), material); mesh.draw(); }
/** * Basic drawing implementation for the game. * * <p>Fills the background (white) and calls Level's drawing method. * * @param g A Graphics context. */ protected void paintComponent(Graphics g) { Rectangle size = g.getClipBounds(); g.setColor(Color.white); g.fillRect(size.x, size.y, size.width, size.height); game.getLevel().draw(g); }
/** paintComponent Draws the level of the game */ public void paintComponent(Graphics g) { super.paintComponent(g); game.getLevel().draw(g); }