-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMockClasses.txt
More file actions
94 lines (74 loc) · 2.59 KB
/
MockClasses.txt
File metadata and controls
94 lines (74 loc) · 2.59 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//Sample code for the game engine which makes a platformer where a little Booth figure can jump on platforms to get a coin.
Partial Mock Class: Booth
public class Booth extends Sprite{
public Booth(){
super(new Image("Booth.png"));
this.setPhysics(new BasicPhysics(this));
}
@Override
public void onInput(InputEvent e){
for(KeyboardKey key: e.getKeysPressed()){
switch(key.getCode()){
case KeyCodes.UP:
this.jump();
break;
case KeyCodes.LEFT:
this.setXVelocity(-20);
break;
case KeyCodes.RIGHT:
this.setXVelocity(20);
break;
}
}
@Override
public void onCollision(CollisionEvent e){
for(Collider sprite: e.getColliders()){
switch(sprite.getClass().getName()){
case "Coin":
this.gotCoin(sprite);
sprite.destroy();
break;
case "Goomba":
this.die();
break;
case "Pit":
this.die();
break;
}
}
}
public void jump(){
//TODO: make jumping work naturally with physics
}
public void die(){
//TODO: animate a bunch of stuff and reset your position.
}
//Probably have other stuff here too.
}
Partial Mock Class: BasicPhysics
public class BasicPhysics implements TimerListener{
private Sprite target;
public class BasicPhysics(Sprite s){
this.target = s;
}
@Override
public void runPerTick(long now){
//Friction for X-Direction movement
if(Math.abs(target.getXVelocity()) < 1){
target.setXVelocity(0);
} else {
target.setXVelocity(target.getXVelocity()*0.5);
}
//TODO: Good Gravity
}
}
Full Mock Interface: Collider
public interface Collider{
public void onCollision(CollisionEvent e);
}
Full Mock Interface: TimerListener
public interface TimerListener{
public void runPerTick(long now);
}
Description of GameScene
GameScene will be the all encompassing mother class which HAS everything. It IS a scene so that anything that extends Application can set it as its Scene. This class will keep track of the master list of ALLLLLLLL the sprites (background, game, info, etc.) AND a master group of all of the Sprites' faces. The GameScene will also hold on to the main Timer (AnimationTimer?) and send off all of the Timer-related events (Collisions, Inputs, etc.). The GameScene also is the keeper of the current x,y position being shown at the bottom-left of the window the GameScene is part of.