Changeset 33
- Timestamp:
- 01/14/08 06:33:51 (11 months ago)
- Files:
-
- trunk/guisterax/TODO (modified) (1 diff)
- trunk/guisterax/src/display.d (modified) (5 diffs)
- trunk/guisterax/src/game.d (modified) (6 diffs)
- trunk/guisterax/src/menu.d (modified) (2 diffs)
- trunk/guisterax/src/scores.d (modified) (2 diffs)
- trunk/guisterax/src/shop.d (modified) (1 diff)
- trunk/guisterax/src/sound.d (modified) (2 diffs)
- trunk/guisterax/src/surface.d (modified) (1 diff)
- trunk/guisterax/src/utils.d (modified) (1 diff)
- trunk/guisterax/src/wave.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/guisterax/TODO
r24 r33 1 1 2 - pause screen 2 3 - add documentation 3 4 - Make collisions working at the universe border 4 - Score5 5 - beeing able to kill bouncing balls 6 6 trunk/guisterax/src/display.d
r32 r33 113 113 static MainDisplay display; 114 114 public: 115 int width, height; 116 bool fullscreen = false; 117 118 public: 115 119 static MainDisplay opCall() { 116 120 assert(display); … … 120 124 this(int w = 640, int h = 480) { 121 125 assert(!display); 126 127 width = w; 128 height = h; 122 129 123 130 DerelictSDL.load(); … … 130 137 } 131 138 132 Uint8 video_bpp = 32; 133 Uint32 videoflags = SDL_HWSURFACE; 134 // videoflags |= SDL_FULLSCREEN; 139 init_screen(); 135 140 136 // SDL_GetVideoInfo().vfmt.BitsPerPixel; 137 // printf("VideoModeOK = %d\n", SDL_VideoModeOK(640, 480, 32, SDL_FULLSCREEN|SDL_SWSURFACE)); 138 139 // printf("set video mode to %d %d\n", w, h); 140 if ( (screen=SDL_SetVideoMode(w,h,video_bpp,videoflags)) == null ) 141 { 142 throw new Error(format("Couldn't set %dx%d video mode", w, h)); 143 } 144 145 // No the audio system 141 // Now the audio system 146 142 int audio_rate = 22050; 147 143 uint audio_format = AUDIO_S16SYS; … … 155 151 // We set the singelton display 156 152 display = this; 153 } 154 155 void init_screen() { 156 Uint8 video_bpp = 32; 157 Uint32 videoflags = SDL_HWSURFACE; 158 if (fullscreen) videoflags |= SDL_FULLSCREEN; 159 if ( (screen=SDL_SetVideoMode(width,height,video_bpp,videoflags)) == null ) 160 { 161 throw new Error(format("Couldn't set %dx%d video mode", width, height)); 162 } 157 163 } 158 164 … … 193 199 } 194 200 201 void switch_fullscreen() { 202 fullscreen = !fullscreen; 203 init_screen(); 204 } 205 195 206 bool[] getKeys() { 196 207 int numkeys; trunk/guisterax/src/game.d
r32 r33 40 40 class Menu : menu.Menu 41 41 { 42 class Entry : menu.Entry 43 { 44 static Surface selected_surf; 45 char[] text; 46 void delegate() func; 47 48 static void s_init() { 49 selected_surf = new Surface("data/menu/selected.png"); 50 } 51 52 this(in char[] text, void delegate() func, in Vect pos) { 53 super(pos); 54 this.text = text.dup; 55 this.func = func; 56 } 57 override void draw(Display disp, in Vect pos, bool selected = false) { 58 if (selected) { 59 selected_surf.draw(disp, pos + this.pos); 60 } 61 Font.font.draw(disp, text, pos + this.pos, true); 62 } 63 64 override void on_activate() { 65 func(); 66 } 67 }; 68 42 alias menu.TextEntry Entry; 43 69 44 static void s_init() { 70 45 Entry.s_init(); … … 73 48 this(Vect pos = Vect()) { 74 49 super(pos); 75 append(new Entry("NEW GAME", &new_game, Vect(0,32))); 76 append(new Entry("HELP", &help, Vect(0, 0))); 77 append(new Entry("HIGH SCORE", &high_score, Vect(0, -32))); 78 append(new Entry("QUIT", &quit, Vect(0,-64))); 50 int y = 64; 51 append(new Entry("NEW GAME", &new_game, Vect(0,y))); 52 append(new Entry("HELP", &help, Vect(0, y-=32))); 53 append(new Entry("SWITCH FULL SCREEN", &switch_fullscreen, Vect(0, y-=32))); 54 append(new Entry("HIGH SCORE", &high_score, Vect(0, y-=32))); 55 append(new Entry("QUIT", &quit, Vect(0,y-=32))); 79 56 } 80 57 … … 92 69 Game g = new Game(); 93 70 g.high_score(); 71 } 72 73 void switch_fullscreen() { 74 MainDisplay().switch_fullscreen(); 94 75 } 95 76 … … 164 145 }; 165 146 147 148 class Pause : Universe { 149 alias menu.Menu Menu; 150 alias menu.TextEntry Entry; 151 152 Universe u; 153 Actor rest; 154 155 this(Universe u) { 156 super(); 157 this.u = u; 158 159 rest = new Actor(); 160 Menu menu = new Menu(); 161 menu.append(new Entry("RESUME", &resume, Vect(0,32))); 162 menu.append(new Entry("ABORT GAME", &abort, Vect(0,0))); 163 rest.append(menu); 164 append(rest); 165 } 166 167 void resume() { 168 kill(); 169 } 170 171 void abort() { 172 173 u.kill(); 174 kill(); 175 } 176 177 override void draw(Display disp, in Vect pos = Vect()) { 178 u.draw(disp, pos); 179 rest.draw(disp, pos + Vect(width / 2, height / 2)); 180 } 181 } 182 166 183 class Quit : Exception 167 184 { … … 257 274 Font.font.draw(MainDisplay(), format("LEVEL %d", level), Vect(u.width / 2, u.height / 2)); 258 275 MainDisplay().flip(); 259 Clock().tick( 100);276 Clock().tick(400); 260 277 run(u); 278 } 279 280 void pause(Universe u) { 281 Pause pause = new Pause(u); 282 run(pause); 283 if (!u.alive) { // The game has been aborted 284 ship.kill(); 285 } 261 286 } 262 287 … … 273 298 while (SDL_PollEvent(&ev)) { 274 299 if (ev.type == SDL_QUIT) {throw new Quit();} 275 if (u.key(SDLK_ESCAPE)) {throw new Quit();}276 300 } 277 301 trunk/guisterax/src/menu.d
r17 r33 26 26 import utils; 27 27 import display; 28 import surface : Surface; 29 import font : Font; 28 30 29 31 public import actor; 30 32 31 class Entry : Actor { 33 class Entry : Actor 34 { 32 35 public: 33 36 Vect pos = Vect(); … … 40 43 super(); 41 44 this.pos = pos; 45 } 46 } 47 48 class TextEntry : Entry 49 { 50 public: 51 static Surface selected_surf; 52 char[] text; 53 void delegate() func; 54 55 static void s_init() { 56 selected_surf = new Surface("data/menu/selected.png"); 57 } 58 59 this(in char[] text, void delegate() func, in Vect pos) { 60 super(pos); 61 this.text = text.dup; 62 this.func = func; 63 } 64 override void draw(Display disp, in Vect pos, bool selected = false) { 65 if (selected) { 66 selected_surf.draw(disp, pos + this.pos); 67 } 68 Font.font.draw(disp, text, pos + this.pos, true); 69 } 70 71 override void on_activate() { 72 func(); 42 73 } 43 74 } trunk/guisterax/src/scores.d
r32 r33 56 56 // We open and parse the scores file 57 57 try { 58 scope File file = new File("scores.txt");58 File file = open(); 59 59 foreach(char[] line; file) { 60 60 char[][] fields = split(line); … … 85 85 } 86 86 87 File open(FileMode mode = FileMode.In) { 88 foreach(path; var_paths("scores.hi")) { 89 try { 90 File file = new File("scores.hi", mode); 91 return file; 92 } 93 catch { 94 } 95 } 96 throw new Error("can't open high score file"); 97 } 98 87 99 void write() { 88 scope File file = new File("scores.txt",FileMode.Out);100 File file = open(FileMode.Out); 89 101 foreach(score; scores) { 90 102 file.writeLine(format("%d %s", score.score, score.name)); trunk/guisterax/src/shop.d
r31 r33 153 153 m_ship = ship; 154 154 155 Menu menu = new Menu(Vect(0, 0));155 Menu menu = new Menu(Vect(0,96)); 156 156 157 157 float dist = 32; trunk/guisterax/src/sound.d
r10 r33 27 27 import std.string; 28 28 29 import utils : data_paths; 30 29 31 class Sound 30 32 { … … 34 36 this(in char[] file) { 35 37 /* Load the WAV */ 36 m_chunk = Mix_LoadWAV(file); 37 if (m_chunk is null) { 38 foreach(path; data_paths(file)) { 39 m_chunk = Mix_LoadWAV(path); 40 if (m_chunk) break; 41 } 42 if (!m_chunk) { 38 43 throw new Error(format("can't open wave file %s", file)); 39 44 } trunk/guisterax/src/surface.d
r31 r33 56 56 assert(MainDisplay()); 57 57 58 SDL_Surface* s1 = IMG_Load(toStringz(file)); 59 if (s1 is null) { 60 throw new Error(format("can't open image %s", file)); 58 SDL_Surface* s1 = null; 59 60 foreach(path; data_paths(file)) { 61 s1 = IMG_Load(toStringz(path)); 62 if (s1) break; 61 63 } 62 // log(file, ' ', s1.h, ' ', s1.w); 64 if (!s1) throw new Error(format("can't open image %s", file)); 65 63 66 surf = SDL_DisplayFormatAlpha(s1); 64 67 SDL_FreeSurface(s1); trunk/guisterax/src/utils.d
r10 r33 167 167 return ret; 168 168 } 169 170 char[][] data_paths(in char[] file) { 171 version(linux) { 172 return ["/usr/share/games/guisterax/" ~ file, file]; 173 } 174 else { 175 return [file]; 176 } 177 } 178 179 char[][] var_paths(in char[] file) { 180 version(linux) { 181 return ["/var/games/guisterax/" ~ file, file]; 182 } 183 else { 184 return [file]; 185 } 186 } 187 188 trunk/guisterax/src/wave.d
r29 r33 36 36 import status; 37 37 import utils; 38 import game : Game; 38 39 39 40 import display; … … 122 123 if (pressed_key(SDLK_k)) {append(new Bounce(safe_pos(128)));} 123 124 } 125 if (pressed_key(SDLK_ESCAPE)) { 126 Game().pause(this); 127 } 124 128 } 125 129
