Changeset 17
- Timestamp:
- 12/09/07 07:23:24 (1 year ago)
- Files:
-
- trunk/guisterax/TODO (modified) (1 diff)
- trunk/guisterax/src/font.d (modified) (3 diffs)
- trunk/guisterax/src/game.d (modified) (3 diffs)
- trunk/guisterax/src/menu.d (modified) (1 diff)
- trunk/guisterax/src/universe.d (modified) (1 diff)
- trunk/guisterax/src/vect.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/guisterax/TODO
r5 r17 2 2 3 3 - Design : 4 - remove all m_xxx when possible 5 - DOC !!! 4 - add doc 6 5 7 6 - Score 8 - Help entry in the main menu9 7 - Best score 10 8 trunk/guisterax/src/font.d
r10 r17 27 27 import display; 28 28 import utils; 29 import actor; 30 import display; 31 32 import std.string; 29 33 30 34 class Font … … 56 60 57 61 void draw(Display disp, in char[] text, Vect pos, bool centered = false) { 62 char[][] lines = split(text, "\n"); 63 if (centered) { 64 pos += Vect(0, (lines.length - 1) * m_h / 2); 65 } 66 foreach(line; lines) { 67 draw_line(disp, line, pos, centered); 68 pos -= Vect(0, m_h); 69 } 70 } 71 72 void draw_line(Display disp, in char[] line, Vect pos, bool centered = false) { 58 73 pos -= Vect(0, m_h / 2); 59 74 if (centered) { 60 pos -= Vect( text.length * m_w / 2);75 pos -= Vect(line.length * m_w / 2, 0); 61 76 } 62 foreach(i, l; text) {77 foreach(i, l; line) { 63 78 disp.blit( 64 79 m_surf, … … 69 84 } 70 85 }; 86 87 class Text : Actor 88 { 89 public: 90 Font font = null; 91 Vect pos; 92 char[] text; 93 bool centered; 94 95 this(Font font, in char[] text, in Vect pos, bool centered = false) { 96 this.font = font; 97 this.text = text.dup; 98 this.pos = pos; 99 this.centered = centered; 100 } 101 102 this(in char[] text, in Vect pos, bool centered = false) { 103 this(Font.font, text, pos, centered); 104 } 105 106 override void draw(Display disp, in Vect pos = Vect()) { 107 font.draw(disp, text, pos + this.pos, centered); 108 } 109 110 }; trunk/guisterax/src/game.d
r16 r17 71 71 super(pos); 72 72 append(new Entry("NEW GAME", &new_game, Vect(0,0))); 73 append(new Entry("QUIT", &quit, Vect(0,-32))); 73 append(new Entry("HELP", &help, Vect(0, -32))); 74 append(new Entry("QUIT", &quit, Vect(0,-64))); 74 75 } 75 76 … … 79 80 } 80 81 82 void help() { 83 Game g = new Game(); 84 g.help(); 85 } 86 81 87 void quit() { 82 88 throw new Quit(); 89 } 90 }; 91 92 class Help : Universe 93 { 94 this() { 95 super(); 96 // Add the help text 97 append(new Text( 98 "GUISTERAX 0.3 99 100 BY GUILLAUME CHEREAU 101 102 CONTROL : 103 UP ARROW : THRUST FORWARD 104 LEFT ARROW : TURN LEFT 105 RIGHT ARROW : TURN RIGHT 106 SPACE BAR : FIRE 107 ", 108 Vect(0, 0), true)); 109 110 } 111 override void iter(float dt) { 112 super.iter(); 113 if (pressed_key(SDLK_RETURN)) { 114 kill(); 115 } 83 116 } 84 117 }; … … 112 145 } 113 146 147 void help() { 148 Help h = new Help(); 149 run(h); 150 } 151 114 152 void play() { 115 116 153 m_ship = new Ship(Vect(10,0)); 117 154 uint level = 1; trunk/guisterax/src/menu.d
r10 r17 84 84 } 85 85 86 if (universe.pressed_key(SDLK_ SPACE)) {86 if (universe.pressed_key(SDLK_RETURN)) { 87 87 selected.on_activate(); 88 88 } trunk/guisterax/src/universe.d
r10 r17 46 46 // I am not sure this is the most efficient way it depends on the way SDL 47 47 // handle blitting surfaces that are not included in the visible screen 48 for(int i = -1; i <= 1; ++i) {49 for(int j = -1; j <= 1; ++j) {48 for(int i = 0; i <= 0; ++i) { 49 for(int j = 0; j <= 0; ++j) { 50 50 disp.blit(surf, pos + Vect(i*u.width, j*u.height), x, y, w, h); 51 51 } trunk/guisterax/src/vect.d
r15 r17 31 31 string toString() {return format("%f,%f", x, y);} 32 32 33 static Vect opCall(float x = 0, float y = 0) {33 static Vect opCall(float x, float y) { 34 34 Vect ret; 35 35 ret.x = x; ret.y = y; 36 36 return ret; 37 } 38 39 static Vect opCall() { 40 return Vect(0,0); 37 41 } 38 42
