bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/invaders_vala
|
2
by Gusatv Hartvigsson
* moved a file ( miss spelled name) |
1 |
using SDL; |
2 |
using SDLGraphics; |
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
3 |
|
4 |
namespace invadersGame{ |
|
5 |
|
|
6 |
class Game : Object{ |
|
7 |
|
|
8 |
|
|
9 |
private const int SCREEN_HEIGHT = 640; |
|
10 |
private const int SCREEN_WIDTH = 480; |
|
11 |
private const int SCREEN_FPS = 60; |
|
12 |
private const int SCREEN_BPP = 32; |
|
13 |
|
|
14 |
private uint32 fpsTimer; |
|
15 |
|
|
16 |
private unowned SDL.Screen screen; |
|
17 |
private GLib.Rand rand; |
|
18 |
|
|
19 |
private bool eventBool[322]; |
|
20 |
private bool isRun; |
|
21 |
|
|
22 |
public Game(){ |
|
|
4
by Gusatv Hartvigsson
* Fixed bug -- see Makefile |
23 |
SDL.init(SDL.InitFlag.EVERYTHING); |
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
24 |
stdout.printf("Running contructor...\n"); |
25 |
this.isRun = true; |
|
26 |
this.rand = new GLib.Rand(); |
|
27 |
for(int i = 0; i < 322; i++) { // init them all to false |
|
28 |
eventBool[i] = false; |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
public void mainLoop(){ |
|
33 |
initScreen(); |
|
34 |
while(this.isRun){ |
|
35 |
fpsTimer = SDL.Timer.get_ticks(); |
|
36 |
draw(); |
|
37 |
process_events(); |
|
|
3
by Gusatv Hartvigsson
* added Make file |
38 |
|
39 |
if(eventBool[KeySymbol.ESCAPE]){ |
|
40 |
stdout.printf("derp!\n"); |
|
41 |
this.isRun = false; |
|
42 |
} |
|
43 |
|
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
44 |
if(SDL.Timer.get_ticks() - fpsTimer < 1000/SCREEN_FPS){ |
45 |
SDL.Timer.delay(1000/SCREEN_FPS - (SDL.Timer.get_ticks() - fpsTimer)); |
|
46 |
} |
|
47 |
} |
|
48 |
} |
|
49 |
public void initScreen(){ |
|
50 |
uint32 VideoFlags = SurfaceFlag.DOUBLEBUF |
|
51 |
| SurfaceFlag.HWACCEL |
|
52 |
| SurfaceFlag.HWSURFACE; |
|
53 |
this.screen = Screen.set_video_mode (SCREEN_WIDTH, SCREEN_HEIGHT, |
|
54 |
SCREEN_BPP, VideoFlags); |
|
55 |
if(this.screen == null){ |
|
56 |
stderr.printf("Could not initize video \n"); |
|
57 |
} |
|
58 |
SDL.WindowManager.set_caption("Invaders_vala",""); |
|
59 |
} |
|
60 |
|
|
61 |
private void draw(){ |
|
62 |
//TODO |
|
63 |
this.screen.flip(); |
|
64 |
} |
|
65 |
|
|
66 |
private void process_events(){ |
|
67 |
Event event = Event(); |
|
|
4
by Gusatv Hartvigsson
* Fixed bug -- see Makefile |
68 |
Event.poll(out event); |
69 |
switch(event.type){ |
|
70 |
case EventType.QUIT: |
|
71 |
stdout.printf("quiting...\n"); |
|
72 |
this.isRun = false; |
|
73 |
break; |
|
74 |
case EventType.KEYDOWN: |
|
75 |
stdout.printf("keydown\n"); |
|
76 |
this.eventBool[event.key.keysym.sym] = true; |
|
77 |
break; |
|
78 |
case EventType.KEYUP: |
|
79 |
stdout.printf("keyup\n"); |
|
80 |
this.eventBool[event.key.keysym.sym] = false; |
|
81 |
break; |
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
82 |
} |
83 |
} |
|
84 |
} |
|
85 |
}
|