Changeset 16
- Timestamp:
- 12/08/07 05:30:38 (1 year ago)
- Files:
-
- trunk/guisterax/Makefile (modified) (1 diff)
- trunk/guisterax/src/game.d (modified) (1 diff)
- trunk/guisterax/src/init.d (modified) (2 diffs)
- trunk/guisterax/src/ship.d (modified) (7 diffs)
- trunk/guisterax/src/shop.d (modified) (2 diffs)
- trunk/guisterax/src/status.d (added)
- trunk/guisterax/src/surface.d (modified) (1 diff)
- trunk/guisterax/src/wave.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/guisterax/Makefile
r10 r16 8 8 9 9 debug: src/*.d 10 gdc -fdebug - o guisterax src/*.d src/derelict/util/*.d src/derelict/sdl/*.d -Isrc/ -Isrc/derelict -ldl10 gdc -fdebug -g -o guisterax src/*.d src/derelict/util/*.d src/derelict/sdl/*.d -Isrc/ -Isrc/derelict -ldl 11 11 12 12 clean: trunk/guisterax/src/game.d
r10 r16 117 117 uint level = 1; 118 118 while(true) { 119 m_ship.parent = null;120 119 shop(); 121 120 wave(level); trunk/guisterax/src/init.d
r10 r16 39 39 import display : MainDisplay; 40 40 import vect : Vect; 41 import status; 41 42 42 43 void init() { … … 55 56 Energy.s_init(); 56 57 Ship.s_init(); 58 Status.s_init(); 57 59 Shop.s_init(); 58 60 } trunk/guisterax/src/ship.d
r10 r16 43 43 import utils; 44 44 45 46 class EnergyLevel : Actor47 {48 private:49 // float m_value = 1;50 float m_target_value;51 float m_speed = 0.05;52 float m_max = 1;53 public:54 float value;55 56 public:57 //float value() {return m_value;}58 59 this(float v = 1) {60 super();61 value = m_target_value = v;62 }63 64 override void iter(float dt) {65 if (abs(m_target_value - value) < m_speed * dt) {66 value = m_target_value;67 return;68 }69 value += (m_target_value > value)? m_speed*dt: -m_speed*dt;70 }71 72 EnergyLevel opAddAssign(float v) {73 m_target_value += v;74 if (m_target_value < 0) {m_target_value = 0;}75 if (m_target_value > m_max) {m_target_value = m_max;}76 return this;77 }78 EnergyLevel opSubAssign(float value) {return (this += -value);}79 80 invariant() {81 assert(value >= 0);82 assert(value <= m_max);83 }84 85 };86 87 class Status : Actor88 {89 private:90 static Surface[] m_surfs;91 Sprite m_sprite;92 public:93 Ship ship;94 95 static void s_init() {96 m_surfs = Sprite.loadSurfs("data/status/life.png", 8, 16);97 }98 99 this(Ship ship) {100 m_sprite = new Sprite(m_surfs);101 m_sprite.index = cast(int)(ship.energy * (m_sprite.length - 1));102 this.ship = ship;103 super();104 }105 106 void draw_energy(Display disp, in Vect pos) {107 m_sprite.draw(disp, pos);108 }109 110 void draw_gold(Display disp, in Vect pos) {111 uint gold = ship.gold;112 Font.font.draw(disp, format("GOLD:%d", gold), pos);113 }114 115 override void draw(Display disp, in Vect pos) {116 draw_energy(disp, Vect(60,43));117 draw_gold(disp, Vect(10,15));118 super.draw(disp, pos);119 }120 121 override void iter(float dt) {122 m_sprite.index = cast(int)(ship.energy * (m_sprite.length - 1));123 }124 };125 126 127 45 class Ship : Element 128 46 { … … 136 54 float m_power = 0.1; 137 55 138 EnergyLevel m_energy;139 140 56 public: 141 57 // public attributes 142 58 Gun gun; 143 59 uint gold = 0; 60 float energy = 1; 144 61 145 62 public: 146 63 alias fire.Fire Fire; 147 148 float energy() {return m_energy.value;}149 64 150 65 static void s_init() { … … 153 68 154 69 Debris.s_init(); 155 Status.s_init();156 70 } 157 71 … … 165 79 gun = new Gun(); 166 80 append(gun); 167 168 m_energy = new EnergyLevel();169 append(m_energy);170 81 } 171 82 … … 185 96 186 97 override void hit(float v) { 187 m_energy -= v; 98 energy -= v; 99 if (energy < 0) {energy = 0;} 100 if (energy > 1) {energy = 1;} 188 101 } 189 102 190 103 override void collide(Element e) { 191 104 if (cast(Asteroid)e || cast(Metal)e || cast(Mine)e) { 192 m_energy -= e.radius / 100;105 hit(e.radius / 100); 193 106 repeal(e.pos, e.mass, true); 194 107 } 108 // TODO: put this into Energy class 195 109 if (cast(Energy)e) { 196 m_energy += 0.1;110 hit(-0.1); 197 111 } 198 112 } … … 222 136 } 223 137 224 if ( m_energy.value<= 0) {138 if (energy <= 0) { 225 139 for (int type=0; type < 2; ++type) { 226 140 Vect speed = rand(0, 1) * Vect.from_angle(rand(0, 2 * PI)) + this.speed; … … 234 148 } 235 149 150 invariant { 151 assert(energy >= 0); 152 assert(energy <= 1); 153 } 236 154 }; 237 155 trunk/guisterax/src/shop.d
r10 r16 31 31 import font; 32 32 import timer; 33 import status; 33 34 import menu; 34 35 … … 155 156 append(new Status(ship)); 156 157 } 157 158 override void iter(float dt) {159 super.iter(dt);160 ship.iter(dt);161 }162 158 163 159 void ok() { trunk/guisterax/src/surface.d
r13 r16 65 65 ~this() { 66 66 if (surf) SDL_FreeSurface(surf); 67 surf = null; 67 68 } 68 69 }; trunk/guisterax/src/wave.d
r14 r16 33 33 import saucer; 34 34 import timer; 35 import status; 35 36 import utils; 36 37
