Commit 55a300cc authored by Gerhard Stein's avatar Gerhard Stein

Sprite class reorganisation

parent e6968c4f
......@@ -369,41 +369,10 @@ int CSpriteObject::checkSolidL( int x1, int x2, int y1, int y2)
int CSpriteObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
{
bool vorticon = (g_pBehaviorEngine->getEpisode() <= 3);
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
y1 -= COLISION_RES;
// Check for sloped tiles here. They must be handled differently
if(!vorticon && solid)
{
char blocked;
if(m_climbing)
{
x1 += 4*COLISION_RES;
x2 -= 4*COLISION_RES;
}
for(int c=x1 ; c<=x2 ; c += COLISION_RES)
{
blocked = TileProperty[mp_Map->at(c>>CSF, y1>>CSF)].bdown;
if(blocked == 17 && m_climbing)
return 0;
if( blocked >= 2 && blocked <= 7 && checkslopedU(c, y1, blocked))
return blocked;
}
blocked = TileProperty[mp_Map->at(x2>>CSF, y1>>CSF)].bdown;
if( blocked >= 2 && blocked <= 7 && checkslopedU(x2, y1, blocked ))
return 1;
if(blocked == 17 && m_climbing)
return 0;
}
if( (((y1+COLISION_RES)>>STC) != (((y1+COLISION_RES)>>CSF)<<TILE_S)) && !push_mode )
return 0;
......@@ -415,12 +384,7 @@ int CSpriteObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
char blocked = TileProperty[mp_Map->at(c>>CSF, y1>>CSF)].bdown;
if(blocked)
{
if(vorticon)
return blocked;
else if(blocked == 1)
return blocked;
}
return blocked;
}
}
......@@ -429,42 +393,10 @@ int CSpriteObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
int CSpriteObject::checkSolidD( int x1, int x2, int y2, const bool push_mode )
{
bool vorticon = (g_pBehaviorEngine->getEpisode() <= 3);
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
y2 += COLISION_RES;
// Check for sloped tiles here. They must be handled differently
if(!vorticon && solid)
{
char blockedu;
if(m_climbing)
{
x1 += 4*COLISION_RES;
x2 -= 4*COLISION_RES;
}
for(int c=x1 ; c<=x2 ; c += COLISION_RES)
{
blockedu = TileProperty[mp_Map->at(c>>CSF, y2>>CSF)].bup;
if( blockedu == 17 && m_climbing)
return 0;
if( blockedu >= 2 && blockedu <= 7 && checkslopedD(c, y2, blockedu) )
return blockedu;
}
blockedu = TileProperty[mp_Map->at(x2>>CSF, y2>>CSF)].bup;
if(blockedu == 17 && m_climbing)
return 0;
if( blockedu >= 2 && blockedu <= 7 && checkslopedD(x2, y2, blockedu) )
return blockedu;
}
if( ( (y2>>STC) != ((y2>>CSF)<<TILE_S) ) && !push_mode )
return 0;
......@@ -476,26 +408,13 @@ int CSpriteObject::checkSolidD( int x1, int x2, int y2, const bool push_mode )
{
blocked = TileProperty[mp_Map->at(c>>CSF, y2>>CSF)].bup;
if(blocked)
{
if( blocked < 2 || blocked > 7 )
{
char blockedd = TileProperty[mp_Map->at(c>>CSF, y2>>CSF)].bdown;
if(blockedd == 0 && m_jumpdown)
return 0;
return blocked;
}
}
if( blocked && (blocked < 2 || blocked > 7) )
return TileProperty[mp_Map->at(c>>CSF, y2>>CSF)].bdown;
}
blocked = TileProperty[mp_Map->at((x2-(1<<STC))>>CSF, y2>>CSF)].bup;
if(blocked)
{
if( blocked < 2 || blocked > 7 )
return blocked;
}
if( blocked && (blocked < 2 || blocked > 7) )
return blocked;
}
if( (Uint32)y2 > ((mp_Map->m_height)<<CSF) )
......@@ -608,25 +527,6 @@ void CSpriteObject::processMoveBitDown()
}
void CSpriteObject::setupGalaxyObjectOnMap(const size_t ActionBaseOffset,
const size_t ActionNumber )
{
m_ActionBaseOffset = ActionBaseOffset;
m_climbing = false;
m_jumped = false;
setActionForce(ActionNumber);
setActionSprite();
CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
performCollisions();
if((rSprite.m_bboxY2-rSprite.m_bboxY1) < 0)
processMove(0, (14<<STC)-(rSprite.m_bboxY2-rSprite.m_bboxY1));
processActionRoutine();
}
void CSpriteObject::processMove(const VectorD2<int>& dir)
{
processMove(dir.x, dir.y);
......
......@@ -24,7 +24,6 @@ m_invincible(false),
m_Pos(x,y),
transluceny(0)
{
m_jumpdown = false;
falling = false;
m_number_of_objects++;
exists = true;
......@@ -42,10 +41,7 @@ transluceny(0)
dontdraw = false;
cansupportplayer = false;
dying = false;
m_ActionBaseOffset = 0x0;
m_vDir = m_hDir = NONE;
m_ActionTicker = 0;
m_climbing = false;
supportedbyobject = false;
blockedd = false;
......@@ -290,7 +286,7 @@ void CSpriteObject::processFalling()
// CAUTION: There is a difference between falling and going down with the gravity...
// So it reaches the maximum of fallspeed
if(!inhibitfall && !m_climbing)
if(!inhibitfall)
{
CPhysicsSettings &Physics = g_pBehaviorEngine->getPhysicsSettings();
......@@ -390,91 +386,6 @@ void CSpriteObject::playSound( const GameSound snd,
g_pSound->playStereofromCoord(snd, mode, scrx);
}
////
// Action format (Galaxy only now...)
////
/**
* So far only used in Galaxy. Here we performs some stuff for the Action format
*/
bool CSpriteObject::getActionNumber(int16_t ActionNumber)
{ return (m_ActionNumber==ActionNumber); }
bool CSpriteObject::getActionStatus(int16_t ActionNumber)
{ return (m_Action.getActionFormat(m_ActionBaseOffset + 30*ActionNumber)); }
int16_t CSpriteObject::getActionNumber()
{ return m_ActionNumber; }
void CSpriteObject::setActionForce(size_t ActionNumber)
{
m_ActionNumber = ActionNumber;
m_Action.setActionFormat(m_ActionBaseOffset + 30*m_ActionNumber);
}
void CSpriteObject::setAction(size_t ActionNumber)
{
if(m_ActionNumber == ActionNumber) return;
setActionForce(ActionNumber);
}
// Sets the proper sprite of action format to the local object
void CSpriteObject::setActionSprite()
{
if(m_hDir == LEFT || m_hDir == NONE)
sprite = m_Action.Left_sprite-124;
else if(m_hDir == RIGHT)
sprite = m_Action.Right_sprite-124;
}
// This new function will setup the sprite based on the Action format
void CSpriteObject::processActionRoutine()
{
setActionSprite();
// Check the Movement Parameter
/*
* This is how the game handles the sprite's movement;
* and is important only with sprites that have movement
* not associated with animation (See below.)The variable
* can have any value between 0-4; zero is used for
* sprites that don't move (Most common occurrence.),
* 1 for nonanimating sprites that may still need to move or hover in place,
* 2 is the stunned sprite value and is also used where smooth movement is needed
* 3 is used for 'fall' moves such as the Bounder or Mad Mushroom and
* 4 is used for sprites that must hit or land on the ground.
*/
if( m_Action.Movement_parameter )
{
if(m_hDir == LEFT )
moveLeft( m_Action.H_anim_move_amount<<1 );
else if(m_hDir == RIGHT )
moveRight( m_Action.H_anim_move_amount<<1 );
if(m_vDir == UP)
moveUp( m_Action.V_anim_move_amount<<1 );
else if(m_vDir == DOWN)
moveDown( m_Action.V_anim_move_amount<<1 );
}
if( m_ActionTicker > m_Action.Delay )
{
if( m_Action.Delay != 0 )
{
if(m_Action.Next_action != 0)
m_Action.setNextActionFormat();
else
exists = false;
}
m_ActionTicker = 0;
}
else
{
m_ActionTicker += 2;
}
}
////
// For drawing
......
......@@ -104,14 +104,6 @@ public:
bool supportedbyobject;
bool dead, dying;
// This is used for action format only
uint16_t m_ActionTicker;
uint16_t m_ActionNumber;
size_t m_ActionBaseOffset;
bool m_jumped;
bool m_climbing;
bool m_jumpdown;
// This container will held the triggered events of the object
CEventContainer m_EventCont;
......@@ -162,11 +154,6 @@ public:
* \param dir The direction where the object has to go to...
*/
/**
* This setups the object on the Map. This is galaxy engine only so far,
*/
void setupGalaxyObjectOnMap(const size_t ActionBaseOffset = 0x0,
const size_t ActionNumber = 0x0 );
void processMove(const VectorD2<int>& dir);
void processMoveBitLeft();
void processMoveBitRight();
......@@ -205,7 +192,7 @@ public:
*/
int checkSolidR( int x1, int x2, int y1, int y2);
int checkSolidL( int x1, int x2, int y1, int y2);
int checkSolidU( int x1, int x2, int y1, const bool push_mode=false );
virtual int checkSolidU( int x1, int x2, int y1, const bool push_mode=false );
virtual int checkSolidD( int x1, int x2, int y2, const bool push_mode=false );
virtual bool checkMapBoundaryL(const int x1);
......@@ -244,14 +231,6 @@ public:
void playSound( const GameSound snd,
const SoundPlayMode mode=PLAY_NOW );
bool getActionNumber(int16_t ActionNumber);
bool getActionStatus(int16_t ActionNumber);
int16_t getActionNumber();
void setActionForce(size_t ActionNumber);
void setAction(size_t ActionNumber);
void setActionSprite();
void processActionRoutine();
void draw();
virtual ~CSpriteObject();
......
......@@ -8,5 +8,248 @@
#include "CGalaxySpriteObject.h"
CGalaxySpriteObject::CGalaxySpriteObject(CMap *pmap, Uint32 x, Uint32 y) :
CSpriteObject(pmap, x, y)
CSpriteObject(pmap, x, y),
m_ActionTicker(0),
m_ActionNumber(0),
m_ActionBaseOffset(0x0),
m_climbing(false),
m_jumpdown(false)
{}
void CGalaxySpriteObject::setupGalaxyObjectOnMap(const size_t ActionBaseOffset,
const size_t ActionNumber )
{
m_ActionBaseOffset = ActionBaseOffset;
m_climbing = false;
m_jumped = false;
setActionForce(ActionNumber);
setActionSprite();
CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
performCollisions();
if((rSprite.m_bboxY2-rSprite.m_bboxY1) < 0)
processMove(0, (14<<STC)-(rSprite.m_bboxY2-rSprite.m_bboxY1));
processActionRoutine();
}
/**
* processes falling of an object. Can be player or any other foe
*/
void CGalaxySpriteObject::processFalling()
{
if(m_climbing)
return;
CSpriteObject::processFalling();
}
int CGalaxySpriteObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
{
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
y1 -= COLISION_RES;
// Check for sloped tiles here. They must be handled differently
if(solid)
{
char blocked;
if(m_climbing)
{
x1 += 4*COLISION_RES;
x2 -= 4*COLISION_RES;
}
for(int c=x1 ; c<=x2 ; c += COLISION_RES)
{
blocked = TileProperty[mp_Map->at(c>>CSF, y1>>CSF)].bdown;
if(blocked == 17 && m_climbing)
return 0;
if( blocked >= 2 && blocked <= 7 && checkslopedU(c, y1, blocked))
return blocked;
}
blocked = TileProperty[mp_Map->at(x2>>CSF, y1>>CSF)].bdown;
if( blocked >= 2 && blocked <= 7 && checkslopedU(x2, y1, blocked ))
return 1;
if(blocked == 17 && m_climbing)
return 0;
}
return CSpriteObject::checkSolidU(x1, x2, y1+COLISION_RES, push_mode);
}
int CGalaxySpriteObject::checkSolidD( int x1, int x2, int y2, const bool push_mode )
{
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
y2 += COLISION_RES;
// Check for sloped tiles here. They must be handled differently
if(solid)
{
char blockedu;
if(m_climbing)
{
x1 += 4*COLISION_RES;
x2 -= 4*COLISION_RES;
}
for(int c=x1 ; c<=x2 ; c += COLISION_RES)
{
blockedu = TileProperty[mp_Map->at(c>>CSF, y2>>CSF)].bup;
if( blockedu == 17 && m_climbing)
return 0;
if( blockedu >= 2 && blockedu <= 7 && checkslopedD(c, y2, blockedu) )
return blockedu;
}
blockedu = TileProperty[mp_Map->at(x2>>CSF, y2>>CSF)].bup;
if(blockedu == 17 && m_climbing)
return 0;
if( blockedu >= 2 && blockedu <= 7 && checkslopedD(x2, y2, blockedu) )
return blockedu;
}
if( ( (y2>>STC) != ((y2>>CSF)<<TILE_S) ) && !push_mode )
return 0;
// Check for down from the object
if(solid)
{
char blocked;
for(int c=x1 ; c<=x2 ; c += COLISION_RES)
{
blocked = TileProperty[mp_Map->at(c>>CSF, y2>>CSF)].bup;
if(blocked)
{
if( blocked < 2 || blocked > 7 )
{
char blockedd = TileProperty[mp_Map->at(c>>CSF, y2>>CSF)].bdown;
if(blockedd == 0 && m_jumpdown)
return 0;
return blocked;
}
}
}
blocked = TileProperty[mp_Map->at((x2-(1<<STC))>>CSF, y2>>CSF)].bup;
if(blocked)
{
if( blocked < 2 || blocked > 7 )
return blocked;
}
}
if( (Uint32)y2 > ((mp_Map->m_height)<<CSF) )
exists=false; // Out of map?
return 0;
}
////
// Action format (Galaxy only now...)
////
/**
* So far only used in Galaxy. Here we performs some stuff for the Action format
*/
bool CGalaxySpriteObject::getActionNumber(int16_t ActionNumber)
{ return (m_ActionNumber==ActionNumber); }
bool CGalaxySpriteObject::getActionStatus(int16_t ActionNumber)
{ return (m_Action.getActionFormat(m_ActionBaseOffset + 30*ActionNumber)); }
int16_t CGalaxySpriteObject::getActionNumber()
{ return m_ActionNumber; }
void CGalaxySpriteObject::setActionForce(size_t ActionNumber)
{
m_ActionNumber = ActionNumber;
m_Action.setActionFormat(m_ActionBaseOffset + 30*m_ActionNumber);
}
void CGalaxySpriteObject::setAction(size_t ActionNumber)
{
if(m_ActionNumber == ActionNumber) return;
setActionForce(ActionNumber);
}
// Sets the proper sprite of action format to the local object
void CGalaxySpriteObject::setActionSprite()
{
if(m_hDir == LEFT || m_hDir == NONE)
sprite = m_Action.Left_sprite-124;
else if(m_hDir == RIGHT)
sprite = m_Action.Right_sprite-124;
}
// This new function will setup the sprite based on the Action format
void CGalaxySpriteObject::processActionRoutine()
{
setActionSprite();
// Check the Movement Parameter
/*
* This is how the game handles the sprite's movement;
* and is important only with sprites that have movement
* not associated with animation (See below.)The variable
* can have any value between 0-4; zero is used for
* sprites that don't move (Most common occurrence.),
* 1 for nonanimating sprites that may still need to move or hover in place,
* 2 is the stunned sprite value and is also used where smooth movement is needed
* 3 is used for 'fall' moves such as the Bounder or Mad Mushroom and
* 4 is used for sprites that must hit or land on the ground.
*/
if( m_Action.Movement_parameter )
{
if(m_hDir == LEFT )
moveLeft( m_Action.H_anim_move_amount<<1 );
else if(m_hDir == RIGHT )
moveRight( m_Action.H_anim_move_amount<<1 );
if(m_vDir == UP)
moveUp( m_Action.V_anim_move_amount<<1 );
else if(m_vDir == DOWN)
moveDown( m_Action.V_anim_move_amount<<1 );
}
if( m_ActionTicker > m_Action.Delay )
{
if( m_Action.Delay != 0 )
{
if(m_Action.Next_action != 0)
m_Action.setNextActionFormat();
else
exists = false;
}
m_ActionTicker = 0;
}
else
{
m_ActionTicker += 2;
}
}
......@@ -14,6 +14,30 @@ class CGalaxySpriteObject: public CSpriteObject
{
public:
CGalaxySpriteObject(CMap *pmap, Uint32 x, Uint32 y);
void setupGalaxyObjectOnMap(const size_t ActionBaseOffset = 0x0,
const size_t ActionNumber = 0x0 );
void processFalling();
int checkSolidU(int x1, int x2, int y1, const bool push_mode=false );
int checkSolidD(int x1, int x2, int y2, const bool push_mode=false );
bool getActionNumber(int16_t ActionNumber);
bool getActionStatus(int16_t ActionNumber);
int16_t getActionNumber();
void setActionForce(size_t ActionNumber);
void setAction(size_t ActionNumber);
void setActionSprite();
void processActionRoutine();
// This is used for action format only
uint16_t m_ActionTicker;
uint16_t m_ActionNumber;
size_t m_ActionBaseOffset;
bool m_jumped;
bool m_climbing;
bool m_jumpdown;
};
#endif /* CGALAXYSPRITEOBJECT_H_ */
......@@ -15,7 +15,7 @@ const Uint32 speed = 10;
const Uint32 hittime = 100;
CBullet::CBullet(CMap *pmap, const Uint32 x, const Uint32 y, const direction_t dir) :
CSpriteObject(pmap, x, y)
CGalaxySpriteObject(pmap, x, y)
{
m_hDir = NONE; m_vDir = NONE;
......
......@@ -10,7 +10,7 @@
#ifndef CBULLET_H_
#define CBULLET_H_
#include "common/CSpriteObject.h"
#include "engine/galaxy/CGalaxySpriteObject.h"
namespace galaxy
{
......@@ -61,7 +61,7 @@ namespace galaxy
};
*/
class CBullet : public CSpriteObject {
class CBullet : public CGalaxySpriteObject {
public:
CBullet(CMap *pmap, Uint32 x, Uint32 y, direction_t dir);
void process();
......
......@@ -14,7 +14,7 @@ namespace galaxy {
CEnemyShot::CEnemyShot(CMap *pmap, const Uint32 x, const Uint32 y,
const int actionFormatOffset, const direction_t dir, const int speed) :
CSpriteObject(pmap, x, y),
CGalaxySpriteObject(pmap, x, y),
m_speed(speed)
{
setupGalaxyObjectOnMap(actionFormatOffset, 0);
......
......@@ -11,11 +11,12 @@
#ifndef CENEMYSHOT_H_
#define CENEMYSHOT_H_
#include "common/CSpriteObject.h"
#include "engine/galaxy/CGalaxySpriteObject.h"
namespace galaxy {
class CEnemyShot : public CSpriteObject {
class CEnemyShot : public CGalaxySpriteObject
{
public:
CEnemyShot(CMap *pmap, const Uint32 x, const Uint32 y,
const int actionFormatOffset, const direction_t dir, const int speed);
......
......@@ -29,10 +29,11 @@ CGalaxySpriteObject( pmap, x, y )
void CStunnable::getTouchedBy(CSpriteObject &theObject)
{
if( theObject.exists && dynamic_cast<CBullet*>(&theObject) )
CBullet *bullet = dynamic_cast<CBullet*>(&theObject);
if( theObject.exists && bullet != NULL )
{
theObject.setAction(A_KEENSHOT_IMPACT);
theObject.playSound( SOUND_SHOT_HIT );
bullet->setAction(A_KEENSHOT_IMPACT);
bullet->playSound( SOUND_SHOT_HIT );
}
}
......
......@@ -19,7 +19,7 @@ const int ELDER_MOVE_TIMER = 10;
CCouncilMember::CCouncilMember(CMap *pmap, Uint32 x, Uint32 y) :
CSpriteObject(pmap, x, y),
CGalaxySpriteObject(pmap, x, y),
rescued(false),
m_timer(0)
{
......
......@@ -10,7 +10,7 @@
#ifndef CCOUNCIL_MEMBER_H_
#define CCOUNCIL_MEMBER_H_
#include "common/CSpriteObject.h"
#include "engine/galaxy/CGalaxySpriteObject.h"
#include <map>
#include <string>
......@@ -19,7 +19,7 @@ namespace galaxy {
#define A_COUNCIL_MEMBER_MOVE 0 /* Ordinary walking council member. */
#define A_COUNCIL_MEMBER_THINK 2 /* Council member stopping to ponder. */
class CCouncilMember : public CSpriteObject
class CCouncilMember : public CGalaxySpriteObject
{
public:
CCouncilMember(CMap *pmap, Uint32 x, Uint32 y);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment