-
Notifications
You must be signed in to change notification settings - Fork 2
/
ExampleGame.java
65 lines (55 loc) · 1.56 KB
/
ExampleGame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import shapes.*;
import java.awt.Color;
public class ExampleGame extends Game {
// Put variables here!
Circle circle;
Rectangle[] walls = new Rectangle[2];
Rectangle finish;
@Override
public void setup() {
// set up the circle
circle = new Circle();
circle.setRadius(20.0);
circle.setColor(Color.ORANGE);
circle.setCenter(new Point(750.0, 450.0));
// prevent shapes from leaving the game window
Game.setBorderBehavior(Game.BorderBehavior.SOLID);
// make walls
for (int i = 0; i < walls.length; i = i + 1) {
walls[i] = new Rectangle();
walls[i].setWidth(700.0);
walls[i].setHeight(100.0);
walls[i].setColor(Color.BLACK);
walls[i].setSolid(true);
}
walls[0].setUpperLeft(new Point(0.0, 200.0));
walls[1].setUpperLeft(new Point(100.0, 400.0));
// make finish line
finish = new Rectangle();
finish.setUpperLeft(new Point(100.0, 100.0));
finish.setWidth(10.0);
finish.setHeight(100.0);
finish.setColor(Color.GREEN);
}
@Override
public void update() {
// move circle
Direction movementDirection = Keyboard.direction();
circle.move(movementDirection, 10.0);
// celebrate if finished
if (circle.isTouching(finish)) {
// victory!
TextStyle titleStyle = new TextStyle("Times New Roman", 60, Color.GREEN);
Game.setTitleStyle(titleStyle);
Game.setTitle("You win!", 1000000);
}
}
public static void main(String[] args) {
new ExampleGame();
}
public ExampleGame() {
super(false);
setup();
ready();
}
}