Changeset 22
- Timestamp:
- 12/10/07 11:32:38 (1 year ago)
- Files:
-
- trunk/guisterax/data/bounce (added)
- trunk/guisterax/data/bounce/bounce.png (added)
- trunk/guisterax/src/asteroid.d (modified) (2 diffs)
- trunk/guisterax/src/bounce.d (added)
- trunk/guisterax/src/element.d (modified) (4 diffs)
- trunk/guisterax/src/fire.d (modified) (2 diffs)
- trunk/guisterax/src/init.d (modified) (2 diffs)
- trunk/guisterax/src/metal.d (modified) (2 diffs)
- trunk/guisterax/src/mine.d (modified) (3 diffs)
- trunk/guisterax/src/saucer.d (modified) (1 diff)
- trunk/guisterax/src/ship.d (modified) (1 diff)
- trunk/guisterax/src/wave.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/guisterax/src/asteroid.d
r10 r22 32 32 import utils; 33 33 import fire; 34 import ship; 34 35 35 36 import std.math : PI, sqrt; … … 118 119 119 120 override void collide(Element e) { 120 m_sounds[m_type].play(); 121 universe.append(new Explosion(m_type, pos, speed), this); 122 123 // Add the elements inside 124 foreach(ee; m_inside) { 125 Vect speed = this.speed + Vect.from_angle(rand(0, 4 * PI)) * 1 / sqrt(ee.mass); 126 speed += rand(0.1, 0.2) * sqrt(e.mass / ee.mass) * e.speed; 127 ee.speed = speed; 128 ee.pos = this.pos; 129 universe.append(ee, this); 121 if (cast(Fire)e || cast(Ship)e) { 122 m_sounds[m_type].play(); 123 universe.append(new Explosion(m_type, pos, speed), this); 124 125 // Add the elements inside 126 foreach(ee; m_inside) { 127 Vect speed = this.speed + Vect.from_angle(rand(0, 4 * PI)) * 1 / sqrt(ee.mass); 128 speed += rand(0.1, 0.2) * sqrt(e.mass / ee.mass) * e.speed; 129 ee.speed = speed; 130 ee.pos = this.pos; 131 universe.append(ee, this); 132 } 133 134 kill(); 130 135 } 131 132 kill();133 136 } 134 137 }; trunk/guisterax/src/element.d
r10 r22 65 65 void hit(float v) {} 66 66 67 this(Sprite sprite = null, in Vect pos = Vect( 0,0)) {67 this(Sprite sprite = null, in Vect pos = Vect()) { 68 68 super(); 69 69 this.pos = pos; … … 71 71 } 72 72 73 void attract(in Vect pos, float strenght, bool direct = false) {73 void attract(in Vect pos, float strenght, bool direct = true) { 74 74 Vect normal = (pos - this.pos).normal(); 75 75 if (!direct) { … … 79 79 } 80 80 } 81 void repeal(in Vect pos, float strenght, bool direct = false) {81 void repeal(in Vect pos, float strenght, bool direct = true) { 82 82 attract(pos, -strenght, direct); 83 83 } … … 94 94 } 95 95 96 override void draw(Display disp, in Vect pos = Vect( 0,0)) {96 override void draw(Display disp, in Vect pos = Vect()) { 97 97 if (sprite) { 98 98 sprite.draw(disp, this.pos + pos); trunk/guisterax/src/fire.d
r10 r22 32 32 import utils; 33 33 import timer; 34 import bounce; 34 35 35 36 … … 57 58 58 59 override void collide(Element e) { 59 kill(); 60 if (!cast(Bounce)e) { 61 kill(); 62 } 60 63 } 61 64 }; trunk/guisterax/src/init.d
r16 r22 40 40 import vect : Vect; 41 41 import status; 42 import bounce; 42 43 43 44 void init() { … … 58 59 Status.s_init(); 59 60 Shop.s_init(); 61 Bounce.s_init(); 60 62 } trunk/guisterax/src/metal.d
r10 r22 31 31 import display; 32 32 import fire; 33 import ship; 33 34 import sound; 34 35 … … 68 69 69 70 override void collide(Element e) { 70 m_sound.play(); 71 // speed += sqrt(e.mass / mass) * (e.speed - speed); 72 repeal(e.pos, e.mass, true); 71 if (cast(Fire)e || cast(Ship)e) { 72 m_sound.play(); 73 // speed += sqrt(e.mass / mass) * (e.speed - speed); 74 repeal(e.pos, e.mass); 75 } 73 76 } 74 77 }; trunk/guisterax/src/mine.d
r10 r22 60 60 override float danger() {return 1;} 61 61 62 this(Element target, in Vect pos, in Vect speed = Vect( 0,0)) {62 this(Element target, in Vect pos, in Vect speed = Vect()) { 63 63 super(new Sprite(m_surfs), pos); 64 64 this.target = target; … … 93 93 if (cast(Fire)e) { 94 94 m_sound.play(); 95 repeal(e.pos, e.mass * 5 , true);95 repeal(e.pos, e.mass * 5); 96 96 speed += 0.5 * e.speed * sqrt(e.mass / mass); 97 97 energy -= 0.1; … … 113 113 } 114 114 115 this(Vect pos, Vect speed = Vect( 0,0)) {115 this(Vect pos, Vect speed = Vect()) { 116 116 super(new Sprite(m_surfs), pos); 117 117 this.speed = speed; trunk/guisterax/src/saucer.d
r15 r22 70 70 } 71 71 override void collide(Element e) { 72 repeal(e.pos, e.mass * 5 , true);72 repeal(e.pos, e.mass * 5); 73 73 energy -= 1; 74 74 } trunk/guisterax/src/ship.d
r16 r22 104 104 if (cast(Asteroid)e || cast(Metal)e || cast(Mine)e) { 105 105 hit(e.radius / 100); 106 repeal(e.pos, e.mass , true);106 repeal(e.pos, e.mass); 107 107 } 108 108 // TODO: put this into Energy class trunk/guisterax/src/wave.d
r16 r22 31 31 import energy; 32 32 import metal; 33 import bounce; 33 34 import saucer; 34 35 import timer; … … 62 63 // Add the metal ball 63 64 for (int i=0; i < level; ++i) { 64 if (rand(1) > 0. 75) {65 if (rand(1) > 0.80) { 65 66 Vect speed = rand(0, 1) * Vect.from_angle(rand(0, 2 * PI)); 66 67 append(new Metal(safe_pos(64), speed)); 67 } 68 } 68 69 } 70 // Maybe add a bouncing ball 71 if (rand(1) > 0.75) { 72 Vect speed = rand(0, 1) * Vect.from_angle(rand(0, 2 * PI)); 73 append(new Bounce(safe_pos(128), speed)); 74 } 75 69 76 // we actually add the asteroids 70 77 update(); … … 113 120 if (pressed_key(SDLK_s)) {add_saucer();} 114 121 if (pressed_key(SDLK_b)) {append(new Metal(safe_pos(64)));} 122 if (pressed_key(SDLK_k)) {append(new Bounce(safe_pos(128)));} 115 123 } 116 124 }
