Weapon damage and some other stuff
authorekku
Mon, 08 Dec 2008 20:23:18 +0000
changeset 305 56799ec8d7be
parent 304 d0f60a97a85e
child 306 4e774439e2c6
Weapon damage and some other stuff
src/Projectile.cc
src/Projectile.hh
src/Rope.cc
src/Rope.hh
src/Weapon.cc
src/Weapon.hh
src/Weapons.cc
--- a/src/Projectile.cc	Mon Dec 08 18:36:06 2008 +0000
+++ b/src/Projectile.cc	Mon Dec 08 20:23:18 2008 +0000
@@ -7,9 +7,7 @@
     PhysicsObject(player->state.world, PROJECTILE_MASS, position, velocity, PROJECTILE, weapon->getBounce()),
     player(player), 
     visible(visible), 
-    radius(weapon->getRadius()),
-    explosionRadius(weapon->getExplosionRadius()), 
-    expire(weapon->getExpire())
+    weapon(weapon)
 {
     // set birth tick
     birth_tick = world.tick_timer.get_ticks();
@@ -17,10 +15,10 @@
     // XXX: projectiles should be particles?
     std::vector<Vector> shape(4);
 
-    shape[0] = Vector(0,        -radius );
-    shape[1] = Vector(+radius,  0       );
-    shape[2] = Vector(0,        +radius );
-    shape[3] = Vector(-radius,  0       );
+    shape[0] = Vector(0                   ,  -weapon->getRadius()  );
+    shape[1] = Vector(weapon->getRadius() ,  0                    );
+    shape[2] = Vector(0                   ,  weapon->getRadius()  );
+    shape[3] = Vector(-weapon->getRadius(),  0                    );
 
     setShape(shape);
     
@@ -34,7 +32,7 @@
  
 void Projectile::onDestroy (Vector position, bool removeGround) {
     if (removeGround)
-        world.removeGround(position, explosionRadius);
+        world.removeGround(position, weapon->getExplosionRadius());
 
     destroy();
 }
@@ -49,7 +47,7 @@
         Player* player = dynamic_cast<Player*>(other);
 
         // XXX: check that player really is !NULL
-        onHitPlayer(player, 10);
+        onHitPlayer(player, weapon->getDamage());
     }
 
     if (collision_elasticity == 0)
