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; |
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
3 |
using Gee; |
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
4 |
|
5 |
namespace invadersGame{ |
|
6 |
|
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
7 |
private const int SCREEN_HEIGHT = 640; |
8 |
private const int SCREEN_WIDTH = 480; |
|
9 |
private const int SCREEN_FPS = 60; |
|
10 |
private const int SCREEN_BPP = 32; |
|
11 |
|
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
12 |
class Game : Object{ |
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
13 |
private ArrayList GameObjectList = new ArrayList<GameObject>(); |
14 |
/**GameObjectList |
|
15 |
* Stores the objects
|
|
16 |
*/
|
|
17 |
|
|
18 |
private GameObject testObject; |
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
19 |
|
20 |
private uint32 fpsTimer; |
|
21 |
|
|
22 |
private unowned SDL.Screen screen; |
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
23 |
//private GLib.Rand rand = new GLib.Rand(); |
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
24 |
|
25 |
private bool eventBool[322]; |
|
26 |
private bool isRun; |
|
27 |
|
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
28 |
public static int getRandom(int i){ |
29 |
/**getRandom |
|
30 |
* Returns a value between 0 and i
|
|
31 |
*
|
|
32 |
*/
|
|
33 |
GLib.Rand rand = new GLib.Rand(); |
|
34 |
return rand.int_range(0, i); |
|
35 |
//return (int) rand.next_int() % i; |
|
36 |
} //getRandom |
|
37 |
|
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
38 |
public Game(){ |
|
4
by Gusatv Hartvigsson
* Fixed bug -- see Makefile |
39 |
SDL.init(SDL.InitFlag.EVERYTHING); |
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
40 |
stdout.printf("Running contructor...\n"); |
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
41 |
this.isRun = true;/* Is the mainloop running? */ |
42 |
//this.rand = new GLib.Rand(); |
|
43 |
|
|
44 |
testObject = new GameObject(); |
|
45 |
|
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
46 |
for(int i = 0; i < 322; i++) { // init them all to false |
47 |
eventBool[i] = false; |
|
48 |
} |
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
49 |
} //Game |
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
50 |
|
51 |
public void mainLoop(){ |
|
52 |
initScreen(); |
|
53 |
while(this.isRun){ |
|
54 |
fpsTimer = SDL.Timer.get_ticks(); |
|
55 |
draw(); |
|
56 |
process_events(); |
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
57 |
process_keys(); |
|
3
by Gusatv Hartvigsson
* added Make file |
58 |
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
59 |
if(SDL.Timer.get_ticks() - fpsTimer < 1000/SCREEN_FPS){ |
60 |
SDL.Timer.delay(1000/SCREEN_FPS - (SDL.Timer.get_ticks() - fpsTimer)); |
|
61 |
} |
|
62 |
} |
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
63 |
}//mainLoop |
64 |
|
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
65 |
public void initScreen(){ |
66 |
uint32 VideoFlags = SurfaceFlag.DOUBLEBUF |
|
67 |
| SurfaceFlag.HWACCEL |
|
68 |
| SurfaceFlag.HWSURFACE; |
|
69 |
this.screen = Screen.set_video_mode (SCREEN_WIDTH, SCREEN_HEIGHT, |
|
70 |
SCREEN_BPP, VideoFlags); |
|
71 |
if(this.screen == null){ |
|
72 |
stderr.printf("Could not initize video \n"); |
|
73 |
} |
|
74 |
SDL.WindowManager.set_caption("Invaders_vala",""); |
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
75 |
} //initScreen |
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
76 |
|
77 |
private void draw(){ |
|
78 |
//TODO |
|
79 |
this.screen.flip(); |
|
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
80 |
} // draw |
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
81 |
|
82 |
private void process_events(){ |
|
83 |
Event event = Event(); |
|
|
4
by Gusatv Hartvigsson
* Fixed bug -- see Makefile |
84 |
Event.poll(out event); |
85 |
switch(event.type){ |
|
86 |
case EventType.QUIT: |
|
87 |
stdout.printf("quiting...\n"); |
|
88 |
this.isRun = false; |
|
89 |
break; |
|
90 |
case EventType.KEYDOWN: |
|
91 |
stdout.printf("keydown\n"); |
|
92 |
this.eventBool[event.key.keysym.sym] = true; |
|
93 |
break; |
|
94 |
case EventType.KEYUP: |
|
95 |
stdout.printf("keyup\n"); |
|
96 |
this.eventBool[event.key.keysym.sym] = false; |
|
97 |
break; |
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
98 |
} |
|
7
by Gusatv Hartvigsson
* added gee-1.0 to Makefile. |
99 |
} // process_events |
100 |
|
|
101 |
private void process_keys(){ |
|
102 |
if(eventBool[KeySymbol.ESCAPE] || eventBool[KeySymbol.q]){ |
|
103 |
stdout.printf("derp!\n"); |
|
104 |
this.isRun = false; |
|
105 |
} |
|
106 |
} // process_keys |
|
107 |
/*----------------------------------------------------------------------*/ |
|
|
1
by Gusatv Hartvigsson
* initial code of a Vala port of invaders... |
108 |
} |
109 |
}
|