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(){ |
|
23 |
stdout.printf("Running contructor...\n"); |
|
24 |
this.isRun = true; |
|
25 |
this.rand = new GLib.Rand(); |
|
26 |
for(int i = 0; i < 322; i++) { // init them all to false |
|
27 |
eventBool[i] = false; |
|
28 |
} |
|
29 |
} |
|
30 |
|
|
31 |
public void mainLoop(){ |
|
32 |
initScreen(); |
|
33 |
while(this.isRun){ |
|
34 |
fpsTimer = SDL.Timer.get_ticks(); |
|
35 |
draw(); |
|
36 |
process_events(); |
|
|
3
by Gusatv Hartvigsson
* added Make file |
37 |
|
38 |
if(eventBool[KeySymbol.ESCAPE]){ |
|
39 |
stdout.printf("derp!\n"); |
|
40 |
this.isRun = false; |
|
41 |
} |
|
42 |
|
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
43 |
if(SDL.Timer.get_ticks() - fpsTimer < 1000/SCREEN_FPS){ |
44 |
SDL.Timer.delay(1000/SCREEN_FPS - (SDL.Timer.get_ticks() - fpsTimer)); |
|
45 |
} |
|
46 |
} |
|
47 |
} |
|
48 |
public void initScreen(){ |
|
49 |
uint32 VideoFlags = SurfaceFlag.DOUBLEBUF |
|
50 |
| SurfaceFlag.HWACCEL |
|
51 |
| SurfaceFlag.HWSURFACE; |
|
52 |
this.screen = Screen.set_video_mode (SCREEN_WIDTH, SCREEN_HEIGHT, |
|
53 |
SCREEN_BPP, VideoFlags); |
|
54 |
if(this.screen == null){ |
|
55 |
stderr.printf("Could not initize video \n"); |
|
56 |
} |
|
57 |
SDL.WindowManager.set_caption("Invaders_vala",""); |
|
58 |
} |
|
59 |
|
|
60 |
private void draw(){ |
|
61 |
//TODO |
|
62 |
this.screen.flip(); |
|
63 |
} |
|
64 |
|
|
65 |
private void process_events(){ |
|
66 |
Event event = Event(); |
|
67 |
while(Event.poll(event) != 0){ |
|
68 |
switch(event.type){ |
|
69 |
case EventType.QUIT: |
|
70 |
stdout.printf("quiting...\n"); |
|
71 |
this.isRun = false; |
|
72 |
break; |
|
73 |
case EventType.KEYDOWN: |
|
74 |
stdout.printf("keydown\n"); |
|
75 |
this.eventBool[event.key.keysym.sym] = true; |
|
76 |
break; |
|
77 |
case EventType.KEYUP: |
|
78 |
stdout.printf("keyup\n"); |
|
79 |
this.eventBool[event.key.keysym.sym] = false; |
|
80 |
break; |
|
81 |
} |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
}
|