weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
--- a/src/GameState.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/GameState.cc Sun Dec 07 21:10:04 2008 +0000
@@ -35,7 +35,10 @@
}
void GameState::draw(Graphics *g, bool displayWeapon) {
- PixelCoordinate camera = local_player->getCoordinate() - world.getDimensions() / 2;
+ PixelCoordinate camera(0, 0);
+
+ if (local_player)
+ camera = local_player->getCoordinate() - world.getDimensions() / 2;
// Draw world/terrain
world.draw(g, camera);
--- a/src/Network/Client.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Network/Client.cc Sun Dec 07 21:10:04 2008 +0000
@@ -66,11 +66,12 @@
Vector position = pkt.read_vector();
Vector velocity = pkt.read_vector();
float explosionRadius = pkt.read_float32();
+ float radius = pkt.read_float32();
Engine::log(INFO, "client.on_projectile_create") << "obj=" << obj << ", pos=" << position << ", velocity=" << velocity;
// create the NetworkClientPorjectile object
- new NetworkClientProjectile(*this, obj, position, velocity, explosionRadius);
+ new NetworkClientProjectile(*this, obj, position, velocity, explosionRadius, radius);
}
void NetworkClient::on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node) {
@@ -225,8 +226,8 @@
}
NetworkClientProjectile::NetworkClientProjectile (NetworkClient &client, NetworkObject_Client *obj, Vector position,
- Vector velocity, float explosionRadius) :
- NetworkClientObjectHelper(client, obj), Projectile(client.state, position, velocity, true, explosionRadius)
+ Vector velocity, float explosionRadius, float radius) :
+ NetworkClientObjectHelper(client, obj), Projectile(client.state, position, velocity, true, explosionRadius, radius)
{
// hook up signals
slots.connect(obj->sig_message(NETMSG_PROJECTILE_DESTROY), this, &NetworkClientProjectile::on_destroy);
--- a/src/Network/Client.hh Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Network/Client.hh Sun Dec 07 21:10:04 2008 +0000
@@ -85,7 +85,7 @@
class NetworkClientProjectile : public NetworkClientObjectHelper, public Projectile {
public:
NetworkClientProjectile (NetworkClient &client, NetworkObject_Client *obj, Vector position, Vector velocity,
- float explosionRadius);
+ float explosionRadius, float radius);
protected:
virtual void onDestroy (Vector position, bool removeGround);
--- a/src/Network/Protocol.hh Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Network/Protocol.hh Sun Dec 07 21:10:04 2008 +0000
@@ -128,6 +128,7 @@
* Vector position
* Vector velocity
* float explosionRadius
+ * float radius
*/
NETMSG_PROJECTILE_CREATE = 0x0401,
--- a/src/Network/Server.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Network/Server.cc Sun Dec 07 21:10:04 2008 +0000
@@ -93,7 +93,7 @@
Engine::log(INFO, "server_player.create_projectile") << "weapon='" << weapon->getName() << "', position=" << position << ", velocity=" << velocity;
// create new NetworkServerProjectile object
- new NetworkServerProjectile(server, position, velocity, weapon->getExplosionRadius(), weapon->getExpireTicks());
+ new NetworkServerProjectile(server, position, velocity, weapon->getExplosionRadius(), weapon->getRadius(), weapon->getExpireTicks());
}
void NetworkServerPlayer::handleChangeWeapon (unsigned int weaponIndex) {
@@ -229,14 +229,15 @@
* NetworkServerProjectile
*/
NetworkServerProjectile::NetworkServerProjectile (NetworkServer &server, Vector position, Vector velocity,
- float explosionRadius, TickCount age) :
- Projectile(server.state, position, velocity, true, explosionRadius, age), server(server), obj(server.netobjs)
+ float explosionRadius, float radius, TickCount age) :
+ Projectile(server.state, position, velocity, true, explosionRadius, radius, age), server(server), obj(server.netobjs)
{
NetworkPacket pkt;
pkt.write_vector(position);
pkt.write_vector(velocity);
pkt.write_float32(explosionRadius);
+ pkt.write_float32(radius);
obj.send_all(NETMSG_PROJECTILE_CREATE, pkt, true);
}
--- a/src/Network/Server.hh Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Network/Server.hh Sun Dec 07 21:10:04 2008 +0000
@@ -67,7 +67,7 @@
NetworkObject_Server obj;
public:
- NetworkServerProjectile (NetworkServer &server, Vector position, Vector velocity, float explosionRadius, TickCount age);
+ NetworkServerProjectile (NetworkServer &server, Vector position, Vector velocity, float explosionRadius, float radius, TickCount age);
protected:
virtual void onDestroy (Vector position, bool removeGround);
--- a/src/Network/TCP.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Network/TCP.cc Sun Dec 07 21:10:04 2008 +0000
@@ -77,6 +77,7 @@
Engine::log(ERROR, "tcp.write_packet") << err;
+ // XXX: these are not handled anywhere :(
throw;
}
}
--- a/src/Player.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Player.cc Sun Dec 07 21:10:04 2008 +0000
@@ -49,7 +49,7 @@
}
void Player::handleCreateProjectile (Weapon *weapon, Vector position, Vector velocity) {
- new Projectile(state, position, velocity, true, weapon->getExplosionRadius());
+ new Projectile(state, position, velocity, true, weapon->getExplosionRadius(), weapon->getRadius(), weapon->getExpireTicks());
}
void Player::handleChangeWeapon (unsigned int weaponIndex) {
--- a/src/Projectile.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Projectile.cc Sun Dec 07 21:10:04 2008 +0000
@@ -2,15 +2,15 @@
#include "Graphics.hh"
#include "Timer.hh"
-Projectile::Projectile(GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age) :
- PhysicsObject(state.world, PLAYER_MASS, position, velocity), state(state), visible(visible), radius(radius), age(age) {
+Projectile::Projectile (GameState &state, Vector position, Vector velocity, bool visible, float explosionRadius, float radius, TickCount age) :
+ PhysicsObject(state.world, PLAYER_MASS, position, velocity), state(state), visible(visible), explosionRadius(explosionRadius), radius(radius), age(age) {
birth_tick = world.tick_timer.get_ticks();
// Don't think these are needed anymore
std::vector<Vector> shape(4);
- shape[0] = Vector(-1, -1);
- shape[1] = Vector(-1, 1);
- shape[2] = Vector(1, 1);
- shape[3] = Vector(1, -1);
+ shape[0] = Vector(0, -radius );
+ shape[1] = Vector(+radius, 0 );
+ shape[2] = Vector(0, +radius );
+ shape[3] = Vector(-radius, 0 );
setShape(shape);
collision_elasticity = 0.9; // = shotType.elasticity
@@ -23,7 +23,7 @@
void Projectile::onDestroy (Vector position, bool removeGround) {
if (removeGround)
- world.removeGround(position, radius);
+ world.removeGround(position, explosionRadius);
destroy();
}
@@ -49,10 +49,10 @@
PixelCoordinate pos = getCoordinate() - camera;
CL_Quad projectile(
- pos.x + 1, pos.y + 1,
- pos.x - 1, pos.y + 1,
- pos.x + 1, pos.y - 1,
- pos.x - 1, pos.y - 1
+ pos.x, pos.y - radius,
+ pos.x + radius, pos.y,
+ pos.x, pos.y + radius,
+ pos.x - radius, pos.y
);
gc->fill_quad(projectile, CL_Color::green);
--- a/src/Projectile.hh Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Projectile.hh Sun Dec 07 21:10:04 2008 +0000
@@ -13,12 +13,13 @@
GameState &state;
bool visible;
float radius;
+ float explosionRadius;
public:
TickCount birth_tick;
TickCount age;
- Projectile (GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age=1000000000);
+ Projectile (GameState &state, Vector position, Vector velocity, bool visible, float explosionRadius, float radius, TickCount age=1000000000);
virtual ~Projectile (void);
virtual void draw (Graphics *g, PixelCoordinate camera) const;
--- a/src/Rope.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Rope.cc Sun Dec 07 21:10:04 2008 +0000
@@ -143,6 +143,7 @@
// If there's not ground on the pivot point anymore, release the rope
if (!world.collides(position)) {
this->state = ROPE_FLYING;
+ player.handleRopeState(state);
}
}
else { // ROPE_FOLDED
--- a/src/Weapon.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Weapon.cc Sun Dec 07 21:10:04 2008 +0000
@@ -1,7 +1,7 @@
#include "Weapon.hh"
-Weapon::Weapon(TickCount age, float velocity, float recoil, float explosionRadius, int reloadTime, std::string name) :
- age(age), velocity(velocity), recoil(recoil), explosionRadius(explosionRadius), reloadTime(reloadTime), name(name), reloadTimer(0)
+Weapon::Weapon(TickCount age, float velocity, float recoil, float explosionRadius, float radius, int reloadTime, std::string name) :
+ age(age), velocity(velocity), recoil(recoil), explosionRadius(explosionRadius), radius(radius), reloadTime(reloadTime), name(name), reloadTimer(0)
{
}
--- a/src/Weapon.hh Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Weapon.hh Sun Dec 07 21:10:04 2008 +0000
@@ -13,7 +13,7 @@
protected:
std::string name;
float velocity;
- float explosionRadius;
+ float explosionRadius, radius;
int reloadTime; //in ms
float recoil;
@@ -24,7 +24,7 @@
int reloadTimer;
public:
- Weapon (TickCount age, float velocity, float recoil, float explosionRadius, int reloadTime, std::string name);
+ Weapon (TickCount age, float velocity, float recoil, float explosionRadius, float radius, int reloadTime, std::string name);
// advance the reload timer
void tickReload (TimeMS dt);
@@ -37,6 +37,7 @@
float getSpeed (void) { return velocity; }
float getRecoil (void) { return recoil; }
float getExplosionRadius (void) { return explosionRadius; }
+ float getRadius (void) { return radius; }
TickCount getExpireTicks (void) { return age; }
// start reloading
--- a/src/Weapons.cc Sun Dec 07 20:49:49 2008 +0000
+++ b/src/Weapons.cc Sun Dec 07 21:10:04 2008 +0000
@@ -6,25 +6,26 @@
float speed;
float recoil;
float explosionRadius;
+ float radius;
TickCount reloadTime;
std::string name;
} WEAPON_PARAMS[] = {
- /* age speed recoil expRadius reloadTime name */
- { 10000, 5 * 80 + 50, 0 * 5 + 4000, 0 * 6 + 5, 0 * 100 + 50, "Weapon 1" },
- { 10000, 4 * 80 + 50, 2 * 5 + 5, 1 * 6 + 5, 1 * 100 + 50, "Weapon 2" },
- { 10000, 3 * 80 + 50, 3 * 5 + 5, 2 * 6 + 5, 2 * 100 + 50, "Weapon 3" },
- { 10000, 2 * 80 + 50, 4 * 5 + 5, 3 * 6 + 5, 3 * 100 + 50, "Weapon 4" },
- { 10000, 1 * 80 + 50, 5 * 5 + 5, 4 * 6 + 5, 4 * 100 + 50, "Weapon 5" },
- { 0, 0, 0, 0, 0, "" }
+ /* age speed recoil expRadius radius reloadTime name */
+ { 10000, 5 * 80 + 50, 0 * 5 + 4000, 0 * 6 + 5, 1, 0 * 100 + 50, "Weapon 1" },
+ { 10000, 4 * 80 + 50, 2 * 5 + 5, 1 * 6 + 5, 2, 1 * 100 + 50, "Weapon 2" },
+ { 10000, 3 * 80 + 50, 3 * 5 + 5, 2 * 6 + 5, 3, 2 * 100 + 50, "Weapon 3" },
+ { 10000, 2 * 80 + 50, 4 * 5 + 5, 3 * 6 + 5, 4, 3 * 100 + 50, "Weapon 4" },
+ { 10000, 1 * 80 + 50, 5 * 5 + 5, 4 * 6 + 5, 5, 4 * 100 + 50, "Weapon 5" },
+ { 0, 0, 0, 0, 0, 0, "" }
};
std::vector<Weapon*> buildWeaponsList (void) {
std::vector<Weapon*> weapons;
for (WeaponParams *wp = WEAPON_PARAMS;
- wp->age || wp->speed || wp->recoil || wp->explosionRadius || wp->reloadTime;
+ wp->age || wp->speed || wp->recoil || wp->explosionRadius || wp->radius || wp->reloadTime;
wp++) {
- weapons.push_back(new Weapon(wp->age, wp->speed, wp->recoil, wp->explosionRadius, wp->reloadTime, wp->name));
+ weapons.push_back(new Weapon(wp->age, wp->speed, wp->recoil, wp->explosionRadius, wp->radius, wp->reloadTime, wp->name));
}
return weapons;