Commit bc8689d8 authored by Gerhard Stein's avatar Gerhard Stein

Merge branch 'saves' of github.com:gerstrong/Commander-Genius

Conflicts:
	build/Xcode/CommanderGenius.xcodeproj/project.pbxproj
parents 56fc3c7e 0616245e
......@@ -275,13 +275,43 @@ bool CSpriteObject::hitdetectWithTileProperty(const int Property, const int x, c
return false;
}
const int COLISION_RES = (1<<STC);
bool CSpriteObject::checkMapBoundaryR(const int x2)
{
if( (Uint16)x2 > ((mp_Map->m_width)<<CSF) ) // Out of map?
{
exists = false; // deactivate it!
return true;
}
return false;
}
bool CSpriteObject::checkMapBoundaryL(const int x1)
{
if( x1 == 0 ) // Out of map?
{
exists = false; // deactivate it!
return true;
}
return false;
}
bool CSpriteObject::checkMapBoundaryU(const int y1)
{
if( y1 <= (1<<CSF) )
return true;
return false;
}
int CSpriteObject::checkSolidR( int x1, int x2, int y1, int y2)
{
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
int blocker;
bool vorticon = (g_pBehaviorEngine->getEpisode() <= 3);
x2 += COLISION_RES;
......@@ -303,33 +333,11 @@ int CSpriteObject::checkSolidR( int x1, int x2, int y1, int y2)
return blocker;
}
if( m_type == OBJ_PLAYER && solid )
{
if(vorticon)
{
if( x2 >= (int)((mp_Map->m_width-2)<<CSF) ) return 1;
}
else
{
if( x2 >= (int)((mp_Map->m_width-1)<<CSF) ) return 1;
}
}
else
{
if( (Uint16)x2 > ((mp_Map->m_width)<<CSF) )
{
exists=false; // Out of map?
return 1;
}
}
return 0;
return checkMapBoundaryR(x2) ? 1 : 0;
}
int CSpriteObject::checkSolidL( int x1, int x2, int y1, int y2)
{
bool vorticon = (g_pBehaviorEngine->getEpisode() <= 3);
int blocker;
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
......@@ -356,21 +364,7 @@ int CSpriteObject::checkSolidL( int x1, int x2, int y1, int y2)
return 0;
}
// borders
if( m_type == OBJ_PLAYER && solid )
{
if( vorticon && (x1 <= (2<<CSF)) ) return 1;
else if( x1 <= (1<<CSF) ) return 1;
}
else
{
if( x1 == 0 )
{
exists = false; // Out of map?
return 1;
}
}
return 0;
return checkMapBoundaryL(x1) ? 1 : 0;
}
int CSpriteObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
......@@ -430,10 +424,7 @@ int CSpriteObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
}
}
if( y1 <= ( ((m_type == OBJ_PLAYER) ? 2 : 1)<<CSF) )
return 1;
return 0;
return checkMapBoundaryU(y1) ? 1 : 0;
}
int CSpriteObject::checkSolidD( int x1, int x2, int y2, const bool push_mode )
......@@ -733,7 +724,7 @@ void CSpriteObject::processPushOutCollision()
const unsigned int y1 = getYPosition()+m_BBox.y1;
const unsigned int y2 = getYPosition()+m_BBox.y2;
if( checkSolidL(x1, x2, y1, y2) /*&& checkSolidR(x1, x2, y1, y2)*/ )
if( checkSolidL(x1, x2, y1, y2) )
{
// Push him right to the position where he is not blocked anymore
int should_x = x1;
......
......@@ -25,8 +25,8 @@
///
CPlayer::CPlayer(const char &Episode, short &Level,
bool *mp_level_completed,
std::vector<CSpriteObject*> &m_Object, CMap &map) :
CSpriteObject(&map, 0, 0, OBJ_PLAYER),
std::vector<CVorticonSpriteObject*> &m_Object, CMap &map) :
CVorticonSpriteObject(&map, 0, 0, OBJ_PLAYER),
m_episode(Episode),
m_level(Level),
pjumpupspeed_decrease(g_pBehaviorEngine->getPhysicsSettings().player.defaultjumpupdecreasespeed),
......@@ -806,11 +806,38 @@ void CPlayer::freeze()
playcontrol[PA_X] = 0;
}
bool CPlayer::checkMapBoundaryR(const int x2)
{
if( solid && x2 >= (int)((mp_Map->m_width-2)<<CSF) )
return true;
return false;
}
bool CPlayer::checkMapBoundaryL(const int x1)
{
if( solid && x1 <= (2<<CSF) )
return true;
return false;
}
bool CPlayer::checkMapBoundaryU(const int y1)
{
if( y1 <= (2<<CSF) )
return true;
return false;
}
bool CPlayer::checkObjSolid()
{
supportedbyobject = false;
std::vector<CSpriteObject*>::iterator it_obj = mp_object->begin();
std::vector<CVorticonSpriteObject*>::iterator it_obj = mp_object->begin();
for( ; it_obj != mp_object->end() ; it_obj++ )
{
if((*it_obj)->cansupportplayer)
......
......@@ -10,7 +10,7 @@
#include <SDL.h>
#include "inventory.h"
#include "CSpriteObject.h"
#include "engine/vorticon/CVorticonSpriteObject.h"
#include "CMap.h"
#include "CStatusScreen.h"
#include "Playerdefines.h"
......@@ -32,7 +32,7 @@ enum level_triggers
///
// Class definition starts here!
///
class CPlayer : public CSpriteObject
class CPlayer : public CVorticonSpriteObject
{
public:
......@@ -44,7 +44,7 @@ public:
CPlayer(const char &Episode, short &Level,
bool *mp_level_completed,
std::vector<CSpriteObject*> &m_Object, CMap &map);
std::vector<CVorticonSpriteObject*> &m_Object, CMap &map);
void setupCameraObject();
void setDatatoZero();
void setDefaultStartValues();
......@@ -86,6 +86,10 @@ public:
int pollLevelTrigger();
void getShotByRay(object_t &obj_type);
bool checkMapBoundaryL(const int x1);
bool checkMapBoundaryR(const int x2);
bool checkMapBoundaryU(const int y1);
// Used for both situations
void processCamera();
void InertiaAndFriction_X();
......@@ -207,6 +211,8 @@ private:
int level_done_timer;
level_triggers m_Level_Trigger;
std::vector<CVorticonSpriteObject*> *mp_object;
};
#endif /* CPLAYER_H_ */
......@@ -340,7 +340,7 @@ void CPlayer::TogglePogo_and_Switches()
if(mp_Map->m_PlatExtending)
{
// Find the object responsible for extending
std::vector<CSpriteObject*>::iterator obj = mp_object->begin();
std::vector<CVorticonSpriteObject*>::iterator obj = mp_object->begin();
for( ; obj != mp_object->end() ; obj++ )
{
if((*obj)->m_type == OBJ_BRIDGE && (*obj)->exists &&
......
......@@ -160,7 +160,7 @@ void CPlayer::selectFrameOnWorldMap()
void CPlayer::MountNessieIfAvailable()
{
// Look for the Nessie object
std::vector<CSpriteObject*>::iterator obj = mp_object->begin();
std::vector<CVorticonSpriteObject*>::iterator obj = mp_object->begin();
for(; obj != mp_object->end() ; obj++)
{
if((*obj)->m_type == OBJ_MESSIE)
......@@ -206,7 +206,7 @@ void CPlayer::UnmountNessie()
if(mp_Map->getObjectat(x+dx, y+dy) == NESSIE_LAND)
{
// Look for the Nessie object
std::vector<CSpriteObject*>::iterator obj = mp_object->begin();
std::vector<CVorticonSpriteObject*>::iterator obj = mp_object->begin();
for(; obj != mp_object->end() ; obj++)
{
if((*obj)->m_type == OBJ_MESSIE)
......
......@@ -5,9 +5,9 @@
* Author: gerstrong
*/
#include "engine/spritedefines.h"
#include "CSpriteObject.h"
#include "CLogFile.h"
#include "engine/spritedefines.h"
#include "sdl/CVideoDriver.h"
int CSpriteObject::m_number_of_objects = 0; // The current number of total objects we have within the game!
......@@ -15,12 +15,10 @@ int CSpriteObject::m_number_of_objects = 0; // The current number of total objec
///
// Initialization Routine
///
CSpriteObject::CSpriteObject(CMap *pmap, Uint32 x, Uint32 y, object_t type) :
m_type(type),
CSpriteObject::CSpriteObject(CMap *pmap, Uint32 x, Uint32 y) :
m_index(m_number_of_objects),
mHealthPoints(1),
sprite(BLANKSPRITE),
mp_object(NULL),
mp_Map(pmap),
m_blinktime(0),
m_invincible(false),
......@@ -57,79 +55,8 @@ transluceny(0)
blockedu = false;
blockedl = false;
blockedr = false;
if(m_type != OBJ_NONE )
{
setupObjectType(g_pBehaviorEngine->getEpisode());
performCollisions();
}
}
void CSpriteObject::setupObjectType(int Episode)
{
switch(m_type)
{
// Mainly Episode 1
case OBJ_GARG: sprite = OBJ_GARG_DEFSPRITE; break;
case OBJ_BUTLER: sprite = OBJ_BUTLER_DEFSPRITE; break;
case OBJ_TANK: sprite = OBJ_BUTLER_DEFSPRITE; break;
case OBJ_ICECHUNK: sprite = OBJ_ICECHUNK_DEFSPRITE; break;
case OBJ_ICEBIT: sprite = OBJ_ICEBIT_DEFSPRITE; break;
case OBJ_ICECANNON: sprite = OBJ_ICECHUNK_DEFSPRITE; break;
case OBJ_ROPE: sprite = OBJ_ROPE_DEFSPRITE; break;
// Mainly Episode 2
case OBJ_SCRUB: sprite = OBJ_SCRUB_DEFSPRITE; break;
case OBJ_GUARDROBOT: sprite = OBJ_TANKEP2_DEFSPRITE; break;
case OBJ_VORTELITE: sprite = OBJ_VORTELITE_DEFSPRITE; break;
case OBJ_SPARK: sprite = OBJ_SPARK_DEFSPRITE_EP2; break;
// Mainly Episode 3
case OBJ_FOOB: sprite = OBJ_FOOB_DEFSPRITE; break;
case OBJ_NINJA: sprite = OBJ_NINJA_DEFSPRITE; break;
case OBJ_MOTHER: sprite = OBJ_MOTHER_DEFSPRITE; break;
case OBJ_MEEP: sprite = OBJ_MEEP_DEFSPRITE; break;
case OBJ_BALL: sprite = OBJ_BALL_DEFSPRITE; break;
case OBJ_JACK: sprite = OBJ_JACK_DEFSPRITE; break;
case OBJ_MESSIE: sprite = OBJ_NESSIE_DEFSPRITE; break;
case OBJ_AUTORAY_V: sprite = RAY_VERT_EP3; break;
case OBJ_SNDWAVE: sprite = OBJ_SNDWAVE_DEFSPRITE; break;
case OBJ_VORT:
{
if(Episode == 1) sprite = OBJ_VORT_DEFSPRITE_EP1;
else if(Episode == 2) sprite = OBJ_VORT_DEFSPRITE_EP2;
else if(Episode == 3) sprite = OBJ_VORT_DEFSPRITE_EP3;
}break;
case OBJ_BABY:
{
if(Episode == 2) sprite = OBJ_BABY_DEFSPRITE_EP2;
else sprite = OBJ_BABY_DEFSPRITE_EP3;
}break;
case OBJ_PLATFORM:
case OBJ_PLATVERT:
{
if(Episode == 2) sprite = OBJ_PLATFORM_DEFSPRITE_EP2;
else sprite = OBJ_PLATFORM_DEFSPRITE_EP3;
}break;
case OBJ_AUTORAY: {
if(Episode == 1) sprite = ENEMYRAY;
else if(Episode == 2) sprite = ENEMYRAYEP2;
sprite = ENEMYRAYEP3;
}break;
case OBJ_DOOR: sprite = DOOR_YELLOW_SPRITE; break;
case OBJ_TELEPORTER: sprite = OBJ_TELEPORTER_DEFSPRITE; break;
case OBJ_SECTOREFFECTOR: sprite = BLANKSPRITE; break;
case OBJ_GOTPOINTS: sprite = PT500_SPRITE; break;
default: sprite = BLANKSPRITE; break;
}
}
void CSpriteObject::setScrPos( int px, int py )
{
......@@ -144,67 +71,18 @@ bool CSpriteObject::calcVisibility()
{
int &visibility = g_pBehaviorEngine->getPhysicsSettings().misc.visibility;
// Platform are always active
if( m_type == OBJ_PLATFORM || m_type == OBJ_PLATVERT )
return true;
// If an object is in the mid-air still moves it still,
// until it gets stuck to ceiling, wall or floor
if( !blockedd && m_type!=OBJ_SCRUB ) return true;
SDL_Rect gameres = g_pVideoDriver->getGameResolution().SDLRect();
Uint32 left = (((mp_Map->m_scrollx<<STC)-(visibility<<CSF))<0) ? 0 :
const Uint32 left = (((mp_Map->m_scrollx<<STC)-(visibility<<CSF))<0) ? 0 :
(mp_Map->m_scrollx<<STC)-(visibility<<CSF);
Uint32 right = ((mp_Map->m_scrollx+gameres.w)<<STC)+(visibility<<CSF);
Uint32 up = (((mp_Map->m_scrolly<<STC)-(visibility<<CSF))<0) ? 0 :
const Uint32 right = ((mp_Map->m_scrollx+gameres.w)<<STC)+(visibility<<CSF);
const Uint32 up = (((mp_Map->m_scrolly<<STC)-(visibility<<CSF))<0) ? 0 :
(mp_Map->m_scrolly<<STC)-(visibility<<CSF);
Uint32 down = ((mp_Map->m_scrolly+gameres.h)<<STC)+(visibility<<CSF);
const Uint32 down = ((mp_Map->m_scrolly+gameres.h)<<STC)+(visibility<<CSF);
bool inscreen = ( right > m_Pos.x && left < m_Pos.x && down > m_Pos.y && up < m_Pos.y );
// Bullets should disappear when offscreen
if(m_type == OBJ_SNDWAVE || m_type == OBJ_RAY || m_type == OBJ_FIREBALL)
{
if(!inscreen)
exists=false;
}
return inscreen;
return ( right > m_Pos.x && left < m_Pos.x && down > m_Pos.y && up < m_Pos.y );
}
/**
* This function will check if the enemy is in the limited scenario,
* so it will triggered. Happens normally when the Object is seen on the screen.
*/
bool CSpriteObject::checkforScenario()
{
if ( !exists || m_type==OBJ_PLAYER ) return false;
if( m_type==OBJ_EXPLOSION || m_type==OBJ_EARTHCHUNK
|| m_type == OBJ_BRIDGE || m_type == OBJ_NONE ) return true;
// Check if enemy is near enough. If he isn't, don't make him perform. Exception is on the map
if(!mp_Map->m_worldmap)
if(!calcVisibility()) return false;
onscreen = true;
if (hasbeenonscreen ||
m_type==OBJ_RAY || m_type==OBJ_ROPE ||
m_type==OBJ_ICECANNON ||
m_type==OBJ_ICECHUNK || m_type==OBJ_PLATFORM ||
m_type==OBJ_PLATVERT || m_type==OBJ_YORP ||
m_type==OBJ_FOOB || m_type==OBJ_SCRUB ||
m_type == OBJ_SECTOREFFECTOR)
{
return true;
}
return false;
}
......@@ -414,8 +292,6 @@ void CSpriteObject::processFalling()
{
// CAUTION: There is a difference between falling and going down with the gravity...
if(m_type == OBJ_MESSIE) return;
// So it reaches the maximum of fallspeed
if(!inhibitfall && !m_climbing)
{
......
......@@ -9,8 +9,8 @@
*/
#ifndef COBJECT_H_
#define COBJECT_H_
#ifndef __CSPRITEOBJECT_H_
#define __CSPRITEOBJECT_H_
#include "engine/CEventContainer.h"
#include "ActionFormat.h"
......@@ -29,6 +29,8 @@
#include "objenums.h"
const int COLISION_RES = (1<<STC);
// The bouncing box used by the object which is used to determine the collisions
struct BoundingBox
{
......@@ -68,9 +70,8 @@ struct ObjMove : public CEvent
class CSpriteObject
{
public:
CSpriteObject(CMap *pmap, Uint32 x, Uint32 y, object_t type);
CSpriteObject(CMap *pmap, Uint32 x, Uint32 y);
object_t m_type; // yorp, vorticon, etc.
unsigned int m_index; // Like an ID for some objects that need this implementation
char mHealthPoints; // episode 1 style four-shots-to-kill
bool exists;
......@@ -96,7 +97,7 @@ public:
bool inhibitfall; // if true common_enemy_ai will not do falling
bool cansupportplayer;
std::vector<CSpriteObject*> *mp_object;
//std::vector<CSpriteObject*> *mp_object;
bool blockedl, blockedr, blockedu, blockedd;
bool onslope;
......@@ -111,8 +112,6 @@ public:
bool dead, dying;
bool needinit; // Deprecated. Is only there so savegame mode still works.
bool m_canturnaround;
// This is used for action format only
......@@ -127,14 +126,11 @@ public:
// This container will held the triggered events of the object
CEventContainer m_EventCont;
void setupObjectType(int Episode);
void calcBoundingBoxes();
void performCollisionsSameBox();
void performCollisions();
void setScrPos( int px, int py );
bool calcVisibility();
bool checkforScenario();
virtual bool calcVisibility();
/**
* \description This will verify whether object has to fall or not.
......@@ -222,6 +218,11 @@ public:
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 );
virtual bool checkMapBoundaryL(const int x1);
virtual bool checkMapBoundaryR(const int x2);
virtual bool checkMapBoundaryU(const int y1);
// special functions for sloped tiles
bool checkslopedU( int c, int y1, char blocked);
bool checkslopedD( int c, int y2, char blocked);
......@@ -240,7 +241,7 @@ public:
Uint32 getYDownPos();
Uint32 getYMidPos();
void processFalling();
virtual void processFalling();
virtual void getTouchedBy(CSpriteObject &theObject) {};
virtual bool isNearby(CSpriteObject &theObject) { return true; }
virtual void getShotByRay(object_t &obj_type);
......@@ -267,6 +268,7 @@ public:
virtual ~CSpriteObject();
protected:
CMap *mp_Map;
......@@ -280,6 +282,7 @@ protected:
ActionFormatType m_Action;
Uint8 transluceny;
};
#endif /* COBJECT_H_ */
#endif // __CSPRITEOBJECT_H_
/*
* CMapLoader.cpp
* CVorticonMapLoader.cpp
*
* Created on: 09.10.2009
* Author: gerstrong
*/
#include "CMapLoader.h"
#include "CVorticonMapLoader.h"
#include <iostream>
#include <fstream>
#include "FindFile.h"
......@@ -42,7 +42,7 @@
#include "engine/vorticon/ai/CIceCannon.h"
#include "engine/vorticon/ai/CSpark.h"
CMapLoader::CMapLoader( SmartPointer<CMap> &map,
CVorticonMapLoader::CVorticonMapLoader( SmartPointer<CMap> &map,
std::vector<CPlayer> *p_PlayerVect ) :
mpMap(map),
mp_vec_Player(p_PlayerVect)
......@@ -53,7 +53,7 @@ mp_vec_Player(p_PlayerVect)
}
// Loads the map into the memory
bool CMapLoader::load( Uint8 episode, Uint8 level, const std::string& path, bool loadNewMusic, bool stategame )
bool CVorticonMapLoader::load( Uint8 episode, Uint8 level, const std::string& path, bool loadNewMusic, bool stategame )
{
std::string levelname = "level";
if(level < 10) levelname += "0";
......@@ -144,7 +144,7 @@ bool CMapLoader::load( Uint8 episode, Uint8 level, const std::string& path, bool
if(mp_objvect && stategame == false)
{
std::vector<CSpriteObject*>::iterator obj = mp_objvect->begin();
std::vector<CVorticonSpriteObject*>::iterator obj = mp_objvect->begin();
for( ; obj != mp_objvect->end() ; obj++ )
{
delete *obj;
......@@ -188,7 +188,7 @@ bool CMapLoader::load( Uint8 episode, Uint8 level, const std::string& path, bool
return true;
}
void CMapLoader::addTile( Uint16 t, Uint16 x, Uint16 y )
void CVorticonMapLoader::addTile( Uint16 t, Uint16 x, Uint16 y )
{
// Special cases. Those happen normally, when levels are replayed.
// For example if one player has battery, the level won't show that item
......@@ -197,7 +197,7 @@ void CMapLoader::addTile( Uint16 t, Uint16 x, Uint16 y )
mpMap->setTile(x, y, t);
}
void CMapLoader::addWorldMapObject(unsigned int t, Uint16 x, Uint16 y, int episode)
void CVorticonMapLoader::addWorldMapObject(unsigned int t, Uint16 x, Uint16 y, int episode)
{
// This function add sprites on the map. Most of the objects are invisible.
// TODO : Please convert this into ifs. There are more conditions than just switch.agree
......@@ -292,7 +292,7 @@ void CMapLoader::addWorldMapObject(unsigned int t, Uint16 x, Uint16 y, int episo
}
}
void CMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode, int level)
void CVorticonMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode, int level)
{
mpMap->m_objectlayer[x][y] = t;
......@@ -316,7 +316,7 @@ void CMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode,
}
else
{
CSpriteObject *enemyobject = NULL;
CVorticonSpriteObject *enemyobject = NULL;
switch(t)
{
......@@ -494,7 +494,7 @@ void CMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode,
* \param curmapY Y-Coordinate of the map not CSFed
* \param episode Episode of the game
*/
void CMapLoader::fixLevelTiles(int &currentTile, const Uint16 curmapX, const Uint16 curmapY, const int episode, const int level)
void CVorticonMapLoader::fixLevelTiles(int &currentTile, const Uint16 curmapX, const Uint16 curmapY, const int episode, const int level)
{
if( episode == 1 && level == 14 )
{
......
/*
* CMapLoader.h
* CVorticonMapLoader.h
*
* Created on: 09.10.2009
* Author: gerstrong
*/
#ifndef CMAPLOADER_H_
#define CMAPLOADER_H_
#ifndef CVorticonMapLoader_H_
#define CVorticonMapLoader_H_
#include "CMap.h"
#include "CPlayer.h"
......@@ -18,10 +18,10 @@
#include <string>
#include <vector>
class CMapLoader
class CVorticonMapLoader
{
public:
CMapLoader(SmartPointer<CMap> &map,
CVorticonMapLoader(SmartPointer<CMap> &map,
std::vector<CPlayer> *p_PlayerVect = NULL);
bool load( Uint8 episode, Uint8 level, const std::string& path, bool loadNewMusic=true, bool stategame=false );
......@@ -33,11 +33,11 @@ public:
bool m_checkpointset;
bool m_NessieAlreadySpawned;
std::vector<CSpriteObject*> *mp_objvect;
std::vector<CVorticonSpriteObject*> *mp_objvect;
private:
SmartPointer<CMap>& mpMap;
std::vector<CPlayer> *mp_vec_Player;
};
#endif /* CMAPLOADER_H_ */
#endif /* CVorticonMapLoader_H_ */
......@@ -16,7 +16,7 @@
#include "engine/spritedefines.h"