1
1
package uk .org .ulcompsoc .ld30 ;
2
2
3
+ import uk .org .ulcompsoc .ld30 .components .Ball ;
4
+ import uk .org .ulcompsoc .ld30 .components .CheatingAI ;
5
+ import uk .org .ulcompsoc .ld30 .components .MouseTracker ;
3
6
import uk .org .ulcompsoc .ld30 .components .Position ;
4
7
import uk .org .ulcompsoc .ld30 .components .Renderable ;
5
8
import uk .org .ulcompsoc .ld30 .components .Renderable .Shape ;
6
9
import uk .org .ulcompsoc .ld30 .components .Solid ;
7
10
import uk .org .ulcompsoc .ld30 .components .Velocity ;
11
+ import uk .org .ulcompsoc .ld30 .systems .BallBoundsSystem ;
12
+ import uk .org .ulcompsoc .ld30 .systems .BallCollisionSystem ;
13
+ import uk .org .ulcompsoc .ld30 .systems .CheatingAISystem ;
14
+ import uk .org .ulcompsoc .ld30 .systems .MouseTrackingSystem ;
8
15
import uk .org .ulcompsoc .ld30 .systems .MovementSystem ;
9
16
import uk .org .ulcompsoc .ld30 .systems .RenderingSystem ;
10
17
18
+ import com .badlogic .ashley .core .ComponentMapper ;
11
19
import com .badlogic .ashley .core .Engine ;
12
20
import com .badlogic .ashley .core .Entity ;
21
+ import com .badlogic .gdx .Application ;
13
22
import com .badlogic .gdx .ApplicationAdapter ;
14
23
import com .badlogic .gdx .Gdx ;
15
24
import com .badlogic .gdx .graphics .Color ;
16
25
import com .badlogic .gdx .graphics .GL20 ;
17
26
import com .badlogic .gdx .graphics .OrthographicCamera ;
18
27
import com .badlogic .gdx .math .Rectangle ;
28
+ import com .badlogic .gdx .math .Vector2 ;
19
29
20
30
public class LD30Test extends ApplicationAdapter {
21
- Engine engine = null ;
22
- Entity rect = null ;
23
- Entity circ = null ;
31
+ public enum VictoryType {
32
+ RED , BLUE , NONE ;
33
+ }
34
+
35
+ public static VictoryType victoryType = VictoryType .NONE ;
36
+
37
+ private Engine engine = null ;
38
+ private Entity playerBat = null ;
39
+ private Entity aiBat = null ;
40
+ private Entity ball = null ;
24
41
25
- OrthographicCamera camera = null ;
42
+ private OrthographicCamera camera = null ;
26
43
27
44
@ Override
28
45
public void create () {
46
+ Gdx .app .setLogLevel (Application .LOG_DEBUG );
29
47
camera = new OrthographicCamera (Gdx .graphics .getWidth (), Gdx .graphics .getHeight ());
30
48
camera .setToOrtho (false , Gdx .graphics .getWidth (), Gdx .graphics .getHeight ());
31
49
32
50
engine = new Engine ();
33
- rect = new Entity ();
34
- circ = new Entity ();
35
-
36
- rect .add (new Position (5.0f , 10.0f ));
37
- Renderable r1 = new Renderable ();
38
- r1 .color = Color .CYAN ;
39
- r1 .shape = Shape .RECTANGLE ;
40
- rect .add (r1 );
41
- rect .add (new Solid ());
51
+ ball = makeBall ();
42
52
43
- circ .add (new Position (30.0f , 30.0f ));
44
- Renderable r2 = new Renderable ();
45
- r2 .color = Color .MAROON ;
46
- r2 .shape = Shape .CIRCLE ;
47
- circ .add (r2 );
48
- circ .add (new Solid ());
49
- circ .add (new Velocity (10.0f , 10.0f ));
53
+ playerBat = makeBat (10.0f , 5.0f , Color .CYAN , false );
54
+ aiBat = makeBat (Gdx .graphics .getWidth () - 5.0f - 8.0f , 5.0f , Color .RED , true );
50
55
51
- engine .addEntity (rect );
52
- engine .addEntity (circ );
56
+ engine .addEntity (ball );
57
+ engine .addEntity (playerBat );
58
+ engine .addEntity (aiBat );
53
59
60
+ engine .addSystem (new MouseTrackingSystem (camera , 0 ));
61
+ engine .addSystem (new CheatingAISystem (1 ));
62
+ engine .addSystem (new BallCollisionSystem (2 ));
54
63
engine .addSystem (new MovementSystem (
55
- new Rectangle (0.0f , 0.0f , Gdx .graphics .getWidth (), Gdx .graphics .getHeight ()), 0 ));
64
+ new Rectangle (0.0f , 0.0f , Gdx .graphics .getWidth (), Gdx .graphics .getHeight ()), 5 ));
56
65
engine .addSystem (new RenderingSystem (camera , 10 ));
66
+ engine .addSystem (new BallBoundsSystem (50 ));
57
67
}
58
68
59
69
@ Override
@@ -64,5 +74,57 @@ public void render() {
64
74
65
75
camera .update ();
66
76
engine .update (deltaTime );
77
+
78
+ if (!victoryType .equals (VictoryType .NONE )) {
79
+ String victoryMessage = "The " + (victoryType .equals (VictoryType .BLUE ) ? "blue" : "red" ) + " player wins!" ;
80
+
81
+ Gdx .app .log ("VICTORY" , victoryMessage );
82
+ LD30Test .victoryType = VictoryType .NONE ;
83
+
84
+ try {
85
+ Thread .sleep (1000 );
86
+ } catch (InterruptedException e ) {
87
+ }
88
+
89
+ ComponentMapper .getFor (Position .class ).get (ball ).reset ();
90
+ Vector2 vel = ComponentMapper .getFor (Velocity .class ).get (ball ).velocity ;
91
+ vel .x = -vel .x ;
92
+ }
93
+ }
94
+
95
+ public Entity makeBat (float x , float y , Color color , boolean isAI ) {
96
+ Entity e = new Entity ();
97
+ e .add (new Position (x , y ));
98
+ e .add (new Velocity ());
99
+ Renderable r1 = new Renderable ();
100
+ r1 .color = color ;
101
+ r1 .shape = Shape .RECTANGLE ;
102
+ r1 .dimension .set (8.0f , 128.0f );
103
+ e .add (r1 );
104
+ e .add (new Solid (10.0f ));
105
+
106
+ if (isAI ) {
107
+ e .add (new CheatingAI (ball ));
108
+ } else {
109
+ e .add (new MouseTracker (3.0f ));
110
+ }
111
+
112
+ return e ;
113
+ }
114
+
115
+ public Entity makeBall () {
116
+ Entity e = new Entity ();
117
+
118
+ e .add (new Position ((float ) Gdx .graphics .getWidth () / 2.0f , (float ) Gdx .graphics .getHeight () / 2.0f ));
119
+ Renderable r2 = new Renderable ();
120
+ r2 .color = Color .YELLOW ;
121
+ r2 .shape = Shape .CIRCLE ;
122
+ r2 .dimension .set (8.0f , 0.0f );
123
+ e .add (r2 );
124
+ e .add (new Solid (1.0f ));
125
+ e .add (new Velocity (10.0f , 10.0f ));
126
+ e .add (new Ball ());
127
+
128
+ return e ;
67
129
}
68
130
}
0 commit comments