@@ -58,7 +56,7 @@
    
 void Projectile::tick (TimeMS dt) {
     // expire projectiles
-    if (world.tick_timer.get_ticks() > birth_tick + expire)
+    if (world.tick_timer.get_ticks() > birth_tick + weapon->getExpire())
         onDestroy(position, true);
 
     // super
@@ -70,13 +68,13 @@
 
     if (visible) {
         PixelCoordinate pos = getCoordinate() - camera;
-        PixelDimension radius = (unsigned int) this->radius;
+        PixelDimension radius = (unsigned int) weapon->getRadius();
 
         CL_Quad projectile(
-                pos.x,          pos.y - radius,
-                pos.x + radius, pos.y,
-                pos.x,          pos.y + radius,
-                pos.x - radius, pos.y
+                pos.x,                      pos.y - weapon->getRadius(),
+                pos.x + weapon->getRadius(), pos.y,
+                pos.x,                      pos.y + weapon->getRadius(),
+                pos.x - weapon->getRadius(),             pos.y
         );
         
         gc->fill_quad(projectile, CL_Color::green);
--- a/src/Projectile.hh	Mon Dec 08 18:36:06 2008 +0000
+++ b/src/Projectile.hh	Mon Dec 08 20:23:18 2008 +0000
@@ -27,20 +27,7 @@
      */
     bool visible;
     
-    /**
-     * The projectile is diamond-shaped, and this is the dimanond's "radius"
-     */
-    float radius;
-
-    /**
-     * The radius of earth removed by this projectile on impact
-     */
-    float explosionRadius;
-
-    /**
-     * How many ticks this projectile lasts before being expiring
-     */
-    TickCount expire;
+    Weapon *weapon;
 
     /**
      * The tick we were spawned at
--- a/src/Rope.cc	Mon Dec 08 18:36:06 2008 +0000
+++ b/src/Rope.cc	Mon Dec 08 20:23:18 2008 +0000
@@ -6,7 +6,7 @@
 #include <stdexcept>
 
 Rope::Rope(Player &player) : 
-    PhysicsObject(player.state.world, ROPE_MASS, Vector(0,0), Vector(0,0), ROPE, 0.00, false), player(player), state(ROPE_FOLDED) 
+    PhysicsObject(player.state.world, ROPE_MASS, Vector(0,0), Vector(0,0), ROPE, 0.00, false), player(player), state(ROPE_FOLDED), pivotObject(NULL) 
 {
     // XXX: better shape
     std::vector<Vector> shape(4);
@@ -38,10 +38,21 @@
 }
 
 void Rope::onCollision (Vector collisionPoint, PhysicsObject *other) {
-    (void) other;
+
+    if (other != NULL) {
+        if (other->getType() == PLAYER) {
+            Player *target = dynamic_cast<Player*>(other);
+            if (target == &(this->player))
+                return;
+            pivotObject = target;            
+        } else if (other->getType() == PROJECTILE) {
+            return;
+        }
+    }
 
     // attached to something!
     state = ROPE_FIXED;
+    velocity = Vector(0,0);
         
     // Ropes location will be used as the pivot point, so move the location to the collisionPoint.
     // Currently the position is something like one pixel away from the collisionPoint where there isn't ground.
--- a/src/Rope.hh	Mon Dec 08 18:36:06 2008 +0000
+++ b/src/Rope.hh	Mon Dec 08 20:23:18 2008 +0000
@@ -29,6 +29,9 @@
     // the owner
     Player &player;
 
+    // possible pivot point (rope is stuck on a player)
+    PhysicsObject *pivotObject;
+
     // How long is the rope in its unstrected state
     float length;
         
--- a/src/Weapon.cc	Mon Dec 08 18:36:06 2008 +0000
+++ b/src/Weapon.cc	Mon Dec 08 20:23:18 2008 +0000
@@ -1,10 +1,11 @@
 #include "Weapon.hh"
 
-Weapon::Weapon(WeaponID id, TickCount expire, float velocity, float recoil, float explosionRadius, float radius,
+Weapon::Weapon(WeaponID id, TickCount expire, float velocity, float recoil, int damage, float explosionRadius, float radius,
         TimeMS reloadTime, std::string name, float bounce) : 
     id(id), 
     name(name), 
     velocity(velocity), 
+    damage(damage),
     explosionRadius(explosionRadius), 
     radius(radius),
     reloadTime(reloadTime), 
--- a/src/Weapon.hh	Mon Dec 08 18:36:06 2008 +0000
+++ b/src/Weapon.hh	Mon Dec 08 20:23:18 2008 +0000
@@ -33,6 +33,11 @@
     float velocity;
 
     /**
+     * Damage it does to player's health.
+     */
+    int damage;
+
+    /**
      * radius of damage done on impact
      */
     float explosionRadius;
@@ -76,7 +81,7 @@
     /**
      * Create a weapon with the given parameters
      */
-    Weapon (WeaponID id, TickCount expire, float velocity, float recoil, float explosionRadius, float radius, TimeMS reloadTime, std::string name, float bounce);
+    Weapon (WeaponID id, TickCount expire, float velocity, float recoil, int damage, float explosionRadius, float radius, TimeMS reloadTime, std::string name, float bounce);
     
     /**
      * Decrement the reload timer, if it's still going
@@ -96,6 +101,7 @@
     float getSpeed (void) const { return velocity; }
     float getRecoil (void) const { return recoil; }
     float getExplosionRadius (void) const { return explosionRadius; }
+    int getDamage (void) const { return damage; }
     float getRadius (void) const { return radius; }
     TickCount getExpire (void) const { return expire; }
     float getBounce (void) const { return bounce; }
--- a/src/Weapons.cc	Mon Dec 08 18:36:06 2008 +0000
+++ b/src/Weapons.cc	Mon Dec 08 20:23:18 2008 +0000
@@ -5,20 +5,21 @@
     TickCount age;
     float speed;
     float recoil;
+    int damage;
     float explosionRadius;
     float radius;
     TickCount reloadTime;
     float bounce;
     std::string name;
 } WEAPON_PARAMS[] = {
-    /*  age     speed           recoil         expRadius   radius  reloadTime      bounce  name        */
-    {   10000,  5 * 80 + 50,    0 * 5 + 10000, 0 * 6 + 5,   1,      0 * 100 + 50,   0.00,   "Weapon 1"      },
-    {   10000,  4 * 80 + 50,    2 * 5 + 5,     1 * 6 + 5,   2,      1 * 100 + 50,   0.00,   "Weapon 2"      },
-    {   10000,  3 * 80 + 50,    3 * 5 + 5,     2 * 6 + 5,   3,      2 * 100 + 50,   0.00,   "Weapon 3"      },
-    {   10000,  2 * 80 + 50,    4 * 5 + 5,     3 * 6 + 5,   4,      3 * 100 + 50,   0.00,   "Weapon 4"      },
-    {   10000,  1 * 80 + 50,    5 * 5 + 5,     4 * 6 + 5,   5,      4 * 100 + 50,   0.00,   "Weapon 5"      },
-    {   1000,   600,            50000,         100,         10,     1000,           1.05,   "BounceBounce"  },
-    {   0,      0,              0,             0,           0,      0,              0.00,   ""              }
+    /*  age     speed           recoil         damage   expRadius   radius  reloadTime      bounce  name        */
+    {   10000,  5 * 80 + 50,    0 * 5 + 10000, 1,       0 * 6 + 5,   1,      0 * 100 + 50,   0.00,   "Weapon 1"      },
+    {   10000,  4 * 80 + 50,    2 * 5 + 5,     2,       1 * 6 + 5,   2,      1 * 100 + 50,   0.00,   "Weapon 2"      },
+    {   10000,  3 * 80 + 50,    3 * 5 + 5,     3,       2 * 6 + 5,   3,      2 * 100 + 50,   0.00,   "Weapon 3"      },
+    {   10000,  2 * 80 + 50,    4 * 5 + 5,     5,       3 * 6 + 5,   4,      3 * 100 + 50,   0.00,   "Weapon 4"      },
+    {   10000,  1 * 80 + 50,    5 * 5 + 5,     8,       4 * 6 + 5,   5,      4 * 100 + 50,   0.00,   "Weapon 5"      },
+    {   1000,   600,            50000,         13,      100,         10,     1000,           1.05,   "BounceBounce"  },
+    {   0,      0,              0,             0,       0,           0,      0,              0.00,   ""              }
 };
 
 std::vector<Weapon*> buildWeaponsList (void) {
@@ -26,9 +27,9 @@
     int idx = 0;
 
     for (WeaponParams *wp = WEAPON_PARAMS; 
-         wp->age || wp->speed || wp->recoil || wp->explosionRadius || wp->radius || wp->bounce || wp->reloadTime; 
+         wp->age || wp->speed || wp->recoil || wp->damage || wp->explosionRadius || wp->radius || wp->bounce || wp->reloadTime; 
          wp++, idx++) {
-        weapons.push_back(new Weapon(idx, wp->age, wp->speed, wp->recoil, wp->explosionRadius, wp->radius, wp->reloadTime, wp->name, wp->bounce));
+        weapons.push_back(new Weapon(idx, wp->age, wp->speed, wp->recoil, wp->damage, wp->explosionRadius, wp->radius, wp->reloadTime, wp->name, wp->bounce));
     }
 
     return weapons;