Commit e80e3d10 authored by Gerhard Stein's avatar Gerhard Stein

Sprite fixes for different characters.

parent f7fae477
......@@ -99,7 +99,7 @@ void CCamera::setPosition(const Vector2D<int>& newpos)
moveToForce(newpos);
// Only the lead camera may change the scroll position
if(mCamlead != mp_AttachedObject->getSpriteVariantId())
if(mCamlead != mp_AttachedObject->getSpecialIdx())
{
return;
}
......@@ -119,9 +119,9 @@ void CCamera::process()
cycleCamlead();
}
const int camId = mp_AttachedObject->getSpriteVariantId();
const int playerIdx = mp_AttachedObject->getSpecialIdx();
if(camId != mCamlead)
if(playerIdx != mCamlead)
return;
if(mCamLeadChange)
......@@ -191,8 +191,8 @@ void CCamera::process()
}
Uint16 &scroll_x = mpMap->m_scrollx;
Uint16 &scroll_y = mpMap->m_scrolly;
const Uint16 &scroll_x = mpMap->m_scrollx;
const Uint16 &scroll_y = mpMap->m_scrolly;
// delta is how much we need to scroll in order to get the camera stalled
int delta_x = (getXPosition()>>STC)-scroll_x;
......
......@@ -16,7 +16,8 @@ const int EFFECT_TIME = 10;
const int EFFECT_SPEED = 10;
CHUD::CHUD(unsigned long &score, signed char &lives,
signed int &charges, const int id) :
signed int &charges, const int playerIdx,
const int spriteVar) :
m_score(score),
mLives(lives),
m_charges(charges),
......@@ -24,7 +25,7 @@ mOldScore(score),
mOldCharges(charges),
timer(0)
{
setup(id);
setup(playerIdx, spriteVar);
}
void CHUD::createHUDBlit()
......@@ -34,9 +35,10 @@ void CHUD::createHUDBlit()
mHUDBlit.fillRGB(0,0,0);
}
void CHUD::setup(const int id)
void CHUD::setup(const int playerIdx,
const int spriteVar)
{
mId = id;
mId = playerIdx;
mRenderRect.x = 8; mRenderRect.y = 4;
......@@ -50,7 +52,7 @@ void CHUD::setup(const int id)
if( Episode >= 1 && Episode <= 3 )
{
mRenderRect.w = 84; mRenderRect.h = 30;
mRenderRect.x += (mRenderRect.w-4)*id;
mRenderRect.x += (mRenderRect.w-4)*playerIdx;
createHUDBlit();
CreateVorticonBackground();
......@@ -59,13 +61,13 @@ void CHUD::setup(const int id)
{
mRenderRect.w = 80; mRenderRect.h = 30;
auto &hudBg = *gGraphics.getSprite(mId,"HUDBACKGROUND");
auto &hudBg = *gGraphics.getSprite(spriteVar, "HUDBACKGROUND");
mHUDBox.copy(hudBg);
mRenderRect.h = mHUDBox.getHeight();
mRenderRect.w = mHUDBox.getWidth()-7;
mRenderRect.x += (mRenderRect.w-2)*id;
mRenderRect.x += (mRenderRect.w-2)*playerIdx;
createHUDBlit();
}
......
......@@ -31,7 +31,7 @@ public:
CHUD(unsigned long &score,
signed char &lives,
signed int &charges,
const int id); // TODO: Must be removed later and replaced by a reference
const int playerIdx, const int spriteVar); // TODO: Must be removed later and replaced by a reference
//CHUD(const CHUD &orig);
......@@ -47,7 +47,7 @@ public:
/**
* \brief Sets up the HUD Box for certain id sprite variant
*/
void setup(const int id);
void setup(const int playerIdx, const int spriteVar);
/**
* \brief This will sync some data in the HUD, especially the oldScore variable
......
......@@ -562,17 +562,17 @@ void CSpriteObject::draw()
int w = Sprite.getWidth();
int h = Sprite.getHeight();
auto visGA = gVideoDriver.mpVideoEngine->mRelativeVisGameArea;
const auto visGA = gVideoDriver.mpVideoEngine->mRelativeVisGameArea;
if( showX+Sprite.getWidth() < visGA.x || showX > visGA.x+visGA.w+16 )
if( showX+w < visGA.x || showX > visGA.x+visGA.w+16 )
return;
if( showY+Sprite.getHeight() < visGA.y || showY > visGA.y+visGA.h+16 )
if( showY+h < visGA.y || showY > visGA.y+visGA.h+16 )
return;
if( showX+w > visGA.x+visGA.w+16 )
if( showX+Sprite.getWidth() > visGA.x+visGA.w+16 )
w = w - ((showX+w) - (visGA.x+visGA.w+16));
if( showY+h > visGA.y+visGA.h+16 )
if( showY+Sprite.getHeight() > visGA.y+visGA.h+16 )
h = h - ((showY+h) - (visGA.y+visGA.h+16));
if(m_blinktime > 0)
......
......@@ -344,12 +344,17 @@ class CSpriteObject
virtual ~CSpriteObject();
int getSpecialIdx() const
{ return mSpecialIdx; }
int getSpriteVariantId() const
{ return mSprVar; }
void setSpecialIdx(const int i)
{ mSpecialIdx = i; }
void setSpriteVariantId(const int i)
{ mSprVar = i; }
protected:
/**
......@@ -413,7 +418,11 @@ class CSpriteObject
Uint8 transluceny;
int mSprVar; // Sprite variant, which is used by the Spritemap
protected:
int mSprVar = 0; // Sprite variant, which is used by the Spritemap
int mSpecialIdx = 0; // Special index for different usages. In case of players, that is it's index
};
......
......@@ -52,7 +52,7 @@ m_LevelPlay( mInventoryVec)
for(int i=0 ; i<numPlayers ; i++)
{
mInventoryVec[i].setup(spriteVars[i]);
mInventoryVec[i].setup(i, spriteVars[i]);
}
m_WorldMap.init();
......@@ -159,9 +159,10 @@ bool CPlayGameGalaxy::loadXMLGameState()
if(node.first == "Player")
{
ptree &playerNode = node.second;
variant = playerNode.get<int>("<xmlattr>.variant");
variant = playerNode.get<int>("<xmlattr>.variant");
const int idx = playerNode.get("<xmlattr>.id", 0);
auto &invNode = playerNode.get_child("inventory");
mInventoryVec[variant].setup(variant);
mInventoryVec[variant].setup(idx, variant);
mInventoryVec[variant] << invNode;
}
}
......@@ -218,7 +219,8 @@ bool CPlayGameGalaxy::saveXMLGameState()
for (size_t id=0 ; id<numPlayers ; id++)
{
ptree &playerNode = pt.add("Player", "");
playerNode.put("<xmlattr>.variant", id);
playerNode.put("<xmlattr>.variant", mInventoryVec[id].mSpriteVar);
playerNode.put("<xmlattr>.id", id);
auto &invNode = playerNode.put("inventory", "");
mInventoryVec[id] >> invNode;
}
......
......@@ -293,7 +293,7 @@ void CGalaxySpriteObject::setActionSprite()
if(mSpriteIdx >= 0)
{
GsSprite &rSprite = gGraphics.getSprite(mSprVar,mSpriteIdx);
GsSprite &rSprite = gGraphics.getSprite(mSprVar, mSpriteIdx);
oldBoxY2 = rSprite.m_bboxY2;
oldBoxY1 = rSprite.m_bboxY1;
}
......
......@@ -13,8 +13,10 @@
#include "graphics/effects/CScrollEffect.h"
CInventory::CInventory(const int id) :
m_HUD(Item.m_points, Item.m_lifes, Item.m_bullets, id)
CInventory::CInventory(const int playerIdx,
const int spriteVar) :
m_HUD(Item.m_points, Item.m_lifes, Item.m_bullets,
playerIdx, spriteVar)
{
reset();
......@@ -123,10 +125,11 @@ void CInventory::drawHUD()
m_HUD.render();
}
void CInventory::setup(const int sprVar)
void CInventory::setup(const int playerIdx,
const int sprVar)
{
mSpriteVar = sprVar;
m_HUD.setup(sprVar);
m_HUD.setup(playerIdx, sprVar);
}
void CInventory::drawStatus()
......
......@@ -23,13 +23,14 @@
class CInventory
{
public:
CInventory(const int id = 0);
CInventory(const int playerIdx = 0,
const int spriteVar = 0);
void reset();
// This function draws the HUD on the Screen
void drawHUD();
void setup(const int sprVar);
void setup(const int playerIdx, const int sprVar);
// This one draw the Status screen whenever it's called
void drawStatus();
......
......@@ -149,23 +149,22 @@ const int CPlayerBase::mEpisodeActionNumMap[3][NUM_KEEN_ACTIONS] =
//{}
};
CPlayerBase::CPlayerBase
(
CMap *pmap,
const Uint16 foeID,
Uint32 x,
Uint32 y,
direction_t facedir,
CInventory &l_Inventory,
int playerID,
int spriteVar
) :
CGalaxySpriteObject(pmap, foeID, x, y, spriteVar),
m_Inventory(l_Inventory),
m_camera(pmap,x,y,this),
mPlayerNum(playerID),
mPlayerCtrlNum(playerID)
CPlayerBase::
CPlayerBase(CMap *pmap,
const Uint16 foeID,
Uint32 x,
Uint32 y,
direction_t facedir,
CInventory &l_Inventory,
const int playerIdx,
const int spriteVar) :
CGalaxySpriteObject(pmap, foeID, x, y, spriteVar),
m_Inventory(l_Inventory),
m_camera(pmap,x,y,this),
mPlayerNum(playerIdx),
mPlayerCtrlNum(playerIdx)
{
mSpecialIdx = playerIdx;
mActionMap[A_KEEN_DIE] = &CPlayerBase::processDying;
mActionMap[A_KEEN_DIE_ALT] = &CPlayerBase::processDying;
......@@ -197,7 +196,8 @@ void CPlayerBase::processExiting()
gEffectController.setupEffect(new CDimDark(8));
auto evExit = new EventExitLevel(mpMap->getLevel(), true, false, mSprVar);
auto evExit = new EventExitLevel(mpMap->getLevel(),
true, false, mSpecialIdx);
evExit->playSound = true;
gEventManager.add( evExit );
m_Inventory.Item.m_gem.clear();
......
......@@ -129,8 +129,8 @@ public:
Uint32 y,
direction_t facedir,
CInventory &l_Inventory,
int playerID,
int spriteVar);
const int playerID,
const int spriteVar);
/**
......
......@@ -1821,7 +1821,8 @@ void CPlayerLevel::processEnterDoor()
gEffectController.setupEffect(new CDimDark(8));
auto evExit = new EventExitLevel(mpMap->getLevel(), true, mustTeleportOnMap, mSprVar);
auto evExit = new EventExitLevel(mpMap->getLevel(), true,
mustTeleportOnMap, mSpecialIdx);
evExit->playSound = true;
gEventManager.add( evExit );
......@@ -1837,7 +1838,7 @@ void CPlayerLevel::processEnterDoor()
gEffectController.setupEffect(new CDimDark(8));
gMusicPlayer.stop();
auto evExit = new EventExitLevel(mpMap->getLevel(), true, false, mSprVar);
auto evExit = new EventExitLevel(mpMap->getLevel(), true, false, mSpecialIdx);
evExit->playSound = true;
gEventManager.add( evExit );
......@@ -2728,7 +2729,7 @@ void CPlayerLevel::process()
gEffectController.setupEffect(new CDimDark(8));
auto evExit = new EventExitLevel(mpMap->getLevel(), true, false, mSprVar);
auto evExit = new EventExitLevel(mpMap->getLevel(), true, false, mSpecialIdx);
evExit->playSound = true;
msgs.push_back( new CMessageBoxBitmapGalaxy(
......
......@@ -149,7 +149,7 @@ void CPlayerWM::pumpEvent(const CEvent *evPtr)
// Events for the Player are processed here.
if( const EventPlayerEndLevel* ev = dynamic_cast<const EventPlayerEndLevel*>(evPtr) )
{
if(ev->who == mSprVar)
if(ev->who == mSpecialIdx)
{
gEventManager.flush();
if(ev->sucess)
......
......@@ -20,7 +20,8 @@ namespace galaxy {
class CSpriteItem : public CGalaxySpriteObject
{
public:
CSpriteItem(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y, Uint32 mSpriteIdx, const int sprVar, const bool gravity = false);
CSpriteItem(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y,
Uint32 mSpriteIdx, const int sprVar, const bool gravity = false);
void process();
void getTouchedBy(CSpriteObject &theObject);
......
......@@ -122,7 +122,7 @@ void CStunnable::draw()
int w = StarSprite.getWidth();
int h = StarSprite.getHeight();
auto visGA = gVideoDriver.mpVideoEngine->mRelativeVisGameArea;
const auto visGA = gVideoDriver.mpVideoEngine->mRelativeVisGameArea;
if( showX+StarSprite.getWidth() < visGA.x || showX > visGA.x+visGA.w )
return;
......
......@@ -211,7 +211,7 @@ void CPlatform::draw()
int showX = scrx+Sprite.getXOffset();
int showY = scry+Sprite.getYOffset();
auto visGA = gVideoDriver.mpVideoEngine->mRelativeVisGameArea;
const auto visGA = gVideoDriver.mpVideoEngine->mRelativeVisGameArea;
if( showX+Sprite.getWidth() < visGA.x || showX > visGA.x+visGA.w )
return;
......
......@@ -78,6 +78,9 @@ CGalaxySpriteObject* CMapLoaderGalaxyEp4::addFoe(CMap &Map, word foe, size_t x,
CGalaxySpriteObject* p_newfoe = nullptr;
const int totalNumPlayer = mInventoryVec.size();
const int variations = gGraphics.spriteVecVec().size();
// Point Item Sprites (Candies, etc...)
for( Uint32 i=61 ; i<=67 ; i++ )
......@@ -85,7 +88,8 @@ CGalaxySpriteObject* CMapLoaderGalaxyEp4::addFoe(CMap &Map, word foe, size_t x,
if( foe == i )
{
const Uint32 newsprite = 103+2*(i-61);
p_newfoe = new galaxy::CSpriteItem(&Map, foe, x, y, newsprite, 0);
p_newfoe = new galaxy::CSpriteItem(&Map, foe, x, y,
newsprite, x%variations);
}
}
......@@ -116,6 +120,7 @@ CGalaxySpriteObject* CMapLoaderGalaxyEp4::addFoe(CMap &Map, word foe, size_t x,
// otherwise look for special foe.
Vector2D<Uint32> loc(x,y);
switch(foe)
{
case 0x01:
......@@ -130,7 +135,8 @@ CGalaxySpriteObject* CMapLoaderGalaxyEp4::addFoe(CMap &Map, word foe, size_t x,
inventory.Item.mLevelName = Map.getLevelName();
p_newfoe = new galaxy::CPlayerLevel(&Map, foe, x, y, m_ObjectPtr,
(foe==0x01) ? RIGHT : LEFT, inventory, 0x98C,
mNumLoadedPlayers, inventory.mSpriteVar);
mNumLoadedPlayers,
inventory.mSpriteVar);
}
mNumLoadedPlayers++;
}
......@@ -148,7 +154,8 @@ CGalaxySpriteObject* CMapLoaderGalaxyEp4::addFoe(CMap &Map, word foe, size_t x,
// Add the Camera into the game scene and attach it to this player
inventory.Item.mLevelName = Map.getLevelName();
p_newfoe = new galaxy::CPlayerWM(&Map, foe, x, y, inventory, 0x15C2,
mNumLoadedPlayers, mNumLoadedPlayers);
mNumLoadedPlayers,
inventory.mSpriteVar);
}
mNumLoadedPlayers++;
}
......
......@@ -226,7 +226,9 @@ void CCouncilMember::getTouchedBy(CSpriteObject &theObject)
}
else
{
auto evExit = new EventExitLevel(mpMap->getLevel(), true, false, mSprVar);
auto evExit = new EventExitLevel(mpMap->getLevel(),
true, false,
player->getSpecialIdx());
evExit->playSound = true;
msgs.push_back( new CMessageBoxBitmapGalaxy(
......
......@@ -36,7 +36,7 @@ void CDiveSuit::getTouchedBy(CSpriteObject &theObject)
gSound.playSound( SOUND_GET_WETSUIT, SoundPlayMode::PLAY_PAUSEALL );
taken = swimsuit = true;
auto evExit = new EventExitLevel(mpMap->getLevel(), true, false, mSprVar);
auto evExit = new EventExitLevel(mpMap->getLevel(), true, false, player->getSpecialIdx());
evExit->playSound = true;
......
......@@ -27,7 +27,7 @@ void CFoot::getTouchedBy(CSpriteObject &theObject)
{
if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
{
gEventManager.add( new EventExitLevelWithFoot(mpMap->getLevel(), player->getSpriteVariantId()) );
gEventManager.add( new EventExitLevelWithFoot(mpMap->getLevel(), player->getSpecialIdx()) );
player->m_Inventory.Item.m_gem.clear();
}
}
......
......@@ -39,7 +39,7 @@ void CSpecialItem::getTouchedBy(CSpriteObject& theObject)
default: break;
}
auto exitEvent = new EventExitLevel(mpMap->getLevel(), true, false, mSprVar);
auto exitEvent = new EventExitLevel(mpMap->getLevel(), true, false, player->getSpecialIdx());
// Play it but afterwards
exitEvent->playSound = true;
......
......@@ -16,74 +16,6 @@
#include "../../menu/CSelectionMenu.h"
#include "widgets/Button.h"
/*
namespace galaxy
{
template <class _T>
class CPlayersSelection : public GalaxyMenu
{
public:
CPlayersSelection(bool numFirst = false) :
GalaxyMenu( GsRect<float>(0.25f, 0.35f, 0.5f, 0.3f) )
{
std::string playerStr;
for( unsigned int i = 1 ; i <= MAX_PLAYERS ; i++ )
{
if(numFirst)
playerStr = itoa(i) + " Player";
else
playerStr = "Player " + itoa(i);
GameButton *button = new GameButton( playerStr, new _T(i) );
mpButtonList.push_back( button );
mpMenuDialog->addControl( mpButtonList.back() );
}
}
std::list<GameButton*> mpButtonList;
};
class CDifficultySelection : public GalaxyMenu
{
public:
CDifficultySelection() :
GalaxyMenu( GsRect<float>(0.25f, 0.2f, 0.5f, 0.5f) )
{
mpMenuDialog->addControl( new GameButton( "EASY", new StartNewGameEvent(EASY) ) );
mpMenuDialog->addControl( new GameButton( "NORMAL", new StartNewGameEvent(NORMAL) ) );
mpMenuDialog->addControl( new GameButton( "HARD", new StartNewGameEvent(HARD) ) );
mpMenuDialog->addControl( new GameButton( "EXPERT", new StartNewGameEvent(EXPERT) ) );
mpMenuDialog->addControl( new GameButton( "NINJA", new StartNewGameEvent(NINJA) ) );
mpMenuDialog->addControl( new GameButton( "ELITE", new StartNewGameEvent(ELITE) ) );
setMenuLabel("NEWGAMELABEL");
mpMenuDialog->setSelection(1);
}
};
class CPlayerSpriteVarSelection : public GalaxyMenu
{
public:
CPlayerSpriteVarSelection() :
GalaxyMenu( GsRect<float>(0.25f, 0.2f, 0.5f, 0.5f) )
{
mpMenuDialog->addControl( new GameButton( "Sprite 1", new SelectPlayerSpriteVarEvent(0)) );
mpMenuDialog->addControl( new GameButton( "Sprite 2", new SelectPlayerSpriteVarEvent(1)) );
mpMenuDialog->addControl( new GameButton( "Sprite 3", new SelectPlayerSpriteVarEvent(2)) );
mpMenuDialog->addControl( new GameButton( "Sprite 4", new SelectPlayerSpriteVarEvent(3)) );
setMenuLabel("NEWGAMELABEL");
}
};
}
*/
#endif /* CGALAXYSELECTIONMENU_H_ */
......@@ -137,7 +137,8 @@ void CPlayGameVorticon::setupPlayers()
stInventory &inventory = m_Player.at(i).inventory;
mpHUDVec.push_back( move(std::unique_ptr<CHUD>(new CHUD(inventory.score, inventory.lives,
inventory.charges, i))) );
inventory.charges, i,
i))) );
}
}
......
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