From f950684bc2dc33849560a3b86fe1c25b52deda76 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 22 Jan 2001 22:58:12 +0000 Subject: [PATCH] --- source/player/player.cpp | 120 +++++++++++++++++++++++++------------- source/player/player.h | 13 ++++- source/player/psbutt.cpp | 6 +- source/player/pschop.cpp | 21 +++---- source/player/psfall.cpp | 8 +-- source/player/psjump.cpp | 6 +- source/player/psrun.cpp | 4 +- source/player/pstates.cpp | 2 +- source/player/pstates.h | 2 +- 9 files changed, 113 insertions(+), 69 deletions(-) diff --git a/source/player/player.cpp b/source/player/player.cpp index 83381e72e..3b7b71525 100644 --- a/source/player/player.cpp +++ b/source/player/player.cpp @@ -25,6 +25,37 @@ #include "pad\pads.h" #endif +#ifndef __PLAYER__PSSTATES_H__ +#include "player\pstates.h" +#endif + +#ifndef __PLAYER__PSJUMP_H__ +#include "player\psjump.h" +#endif + +#ifndef __PLAYER__PSRUN_H__ +#include "player\psrun.h" +#endif + +#ifndef __PLAYER__PSFALL_H__ +#include "player\psfall.h" +#endif + +#ifndef __PLAYER__PSBUTT_H__ +#include "player\psbutt.h" +#endif + +#ifndef __PLAYER__PSCHOP_H__ +#include "player\pschop.h" +#endif + +#ifndef __PLAYER__PSDUCK_H__ +#include "player\psduck.h" +#endif + +#ifndef __GAME_GAMESLOT_H__ +#include "game\gameslot.h" +#endif // to be removed #include "gfx\tpage.h" @@ -52,19 +83,6 @@ Vars ---- */ -/*---------------------------------------------------------------------- - Function: - Purpose: - Params: - Returns: - ---------------------------------------------------------------------- */ -#include "player\pstates.h" -#include "player\psjump.h" -#include "player\psrun.h" -#include "player\psfall.h" -#include "player\psbutt.h" -#include "player\pschop.h" -#include "player\psduck.h" CPlayerStateIdle stateIdle; CPlayerStateJump stateJump; CPlayerStateRun stateRun; @@ -79,7 +97,30 @@ CPlayerStateDuck stateDuck; CPlayerStateSoakUp stateSoackUp; CPlayerStateGetUp stateGetup; +CPlayerState *CPlayer::s_states[NUM_STATES]= +{ + &stateIdle, // STATE_IDLE + &stateJump, // STATE_JUMP + &stateRun, // STATE_RUN + &stateFall, // STATE_FALL + &stateFallFar, // STATE_FALLFAR + &stateButtBounce, // STATE_BUTTBOUNCE + &stateButtBounceFall, // STATE_BUTTFALL + &stateButtBounceLand, // STATE_BUTTLAND + &stateChop, // STATE_CHOP + &stateRunChop, // STATE_RUNCHOP + &stateDuck, // STATE_DUCK + &stateSoackUp, // STATE_SOAKUP + &stateGetup, // STATE_GETUP +}; + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ void CPlayer::init() { CThing::init(); @@ -96,6 +137,10 @@ m_animFrame=0; m_moveVel.vy=0; setFacing(FACING_RIGHT); + m_lives=CGameSlotManager::getSlotData().m_lives; + + m_invincibleFrameCount=INVIBCIBLE_FRAMES__START; + #ifdef __USER_paul__ Pos.vx=50; Pos.vy=200; @@ -164,6 +209,11 @@ void CPlayer::think(int _frames) } m_moveVel.vy=0; } + + if(m_invincibleFrameCount) + { + m_invincibleFrameCount--; + } } #endif if(Pos.vx<0)Pos.vx=0; @@ -177,18 +227,23 @@ void CPlayer::think(int _frames) Returns: ---------------------------------------------------------------------- */ int panim=-1; +int MASK=2; void CPlayer::render() { CThing::render(); // Render - m_skel.setFrame(m_animFrame); - if(panim!=-1) - m_skel.setAnimNo(panim); - else - m_skel.setAnimNo(m_animNo); - m_skel.Animate(this); - m_skel.Render(this); + if(m_invincibleFrameCount==0|| + m_invincibleFrameCount&MASK) + { + m_skel.setFrame(m_animFrame); + if(panim!=-1) + m_skel.setAnimNo(panim); + else + m_skel.setAnimNo(m_animNo); + m_skel.Animate(this); + m_skel.Render(this); + } } @@ -216,7 +271,7 @@ PlayerMetrics s_normalPlayerMetrics= 1, // PM__RUN_SLOWDOWN } }; -PlayerMetrics *CPlayer::getPlayerMetrics() +const PlayerMetrics *CPlayer::getPlayerMetrics() { return &s_normalPlayerMetrics; } @@ -231,23 +286,6 @@ PlayerMetrics *CPlayer::getPlayerMetrics() Params: Returns: ---------------------------------------------------------------------- */ -CPlayerState *CPlayer::s_states[NUM_STATES]= -{ - &stateIdle, // STATE_IDLE - &stateJump, // STATE_JUMP - &stateRun, // STATE_RUN - &stateFall, // STATE_FALL - &stateFallFar, // STATE_FALLFAR - &stateButtBounce, // STATE_BUTTBOUNCE - &stateButtBounceFall, // STATE_BUTTFALL - &stateButtBounceLand, // STATE_BUTTLAND - &stateChop, // STATE_CHOP - &stateRunChop, // STATE_RUNCHOP - &stateDuck, // STATE_DUCK - &stateSoackUp, // STATE_SOAKUP - &stateGetup, // STATE_GETUP -}; - void CPlayer::setState(PLAYER_STATE _state) { m_currentState=s_states[_state]; @@ -345,7 +383,7 @@ int CPlayer::isOnSolidGround() void CPlayer::moveLeft() { - PlayerMetrics *metrics; + const PlayerMetrics *metrics; metrics=getPlayerMetrics(); setFacing(FACING_LEFT); @@ -364,7 +402,7 @@ void CPlayer::moveLeft() } void CPlayer::moveRight() { - PlayerMetrics *metrics; + const PlayerMetrics *metrics; metrics=getPlayerMetrics(); setFacing(FACING_RIGHT); @@ -383,7 +421,7 @@ void CPlayer::moveRight() } void CPlayer::slowdown() { - PlayerMetrics *metrics; + const PlayerMetrics *metrics; metrics=getPlayerMetrics(); if(m_moveVel.vx<0) diff --git a/source/player/player.h b/source/player/player.h index b0ce3f652..feda1cc42 100644 --- a/source/player/player.h +++ b/source/player/player.h @@ -107,7 +107,7 @@ public: void render(); protected: - PlayerMetrics *getPlayerMetrics(); + const PlayerMetrics *getPlayerMetrics(); void setState(PLAYER_STATE _state); int getFacing(); @@ -143,10 +143,21 @@ private: DVECTOR m_moveVel; int m_facing; + enum + { + INVIBCIBLE_FRAMES__START=120, // Invincible for this many frames at start of life + INVINCIBLE_FRAMES__HIT=25, // Invincible for this many frames after taking damage + }; + int m_invincibleFrameCount; + static class CPlayerState *s_states[NUM_STATES]; class CPlayerState *m_currentState; + + + int m_lives; + }; diff --git a/source/player/psbutt.cpp b/source/player/psbutt.cpp index 01bb75804..59654b8ef 100644 --- a/source/player/psbutt.cpp +++ b/source/player/psbutt.cpp @@ -103,9 +103,9 @@ void CPlayerStateButtBounceFall::enter(CPlayer *_player) ---------------------------------------------------------------------- */ void CPlayerStateButtBounceFall::think(CPlayer *_player) { - PlayerMetrics *metrics; - int control; - DVECTOR move; + const PlayerMetrics *metrics; + int control; + DVECTOR move; metrics=getPlayerMetrics(_player); control=getPadInput(_player); diff --git a/source/player/pschop.cpp b/source/player/pschop.cpp index 72955081f..415a4bcd7 100644 --- a/source/player/pschop.cpp +++ b/source/player/pschop.cpp @@ -103,22 +103,19 @@ void CPlayerStateRunChop::think(CPlayer *_player) } else { - DVECTOR move; - move=getMoveVelocity(_player); - if(move.vx==0) - { - setState(_player,STATE_IDLE); - setAnimNo(_player,ANIM_PLAYER_ANIM_RUNSTOP); - } - else - { - slowdown(_player); - } + slowdown(_player); } if(advanceAnimFrameAndCheckForEndOfAnim(_player)) { - setState(_player,STATE_RUN); + if(getMoveVelocity(_player).vx==0) + { + setState(_player,STATE_IDLE); + } + else + { + setState(_player,STATE_RUN); + } } } diff --git a/source/player/psfall.cpp b/source/player/psfall.cpp index 7e63b5d71..48b793096 100644 --- a/source/player/psfall.cpp +++ b/source/player/psfall.cpp @@ -78,9 +78,9 @@ void CPlayerStateFall::enter(CPlayer *_player) ---------------------------------------------------------------------- */ void CPlayerStateFall::think(CPlayer *_player) { - PlayerMetrics *metrics; - int control; - DVECTOR move; + const PlayerMetrics *metrics; + int control; + DVECTOR move; metrics=getPlayerMetrics(_player); control=getPadInput(_player); @@ -111,7 +111,7 @@ void CPlayerStateFall::think(CPlayer *_player) slowdown(_player); } - if(control&CPadConfig::getButton(CPadConfig::PAD_CFG_ACTION)&&control&CPadConfig::getButton(CPadConfig::PAD_CFG_DOWN)) + if(control&CPadConfig::getButton(CPadConfig::PAD_CFG_DOWN)) { move.vx=0; move.vy=0; diff --git a/source/player/psjump.cpp b/source/player/psjump.cpp index 5305528bc..aad62ef1c 100644 --- a/source/player/psjump.cpp +++ b/source/player/psjump.cpp @@ -63,7 +63,7 @@ ---------------------------------------------------------------------- */ void CPlayerStateJump::enter(CPlayer *_player) { - PlayerMetrics *metrics; + const PlayerMetrics *metrics; metrics=getPlayerMetrics(_player); @@ -83,8 +83,8 @@ void CPlayerStateJump::enter(CPlayer *_player) ---------------------------------------------------------------------- */ void CPlayerStateJump::think(CPlayer *_player) { - PlayerMetrics *metrics; - int control; + const PlayerMetrics *metrics; + int control; metrics=getPlayerMetrics(_player); control=getPadInput(_player); diff --git a/source/player/psrun.cpp b/source/player/psrun.cpp index 6e200422e..844837cb5 100644 --- a/source/player/psrun.cpp +++ b/source/player/psrun.cpp @@ -122,9 +122,7 @@ void CPlayerStateRun::think(CPlayer *_player) } else { - DVECTOR move; - move=getMoveVelocity(_player); - if(move.vx==0) + if(getMoveVelocity(_player).vx==0) { setState(_player,STATE_IDLE); setAnimNo(_player,ANIM_PLAYER_ANIM_RUNSTOP); diff --git a/source/player/pstates.cpp b/source/player/pstates.cpp index 9848d69ad..4692a758e 100644 --- a/source/player/pstates.cpp +++ b/source/player/pstates.cpp @@ -24,7 +24,7 @@ /*----------------------------------------------------------------------*/ -PlayerMetrics *CPlayerState::getPlayerMetrics(CPlayer *_player) +const PlayerMetrics *CPlayerState::getPlayerMetrics(CPlayer *_player) { return _player->getPlayerMetrics(); } diff --git a/source/player/pstates.h b/source/player/pstates.h index 9acfd8382..c3c6785cd 100644 --- a/source/player/pstates.h +++ b/source/player/pstates.h @@ -42,7 +42,7 @@ public: protected: - struct PlayerMetrics *getPlayerMetrics(class CPlayer *_player); + const struct PlayerMetrics *getPlayerMetrics(class CPlayer *_player); void setState(class CPlayer *_player,int _state); int getFacing(class CPlayer *_player); void setFacing(class CPlayer *_player,int _facing);