Commit b143187e authored by Gerstrong's avatar Gerstrong

Introduced the Starring class

parent 57fc0b55
/*
* ActionFormat.cpp
*
* Created on: 25.06.2011
* Author: gerstrong
*
* Action-Format is released as CXX Module because of some dependencies
*/
#include "ActionFormat.h"
#include "common/CBehaviorEngine.h"
void ActionFormatType::setActionFormat( const size_t sprite_offset )
{
byte *ptr = g_pBehaviorEngine->m_ExeFile.getDSegPtr();
ptr += sprite_offset;
memcpy( this, ptr, 15*sizeof(int16_t) );
}
void ActionFormatType::setNextActionFormat()
{
setActionFormat(Next_action);
}
bool ActionFormatType::getActionFormat( const size_t sprite_offset )
{
byte *ptr = g_pBehaviorEngine->m_ExeFile.getDSegPtr();
ptr += sprite_offset;
return (memcmp( this, ptr, 15*sizeof(int16_t) ) == 0);
}
......@@ -18,7 +18,7 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "common/CBehaviorEngine.h"
struct ActionFormatType {
int16_t Left_sprite; // 124-400
......@@ -42,33 +42,19 @@ struct ActionFormatType {
* \param sprite_offset Offset of the sprite. This is per sprite(object) just one and the same
* direction
*/
void setActionFormat( size_t sprite_offset )
{
byte *ptr = g_pBehaviorEngine->m_ExeFile.getDSegPtr();
ptr += sprite_offset;
memcpy( this, ptr, 15*sizeof(int16_t) );
}
void setActionFormat( const size_t sprite_offset );
/**
* \brief just sets the next action format struct
*/
void setNextActionFormat()
{
setActionFormat(Next_action);
}
void setNextActionFormat();
/**
* \brief get Action Format of the sprite
* \param sprite_offset Offset of the sprite. This is per sprite(object) just one and the same
* direction
*/
bool getActionFormat( size_t sprite_offset )
{
byte *ptr = g_pBehaviorEngine->m_ExeFile.getDSegPtr();
ptr += sprite_offset;
return (memcmp( this, ptr, 15*sizeof(int16_t) ) == 0);
}
bool getActionFormat( const size_t sprite_offset );
};
#endif /* ACTIONFORMAT_H_ */
......@@ -12,6 +12,7 @@
* of AI they are needed and especially for the collision
*/
#ifndef CBEHAVIORENGINE_H_
#define CBEHAVIORENGINE_H_
......@@ -26,6 +27,8 @@
#include "common/options.h"
#include "CSingleton.h"
#define g_pBehaviorEngine CBehaviorEngine::Get()
/*
......
......@@ -8,25 +8,28 @@
* It also handles the AI if any.
*/
#ifndef COBJECT_H_
#define COBJECT_H_
#include "CBehaviorEngine.h"
#include "engine/CEventContainer.h"
#include "ActionFormat.h"
#include "CVec.h"
#include "direction.h"
#include "CBehaviorEngine.h"
// structures for each AI module's data
#include "engine/vorticon/ai/enemydata.h"
#include "CMap.h"
#include "graphics/CGfxEngine.h"
#include "options.h"
#include "engine/CEventContainer.h"
#include "sdl/sound/CSound.h"
#include "CVec.h"
// Enumerations are here
#include "objenums.h"
#define SAFE_DELETE_ARRAY(x) if(x) { delete [] x; x = NULL; }
#define SAFE_DELETE(x) if(x) { delete x; x = NULL; }
......
/*
* CEvent.cpp
*
* Created on: 03.08.2010
* Author: gerstrong
*/
#include "CEvent.h"
#include "fileio/TypeDefinitions.h"
......@@ -6,6 +6,7 @@
*
* Intendet to represent an event.
* Doesn't do any handling.
* TODO: If more events come and this file gets long we might have to split it up.
*/
#ifndef CEVENT_H_
......@@ -15,7 +16,12 @@
#include <string>
#include <list>
#include "common/direction.h"
//#include "common/CObject.h"
#include "SmartPointer.h"
#include "CVec.h"
class CObject;
struct CEvent { virtual ~CEvent() {} };
......@@ -102,5 +108,19 @@ struct EventSendSelectionDialogMsg : CEvent {
};
/**
* \description This event will spawn a new object
*
* \param pObject Pointer to the allocated memory of the Object. Caution: This allocation
*/
struct EventSpawnObject : CEvent {
const CObject* pObject;
EventSpawnObject( const CObject* pObject ) :
pObject(pObject) {}
};
#endif /* CEVENT_H_ */
......@@ -14,6 +14,7 @@
#include "SmartPointer.h"
#include <list>
class CEventContainer {
public:
bool empty() { return m_EventList.empty(); }
......
......@@ -7,6 +7,7 @@
#include "CMapPlayGalaxy.h"
#include "engine/galaxy/ai/CPlayerBase.h"
#include "common/CBehaviorEngine.h"
CMapPlayGalaxy::CMapPlayGalaxy(CExeFile &ExeFile, CInventory &Inventory) :
m_active(false),
......@@ -188,8 +189,15 @@ void CMapPlayGalaxy::process()
m_Cheatmode.noclipping = true;
m_MessageBoxes.push_back(new CMessageBoxGalaxy("No clipping toggle!"));
}
}
CEventContainer &EventContainer = g_pBehaviorEngine->m_EventList;
if( EventSpawnObject *ev = EventContainer.occurredEvent<EventSpawnObject>() )
{
m_ObjectPtr.push_back( const_cast<CObject*>(ev->pObject) );
EventContainer.pop_Event();
}
}
......
......@@ -188,7 +188,7 @@ void CPlayGameGalaxy::process()
else if( EventPlayTrack *ev = EventContainer.occurredEvent<EventPlayTrack>() )
{
g_pMusicPlayer->stop();
if(g_pMusicPlayer->loadTrack(m_ExeFile, ev->track));
if( g_pMusicPlayer->loadTrack(m_ExeFile, ev->track) )
g_pMusicPlayer->play();
EventContainer.pop_Event();
}
......
/*
* CStarRing.cpp
*
* Created on: 25.06.2011
* Author: gerstrong
*/
#include "CStarRing.h"
namespace galaxy
{
const unsigned int STARRING_ANIMATION_TIME = 5;
CStarRing::CStarRing(CMap *pmap, Uint32 x, Uint32 y, object_t type) :
CObject(pmap, x, y, type),
m_animation_timer(0)
{
sprite = STARRING_SPRITE;
}
void CStarRing::process()
{
const unsigned char anim = m_animation_timer % STARRING_ANIMATION_TIME;
if(anim == 0)
{
sprite++;
if(sprite > STARRING_SPRITE+2)
{
sprite = STARRING_SPRITE;
m_animation_timer = 0;
}
}
// Animation timer increasing all the time
m_animation_timer++;
}
};
/*
* CStarRing.h
*
* Created on: 25.06.2011
* Author: gerstrong
*
* This object is spawned whenever an enemy gets stunned. it justs represents the stars above
* his head. Note: Not all Enemies use this, but most of them
*/
#ifndef CSTARRING_H_
#define CSTARRING_H_
#include "common/CObject.h"
namespace galaxy
{
const unsigned int STARRING_SPRITE = 40;
class CStarRing : public CObject {
public:
CStarRing(CMap *pmap, Uint32 x, Uint32 y, object_t type);
private:
void process();
unsigned char m_animation_timer;
};
};
#endif /* CSTARRING_H_ */
......@@ -12,6 +12,9 @@
#include "CStunnable.h"
#include "CBullet.h"
#include "common/CBehaviorEngine.h"
#include "engine/galaxy/ai/CStarRing.h"
namespace galaxy
{
......@@ -19,8 +22,8 @@ namespace galaxy
CStunnable::CStunnable( CMap *pmap,
Uint32 x,
Uint32 y,
object_t type ):
CObject(pmap, x, y, type)
object_t type ) :
CObject( pmap, x, y, type )
{}
void CStunnable::getTouchedBy(CObject &theObject)
......@@ -29,6 +32,15 @@ void CStunnable::getTouchedBy(CObject &theObject)
{
theObject.setAction(A_KEENSHOT_IMPACT);
theObject.playSound( SOUND_SHOT_HIT );
CSprite &StarRing = g_pGfxEngine->getSprite( STARRING_SPRITE );
// Calculate the Position of the Star-Ring. Make it centered and above its head
const Uint32 star_x = getXMidPos() - ( (StarRing.getWidth()<<STC)/2 );
const Uint32 star_y = getYUpPos() - ( StarRing.getHeight()<<STC );
EventSpawnObject *Ev = new EventSpawnObject( new CStarRing(mp_Map, star_x, star_y, OBJ_NONE) );
g_pBehaviorEngine->m_EventList.add( Ev );
}
}
......
......@@ -6,6 +6,7 @@
*/
#include "common/options.h"
#include "common/CBehaviorEngine.h"
#include "fileio/CConfiguration.h"
#include "CLogFile.h"
#include "FindFile.h"
......@@ -14,7 +15,6 @@
#include "CVideoDriver.h"
#include "CTimer.h"
#include "sound/CSound.h"
#include "common/CBehaviorEngine.h"
/**
* \brief The CSettings class handles the saving and loading of all the settings that are saved in
......
......@@ -5,14 +5,14 @@
* Author: gerstrong and albert
*/
#ifndef CSETTINGS_H_
#define CSETTINGS_H_
#include <string>
#include "common/options.h"
#include "fileio/CConfiguration.h"
#ifndef CSETTINGS_H_
#define CSETTINGS_H_
class CSettings {
public:
// NOTE: If no option structure is passed, you must be no means use
......
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