Commit eddbb8d4 authored by Gerhard Stein's avatar Gerhard Stein

Introduced the flags in Keen 4 and integrated Vector2D class to CG

parent fa5a9732
This diff is collapsed.
......@@ -234,6 +234,18 @@ void CObject::moveToForce(int new_x, int new_y)
solid = laststate;
}
// For the vector functions
void CObject::moveDir(const VectorD2<int> &dir)
{
moveXDir(dir.x);
moveYDir(dir.y);
}
void CObject::moveTo(const VectorD2<Uint32> &new_loc)
{
moveTo(new_loc.x, new_loc.y);
}
void CObject::moveTo(int new_x, int new_y)
{
int amount_x = new_x-x;
......
......@@ -13,6 +13,7 @@
#include "CBehaviorEngine.h"
#include "objenums.h"
#include "CVec.h"
#define SAFE_DELETE_ARRAY(x) if(x) { delete [] x; x = NULL; }
#define SAFE_DELETE(x) if(x) { delete x; x = NULL; }
......@@ -93,6 +94,8 @@ public:
// Moving parts
void moveToForce(int new_x, int new_y);
void moveDir(const VectorD2<int> &dir);
void moveTo(const VectorD2<Uint32> &new_loc);
void moveTo(int x, int y);
void moveXDir(int amount, bool force = false);
void moveYDir(int amount);
......
......@@ -296,7 +296,7 @@ void CMapLoaderGalaxy::addFoe(CMap &Map, word foe, size_t x, size_t y)
{
case 3:
// This is the player on map
p_newfoe = new galaxy::CPlayerWM(&Map, x, y);
p_newfoe = new galaxy::CPlayerWM(&Map, x, y, m_ObjectPtr);
// Add the Camera into the game scene and attach it to this player
camera = new CCamera(&Map,x,y);
......
......@@ -52,7 +52,9 @@ void CPlayGameGalaxy::loadLevel()
//m_Map.drawAll();
}
// The main ingame process cycle when keen galaxy is up and running
/**
* The main ingame process cycle when keen galaxy is up and running
*/
void CPlayGameGalaxy::process()
{
if(mp_Menu) // In case the menu is open
......
......@@ -42,10 +42,10 @@ void CWorldMap::process()
// Animate the tiles of the map
m_Map.animateAllTiles();
for( std::vector<CObject*>::iterator obj=m_ObjectPtr.begin() ;
obj!=m_ObjectPtr.end() ; obj++ )
for(size_t i=0 ; i<m_ObjectPtr.size() ; i++)
{
(*obj)->process();
CObject* p_Object = m_ObjectPtr[i];
p_Object->process();
}
g_pVideoDriver->blitScrollSurface();
......
/*
* CFlag.cpp
*
* Created on: 30.07.2010
* Author: gerstrong
*/
#include "CFlag.h"
namespace galaxy {
const Uint16 FLYING_BASEFRAME = 174;
const Uint16 WAVING_BASEFRAME = 181;
const Uint16 ANIMATION_TIME = 8;
const Uint16 SPEED = 128;
CFlag::CFlag(CMap *pmap, const VectorD2<Uint32> &Location,
const VectorD2<Uint32> &Destination) :
CObject(pmap, Location.x, Location.y, OBJ_NONE),
m_location(Location),
m_destination(Destination),
m_baseframe(FLYING_BASEFRAME),
processState(&CFlag::processFlying)
{
solid = false;
honorPriority = false;
// Here we move the coordinates in order get it positioned correctly in the pole
m_destination.x += (6<<STC);
CSprite &Sprite = g_pGfxEngine->getSprite(WAVING_BASEFRAME);
m_destination.y -= Sprite.m_bboxY2;
m_destination.y += (1<<STC);
}
/**
* Main process cycle
*/
void CFlag::process()
{
(this->*processState)();
}
/**
* Called when Flag is flying to the pole
*/
void CFlag::processFlying()
{
if(mp_Map->getAnimtiletimer()%ANIMATION_TIME == 0)
{
if(sprite-m_baseframe >= 4)
sprite = m_baseframe;
else
sprite++;
}
if(m_destination != m_location)
{
VectorD2<int> dir = m_destination - m_location;
float length = dir.GetLength();
VectorD2<float> base_dir( dir.x/length, dir.y/length );
if( fabs(length) < SPEED )
{
moveTo(m_destination);
}
else
moveDir(base_dir*SPEED);
m_location.x = getXPosition();
m_location.y = getYPosition();
}
else
{
processState = &CFlag::processWaving;
m_baseframe = WAVING_BASEFRAME;
}
}
/*
* Called when flag is in the pole
*/
void CFlag::processWaving()
{
if(mp_Map->getAnimtiletimer()%ANIMATION_TIME == 0)
{
if(sprite-m_baseframe >= 3)
sprite = m_baseframe;
else
sprite++;
}
}
}
/*
* CFlag.h
*
* Created on: 30.07.2010
* Author: gerstrong
*
* This class represents the flag sign object
* which is shown and performed when Keen finished a Level
*/
#ifndef CFLAG_H_
#define CFLAG_H_
#include "common/CObject.h"
#include "CVec.h"
namespace galaxy {
class CFlag : public CObject {
public:
CFlag(CMap *pmap, const VectorD2<Uint32> &Location,
const VectorD2<Uint32> &Destination);
// The flag is flying when player throws it.
// It's waving all the time being stuck on the pole.
void process();
void processFlying();
void processWaving();
private:
// Where the flag/sign will pop in
VectorD2<Uint32> m_location;
VectorD2<Uint32> m_destination;
Uint16 m_baseframe;
void (CFlag::*processState)();
};
}
#endif /* CFLAG_H_ */
......@@ -6,21 +6,25 @@
*/
#include "CPlayerWM.h"
#include "../../../common/CBehaviorEngine.h"
#include "../../../sdl/CInput.h"
#include "engine/galaxy/ai/CFlag.h"
#include "common/CBehaviorEngine.h"
#include "sdl/CInput.h"
#include "CVec.h"
const Uint16 WALKBASEFRAME = 130;
const Uint16 SWIMBASEFRAME = 156;
namespace galaxy {
CPlayerWM::CPlayerWM(CMap *pmap, Uint32 x, Uint32 y):
CPlayerWM::CPlayerWM(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CObject*>& ObjectPtrs):
CObject(pmap, x, y, OBJ_PLAYER),
m_basesprite(130),
m_looking_dir(LEFT),
m_animation(0),
m_animation_time(1),
m_animation_ticker(0)
m_animation_ticker(0),
m_ObjectPtrs(ObjectPtrs)
{
// TODO Auto-generated constructor stub
sprite = m_basesprite;
......@@ -95,7 +99,7 @@ void CPlayerWM::processWalking()
solid = !solid;
// perform actions depending if the action button was pressed
if(g_pInput->getHoldedCommand(IC_JUMP))
if(g_pInput->getPressedCommand(IC_JUMP))
{
Uint16 object = mp_Map->getPlaneDataAt(2, getXMidPos(), getYMidPos());
if(object)
......@@ -125,11 +129,27 @@ void CPlayerWM::finishlevel(Uint16 object)
Uint16 door = (object - 0xC000) + 0xD000;
while(mp_Map->findTile(door, &x, &y, 2))
{
// Open blocks in case there are
mp_Map->setTile( x, y, 0, true, 1);
mp_Map->setTile( x, y, 0, true, 2);
mp_Map->redrawAt( x, y);
}
Uint16 flag_dest = (object - 0xC000) + 0xF000;
if(mp_Map->findTile(flag_dest, &x, &y, 2))
{
// generate the flag
VectorD2<Uint32> src(this->x, this->y);
VectorD2<Uint32> dst((x<<CSF), (y<<CSF));
CFlag *pFlag = new CFlag(mp_Map, src, dst);
m_ObjectPtrs.push_back(pFlag);
// Mark the tileinfo on the map as marked!!
mp_Map->setTile( x, y, 0, true, 2);
}
// TODO: spawn the flag that will be spawn
}
......
......@@ -14,7 +14,8 @@ namespace galaxy {
class CPlayerWM : public CObject {
public:
CPlayerWM(CMap *pmap, Uint32 x, Uint32 y);
CPlayerWM(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CObject*>& ObjectPtrs);
void process();
void processWalking();
......@@ -32,6 +33,7 @@ private:
Uint8 m_animation;
Uint8 m_animation_time;
Uint8 m_animation_ticker;
std::vector<CObject*>& m_ObjectPtrs;
};
}
......
......@@ -22,8 +22,10 @@ CRay(p_map, x, y, dir, byType, byID)
blockedl = blockedr = 0;
canbezapped = 1;
if(dir == LEFT)
this->x-=(1<<CSF);
this->x-=(14<<STC);
m_speed = (mp_Map->m_Difficulty>1) ? FIREBALL_HARD_SPEED : FIREBALL_SPEED;
sprite = (m_Direction == RIGHT) ? FIREBALL_RIGHT_FRAME : FIREBALL_LEFT_FRAME;
setupinitialCollisions();
}
void CFireBall::process()
......
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