-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava_game.pde
57 lines (52 loc) · 1.14 KB
/
java_game.pde
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
Player player;
Monster monster;
World world;
int loading = 2;
private PImage logo;
void setup() {
size(960, 540);
logo = loadImage("rahscs_logo.png");
}
// This function runs when the game starts up. Create objects in here.
private void on_init() {
// Initialize objects
player = new Player();
monster = new Monster();
world = new World();
}
// This function runs whenever a key is pressed - input is handled here
public void keyPressed() {
if(key == CODED) {
if(keyCode == UP)
player.y -= 5;
else if (keyCode == DOWN)
player.y += 5;
else if (keyCode == RIGHT)
player.x += 5;
else if (keyCode == LEFT)
player.x -= 5;
}
}
// This function runs every frame-game logic & rendering happens in here
private void on_frame() {
world.loop();
monster.loop(player);
player.loop();
}
void draw() {
background(0);
switch(loading) {
case 0:
textSize(32);
background(0,127,0);
on_frame();
break;
case 1:
on_init();
default:
float ih = width * 0.5625f;
background(127,127,255);
image(logo, 0, (height - ih) / 2.0f, width, ih);
loading--;
}
}