Skip to content

Commit

Permalink
attack animations, X button for bombs, B button for sword attack
Browse files Browse the repository at this point in the history
  • Loading branch information
binary1230 committed Sep 12, 2008
1 parent 23735e6 commit 4e41638
Show file tree
Hide file tree
Showing 9 changed files with 557 additions and 5,912 deletions.
3 changes: 3 additions & 0 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ void Animation::SwitchToNextFrame()

// the next frame MUST BE a sprite frame.
assert(currentFrame->frame_type == ANIMFRAME_SPRITE);

if (currentFrame == frames[0] && attachedObject)
attachedObject->OnAnimationLooped();
}

//! Reset this animation back to the first frame
Expand Down
3 changes: 3 additions & 0 deletions src/animations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ AnimationMapping GetPlayerAnimationMappings() {
animation["sliding"] = PLAYER_SLIDING_DOWN_WALL;
animation["jumping"] = PLAYER_JUMPING;
animation["lookup"] = PLAYER_LOOKUP;
animation["attack1"] = PLAYER_ATTACK1;
animation["attack2"] = PLAYER_ATTACK2;
animation["attack3"] = PLAYER_ATTACK3;
return animation;
}

Expand Down
10 changes: 10 additions & 0 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define DEFAULT_PLAYERKEY_P1_UP KEY_UP
#define DEFAULT_PLAYERKEY_P1_DOWN KEY_DOWN
#define DEFAULT_PLAYERKEY_P1_ACTION1 KEY_D
#define DEFAULT_PLAYERKEY_P1_ACTION2 KEY_F

// Player 2 default game keys
#define DEFAULT_PLAYERKEY_P2_JUMP KEY_E
Expand All @@ -26,6 +27,7 @@
#define DEFAULT_PLAYERKEY_P2_UP KEY_HOME
#define DEFAULT_PLAYERKEY_P2_DOWN KEY_END
#define DEFAULT_PLAYERKEY_P2_ACTION1 KEY_3
#define DEFAULT_PLAYERKEY_P2_ACTION2 KEY_4

