Changeset 31
- Timestamp:
- 12/16/07 10:12:45 (1 year ago)
- Files:
-
- trunk/guisterax/src/actor.d (modified) (5 diffs)
- trunk/guisterax/src/asteroid.d (modified) (6 diffs)
- trunk/guisterax/src/display.d (modified) (1 diff)
- trunk/guisterax/src/gold.d (modified) (2 diffs)
- trunk/guisterax/src/ship.d (modified) (5 diffs)
- trunk/guisterax/src/shop.d (modified) (3 diffs)
- trunk/guisterax/src/surface.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/guisterax/src/actor.d
r23 r31 37 37 { 38 38 protected: 39 40 Actor[] m_next_children; 41 39 /// The children as they will be in the next iteration 40 Actor[] next_children; 42 41 public: 43 42 /// The parent of this actor. … … 47 46 /// Defines if the actor has to be deleted or not. 48 47 bool alive = true; 49 50 48 public: 51 49 /// Return all the children that are of type T. … … 81 79 void append(Actor a, bool end = true) { 82 80 if (end) { 83 m_next_children ~= a;81 next_children ~= a; 84 82 } else { 85 m_next_children = [a] ~ m_next_children;83 next_children = [a] ~ next_children; 86 84 } 87 85 a.parent = this; … … 94 92 */ 95 93 void append(Actor a, Actor pos) { 96 m_next_children = insert(m_next_children, a, pos);94 next_children = insert(next_children, a, pos); 97 95 a.parent = this; 98 96 } … … 116 114 // update actor list 117 115 bool isalive(in Actor a) {return a.alive;} 118 children = filter!(Actor)( m_next_children, &isalive);119 m_next_children = children.dup;116 children = filter!(Actor)(next_children, &isalive); 117 next_children = children.dup; 120 118 foreach(a; children) { 121 119 a.update(); trunk/guisterax/src/asteroid.d
r30 r31 35 35 import game; 36 36 37 37 38 import std.math : PI, sqrt; 38 39 … … 42 43 enum {SMALL = 0, NORMAL, BIG}; 43 44 private: 44 static Surface[][][3] m_surfs;45 static Sound[3] m_sounds;45 static Surface[][][3] surfs; 46 static Sound[3] sounds; 46 47 47 static float[3] m_radii = [15, 30, 64];48 static float[3] radii = [15, 30, 64]; 48 49 49 Element[] m_inside;50 float m_rot_speed;51 uint m_type = NORMAL;52 uint m_nb_gold = 3;53 uint m_nb_energy = 1;50 Element[] inside; 51 float rot_speed; 52 uint type = NORMAL; 53 uint nb_gold = 3; 54 uint nb_energy = 1; 54 55 public: 55 56 56 override float danger() {return 0.1 * ( m_type + 1);}57 override float danger() {return 0.1 * (type + 1);} 57 58 58 59 static void s_init() { 59 m_surfs[SMALL] = [60 surfs[SMALL] = [ 60 61 Sprite.loadSurfs("data/asteroid/small/small1/small1.png", 8, 8), 61 62 Sprite.loadSurfs("data/asteroid/small/small2/small2.png", 8, 8) 62 63 ]; 63 m_surfs[NORMAL] = [64 surfs[NORMAL] = [ 64 65 Sprite.loadSurfs("data/asteroid/normal/normal1/normal1.png", 8, 8), 65 66 Sprite.loadSurfs("data/asteroid/normal/normal2/normal2.png", 8, 8) 66 67 ]; 67 m_surfs[BIG] = [68 surfs[BIG] = [ 68 69 Sprite.loadSurfs("data/asteroid/big/big1/big1.png", 16, 8) 69 70 ]; 70 71 71 m_sounds[SMALL] = new Sound("data/asteroid/small/explosion/explosion.wav");72 m_sounds[NORMAL] = new Sound("data/asteroid/normal/explosion/explosion.wav");73 m_sounds[BIG] = new Sound("data/asteroid/big/explosion/explosion.wav");72 sounds[SMALL] = new Sound("data/asteroid/small/explosion/explosion.wav"); 73 sounds[NORMAL] = new Sound("data/asteroid/normal/explosion/explosion.wav"); 74 sounds[BIG] = new Sound("data/asteroid/big/explosion/explosion.wav"); 74 75 75 76 Explosion.s_init(); … … 77 78 78 79 this(int type, Vect pos = Vect(0,0), Vect speed = Vect(0,0)) { 79 m_type = type;80 this.type = type; 80 81 super( 81 new Sprite( m_surfs[type][randint(0, m_surfs[type].length)]),82 new Sprite(surfs[type][randint(0, surfs[type].length)]), 82 83 pos 83 84 ); 84 radius = m_radii[type];85 radius = radii[type]; 85 86 mass = type + 1; 86 87 angle = rand(0, 2 * PI); 87 m_rot_speed = rand(-0.05, 0.05);88 rot_speed = rand(-0.05, 0.05); 88 89 this.speed = speed; 89 90 max_speed = 5; 90 91 91 92 if (type > SMALL) { 92 for(int i = 0; i < 3; ++i) { m_inside ~= new Asteroid(type - 1);}93 for(int i = 0; i < 3; ++i) {inside ~= new Asteroid(type - 1);} 93 94 } 94 95 } 95 96 97 /** 98 Add an element inside the asteroid. 99 100 The element will appear after the asteroid is destroyed. 101 */ 96 102 void put_inside(Element e) { 97 assert(!contains!(Element)( m_inside, e));103 assert(!contains!(Element)(inside, e)); 98 104 99 105 bool is_asteroid(in Element ee) { 100 106 return cast(Asteroid)ee !is null; 101 107 } 102 Asteroid[] asteroids = cast(Asteroid[])filter!(Element)( m_inside, &is_asteroid);108 Asteroid[] asteroids = cast(Asteroid[])filter!(Element)(inside, &is_asteroid); 103 109 104 110 int r = randint(-1, asteroids.length); 105 111 if (r == -1) { 106 m_inside ~= e;112 inside ~= e; 107 113 } 108 114 else { … … 112 118 113 119 override void iter(float dt = 1) { 114 angle = angle + dt * m_rot_speed;120 angle = angle + dt * rot_speed; 115 121 super.iter(dt); 116 122 } … … 122 128 override void collide(Element e) { 123 129 if (cast(Fire)e || cast(Ship)e) { 124 m_sounds[m_type].play();130 sounds[type].play(); 125 131 if (cast(Fire)e) { 126 132 Game().score += 1; 127 133 } 128 134 129 universe.append(new Explosion( m_type, pos, speed), this);135 universe.append(new Explosion(type, pos, speed), this); 130 136 131 137 // Add the elements inside 132 foreach(ee; m_inside) {138 foreach(ee; inside) { 133 139 Vect speed = this.speed + Vect.from_angle(rand(0, 4 * PI)) * 1 / sqrt(ee.mass); 134 140 speed += rand(0.1, 0.2) * sqrt(e.mass / ee.mass) * e.speed; … … 149 155 private: 150 156 static int NBIMGS = 64; 151 static Surface[][3] m_surfs;152 float m_rot_speed;157 static Surface[][3] surfs; 158 float rot_speed; 153 159 154 160 public: 155 161 static void s_init() { 156 m_surfs[Asteroid.SMALL] = Sprite.loadSurfs("data/asteroid/small/explosion/explosion.png", 8, 8);157 m_surfs[Asteroid.NORMAL] = Sprite.loadSurfs("data/asteroid/normal/explosion/explosion.png", 8, 8);158 m_surfs[Asteroid.BIG] = Sprite.loadSurfs("data/asteroid/big/explosion/explosion.png", 8, 8);162 surfs[Asteroid.SMALL] = Sprite.loadSurfs("data/asteroid/small/explosion/explosion.png", 8, 8); 163 surfs[Asteroid.NORMAL] = Sprite.loadSurfs("data/asteroid/normal/explosion/explosion.png", 8, 8); 164 surfs[Asteroid.BIG] = Sprite.loadSurfs("data/asteroid/big/explosion/explosion.png", 8, 8); 159 165 } 160 166 161 167 162 168 this(int type, Vect pos, Vect speed = Vect(0,0)) { 163 super(new Sprite( m_surfs[type]), pos);169 super(new Sprite(surfs[type]), pos); 164 170 this.speed = speed; 165 m_rot_speed = 0.6 / (type + 1);171 rot_speed = 0.6 / (type + 1); 166 172 } 167 173 168 174 override void iter(float dt = 1) { 169 angle = angle + dt * m_rot_speed;175 angle = angle + dt * rot_speed; 170 176 if (angle >= 2 * PI) {kill();} 171 177 trunk/guisterax/src/display.d
r30 r31 118 118 } 119 119 120 // static MainDisplay opCall(MainDisplay disp) {121 // display = disp;122 // return display;123 // }124 125 120 this(int w = 640, int h = 480) { 126 121 assert(!display); trunk/guisterax/src/gold.d
r30 r31 55 55 radius = 5; 56 56 mass = 2; 57 max_speed = 5; 57 58 rot_speed = rand(-0.05, 0.05); 58 59 this.speed = speed; … … 84 85 } 85 86 }; 87 88 class GoldMagnet : Actor 89 { 90 public: 91 float force = 0.1; 92 float friction = 0.02; 93 public: 94 override void iter(float dt) { 95 Element ship = parent_as!(Element)(); 96 Universe universe = universe(); 97 98 foreach(g; universe.children_as!(Gold)()) { 99 g.attract(ship.pos, force, false); 100 g.friction = friction; 101 } 102 } 103 }; 104 trunk/guisterax/src/ship.d
r29 r31 46 46 { 47 47 private: 48 static Surface[] m_normal_surfs;49 Sprite m_normal_sprite;50 static Surface[] m_power_surfs;51 Sprite m_power_sprite;48 static Surface[] normal_surfs; 49 Sprite normal_sprite; 50 static Surface[] power_surfs; 51 Sprite power_sprite; 52 52 53 float m_angle_speed = 0.1;54 float m_power = 0.1;53 float angle_speed = 0.1; 54 float power = 0.1; 55 55 56 56 public: … … 64 64 65 65 static void s_init() { 66 m_normal_surfs = Sprite.loadSurfs("data/ship/normal/ship.png", 8, 8);67 m_power_surfs = Sprite.loadSurfs("data/ship/power/power.png", 8, 8);66 normal_surfs = Sprite.loadSurfs("data/ship/normal/ship.png", 8, 8); 67 power_surfs = Sprite.loadSurfs("data/ship/power/power.png", 8, 8); 68 68 69 69 Debris.s_init(); … … 71 71 72 72 this(in Vect pos = Vect()) { 73 m_normal_sprite = new Sprite(m_normal_surfs);74 m_power_sprite = new Sprite(m_power_surfs);75 super( m_normal_sprite, pos);73 normal_sprite = new Sprite(normal_surfs); 74 power_sprite = new Sprite(power_surfs); 75 super(normal_sprite, pos); 76 76 max_speed = 5; 77 77 radius = 12; … … 111 111 if (universe) { 112 112 if (universe.key(SDLK_UP)) { 113 force += m_power * normal();114 sprite = m_power_sprite;113 force += power * normal(); 114 sprite = power_sprite; 115 115 } 116 116 else { 117 sprite = m_normal_sprite;117 sprite = normal_sprite; 118 118 } 119 119 120 120 if (universe.key(SDLK_LEFT)) { 121 angle = angle + dt * m_angle_speed;121 angle = angle + dt * angle_speed; 122 122 } 123 123 if (universe.key(SDLK_RIGHT)) { 124 angle = angle - dt * m_angle_speed;124 angle = angle - dt * angle_speed; 125 125 } 126 126 … … 154 154 { 155 155 private: 156 static Surface[][2] m_surfs;157 float m_rot_speed;156 static Surface[][2] surfs; 157 float rot_speed; 158 158 159 159 public: 160 160 static void s_init() { 161 m_surfs[0] = Sprite.loadSurfs("data/ship/debris0/debris0.png", 8, 4);162 m_surfs[1] = Sprite.loadSurfs("data/ship/debris1/debris1.png", 8, 4);161 surfs[0] = Sprite.loadSurfs("data/ship/debris0/debris0.png", 8, 4); 162 surfs[1] = Sprite.loadSurfs("data/ship/debris1/debris1.png", 8, 4); 163 163 } 164 164 165 165 this(int type, in Vect pos, in Vect speed = Vect(0,0)) { 166 super(new Sprite( m_surfs[type]), pos);166 super(new Sprite(surfs[type]), pos); 167 167 this.speed = speed; 168 m_rot_speed = 0.1;168 rot_speed = 0.1; 169 169 } 170 170 171 171 void iter(in float dt = 1) { 172 angle = angle + dt * m_rot_speed;172 angle = angle + dt * rot_speed; 173 173 super.iter(dt); 174 174 } trunk/guisterax/src/shop.d
r16 r31 33 33 import status; 34 34 import menu; 35 static import gold; 35 36 36 37 class Product : Entry … … 110 111 }; 111 112 113 class GoldMagnet : Product { 114 public: 115 this(in Vect pos = Vect()){super(pos, "GOLD MAGNET", 10);} 116 override void on_buy() { 117 ship.append(new gold.GoldMagnet()); 118 } 119 } 120 112 121 class Energy : Product { 113 122 public: … … 151 160 menu.append(new LongFire(Vect(0, -dist * 2))); 152 161 menu.append(new GoldFire(Vect(0, -dist * 3))); 153 menu.append(new Energy(Vect(0, -dist * 4))); 162 menu.append(new GoldMagnet(Vect(0, -dist * 4))); 163 menu.append(new Energy(Vect(0, -dist * 5))); 154 164 append(menu); 155 165 trunk/guisterax/src/surface.d
r23 r31 37 37 class Surface 38 38 { 39 public: 39 40 SDL_Surface* surf = null; 40 41 … … 46 47 this() {} 47 48 48 49 /** 50 Create a surface from an image file. 51 Params: 52 file = the path to the image 53 */ 49 54 this(in char[] file) { 50 55 // to ensure that the display is created
