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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
using SDL;
using SDLGraphics;
using Gee;
namespace invadersGame{
private const int SCREEN_HEIGHT = 640;
private const int SCREEN_WIDTH = 480;
private const int SCREEN_FPS = 60;
private const int SCREEN_BPP = 32;
class Game : Object{
private ArrayList GameObjectList = new ArrayList<GameObject>();
/**GameObjectList
* Stores the objects
*/
private GameObject testObject;
private uint32 fpsTimer;
private unowned SDL.Screen screen;
//private GLib.Rand rand = new GLib.Rand();
private bool eventBool[322];
private bool isRun;
public static int getRandom(int i){
/**getRandom
* Returns a value between 0 and i
*
*/
GLib.Rand rand = new GLib.Rand();
return rand.int_range(0, i);
//return (int) rand.next_int() % i;
} //getRandom
public Game(){
SDL.init(SDL.InitFlag.EVERYTHING);
stdout.printf("Running contructor...\n");
this.isRun = true;/* Is the mainloop running? */
//this.rand = new GLib.Rand();
testObject = new GameObject();
for(int i = 0; i < 322; i++) { // init them all to false
eventBool[i] = false;
}
} //Game
public void mainLoop(){
initScreen();
while(this.isRun){
fpsTimer = SDL.Timer.get_ticks();
draw();
process_events();
process_keys();
if(SDL.Timer.get_ticks() - fpsTimer < 1000/SCREEN_FPS){
SDL.Timer.delay(1000/SCREEN_FPS - (SDL.Timer.get_ticks() - fpsTimer));
}
}
}//mainLoop
public void initScreen(){
uint32 VideoFlags = SurfaceFlag.DOUBLEBUF
| SurfaceFlag.HWACCEL
| SurfaceFlag.HWSURFACE;
this.screen = Screen.set_video_mode (SCREEN_WIDTH, SCREEN_HEIGHT,
SCREEN_BPP, VideoFlags);
if(this.screen == null){
stderr.printf("Could not initize video \n");
}
SDL.WindowManager.set_caption("Invaders_vala","");
} //initScreen
private void draw(){
//TODO
this.screen.flip();
} // draw
private void process_events(){
Event event = Event();
Event.poll(out event);
switch(event.type){
case EventType.QUIT:
stdout.printf("quiting...\n");
this.isRun = false;
break;
case EventType.KEYDOWN:
stdout.printf("keydown\n");
this.eventBool[event.key.keysym.sym] = true;
break;
case EventType.KEYUP:
stdout.printf("keyup\n");
this.eventBool[event.key.keysym.sym] = false;
break;
}
} // process_events
private void process_keys(){
if(eventBool[KeySymbol.ESCAPE] || eventBool[KeySymbol.q]){
stdout.printf("derp!\n");
this.isRun = false;
}
} // process_keys
/*----------------------------------------------------------------------*/
}
}
|