Commit c0d357b3 authored by Gerhard Stein's avatar Gerhard Stein

bridges are working again. Separated from the SE class.

parent ceb818e8
......@@ -54,8 +54,6 @@ public:
virtual ~CBehaviorEngine();
bool m_PlatExtending;
private:
std::vector<CTileProperties> m_TileProperties[2];
CPhysicsSettings m_PhysicsSettings;
......
......@@ -85,6 +85,7 @@ public:
bool m_animation_enabled;
bool m_Dark;
char m_Difficulty;
bool m_PlatExtending;
private:
......
......@@ -22,6 +22,8 @@
#include "../engine/vorticon/CCamera.h"
#include <stdlib.h>
size_t CPlayer::m_playerID = 0;
///
// Initialization Part
///
......@@ -38,8 +40,10 @@ mp_levels_completed(mp_level_completed),
mp_option(mp_option),
mp_StatusScr(NULL)
{
m_playerID++;
mp_object = &m_Object;
canbezapped = true;
m_index = 0;
// Ankhshield is a special object the player is holded.
// It's normally seen in Ep3 and when he gets invincible by the ankh
......@@ -892,4 +896,5 @@ bool CPlayer::drawStatusScreen()
// Cleanup Part
///
CPlayer::~CPlayer() {
m_playerID--;
}
......@@ -55,7 +55,7 @@ public:
int getNewObject();
// In Level specific
void processInLevel(const bool &platextending);
void processInLevel();
void touchedExit(int mpx);
void walkbehindexitdoor();
void kill(bool force);
......@@ -65,7 +65,7 @@ public:
void getgoodies();
void playpushed();
void keencicle();
void TogglePogo_and_Switches(const bool &platextending);
void TogglePogo_and_Switches();
void JumpAndPogo();
void Playerfalling();
void raygun();
......@@ -183,6 +183,15 @@ public:
stOption *mp_option;
private:
// defined under CPlayerItems.cpp
bool getGoodie(int px, int py);
void procGoodie(int tile, int mpx, int mpy);
void riseBonus(int spr, int x, int y);
void getBonuspoints(int numpts, int mpx, int mpy);
void incScore(int numpts);
void openDoor(int doortile, int doorsprite, int mpx, int mpy);
void giveAnkh();
CStatusScreen *mp_StatusScr;
bool lastpogo;
......@@ -194,14 +203,8 @@ private:
level_triggers m_Level_Trigger;
// defined under CPlayerItems.cpp
bool getGoodie(int px, int py);
void procGoodie(int tile, int mpx, int mpy);
void riseBonus(int spr, int x, int y);
void getBonuspoints(int numpts, int mpx, int mpy);
void incScore(int numpts);
void openDoor(int doortile, int doorsprite, int mpx, int mpy);
void giveAnkh();
static size_t m_playerID;
};
#endif /* CPLAYER_H_ */
......@@ -9,6 +9,7 @@
#include "../engine/vorticon/ai/CSectorEffector.h"
#include "../engine/vorticon/ai/CRay.h"
#include "../engine/vorticon/ai/CBridges.h"
#include "../engine/spritedefines.h"
#include "../keen.h"
#include "../sdl/sound/CSound.h"
......@@ -21,7 +22,7 @@
////
// Process the stuff of the player when playing in a normal level
void CPlayer::processInLevel(const bool &platextending)
void CPlayer::processInLevel()
{
StatusBox();
......@@ -67,7 +68,7 @@ void CPlayer::processInLevel(const bool &platextending)
InertiaAndFriction_X();
TogglePogo_and_Switches(platextending);
TogglePogo_and_Switches();
JumpAndPogo();
// Check collision with other objects
......@@ -307,7 +308,7 @@ void CPlayer::playpushed()
}
// allow Keen to toggle the pogo stick and hit switches
void CPlayer::TogglePogo_and_Switches(const bool &platextending)
void CPlayer::TogglePogo_and_Switches()
{
int i;
int mx, my;
......@@ -347,7 +348,7 @@ void CPlayer::TogglePogo_and_Switches(const bool &platextending)
}
else
{
if(!platextending)
if(!mp_Map->m_PlatExtending)
{
m_Level_Trigger = LVLTRIG_BRIDGE;
char pxoff = (bridge & 0x00ff);
......@@ -356,11 +357,9 @@ void CPlayer::TogglePogo_and_Switches(const bool &platextending)
int platy = my + pyoff;
// spawn a "sector effector" to extend/retract the platform
//CSectorEffector *platobject = new CSectorEffector(mp_Map, mx<<CSF,my<<CSF,
// ,*mp_object, SE_EXTEND_PLATFORM);
//platobject->platx = platx;
//platobject->platy = platy;
//mp_object->push_back(platobject);
CBridges *platobject = new CBridges(mp_Map, mx<<CSF,my<<CSF,
platx, platy);
mp_object->push_back(platobject);
}
}
......
......@@ -56,6 +56,10 @@ void CPlayGameGalaxy::process()
processInput();
// process WM. If a level is open process it also in this class
// process Finale
processRendering();
}
......
/*
* CBridges.cpp
*
* Created on: 10.07.2010
* Author: gerstrong
*/
#include "CBridges.h"
#include "../../spritedefines.h"
#include "../../../CLogFile.h"
unsigned int CBridges::m_bgtile = 0;
CBridges::CBridges(CMap *pmap, Uint32 x, Uint32 y, Uint32 platx, Uint32 platy):
CObject(pmap, x, y, OBJ_NONE),
m_state(EXTEND),
m_platx(platx),
m_platy(platy),
m_dir(LEFT)
{
timer = 0;
inhibitfall = true;
canbezapped = false;
sprite = BLANKSPRITE;
// if the platform is already extended, turn ourselves
// into an se_retract_plat()
if ( mp_Map->at(m_platx, m_platy) == TILE_EXTENDING_PLATFORM )
{
// figure out which direction the bridge is supposed to go
//if(platx-1 > m_Objvect.size())
//return;
m_state = RETRACT;
if (mp_Map->at(m_platx-1, m_platy) != TILE_EXTENDING_PLATFORM)
m_dir = LEFT;
else if(mp_Map->at(m_platx+1, m_platy) != TILE_EXTENDING_PLATFORM)
m_dir = RIGHT;
else
m_dir = LEFT;
// scan across until we find the end of the platform--that will
// be where we will start (remove platform in oppisote direction
// it was extended)
do
{
if (mp_Map->at(m_platx, m_platy) != TILE_EXTENDING_PLATFORM)
{ // we've found the end of the platform
break;
}
if (m_dir==LEFT)
{
if (m_platx==mp_Map->m_width)
{
g_pLogFile->ftextOut("SE_RETRACT_PLATFORM: Failed to find end of platform when scanning right.");
return;
}
m_platx++;
}
else
{ // platform will be removed in a right-going direction
if (m_platx==0)
{
g_pLogFile->ftextOut("SE_RETRACT_PLATFORM: Failed to find end of platform when scanning left.");
return;
}
m_platx--;
}
} while(1);
// when we were scanning we went one tile too far, go back one
if (m_dir==LEFT) m_platx--;
else m_platx++;
return;
}
// figure out which direction the bridge is supposed to go
CTileProperties &TileProperties = g_pBehaviorEngine->getTileProperties(1).at(mp_Map->at(m_platx+1, m_platy));
if (!TileProperties.bleft)
m_dir = RIGHT;
else
m_dir = LEFT;
// get the background tile from the tile above the starting point
if(m_dir == RIGHT)
m_bgtile = mp_Map->at(m_platx+1, m_platy);
else
m_bgtile = mp_Map->at(m_platx-1, m_platy);
}
void CBridges::process()
{
if(m_state == EXTEND)
extend();
else
retract();
}
void CBridges::extend()
{
#define PLAT_EXTEND_RATE 3
std::vector<CTileProperties> &TileProperties = g_pBehaviorEngine->getTileProperties();
if (!timer)
{
if (m_dir==RIGHT &&
!TileProperties[mp_Map->at(m_platx, m_platy)].bleft)
{
mp_Map->changeTile(m_platx, m_platy, TILE_EXTENDING_PLATFORM);
m_platx++;
timer = PLAT_EXTEND_RATE;
}
else if(m_dir==LEFT &&
!TileProperties[mp_Map->at(m_platx, m_platy)].bright)
{
mp_Map->changeTile(m_platx, m_platy, TILE_EXTENDING_PLATFORM);
m_platx--;
timer = PLAT_EXTEND_RATE;
}
else
{
exists = false;
mp_Map->m_PlatExtending = false;
return;
}
}
else timer--;
}
void CBridges::retract()
{
if (!timer)
{
if (mp_Map->at(m_platx, m_platy) == TILE_EXTENDING_PLATFORM)
{
mp_Map->setTile(m_platx, m_platy, m_bgtile, true);
if (m_dir==RIGHT)
m_platx++;
else
m_platx--;
timer = PLAT_EXTEND_RATE;
}
else
{
exists = false;
mp_Map->m_PlatExtending = false;
}
}
else timer--;
}
CBridges::~CBridges() {
// TODO Auto-generated destructor stub
}
/*
* CBridges.h
*
* Created on: 10.07.2010
* Author: gerstrong
*/
#ifndef CBRIDGES_H_
#define CBRIDGES_H_
#include "../../../common/CObject.h"
class CBridges : public CObject
{
public:
CBridges(CMap *pmap, Uint32 x, Uint32 y, Uint32 platx, Uint32 platy);
void process();
void extend();
void retract();
virtual ~CBridges();
private:
enum{
EXTEND,
RETRACT
}m_state;
int timer;
Uint32 m_platx;
Uint32 m_platy;
direction_t m_dir;
static unsigned int m_bgtile;
};
#endif /* CBRIDGES_H_ */
......@@ -23,8 +23,7 @@ CSectorEffector::CSectorEffector(CMap *p_map, Uint32 x, Uint32 y,
CObject(p_map, x, y, OBJ_SECTOREFFECTOR),
setype(se_type),
m_Player(Player),
m_Object(Object),
m_PlatExtending(g_pBehaviorEngine->m_PlatExtending)
m_Object(Object)
{}
......@@ -32,8 +31,6 @@ void CSectorEffector::process()
{
switch(setype)
{
case SE_EXTEND_PLATFORM: se_extend_plat(); break;
case SE_RETRACT_PLATFORM: se_retract_plat( ); break;
case SE_MORTIMER_ARM: se_mortimer_arm(); break;
case SE_MORTIMER_LEG_LEFT: se_mortimer_leg_left(); break;
case SE_MORTIMER_LEG_RIGHT: se_mortimer_leg_right(); break;
......@@ -49,79 +46,8 @@ void CSectorEffector::process()
}
void CSectorEffector::se_extend_plat()
{
#define PLAT_EXTEND_RATE 3
std::vector<CTileProperties> &TileProperties = g_pBehaviorEngine->getTileProperties();
if (needinit)
{
timer = 0;
inhibitfall = true;
canbezapped = false;
sprite = BLANKSPRITE;
// if the platform is already extended, turn ourselves
// into an se_retract_plat()
if ( mp_Map->at(platx, platy) == TILE_EXTENDING_PLATFORM )
{
setype = SE_RETRACT_PLATFORM;
se_retract_plat();
return;
}
// figure out which direction the bridge is supposed to go
if (!TileProperties[mp_Map->at(platx+1, platy)].bleft)
dir = RIGHT;
else
dir = LEFT;
// get the background tile from the tile above the starting point
if(dir == RIGHT)
m_bgtile = mp_Map->at(platx+1, platy);
else
m_bgtile = mp_Map->at(platx-1, platy);
needinit = false;
}
if (!timer)
{
if (dir==RIGHT &&
!TileProperties[mp_Map->at(platx, platy)].bleft)
{
mp_Map->changeTile(platx, platy, TILE_EXTENDING_PLATFORM);
platx++;
timer = PLAT_EXTEND_RATE;
}
else if(dir==LEFT &&
!TileProperties[mp_Map->at(platx, platy)].bright)
{
mp_Map->changeTile(platx, platy, TILE_EXTENDING_PLATFORM);
platx--;
timer = PLAT_EXTEND_RATE;
}
else
{
exists = false;
m_PlatExtending = false;
return;
}
}
else timer--;
}
void CSectorEffector::getTouchedBy(CObject &theObject)
{
if(setype == SE_EXTEND_PLATFORM)
{
if (!timer)
{
kill_intersecting_tile(platx, platy, theObject);
}
}
bool it_is_mortimer_machine = false;
it_is_mortimer_machine = (setype == SE_MORTIMER_LEG_LEFT)
......@@ -138,80 +64,6 @@ void CSectorEffector::getTouchedBy(CObject &theObject)
}
}
void CSectorEffector::se_retract_plat()
{
if (needinit)
{
// figure out which direction the bridge is supposed to go
//if(platx-1 > m_Objvect.size())
//return;
if (mp_Map->at(platx-1, platy) != TILE_EXTENDING_PLATFORM)
dir = LEFT;
else if(mp_Map->at(platx+1, platy) != TILE_EXTENDING_PLATFORM)
dir = RIGHT;
else
dir = LEFT;
// scan across until we find the end of the platform--that will
// be where we will start (remove platform in oppisote direction
// it was extended)
do
{
if (mp_Map->at(platx, platy) != TILE_EXTENDING_PLATFORM)
{ // we've found the end of the platform
break;
}
if (dir==LEFT)
{
if (platx==mp_Map->m_width)
{
g_pLogFile->ftextOut("SE_RETRACT_PLATFORM: Failed to find end of platform when scanning right.");
return;
}
platx++;
}
else
{ // platform will be removed in a right-going direction
if (platx==0)
{
g_pLogFile->ftextOut("SE_RETRACT_PLATFORM: Failed to find end of platform when scanning left.");
return;
}
platx--;
}
} while(1);
// when we were scanning we went one tile too far, go back one
if (dir==LEFT) platx--;
else platx++;
needinit = false;
}
if (!timer)
{
if (mp_Map->at(platx, platy) == TILE_EXTENDING_PLATFORM)
{
mp_Map->setTile(platx, platy, m_bgtile, true);
if (dir==RIGHT)
platx++;
else
platx--;
timer = PLAT_EXTEND_RATE;
}
else
{
exists = false;
m_PlatExtending = false;
}
}
else timer--;
}
#define ARM_GO 0
#define ARM_WAIT 1
......
......@@ -15,8 +15,6 @@
// "Sector Effector" types
enum sector_effector_type{
SE_EXTEND_PLATFORM,
SE_RETRACT_PLATFORM,
SE_MORTIMER_ARM,
SE_MORTIMER_LEG_LEFT,
SE_MORTIMER_LEG_RIGHT,
......@@ -60,8 +58,6 @@ public:
std::vector<CPlayer>& m_Player;
std::vector<CObject*>& m_Object;
bool &m_PlatExtending;
unsigned int m_bgtile;
};
#endif /* SE_H_ */
......@@ -23,7 +23,7 @@ void CPlayGameVorticon::processInLevel()
continue;
// Process the other stuff like, items, jump, etc.
m_Player[i].processInLevel(getPlatMoving());
m_Player[i].processInLevel();
// If the player touched a hint trigger in which we have to show a Message, do it so
std::string hinttext;
......@@ -89,9 +89,9 @@ void CPlayGameVorticon::processLevelTrigger(int trigger)
else if (trigger == LVLTRIG_BRIDGE)
{ // it's a moving platform switch--don't allow player to hit it again while
// the plat is still moving as this will glitch
if (!getPlatMoving())
if (!m_Map.m_PlatExtending)
{
triggerPlat(true);
m_Map.m_PlatExtending = true;
}
// The spawning of the plat extension is defined in the CPlayer class
}
......
......@@ -30,8 +30,7 @@ CPlayGame(ExeFile, level, numplayers, difficulty, p_option),
mp_ObjectAI(NULL),
m_SavedGame(SavedGame),
mp_HighScores(NULL),
mp_HUD(NULL),
PlatExtending(false)
mp_HUD(NULL)
{
mp_Menu = NULL;
mp_Finale = NULL;
......
......@@ -91,10 +91,6 @@ public:
void readTeleportDestCoordinatesEP1(int objectID, int &destx, int &desty);
void readTeleportDestCoordinatesEP3(int objectID, int &destx, int &desty);
// Platform stuff
bool getPlatMoving() { return PlatExtending; }
void triggerPlat(bool value) { PlatExtending = value; }
void cleanup();
virtual ~CPlayGameVorticon();
......@@ -113,8 +109,5 @@ private:
std::vector<CObject*> m_Object;
CHighScores *mp_HighScores;
CHUD *mp_HUD;
// if true, a moving platform is currently extending/retracting (ep2)
bool PlatExtending;
};
#endif /* CPlayGameVorticon_H_ */
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