Commit f30ca60e authored by Gerhard Stein's avatar Gerhard Stein

now keen can walk on the world map in galaxy

parent 375ae147
...@@ -129,7 +129,7 @@ bool CMap::findObject(unsigned int obj, int *xout, int *yout) ...@@ -129,7 +129,7 @@ bool CMap::findObject(unsigned int obj, int *xout, int *yout)
// if it is found returns nonzero and places the // if it is found returns nonzero and places the
// coordinates of the first occurance of the tile // coordinates of the first occurance of the tile
// in (xout,yout) // in (xout,yout)
bool CMap::findTile(unsigned int tile, int *xout, int *yout) bool CMap::findTile(unsigned int tile, int *xout, int *yout, int plane)
{ {
unsigned int x,y; unsigned int x,y;
...@@ -137,7 +137,7 @@ bool CMap::findTile(unsigned int tile, int *xout, int *yout) ...@@ -137,7 +137,7 @@ bool CMap::findTile(unsigned int tile, int *xout, int *yout)
{ {
for(x=2;x<m_width-2;x++) for(x=2;x<m_width-2;x++)
{ {
if (m_Plane[1].getMapDataAt(x,y)==tile) if (m_Plane[plane].getMapDataAt(x,y)==tile)
{ {
*xout = x; *xout = x;
*yout = y; *yout = y;
...@@ -148,21 +148,21 @@ bool CMap::findTile(unsigned int tile, int *xout, int *yout) ...@@ -148,21 +148,21 @@ bool CMap::findTile(unsigned int tile, int *xout, int *yout)
return false; return false;
} }
bool CMap::setTile(Uint16 x, Uint16 y, Uint16 t) bool CMap::setTile(Uint16 x, Uint16 y, Uint16 t, Uint16 plane)
{ {
if( x<m_width && y<m_height ) if( x<m_width && y<m_height )
{ {
//mp_foreground_data[y*m_width + x] = t; //mp_foreground_data[y*m_width + x] = t;
m_Plane[1].setMapDataAt(t, x, y); m_Plane[plane].setMapDataAt(t, x, y);
return true; return true;
} }
else else
return false; return false;
} }
bool CMap::setTile(Uint16 x, Uint16 y, Uint16 t, bool update) bool CMap::setTile(Uint16 x, Uint16 y, Uint16 t, bool update, Uint16 plane)
{ {
if(setTile( x, y, t)) if(setTile( x, y, t, plane))
{ {
if(update) redrawAt(x,y); if(update) redrawAt(x,y);
return true; return true;
...@@ -315,7 +315,8 @@ void CMap::redrawAt(int mx, int my) ...@@ -315,7 +315,8 @@ void CMap::redrawAt(int mx, int my)
size_t bg = m_Plane[0].getMapDataAt(mx, my); size_t bg = m_Plane[0].getMapDataAt(mx, my);
size_t fg = m_Plane[1].getMapDataAt(mx, my); size_t fg = m_Plane[1].getMapDataAt(mx, my);
m_Tilemaps.at(0).drawTile(mp_scrollsurface, (mx<<4)&511, (my<<4)&511, bg); m_Tilemaps.at(0).drawTile(mp_scrollsurface, (mx<<4)&511, (my<<4)&511, bg);
m_Tilemaps.at(1).drawTile(mp_scrollsurface, (mx<<4)&511, (my<<4)&511, fg); if(fg)
m_Tilemaps.at(1).drawTile(mp_scrollsurface, (mx<<4)&511, (my<<4)&511, fg);
} }
else else
{ {
......
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
// animation rate of animated tiles // animation rate of animated tiles
#define ANIM_TILE_TIME 256 #define ANIM_TILE_TIME 256
#define CSF 9
#define TILE_S 4
#define STC (CSF-TILE_S)
class CMap { class CMap {
public: public:
CMap(); CMap();
...@@ -44,10 +49,10 @@ public: ...@@ -44,10 +49,10 @@ public:
Uint16 at(Uint16 x, Uint16 y, Uint16 t=1); Uint16 at(Uint16 x, Uint16 y, Uint16 t=1);
Uint16 getObjectat(Uint16 x, Uint16 y); Uint16 getObjectat(Uint16 x, Uint16 y);
bool findObject(unsigned int obj, int *xout, int *yout); bool findObject(unsigned int obj, int *xout, int *yout);
bool findTile(unsigned int tile, int *xout, int *yout); bool findTile(unsigned int tile, int *xout, int *yout, int plane=1);
bool setTile(Uint16 x, Uint16 y, Uint16 t); bool setTile(Uint16 x, Uint16 y, Uint16 t, Uint16 plane=1);
bool setTile(Uint16 x, Uint16 y, Uint16 t, bool update); bool setTile(Uint16 x, Uint16 y, Uint16 t, bool update, Uint16 plane=1);
bool changeTile(Uint16 x, Uint16 y, Uint16 t); bool changeTile(Uint16 x, Uint16 y, Uint16 t);
// Animation methods // Animation methods
...@@ -57,6 +62,10 @@ public: ...@@ -57,6 +62,10 @@ public:
unsigned int getlevelat(unsigned int x, unsigned int y) { unsigned int getlevelat(unsigned int x, unsigned int y) {
return m_objectlayer[x>>4][y>>4]; } return m_objectlayer[x>>4][y>>4]; }
Uint16 getPlaneDataAt(char plane, unsigned int x, unsigned int y){
return m_Plane[plane].getMapDataAt(x>>CSF, y>>CSF);
}
word *getData(Uint8 PlaneNum); word *getData(Uint8 PlaneNum);
word *getForegroundData(); word *getForegroundData();
word *getBackgroundData(); word *getBackgroundData();
......
...@@ -54,14 +54,7 @@ m_blinktime(0) ...@@ -54,14 +54,7 @@ m_blinktime(0)
{ {
setupObjectType(g_pBehaviorEngine->getEpisode()); setupObjectType(g_pBehaviorEngine->getEpisode());
if ( sprite == BLANKSPRITE ) setupinitialCollisions();
{
CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
bboxX1 = rSprite.m_bboxX1; bboxX2 = rSprite.m_bboxX2;
bboxY1 = rSprite.m_bboxY1; bboxY2 = rSprite.m_bboxY2;
checkinitialCollisions();
}
} }
} }
...@@ -129,24 +122,33 @@ void CObject::setupObjectType(int Episode) ...@@ -129,24 +122,33 @@ void CObject::setupObjectType(int Episode)
case OBJ_GOTPOINTS: sprite = PT500_SPRITE; break; case OBJ_GOTPOINTS: sprite = PT500_SPRITE; break;
default: sprite = BLANKSPRITE; default: sprite = BLANKSPRITE;
} }
} }
// This is needed when a new object is created, because the collision // This is needed when a new object is created, because the collision
// per tile, really checks per tile and not pixel based // per tile, really checks per tile and not pixel based
void CObject::checkinitialCollisions() void CObject::setupinitialCollisions()
{ {
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties(); std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
blockedr = blockedl = false; blockedr = blockedl = false;
blockedu = blockedd = false; blockedu = blockedd = false;
// Check initial collision. This will avoid that ray go through the first blocking element
for(size_t j=bboxY1; j<=bboxY2 ; j+=(1<<STC)) if ( sprite != BLANKSPRITE )
{ {
for(size_t i=bboxX1; i<=bboxX2 ; i+=(1<<STC)) CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
bboxX1 = rSprite.m_bboxX1; bboxX2 = rSprite.m_bboxX2;
bboxY1 = rSprite.m_bboxY1; bboxY2 = rSprite.m_bboxY2;
// Check initial collision. This will avoid that ray go through the first blocking element
for(size_t j=bboxY1; j<=bboxY2 ; j+=(1<<STC))
{ {
blockedr |= TileProperty[mp_Map->at((x+i)>>CSF,(y+j)>>CSF)].bleft; for(size_t i=bboxX1; i<=bboxX2 ; i+=(1<<STC))
blockedl |= TileProperty[mp_Map->at((x+i)>>CSF,(y+j)>>CSF)].bright; {
blockedu |= TileProperty[mp_Map->at((x+i)>>CSF,(y+j)>>CSF)].bdown; blockedr |= TileProperty[mp_Map->at((x+i)>>CSF,(y+j)>>CSF)].bleft;
blockedd |= TileProperty[mp_Map->at((x+i)>>CSF,(y+j)>>CSF)].bup; blockedl |= TileProperty[mp_Map->at((x+i)>>CSF,(y+j)>>CSF)].bright;
blockedu |= TileProperty[mp_Map->at((x+i)>>CSF,(y+j)>>CSF)].bdown;
blockedd |= TileProperty[mp_Map->at((x+i)>>CSF,(y+j)>>CSF)].bup;
}
} }
} }
} }
...@@ -371,7 +373,7 @@ void CObject::moveRight(int amount, bool force) ...@@ -371,7 +373,7 @@ void CObject::moveRight(int amount, bool force)
blockedu = false; blockedu = false;
if(!performSlopedTileDown(x, y2+(1<<STC), amount)); if(!performSlopedTileDown(x, y2+(1<<STC), amount));
performSlopedTileUp(x, y1-(1<<STC), -amount); performSlopedTileUp(x, y1-(1<<STC), amount);
} }
void CObject::moveUp(int amount) void CObject::moveUp(int amount)
...@@ -732,8 +734,10 @@ bool CObject::performSlopedTileDown( int x, int y, int xspeed ) ...@@ -732,8 +734,10 @@ bool CObject::performSlopedTileDown( int x, int y, int xspeed )
if(slope == 2 or slope == 3) if(slope == 2 or slope == 3)
moveYDir(xspeed/2); moveYDir(xspeed/2);
else if(slope == 4 or slope == 5) else if(slope == 4)
moveYDir(xspeed); moveYDir(xspeed);
else if(slope == 5)
moveYDir(-xspeed);
else if(slope == 6) else if(slope == 6)
moveYDir(-xspeed/2); moveYDir(-xspeed/2);
else if(slope == 7) else if(slope == 7)
...@@ -858,7 +862,7 @@ void CObject::blink(Uint16 frametime) ...@@ -858,7 +862,7 @@ void CObject::blink(Uint16 frametime)
// or priority tile! // or priority tile!
void CObject::draw() void CObject::draw()
{ {
if(sprite >= BLANKSPRITE) if( sprite == BLANKSPRITE )
return; return;
CSprite &Sprite = g_pGfxEngine->getSprite(sprite); CSprite &Sprite = g_pGfxEngine->getSprite(sprite);
......
...@@ -24,7 +24,11 @@ ...@@ -24,7 +24,11 @@
enum direction_t{ enum direction_t{
NONE, NONE,
RIGHT, RIGHT,
RIGHTUP,
RIGHTDOWN,
LEFT, LEFT,
LEFTUP,
LEFTDOWN,
UP, UP,
DOWN DOWN
}; };
...@@ -39,11 +43,6 @@ enum direction_t{ ...@@ -39,11 +43,6 @@ enum direction_t{
// Enumerations are here // Enumerations are here
#include "objenums.h" #include "objenums.h"
#define CSF 9
#define TILE_S 4
#define STC (CSF-TILE_S)
class CObject { class CObject {
public: public:
CObject(CMap *pmap, Uint32 x, Uint32 y, object_t type); CObject(CMap *pmap, Uint32 x, Uint32 y, object_t type);
...@@ -87,7 +86,7 @@ public: ...@@ -87,7 +86,7 @@ public:
bool needinit; bool needinit;
void setupObjectType(int Episode); void setupObjectType(int Episode);
void checkinitialCollisions(); void setupinitialCollisions();
void setScrPos( int px, int py ); void setScrPos( int px, int py );
bool calcVisibility(); bool calcVisibility();
bool checkforScenario(); bool checkforScenario();
......
...@@ -66,6 +66,8 @@ void CPlayer::setDatatoZero() ...@@ -66,6 +66,8 @@ void CPlayer::setDatatoZero()
// When worldmap is set up, use that frame // When worldmap is set up, use that frame
sprite = PMAPDOWNFRAME; sprite = PMAPDOWNFRAME;
setupinitialCollisions();
m_type = OBJ_PLAYER; m_type = OBJ_PLAYER;
moveTo(0,0); moveTo(0,0);
ankhtime = 0; ankhtime = 0;
...@@ -84,6 +86,7 @@ void CPlayer::setDatatoZero() ...@@ -84,6 +86,7 @@ void CPlayer::setDatatoZero()
honorPriority = true; honorPriority = true;
solid = true; solid = true;
bumped = false; bumped = false;
pjumptime = 0; pjumptime = 0;
pjumping = PNOJUMP; pjumping = PNOJUMP;
......
...@@ -17,13 +17,14 @@ ...@@ -17,13 +17,14 @@
#include "../CLogFile.h" #include "../CLogFile.h"
#include "../sdl/CVideoDriver.h" #include "../sdl/CVideoDriver.h"
#include "../sdl/CInput.h" #include "../sdl/CInput.h"
#include "spritedefines.h"
CCamera::CCamera(CMap *pmap, Uint32 x, Uint32 y): CCamera::CCamera(CMap *pmap, Uint32 x, Uint32 y):
CObject(pmap, x, y, OBJ_NONE), CObject(pmap, x, y, OBJ_NONE),
mp_AttachedObject(NULL) mp_AttachedObject(NULL)
{ {
g_pLogFile->ftextOut("Starting the camera system...<br>"); g_pLogFile->ftextOut("Starting the camera system...<br>");
sprite = 0; sprite = BLANKSPRITE;
solid = false; solid = false;
} }
...@@ -71,14 +72,14 @@ void CCamera::process() ...@@ -71,14 +72,14 @@ void CCamera::process()
} }
else else
{ {
if(!mp_AttachedObject->getXPosition() < x) if(mp_AttachedObject->getXPosition() > x)
moveLeft(x - mp_AttachedObject->getXPosition()); moveLeft(x - mp_AttachedObject->getXPosition());
else if(!mp_AttachedObject->getXPosition() > x) else if(mp_AttachedObject->getXPosition() < x)
moveRight(mp_AttachedObject->getXPosition() - x); moveRight(mp_AttachedObject->getXPosition() - x);
if(!mp_AttachedObject->getYPosition() < y) if(mp_AttachedObject->getYPosition() > y)
moveUp(y - mp_AttachedObject->getYPosition()); moveUp(y - mp_AttachedObject->getYPosition());
else if(!mp_AttachedObject->getYPosition() > y) else if(mp_AttachedObject->getYPosition() < y)
moveDown(mp_AttachedObject->getYPosition() - y); moveDown(mp_AttachedObject->getYPosition() - y);
} }
......
...@@ -29,7 +29,6 @@ bool CPlayGameGalaxy::loadGameState() ...@@ -29,7 +29,6 @@ bool CPlayGameGalaxy::loadGameState()
// Setup for the ingame // Setup for the ingame
bool CPlayGameGalaxy::init() bool CPlayGameGalaxy::init()
{ {
loadLevel(); loadLevel();
return false; return false;
......
...@@ -12,16 +12,17 @@ ...@@ -12,16 +12,17 @@
namespace galaxy { namespace galaxy {
CPlayerWM::CPlayerWM(CMap *pmap, Uint32 x, Uint32 y): CPlayerWM::CPlayerWM(CMap *pmap, Uint32 x, Uint32 y):
CObject(pmap, x, y, OBJ_PLAYER) CObject(pmap, x, y, OBJ_PLAYER),
m_basesprite(130),
m_looking_dir(LEFT),
m_animation(0),
m_animation_time(1),
m_animation_ticker(0)
{ {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
sprite=138; sprite = m_basesprite;
CSprite &rSprite = g_pGfxEngine->getSprite(sprite); setupinitialCollisions();
bboxX1 = rSprite.m_bboxX1; bboxX2 = rSprite.m_bboxX2;
bboxY1 = rSprite.m_bboxY1; bboxY2 = rSprite.m_bboxY2;
checkinitialCollisions();
} }
/** /**
...@@ -29,6 +30,14 @@ CObject(pmap, x, y, OBJ_PLAYER) ...@@ -29,6 +30,14 @@ CObject(pmap, x, y, OBJ_PLAYER)
*/ */
void CPlayerWM::process() void CPlayerWM::process()
{ {
// Perform animation cycle
if(m_animation_ticker >= m_animation_time)
{
m_animation++;
m_animation_ticker = 0;
}
else m_animation_ticker++;
processWalking(); processWalking();
} }
...@@ -38,21 +47,116 @@ void CPlayerWM::process() ...@@ -38,21 +47,116 @@ void CPlayerWM::process()
void CPlayerWM::processWalking() void CPlayerWM::processWalking()
{ {
size_t movespeed = 100; size_t movespeed = 100;
bool walking=false;
// TODO: Implement animation speed! // Normal walking
if(g_pInput->getHoldedCommand(IC_LEFT)) if(g_pInput->getHoldedCommand(IC_LEFT))
{
moveLeft(movespeed); moveLeft(movespeed);
if(g_pInput->getHoldedCommand(IC_RIGHT)) walking = true;
m_looking_dir = LEFT;
}
else if(g_pInput->getHoldedCommand(IC_RIGHT))
{
moveRight(movespeed); moveRight(movespeed);
walking = true;
m_looking_dir = RIGHT;
}
if(g_pInput->getHoldedCommand(IC_UP)) if(g_pInput->getHoldedCommand(IC_UP))
{
moveUp(movespeed); moveUp(movespeed);
if(g_pInput->getHoldedCommand(IC_DOWN)) walking = true;
if(m_looking_dir == LEFT)
m_looking_dir = LEFTUP;
else if(m_looking_dir == RIGHT)
m_looking_dir = RIGHTUP;
else
m_looking_dir = UP;
}
else if(g_pInput->getHoldedCommand(IC_DOWN))
{
moveDown(movespeed); moveDown(movespeed);
walking = true;
if(m_looking_dir == LEFT)
m_looking_dir = LEFTDOWN;
else if(m_looking_dir == RIGHT)
m_looking_dir = RIGHTDOWN;
else
m_looking_dir = DOWN;
}
if(g_pInput->getHoldedCommand(IC_STATUS)) if(g_pInput->getHoldedCommand(IC_STATUS))
solid = !solid; solid = !solid;
// perform actions depending if the action button was pressed
if(g_pInput->getHoldedCommand(IC_JUMP))
{
Uint16 object = mp_Map->getPlaneDataAt(2, getXMidPos(), getYMidPos());
if(object)
finishlevel(object);
g_pInput->flushCommands();
}
performWalkingAnimation(walking);
}
/*
* makes the player finish the level
*/
void CPlayerWM::finishlevel(Uint16 object)
{
// if a door or other blocker was found remove it
int x, y;
Uint16 door = (object - 0xC000) + 0xD000;
while(mp_Map->findTile(door, &x, &y, 2))
{
mp_Map->setTile( x, y, 0, true, 1);
mp_Map->setTile( x, y, 0, true, 2);
mp_Map->redrawAt( x, y);
}
// TODO: spawn the flag that will be spawn
}
/**
* This performs the animation when player is walking on the map
*/
void CPlayerWM::performWalkingAnimation(bool walking)
{
if(m_looking_dir == LEFT)
sprite = m_basesprite;
else if(m_looking_dir == RIGHT)
sprite = m_basesprite + 3;
else if(m_looking_dir == UP)
sprite = m_basesprite + 6;
else if(m_looking_dir == DOWN)
sprite = m_basesprite + 9;
else if(m_looking_dir == RIGHTDOWN)
sprite = m_basesprite + 12;
else if(m_looking_dir == LEFTDOWN)
sprite = m_basesprite + 15;
else if(m_looking_dir == LEFTUP)
sprite = m_basesprite + 18;
else if(m_looking_dir == RIGHTUP)
sprite = m_basesprite + 21;
if(walking)
{
m_animation_time = 5;
sprite += m_animation%2;
}
else
sprite += 2;
} }
CPlayerWM::~CPlayerWM() { CPlayerWM::~CPlayerWM() {
......
...@@ -17,7 +17,19 @@ public: ...@@ -17,7 +17,19 @@ public:
CPlayerWM(CMap *pmap, Uint32 x, Uint32 y); CPlayerWM(CMap *pmap, Uint32 x, Uint32 y);
void process(); void process();
void processWalking(); void processWalking();
void finishlevel(Uint16 object);
void performWalkingAnimation(bool walking);
virtual ~CPlayerWM(); virtual ~CPlayerWM();
private:
Uint16 m_basesprite;
direction_t m_looking_dir;
Uint8 m_animation;
Uint8 m_animation_time;
Uint8 m_animation_ticker;
}; };
} }
......
...@@ -46,7 +46,7 @@ m_Player(PlayerVect) ...@@ -46,7 +46,7 @@ m_Player(PlayerVect)
speed = JACK_SPEED; speed = JACK_SPEED;
canbezapped = 0; canbezapped = 0;
} }
checkinitialCollisions(); setupinitialCollisions();
} }
void CBallJack::process() void CBallJack::process()
......
...@@ -33,7 +33,7 @@ m_speed(RAY_SPEED) ...@@ -33,7 +33,7 @@ m_speed(RAY_SPEED)
state = RAY_STATE_FLY; state = RAY_STATE_FLY;
inhibitfall = true; inhibitfall = true;
checkinitialCollisions(); setupinitialCollisions();
} }
void CRay::setOwner(object_t type, unsigned int index) void CRay::setOwner(object_t type, unsigned int index)
......
...@@ -43,7 +43,7 @@ m_Player(Player) ...@@ -43,7 +43,7 @@ m_Player(Player)
needinit = false; needinit = false;
canbezapped = 1; canbezapped = 1;
checkinitialCollisions(); setupinitialCollisions();
dead = 0; dead = 0;
fallinctimer = 0; fallinctimer = 0;
fallspeed = 0; fallspeed = 0;
......
...@@ -26,7 +26,7 @@ offscreentime(0) ...@@ -26,7 +26,7 @@ offscreentime(0)
bboxX1 = rSprite.m_bboxX1; bboxX2 = rSprite.m_bboxX2; bboxX1 = rSprite.m_bboxX1; bboxX2 = rSprite.m_bboxX2;
bboxY1 = rSprite.m_bboxY1; bboxY2 = rSprite.m_bboxY2; bboxY1 = rSprite.m_bboxY1; bboxY2 = rSprite.m_bboxY2;
checkinitialCollisions(); setupinitialCollisions();
} }
void CSoundWave::process() void CSoundWave::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