Changeset 32
- Timestamp:
- 12/26/07 17:21:41 (1 year ago)
- Files:
-
- trunk/guisterax/data/asteroid/big/explosion/explosion.wav (modified) (previous)
- trunk/guisterax/data/asteroid/normal/explosion/explosion.wav (modified) (previous)
- trunk/guisterax/data/asteroid/small/explosion/explosion.wav (modified) (previous)
- trunk/guisterax/data/font/font.png (modified) (previous)
- trunk/guisterax/data/font/font_grey.png (modified) (previous)
- trunk/guisterax/data/ship/explosion.wav (added)
- trunk/guisterax/src/display.d (modified) (1 diff)
- trunk/guisterax/src/font.d (modified) (2 diffs)
- trunk/guisterax/src/game.d (modified) (8 diffs)
- trunk/guisterax/src/main.d (modified) (2 diffs)
- trunk/guisterax/src/scores.d (added)
- trunk/guisterax/src/ship.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/guisterax/src/display.d
r31 r32 206 206 207 207 ~this() { 208 printf("SDL_Quit\n");209 208 SDL_Quit(); 210 209 } trunk/guisterax/src/font.d
r17 r32 47 47 public: 48 48 static void s_init() { 49 font = new Font("data/font/font.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$ ", 16, 25);50 font_grey = new Font("data/font/font_grey.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$ ", 16, 25);49 font = new Font("data/font/font.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$_=", 16, 25); 50 font_grey = new Font("data/font/font_grey.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$_=", 16, 25); 51 51 } 52 52 this(in char[] file, in char[] letters, uint w, uint h) { … … 109 109 110 110 }; 111 112 /** 113 Used to get the user input 114 */ 115 class TextInput : Text 116 { 117 this(Font font, in Vect pos, bool centered = false) { 118 super(font, "", pos, centered); 119 } 120 121 this(in Vect pos, bool centered = false) { 122 this(Font.font, pos, centered); 123 } 124 125 override void iter(float dt) { 126 for(int key = 'a'; key <= 'z'; ++key) 127 if (universe.pressed_key(key)) { 128 text ~= key; 129 text = toupper(text); 130 } 131 if (universe.pressed_key(SDLK_BACKSPACE) && text.length > 0) { 132 text.length = text.length - 1; 133 } 134 } 135 136 override void draw(Display disp, in Vect pos = Vect()) { 137 font.draw(disp, text ~ "_", pos + this.pos, centered); 138 } 139 }; trunk/guisterax/src/game.d
r30 r32 34 34 import bonus_levels; 35 35 import derelict.sdl.sdl; 36 import scores; 37 import std.string : format; 36 38 static import menu; 37 39 … … 71 73 this(Vect pos = Vect()) { 72 74 super(pos); 73 append(new Entry("NEW GAME", &new_game, Vect(0,0))); 74 append(new Entry("HELP", &help, Vect(0, -32))); 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))); 75 78 append(new Entry("QUIT", &quit, Vect(0,-64))); 76 79 } … … 84 87 Game g = new Game(); 85 88 g.help(); 89 } 90 91 void high_score() { 92 Game g = new Game(); 93 g.high_score(); 86 94 } 87 95 … … 118 126 }; 119 127 128 class InputName : Universe 129 { 130 TextInput text_input; 131 char[] name; 132 133 this() { 134 super(); 135 append(new Text("TYPE YOUR NAME", Vect(0, 32), true)); 136 append(text_input = new TextInput(Vect(0,0), true)); 137 } 138 139 override void iter(float dt) { 140 super.iter(dt); 141 if (pressed_key(SDLK_RETURN)) { 142 name = text_input.text; 143 kill(); 144 } 145 } 146 }; 147 148 class HighScore : Universe { 149 this() { 150 super(); 151 append(new Text("HIGH SCORE", Vect(0, 200), true)); 152 foreach(i, score; Scores().scores) { 153 char[] text = format("%d %s : %d", i+1, score.name, score.score); 154 append(new Text(text, Vect(0, 138. - 32. * i), true)); 155 } 156 } 157 158 override void iter(float dt) { 159 super.iter(dt); 160 if (pressed_key(SDLK_RETURN)) { 161 kill(); 162 } 163 } 164 }; 165 120 166 class Quit : Exception 121 167 { … … 167 213 ship = new Ship(); 168 214 uint level = 1; 169 while( true) {215 while(ship.alive) { 170 216 // auto bonus_level = new MinesLevel(); 171 217 // run(bonus_level); … … 173 219 shop(); 174 220 wave(level); 175 if (!ship.alive) {176 return;177 }178 221 level++; 179 222 } 223 if (Scores().is_high(score)) { 224 char[] name = input_name(); 225 Scores().add_score(score, name); 226 high_score(); 227 } 228 180 229 } 181 230 … … 184 233 run(s); 185 234 } 235 236 /** 237 Get the name of the player 238 */ 239 char[] input_name() { 240 InputName u = new InputName(); 241 run(u); 242 return u.name; 243 } 244 245 void high_score() { 246 HighScore u = new HighScore(); 247 run(u); 248 } 186 249 187 250 void wave(uint level) { 188 writefln("level ", level);189 251 Wave u = new Wave(level, ship); 190 252 u.update(); … … 230 292 } 231 293 } 294 trunk/guisterax/src/main.d
r30 r32 34 34 import display; 35 35 import game; 36 import scores; 36 37 import init : init; 37 38 … … 50 51 new MainDisplay(); 51 52 Clock(new Clock()); 53 // The scores 54 new Scores(); 52 55 53 56 init(); trunk/guisterax/src/ship.d
r31 r32 37 37 import metal; 38 38 import mine; 39 import sound; 39 40 40 41 import std.math : abs; … … 50 51 static Surface[] power_surfs; 51 52 Sprite power_sprite; 53 static Sound explosion_sound; 52 54 53 55 float angle_speed = 0.1; … … 66 68 normal_surfs = Sprite.loadSurfs("data/ship/normal/ship.png", 8, 8); 67 69 power_surfs = Sprite.loadSurfs("data/ship/power/power.png", 8, 8); 70 explosion_sound = new Sound("data/ship/explosion.wav"); 68 71 69 72 Debris.s_init(); … … 133 136 134 137 if (energy <= 0) { 138 explosion_sound.play(); 135 139 for (int type=0; type < 2; ++type) { 136 140 Vect speed = rand(0, 1) * Vect.from_angle(rand(0, 2 * PI)) + this.speed;
