@Override public void paint(Graphics g) { if (state == GameState.Running) { g.drawImage(background, bg1.getBgX(), bg1.getBgY(), this); g.drawImage(background, bg2.getBgX(), bg2.getBgY(), this); paintTiles(g); ArrayList<Projectile> projectiles = robot.getProjectiles(); for (int i = 0; i < projectiles.size(); i++) { Projectile p = (Projectile) projectiles.get(i); g.setColor(Color.YELLOW); g.fillRect(p.getX(), p.getY(), 10, 5); } // g.drawRect((int)robot.rect.getX(), (int)robot.rect.getY(), // (int)robot.rect.getWidth(), (int)robot.rect.getHeight()); // g.drawRect((int)robot.rect2.getX(), (int)robot.rect2.getY(), // (int)robot.rect2.getWidth(), (int)robot.rect2.getHeight()); g.drawImage(currentSprite, robot.getCenterX() - 61, robot.getCenterY() - 63, this); g.drawImage(hanim.getImage(), hb.getCenterX() - 48, hb.getCenterY() - 48, this); g.drawImage(hanim.getImage(), hb2.getCenterX() - 48, hb2.getCenterY() - 48, this); g.setFont(font); g.setColor(Color.WHITE); g.drawString(Integer.toString(score), 740, 30); } else if (state == GameState.Dead) { g.setColor(Color.BLACK); g.fillRect(0, 0, 800, 480); g.setColor(Color.WHITE); g.drawString("Dead", 360, 240); } }
@Override public void run() { if (state == GameState.Running) { while (true) { robot.update(); if (robot.isJumped()) { currentSprite = characterJumped; } else if (robot.isDucked() == false) { // currentSprite = character; currentSprite = anim.getImage(); } ArrayList<Projectile> projectiles = robot.getProjectiles(); for (int i = 0; i < projectiles.size(); i++) { Projectile p = (Projectile) projectiles.get(i); if (p.isVisible() == true) { p.update(); } else { projectiles.remove(i); } } // Update objects updateTiles(); hb.update(); hb2.update(); bg1.update(); bg2.update(); animate(); repaint(); try { Thread.sleep(17); } catch (InterruptedException e) { e.printStackTrace(); } if (robot.getCenterY() > 500) { state = GameState.Dead; } } } }