6
6
namespace invadersGame{
8
private const int SCREEN_HEIGHT = 640;
9
private const int SCREEN_WIDTH = 480;
10
private const int SCREEN_FPS = 60;
8
private const int16 SCREEN_HEIGHT = 640;
9
private const int16 SCREEN_WIDTH = 480;
10
private const int SCREEN_FPS = 120;
11
11
private const int SCREEN_BPP = 32;
14
private ArrayList GameObjectList = new ArrayList<GameObject>();
13
* The main class for the game.
15
public class Game : Object{
17
private SDL.Rect my_fill_rect;
18
private MovementDelta my_movement_delta;
16
21
* Stores the objects
19
private GameObject testObject;
23
private ArrayList<GameObject> GameObjectList = new ArrayList<GameObject>();
21
25
private uint32 fpsTimer;
25
29
private bool eventBool[322];
26
30
private bool isRun;
32
private GameObjectPlayer player;
35
* Returns a value between 0 and i.
36
* (This is probobly not the most efficient to do this).
28
38
public static int getRandom(int i){
30
* Returns a value between 0 and i.
31
* (This is probobly not the most efficient to do this).
33
40
GLib.Rand rand = new GLib.Rand();
34
41
return rand.int_range(0, i);
35
42
//return (int) rand.next_int() % i;
47
ResourceHandler.init();
49
player = new GameObjectPlayer();
51
for(int16 i = 0; i < 10; i++) {
52
stdout.printf("Adding object!\n");
53
GameObjectList.add(new GameObject(i*16, i*16, 0, 0,0, 0));
58
my_fill_rect.h = SCREEN_HEIGHT;
59
my_fill_rect.w = SCREEN_WIDTH;
39
61
SDL.init(SDL.InitFlag.EVERYTHING);
40
62
stdout.printf("Running contructor...\n");
41
63
this.isRun = true;/* Is the mainloop running? */
42
64
//this.rand = new GLib.Rand();
44
testObject = new GameObject();
46
66
for(int i = 0; i < 322; i++) { // init them all to false
47
67
eventBool[i] = false;
51
71
public void mainLoop(){
54
76
fpsTimer = SDL.Timer.get_ticks();
81
player.set_movment_delta(my_movement_delta);
59
83
if(SDL.Timer.get_ticks() - fpsTimer < 1000/SCREEN_FPS){
60
SDL.Timer.delay(1000/SCREEN_FPS - (SDL.Timer.get_ticks() - fpsTimer));
84
SDL.Timer.delay(1000/SCREEN_FPS - (SDL.Timer.get_ticks() - fpsTimer));
77
102
private void draw(){
103
/* Draw the player! */
106
/* Draw all the items in the list! */
107
foreach(var g in GameObjectList) {
79
111
this.screen.flip();
112
this.screen.fill(my_fill_rect, 0x0000000);
82
115
private void process_events(){
99
132
} // process_events
101
134
private void process_keys(){
135
my_movement_delta = {0,0};
102
137
if(eventBool[KeySymbol.ESCAPE] || eventBool[KeySymbol.q]){
103
138
stdout.printf("derp!\n");
104
139
this.isRun = false;
143
if (eventBool[KeySymbol.DOWN] && eventBool[KeySymbol.UP]) {
145
} else if (eventBool[KeySymbol.UP]){
146
my_movement_delta.y = -1;
147
} else if (eventBool[KeySymbol.DOWN]){
148
my_movement_delta.y = 1;
151
if (eventBool[KeySymbol.RIGHT] && eventBool[KeySymbol.LEFT]){
153
} else if (eventBool[KeySymbol.LEFT]){
154
my_movement_delta.x = -1;
155
} else if (eventBool[KeySymbol.RIGHT]){
156
my_movement_delta.x = 1;
106
160
} // process_keys
107
161
/*----------------------------------------------------------------------*/