1 package de.jos.game.objects;
2
3 import com.golden.gamedev.object.Sprite;
4 import com.golden.gamedev.object.Timer;
5
6 public class Countdown {
7
8
9 public static final int MAX_HEIGHT = 180;
10
11 private static final double TIMER_INCREMENT = 0.54d;
12
13 public static final int COUNTDOWN_X_POS = 525;
14 public static final int COUNTDOWN_MAX_POS = 202;
15 private static final int COUNTDOWN_MIN_POS = COUNTDOWN_MAX_POS + MAX_HEIGHT;
16
17 private Timer timerStandard = new Timer(1000);
18 private Timer timerTimeBonus = new Timer(40);
19
20 private double timeBonus = 0.0d;
21
22
23 Sprite sprite = null;
24
25 public Countdown() {}
26
27 public void init() {
28 if (sprite != null) {
29 sprite.setX(COUNTDOWN_X_POS);
30 sprite.setY(COUNTDOWN_MAX_POS);
31 }
32 }
33
34 public void update(long elapsedTime) {
35 if (timerStandard.action(elapsedTime)) {
36 sprite.moveY(TIMER_INCREMENT);
37 }
38 if (timerTimeBonus.action(elapsedTime)) {
39 if (getTimeBonus() > 0.0d) {
40 sprite.moveY(-TIMER_INCREMENT);
41 setTimeBonus(getTimeBonus() - TIMER_INCREMENT);
42 if (sprite.getY() < COUNTDOWN_MAX_POS) {
43 setTimeBonus(0.0d);
44 sprite.setY(COUNTDOWN_MAX_POS);
45 }
46 }
47 }
48 }
49
50 public boolean isTimedOut() {
51 if (sprite.getY() > COUNTDOWN_MIN_POS) {
52 return true;
53 }
54 return false;
55 }
56
57 public Sprite getSprite() {
58 return sprite;
59 }
60
61 public void setSprite(Sprite sprite) {
62 this.sprite = sprite;
63 }
64
65 public double getTimeBonus() {
66 return timeBonus;
67 }
68
69 public void setTimeBonus(double timeBonus) {
70 this.timeBonus = timeBonus;
71 }
72
73 }