// Other keys
#define DEFAULT_GAMEKEY_EXIT KEY_ESC
Expand Down Expand Up @@ -441,13 +443,15 @@ void Input::LoadDefaultKeyMappings() {
gamekey_to_realkey[PLAYERKEY_UP+player1_offset] =DEFAULT_PLAYERKEY_P1_UP;
gamekey_to_realkey[PLAYERKEY_DOWN+player1_offset] =DEFAULT_PLAYERKEY_P1_DOWN;
gamekey_to_realkey[PLAYERKEY_ACTION1+player1_offset] =DEFAULT_PLAYERKEY_P1_ACTION1;
gamekey_to_realkey[PLAYERKEY_ACTION2+player1_offset] =DEFAULT_PLAYERKEY_P1_ACTION2;

gamekey_to_realkey[PLAYERKEY_JUMP+player2_offset] =DEFAULT_PLAYERKEY_P2_JUMP;
gamekey_to_realkey[PLAYERKEY_LEFT+player2_offset] =DEFAULT_PLAYERKEY_P2_LEFT;
gamekey_to_realkey[PLAYERKEY_RIGHT+player2_offset]=DEFAULT_PLAYERKEY_P2_RIGHT;
gamekey_to_realkey[PLAYERKEY_UP+player2_offset] =DEFAULT_PLAYERKEY_P2_UP;
gamekey_to_realkey[PLAYERKEY_DOWN+player2_offset] =DEFAULT_PLAYERKEY_P2_DOWN;
gamekey_to_realkey[PLAYERKEY_ACTION1+player2_offset] =DEFAULT_PLAYERKEY_P2_ACTION1;
gamekey_to_realkey[PLAYERKEY_ACTION2+player2_offset] =DEFAULT_PLAYERKEY_P2_ACTION2;

gamekey_to_realkey[GAMEKEY_EXIT] = DEFAULT_GAMEKEY_EXIT;
gamekey_to_realkey[GAMEKEY_START] = DEFAULT_GAMEKEY_START;
Expand Down Expand Up @@ -592,12 +596,14 @@ void Input::UpdateLive() {
// TODO: Move this to another file. please.
#define XBOX_CONTROLLER_A 0
#define XBOX_CONTROLLER_B 1
#define XBOX_CONTROLLER_X 2

#define XBOX360_CONTROLLER_DPAD 1

// map joystick buttons to physical joystick
#define JOY_BTN_JUMP XBOX_CONTROLLER_A
#define JOY_BTN_ACTION1 XBOX_CONTROLLER_B
#define JOY_BTN_ACTION2 XBOX_CONTROLLER_X
#define JOY_AXIS_DPAD XBOX360_CONTROLLER_DPAD

//! OK, a quick hack for joysticks
Expand Down Expand Up @@ -641,6 +647,10 @@ void Input::DoJoystickUpdateHack() {
key = PLAYERKEY_ACTION1;
break;

case JOY_BTN_ACTION2:
key = PLAYERKEY_ACTION2;
break;

default: // then we don't care
key = -1;
break;
Expand Down
35 changes: 19 additions & 16 deletions src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "globals.h"

//! The max number of "player keys" (e.g. JUMP, LEFT, etc)
#define PLAYERKEY_COUNT 6
#define PLAYERKEY_COUNT 7

//! The player keys (these are NOT indices into game_key[])
//! These constants are used with a controller number
Expand All @@ -15,6 +15,7 @@
#define PLAYERKEY_UP 3
#define PLAYERKEY_DOWN 4
#define PLAYERKEY_ACTION1 5
#define PLAYERKEY_ACTION2 6

// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// The logical mapping of the keys
Expand All @@ -28,25 +29,27 @@
#define PLAYERKEY1_UP 3
#define PLAYERKEY1_DOWN 4
#define PLAYERKEY1_ACTION1 6

#define PLAYERKEY2_JUMP 7
#define PLAYERKEY2_LEFT 8
#define PLAYERKEY2_RIGHT 9
#define PLAYERKEY2_UP 10
#define PLAYERKEY2_DOWN 11
#define PLAYERKEY2_ACTION1 12

#define GAMEKEY_EXIT 13
#define GAMEKEY_START 14
#define GAMEKEY_DEBUGPAUSE 15
#define GAMEKEY_DEBUGSTEP 16
#define GAMEKEY_SCREENSHOT 17
#define GAMEKEY_TOGGLE_PHYSICS_DISPLAY 18
#define PLAYERKEY1_ACTION2 7

#define PLAYERKEY2_JUMP 8
#define PLAYERKEY2_LEFT 9
#define PLAYERKEY2_RIGHT 10
#define PLAYERKEY2_UP 11
#define PLAYERKEY2_DOWN 12
#define PLAYERKEY2_ACTION1 13
#define PLAYERKEY2_ACTION2 14

#define GAMEKEY_EXIT 15
#define GAMEKEY_START 16
#define GAMEKEY_DEBUGPAUSE 17
#define GAMEKEY_DEBUGSTEP 18
#define GAMEKEY_SCREENSHOT 19
#define GAMEKEY_TOGGLE_PHYSICS_DISPLAY 20

/* End of logical mapping */

//! The max number of defined keys
#define GAMEKEY_COUNT 19
#define GAMEKEY_COUNT 21

enum MouseClickType {
MOUSE_LEFT_BTN = 0x00000001,
Expand Down
3 changes: 3 additions & 0 deletions src/objectIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ enum ENGINE_OBJECTID {
#define PLAYER_JUMPING 2
#define PLAYER_LOOKUP 3
#define PLAYER_SLIDING_DOWN_WALL 4
#define PLAYER_ATTACK1 5
#define PLAYER_ATTACK2 6
#define PLAYER_ATTACK3 7

#define DOOR_CLOSED 0
#define DOOR_OPENING 1
Expand Down
5 changes: 4 additions & 1 deletion src/objects/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Object {

// TODO: Make this take an animation code, for now it just takes the index of the animation
// as defined by the order we found them in the XML file. Very prone to errors. HACKY
void PlayAnimation(uint uiIndex);
virtual void PlayAnimation(uint uiIndex);

void SetDrawBounds(bool bDrawBounds) {m_bDrawBoundingBox = bDrawBounds;}

Expand Down Expand Up @@ -358,6 +358,9 @@ class Object {

//! Handle collisions with another object
virtual void OnCollide(Object* obj, const b2ContactPoint* pkContactPoint);

// When an animation we're playing loops, we get this call
virtual void OnAnimationLooped() {};

inline bool IsDead() const {return is_dead;};
inline void SetIsDead(bool bVal) {is_dead = bVal;}
Expand Down
121 changes: 51 additions & 70 deletions src/objects/objectPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ void PlayerObject::UpdateSpriteFlip() {
}
}

void PlayerObject::UpdateRunningAnimationSpeed() {
void PlayerObject::UpdateRunningAnimationSpeed()
{

// HACK?
if (m_bShouldNotSwitchAnimationsRightNow)
return;

// alter the speed of the animation based on the velocity
// TRACE("vel=%f\n", fabs(vel.x));
if (fabs(GetVelX()) < 3.0f)
Expand Down Expand Up @@ -322,7 +328,7 @@ void PlayerObject::DoCrouchingDown() {
// Do things common to most every state
void PlayerObject::DoCommonStuff()
{
DropBombs();
DropBombsIfNeeded();
LimitMaxHorizontalVelocityTo(10.0f);

// If we're moving in a different direction than what we want to do, make us slow down faster.
Expand Down Expand Up @@ -432,6 +438,7 @@ bool PlayerObject::Init()
m_kPlayerState = FALLING;
door_in_front_of_us = NULL;
ring_count = 0;
m_bShouldNotSwitchAnimationsRightNow = false;

return BaseInit();
}
Expand Down Expand Up @@ -508,84 +515,45 @@ void PlayerObject::UpdateState() {
}
}

void PlayerObject::DropBombs()
void PlayerObject::DropBombsIfNeeded()
{
if (INPUT->KeyOnce(PLAYERKEY_ACTION1, controller_num) &&
m_kPlayerState != WALKING_THRU_DOOR)
{
Object* objBall = EFFECTS->TriggerEffect(this, "bomb");
if (!objBall)
return;

float sign = flip_x ? -1 : 1;
float strength = 0.5;

if (GetInput(PLAYERKEY_UP, controller_num))
objBall->SetImpulse(0.0f, strength);

else if (GetInput(PLAYERKEY_DOWN, controller_num))
objBall->SetImpulse(0.0f, strength*0.1);

else
objBall->SetImpulse(sign * strength, strength / 3.0);
}


// ORIG PHYSICS TEST CODE:
/*if (INPUT->KeyOnce(PLAYERKEY_ACTION1, controller_num) &&
m_kPlayerState != WALKING_THRU_DOOR)
{
b2Body* pkBody = PHYSICS->CreateDynamicPhysicsBox(pos.x, pos.y, 15, 10);
float sign = flip_x ? -1 : 1;
float strength = 0.1;
if (GetInput(PLAYERKEY_UP, controller_num))
pkBody->ApplyImpulse(b2Vec2(0.0f, strength*1.7), pkBody->GetWorldCenter());
if (m_kPlayerState == WALKING_THRU_DOOR)
return;

else if (GetInput(PLAYERKEY_DOWN, controller_num))
pkBody->ApplyImpulse(b2Vec2(0.0f, strength*1.7), pkBody->GetWorldCenter());
int iAttackAnimation = -1;

else
pkBody->ApplyImpulse(b2Vec2(sign * strength, strength / 3.0f), pkBody->GetWorldCenter());
if (INPUT->KeyOnce(PLAYERKEY_ACTION1, controller_num))
{
iAttackAnimation = PLAYER_ATTACK1 + Rand(0,1);
}
else if (INPUT->KeyOnce(PLAYERKEY_ACTION2, controller_num))
{
iAttackAnimation = PLAYER_ATTACK3;
}

return;
*/

// ORIGINAL CODE:

/*
if (INPUT->KeyOnce(PLAYERKEY_ACTION1, controller_num) &&
m_kPlayerState != WALKING_THRU_DOOR)
{
int strength;
if (!GLOBALS->Value("bomb_throw_strength", strength))
return;
Object* objBall = EFFECTS->TriggerEffect(this, "bomb");
if (iAttackAnimation == -1)
return;

if (!objBall)
return;
PlayAnimation(iAttackAnimation);
currentAnimation->SetSpeedMultiplier(1);
m_bShouldNotSwitchAnimationsRightNow = true;

float sign;
if (flip_x)
sign = -1;
else
sign = 1;
if (GetInput(PLAYERKEY_UP, controller_num))
objBall->SetVelXY(0.0f, vel.y + strength*1.7);
if (iAttackAnimation != PLAYER_ATTACK3)
return;

else if (GetInput(PLAYERKEY_DOWN, controller_num))
objBall->SetVelXY(0.0f, vel.y - strength);
Object* objBall = EFFECTS->TriggerEffect(this, "bomb");
if (!objBall)
return;

else
objBall->SetVelXY(sign * strength + vel.x, vel.y + 6.0f);
float sign = flip_x ? -1 : 1;
float strength = 0.4;

//objBall->SetVelXY(vel.x, 0.0f);
}
*/
if (GetInput(PLAYERKEY_UP, controller_num))
objBall->SetImpulse(0.0f, strength);
else if (GetInput(PLAYERKEY_DOWN, controller_num))
objBall->SetImpulse(0.0f, strength*0.1);
else
objBall->SetImpulse(sign * strength, strength / 3.0);
}

void PlayerObject::LimitMaxHorizontalVelocityTo( float fMaxHorizontalVelocity )
Expand All @@ -604,4 +572,17 @@ void PlayerObject::LimitMaxVerticalVelocityTo( float fMaxVerticalVelocity )

if (GetVelY() < -fMaxVerticalVelocity)
SetVelY(-fMaxVerticalVelocity);
}

void PlayerObject::OnAnimationLooped()
{
m_bShouldNotSwitchAnimationsRightNow = false;
}

void PlayerObject::PlayAnimation(uint uiIndex)
{
if (m_bShouldNotSwitchAnimationsRightNow)
return;

Object::PlayAnimation(uiIndex);
}
15 changes: 10 additions & 5 deletions src/objects/objectPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PlayerObject : public Object {
void LimitMaxHorizontalVelocityTo( float fMaxHorizontalVelocity );
void LimitMaxVerticalVelocityTo( float fMaxVerticalVelocity );

void DropBombs();
void DropBombsIfNeeded();

void DoStanding();
void DoWalking();
Expand Down Expand Up @@ -92,15 +92,20 @@ class PlayerObject : public Object {
// If the running animation is a skateboard (only set at init time)
bool on_skateboard;

bool m_bShouldNotSwitchAnimationsRightNow;

public:
bool Init();
void Shutdown();
virtual bool Init();
virtual void Shutdown();

//! Load object properties from XML
bool LoadPlayerProperties(XMLNode &xDef);

void Update();
void OnCollide(Object* obj, const b2ContactPoint* pkContactPoint);
virtual void Update();
virtual void OnCollide(Object* obj, const b2ContactPoint* pkContactPoint);

virtual void OnAnimationLooped();
virtual void PlayAnimation(uint uiIndex);

int GetNumRings() {return ring_count;};

Expand Down
Loading

0 comments on commit 4e41638

Please sign in to comment.