/** * Draws everything onto the main panel. * * @param page Graphics component to draw on */ public void paintComponent(Graphics page) { super.paintComponent(page); setForeground(Color.cyan); renderer.draw(page, this, offX, offY); // hero.draw(this, page, offX, offY); for (Entity effect : effects) { effect.draw(this, page, offX, offY); /*if (effect instanceof Burst) { Burst pop = (Burst) effect; pop.draw(this, page, offX, offY); }*/ } // Draw hero position information Rectangle r = hero.getBounds(); page.drawString("Position: x = " + (r.x + (r.width >> 1)), SCORE_PLACE_X, SCORE_PLACE_Y); final int tab = 100; final int lineHeight = 20; page.drawString("y = " + (r.y + (r.height >> 1)), SCORE_PLACE_X + tab, SCORE_PLACE_Y); page.drawString("Frame: " + frame, SCORE_PLACE_X, SCORE_PLACE_Y + lineHeight); if (!running) { page.drawString("Game over :(", WIDTH / 2, HEIGHT / 2); } }
/** * Tests if the hero triggers world events, like by touching a light. * * @param trigs A list of triggers to test. */ private void testTriggers(ArrayList<Trigger> trigs) { for (Trigger trigger : trigs) { if (trigger.isTriggered(hero.getBounds())) { trigger.triggerAction(); Entity burst = new Burst(tp); burst.setPos(((Light) trigger).getPos()); effects.add(burst); if (trigger instanceof Drawable) { renderer.invalidate(((Drawable) trigger).getBounds()); } } } }