Changeset 36
- Timestamp:
- 01/22/08 21:47:44 (11 months ago)
- Files:
-
- trunk/guisterax/README (modified) (1 diff)
- trunk/guisterax/data/font/font.png (modified) (previous)
- trunk/guisterax/src/display.d (modified) (1 diff)
- trunk/guisterax/src/font.d (modified) (1 diff)
- trunk/guisterax/src/game.d (modified) (1 diff)
- trunk/guisterax/src/menu.d (modified) (6 diffs)
- trunk/guisterax/src/scores.d (modified) (1 diff)
- trunk/guisterax/src/shop.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/guisterax/README
r26 r36 1 1 2 GUISTERAX 0. 32 GUISTERAX 0.4 3 3 4 4 Code, graphics and sound by Guillaume 'Charlie' Chereau (charlie137@gmail.com) trunk/guisterax/src/display.d
r33 r36 172 172 int h = (src)?src.h : surf.h; 173 173 dest.y = screen.h - cast(int)round(pos.y + h); 174 dest.w = surf.surf.w;175 dest.h = surf.surf.h;174 dest.w = (src)? src.w : surf.surf.w; 175 dest.h = (src)? src.h : surf.surf.h; 176 176 SDL_BlitSurface(surf.surf, src, screen, &dest); 177 177 } trunk/guisterax/src/font.d
r32 r36 32 32 import std.string; 33 33 34 import std.math : PI; 35 34 36 class Font 35 37 { 36 private: 37 Surface m_surf; 38 uint[char] m_letters; 39 uint m_w, m_h; 40 41 38 public: 39 Surface surf; 40 uint[char] letters; 41 uint w, h; 42 uint nb_angles; // used for rotating font : number of different font angles 42 43 public: 43 44 44 45 static Font font; 45 46 static Font font_grey; 47 static Font font_moving; 46 48 47 49 public: 48 50 static void s_init() { 49 51 font = new Font("data/font/font.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$_=", 16, 25); 52 font_moving = new Font("data/font/font_moving.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$_=", 16, 25, 32); 50 53 font_grey = new Font("data/font/font_grey.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .:/$_=", 16, 25); 51 54 } 52 this(in char[] file, in char[] letters, uint w, uint h ) {53 m_surf = new Surface(file);55 this(in char[] file, in char[] letters, uint w, uint h, uint nb = 1) { 56 surf = new Surface(file); 54 57 foreach(i,l; letters) { 55 m_letters[l] = i;58 this.letters[l] = i; 56 59 } 57 m_w = w; 58 m_h = h; 60 this.w = w; 61 this.h = h; 62 this.nb_angles = nb; 63 64 assert(nb == surf.h / h); 59 65 } 60 66 61 void draw(Display disp, in char[] text, Vect pos, bool centered = false ) {67 void draw(Display disp, in char[] text, Vect pos, bool centered = false, float angle = 0) { 62 68 char[][] lines = split(text, "\n"); 63 69 if (centered) { 64 pos += Vect(0, (lines.length - 1) * m_h / 2);70 pos += Vect(0, (lines.length - 1) * h / 2); 65 71 } 66 72 foreach(line; lines) { 67 draw_line(disp, line, pos, centered );68 pos -= Vect(0, m_h);73 draw_line(disp, line, pos, centered, angle); 74 pos -= Vect(0, h); 69 75 } 70 76 } 71 77 72 void draw_line(Display disp, in char[] line, Vect pos, bool centered = false ) {73 pos -= Vect(0, m_h / 2);78 void draw_line(Display disp, in char[] line, Vect pos, bool centered = false, float angle = 0) { 79 pos -= Vect(0, h / 2); 74 80 if (centered) { 75 pos -= Vect(line.length * m_w / 2, 0);81 pos -= Vect(line.length * w / 2, 0); 76 82 } 83 assert(angle >= 0 && angle < 2 * PI); 84 uint a_index = cast(int)(angle / (2 * PI) * nb_angles); 85 77 86 foreach(i, l; line) { 78 87 disp.blit( 79 m_surf,80 pos + Vect( m_w,0) * i,81 m_letters[l] * m_w, 0, m_w, m_h88 surf, 89 pos + Vect(w,0) * i, 90 letters[l] * w, a_index * h, w, h 82 91 ); 83 92 } trunk/guisterax/src/game.d
r33 r36 86 86 // Add the help text 87 87 append(new Text( 88 "GUISTERAX 0. 388 "GUISTERAX 0.4 89 89 90 90 BY GUILLAUME CHEREAU trunk/guisterax/src/menu.d
r33 r36 35 35 public: 36 36 Vect pos = Vect(); 37 bool selected = false; 38 39 public: 37 40 void draw(Display disp, in Vect pos, bool selected = false) {} 38 41 void on_activate() {} … … 46 49 } 47 50 51 /** 52 53 */ 48 54 class TextEntry : Entry 49 55 { … … 52 58 char[] text; 53 59 void delegate() func; 60 float angle = 0; /// This angle is used to make the text rotating 61 float rot_speed = 0.075; 54 62 55 63 static void s_init() { … … 62 70 this.func = func; 63 71 } 64 override void draw(Display disp, in Vect pos , bool selected = false) {72 override void draw(Display disp, in Vect pos) { 65 73 if (selected) { 66 74 selected_surf.draw(disp, pos + this.pos); 75 Font.font_moving.draw(disp, text, pos + this.pos, true, angle); 67 76 } 68 Font.font.draw(disp, text, pos + this.pos, true); 77 else { 78 Font.font.draw(disp, text, pos + this.pos, true); 79 } 69 80 } 81 82 override void iter(float dt) { 83 if (selected) { 84 angle += dt * rot_speed; 85 angle = modulo(angle, 2*PI); 86 } 87 else { 88 angle = 0; 89 } 90 } 91 70 92 71 93 override void on_activate() { … … 94 116 Entry selected() {return cast(Entry)children[index];} 95 117 118 override void draw(Display disp, in Vect pos = Vect()) { 119 super.draw(disp, pos + this.pos); 120 } 121 96 122 void up() { 123 selected.selected = false; 97 124 do { 98 125 index = modulo(index - 1, children.length); 99 126 } while (!selected.selectable()) 127 selected.selected = true; 100 128 } 101 129 102 130 void down() { 131 selected.selected = false; 103 132 do { 104 133 index = modulo(index + 1, children.length); 105 134 } while (!selected.selectable()) 135 selected.selected = true; 106 136 } 107 137 108 138 override void iter(float dt) { 109 139 super.iter(dt); 140 141 selected.selected = true; // we update the selected entry 142 110 143 if (universe.pressed_key(SDLK_UP)) { 111 144 up(); … … 120 153 } 121 154 122 override void draw(Display disp, in Vect pos = Vect()) {123 foreach(i, c; children) {124 Entry e = cast(Entry)c;125 assert(e);126 e.draw(disp, pos + this.pos, i == index);127 }128 }129 130 155 }; 131 156 trunk/guisterax/src/scores.d
r33 r36 71 71 bool is_high(int score) { 72 72 if (scores.length < nb_scores) {return true;} 73 if (score > scores[ $].score) {return true;}73 if (score > scores[length - 1].score) {return true;} 74 74 return false; 75 75 } trunk/guisterax/src/shop.d
r33 r36 64 64 } 65 65 66 override void draw(Display disp, in Vect pos , bool selected = false) {66 override void draw(Display disp, in Vect pos) { 67 67 if (selected) {m_selected_surf.draw(disp, pos + this.pos);} 68 68 Font font = selectable() ? Font.font : Font.font_grey; … … 153 153 m_ship = ship; 154 154 155 Menu menu = new Menu(Vect(0,96)); 155 append(new Text("SHOPPING", Vect(0, 200), true)); 156 157 Menu menu = new Menu(Vect(0,128)); 156 158 157 159 float dist = 32;
