--- a/src/Input.cc Sat Dec 06 23:47:13 2008 +0000
+++ b/src/Input.cc Sun Dec 07 00:01:07 2008 +0000
@@ -16,8 +16,8 @@
{ INPUT_JUMP, -CL_KEY_ENTER, CL_KEY_RSHIFT },
{ INPUT_DIG, CL_KEY_LEFT, CL_KEY_RIGHT },
{ INPUT_SHOOT, CL_KEY_RCONTROL },
- { INPUT_CHANGE, CL_KEY_ENTER, CL_KEY_LEFT },
- { INPUT_CHANGE, CL_KEY_ENTER, CL_KEY_RIGHT },
+ { INPUT_CHANGE_PREV, CL_KEY_ENTER, CL_KEY_LEFT },
+ { INPUT_CHANGE_NEXT, CL_KEY_ENTER, CL_KEY_RIGHT },
{ INPUT_ROPE, CL_KEY_ENTER, CL_KEY_RSHIFT },
{ INPUT_UNROPE, -CL_KEY_ENTER, CL_KEY_RSHIFT },
{ INPUT_ROPE_UP, CL_KEY_ENTER, CL_KEY_UP },
--- a/src/Input.hh Sat Dec 06 23:47:13 2008 +0000
+++ b/src/Input.hh Sun Dec 07 00:01:07 2008 +0000
@@ -19,11 +19,12 @@
INPUT_JUMP = 0x0010,
INPUT_DIG = 0x0020,
INPUT_SHOOT = 0x0040,
- INPUT_CHANGE = 0x0080,
- INPUT_ROPE = 0x0100,
- INPUT_UNROPE = 0x0200,
- INPUT_ROPE_UP = 0x0400,
- INPUT_ROPE_DOWN = 0x0800,
+ INPUT_CHANGE_NEXT = 0x0080,
+ INPUT_CHANGE_PREV = 0x0100,
+ INPUT_ROPE = 0x0200,
+ INPUT_UNROPE = 0x0400,
+ INPUT_ROPE_UP = 0x0800,
+ INPUT_ROPE_DOWN = 0x1000,
};
enum GuiInputBit {
--- a/src/Player.cc Sat Dec 06 23:47:13 2008 +0000
+++ b/src/Player.cc Sun Dec 07 00:01:07 2008 +0000
@@ -52,6 +52,12 @@
void Player::handleCreateProjectile (Weapon *weapon, Vector position, Vector velocity) {
new Projectile(state, position, velocity, true, weapon->getExplosionRadius());
}
+
+void Player::handleChangeWeapon (unsigned int weaponIndex) {
+ assert(weaponIndex < weapons.size());
+
+ selectedWeapon = weaponIndex;
+}
void Player::printDebugInfo (void) {
Engine::log(DEBUG, "layer.debug") << "In air: " << this->inAir;
@@ -77,6 +83,11 @@
// execute
handleCreateProjectile(weapon, shotPosition, shotVelocity);
}
+
+void LocalPlayer::changeWeapon (int delta) {
+ // need to handle negative deltas
+ handleChangeWeapon((weapons.size() + selectedWeapon + delta) % weapons.size());
+}
void LocalPlayer::handleInput (PlayerInput input) {
// Movement force, vertical is always zero
@@ -122,11 +133,12 @@
if (input & INPUT_DIG)
handleDig(position, 15);
- // XXX: currently not network safe
- if (input & INPUT_CHANGE) {
- selectedWeapon = (selectedWeapon + 1) % weapons.size();
- Engine::log(DEBUG, "player.input ") << "changed weapon to " << selectedWeapon;
- }
+ // change weapon back/forth
+ if (input & INPUT_CHANGE_PREV)
+ changeWeapon(-1);
+
+ if (input & INPUT_CHANGE_NEXT)
+ changeWeapon(+1);
// validate shoot events, and then outsource to handleShoot so Network can intercept it
if ((input & INPUT_SHOOT) && getCurrentWeapon()->canShoot())
@@ -223,7 +235,7 @@
g->getSimpleFont().draw(
position.x - g->getSimpleFont().get_width(weaponName) / 2,
- position.y + 10,
+ position.y - 20,
weaponName,
g->get_gc()
);
--- a/src/Player.hh Sat Dec 06 23:47:13 2008 +0000
+++ b/src/Player.hh Sun Dec 07 00:01:07 2008 +0000
@@ -35,6 +35,7 @@
// used by the network code to execute actions for players
virtual void handleDig (Vector position, float radius);
virtual void handleCreateProjectile (Weapon *weapon, Vector position, Vector velocity);
+ virtual void handleChangeWeapon (unsigned int weaponIndex);
/*
* The currently selected weapon
@@ -66,6 +67,11 @@
* Calculates projectil position/velocity and calls handleCreateProjectile
*/
void fireWeapon (Weapon *weapon);
+
+ /*
+ * Change weapon index, should be negative or positive 1
+ */
+ void changeWeapon (int delta);
public:
/*
--- a/src/Weapons.cc Sat Dec 06 23:47:13 2008 +0000
+++ b/src/Weapons.cc Sun Dec 07 00:01:07 2008 +0000
@@ -9,11 +9,11 @@
std::string name;
} WEAPON_PARAMS[] = {
/* age speed expRadius reloadTime name */
- { 10000, 5 * 80 + 30, 0 * 6 + 5, 0 * 100 + 50, "Weapon 1" },
- { 10000, 4 * 80 + 30, 1 * 6 + 5, 1 * 100 + 50, "Weapon 2" },
- { 10000, 3 * 80 + 30, 2 * 6 + 5, 2 * 100 + 50, "Weapon 3" },
- { 10000, 2 * 80 + 30, 3 * 6 + 5, 3 * 100 + 50, "Weapon 4" },
- { 10000, 1 * 80 + 30, 4 * 6 + 5, 4 * 100 + 50, "Weapon 5" },
+ { 10000, 5 * 80 + 50, 0 * 6 + 5, 0 * 100 + 50, "Weapon 1" },
+ { 10000, 4 * 80 + 50, 1 * 6 + 5, 1 * 100 + 50, "Weapon 2" },
+ { 10000, 3 * 80 + 50, 2 * 6 + 5, 2 * 100 + 50, "Weapon 3" },
+ { 10000, 2 * 80 + 50, 3 * 6 + 5, 3 * 100 + 50, "Weapon 4" },
+ { 10000, 1 * 80 + 50, 4 * 6 + 5, 4 * 100 + 50, "Weapon 5" },
{ 0, 0, 0, 0, "" }
};