Commit aebc6797 authored by Gerhard Stein's avatar Gerhard Stein

checked collision behavior of sprites and did some fixes. Now it's perfect!

Added more code to the CPlayerWM and attach Code to CCamera
parent 5cf8af3c
......@@ -23,7 +23,7 @@ CObject(pmap, x, y, OBJ_NONE),
mp_AttachedObject(NULL)
{
g_pLogFile->ftextOut("Starting the camera system...<br>");
sprite = 138;
sprite = 0;
solid = false;
}
......@@ -58,24 +58,29 @@ void CCamera::process()
{
if(mp_AttachedObject == NULL)
{ // This means, that there is no attached object. Let the camera scroll freely!
size_t movespeed = 100;
if(g_pInput->getHoldedKey(KA))
moveLeft(100);
else if(g_pInput->getHoldedKey(KD))
moveRight(100);
if(g_pInput->getHoldedKey(KW))
moveUp(100);
else if(g_pInput->getHoldedKey(KS))
moveDown(100);
/*if(g_pInput->getHoldedCommand(IC_LEFT))
moveLeft(10);
if(g_pInput->getHoldedCommand(IC_LEFT))
moveLeft(movespeed);
else if(g_pInput->getHoldedCommand(IC_RIGHT))
moveRight(10);
moveRight(movespeed);
if(g_pInput->getHoldedCommand(IC_UP))
moveUp(10);
moveUp(movespeed);
else if(g_pInput->getHoldedCommand(IC_DOWN))
moveDown(10);*/
moveDown(movespeed);
}
else
{
if(!mp_AttachedObject->getXPosition() < x)
moveLeft(x - mp_AttachedObject->getXPosition());
else if(!mp_AttachedObject->getXPosition() > x)
moveRight(mp_AttachedObject->getXPosition() - x);
if(!mp_AttachedObject->getYPosition() < y)
moveUp(y - mp_AttachedObject->getYPosition());
else if(!mp_AttachedObject->getYPosition() > y)
moveDown(mp_AttachedObject->getYPosition() - y);
}
int px, py, left, up, right, down, speed;
......
......@@ -274,22 +274,6 @@ void CEGAGraphicsGalaxy::extractTile(SDL_Surface *sfc, std::vector<unsigned char
// Decode the image data
for(size_t p = 0; p < 4; p++)
{
// /* Decode the image data */
// for(p = 0; p < 4; p++)
// {
// /* Decode the lines of the bitmap data */
// pointer = EgaGraph[EpisodeInfo[ep].Index8Tiles].data + (i * 4 * 8) + p * 8;
// for(y = 0; y < 8; y++)
// memcpy(planes[p]->lines[y], pointer + y, 1);
// }
//
// bmp = bmp_merge(planes[2], planes[1], planes[0], planes[3]);
// bmp_blit(bmp, 0, 0, tiles, 0, 8 * i, 8, 8);
// bmp_free(bmp);
// //printf("\x8\x8\x8\x8");
// Decode the lines of the bitmap data
size_t tileoff = usetileoffset ? (tile*4*columns*(size/8)*size) : 0;
Uint8 *pointer = &(data[0]) + tileoff + p * (size/8) * size;
......@@ -721,10 +705,14 @@ bool CEGAGraphicsGalaxy::readSprites( size_t NumSprites, size_t IndexSprite )
Sprite.setSize( Head.Width*8, Head.Height );
// Setup the collision information
Sprite.setBouncingBoxCoordinates( ((Head.Rx1 - Head.OrgX) << STC),
((Head.Ry1 - Head.OrgY) << STC),
((Head.Rx2 - Head.OrgX) << STC),
((Head.Ry2 - Head.OrgY) << STC));
Uint16 boxX1 = ((Head.Rx1 - Head.OrgX) << (STC-Head.Shifts));
Uint16 boxY1 = ((Head.Ry1 - Head.OrgY) << (STC-Head.Shifts));
Uint16 boxX2 = ((Head.Rx2 - Head.OrgX) << (STC-Head.Shifts));
Uint16 boxY2 = ((Head.Ry2 - Head.OrgY) << (STC-Head.Shifts));
Sprite.setBouncingBoxCoordinates( boxX1, boxY1, boxX2, boxY2 );
Sprite.createSurface( g_pVideoDriver->BlitSurface->flags,
g_pGfxEngine->Palette.m_Palette );
......
......@@ -16,6 +16,10 @@
#include "../../sdl/CVideoDriver.h"
#include "../../CLogFile.h"
#include "../CCamera.h"
// AI Headers
#include "ai/CPlayerWM.h"
#include <fstream>
CMapLoaderGalaxy::CMapLoaderGalaxy(CExeFile &ExeFile, std::vector<CObject*>& ObjectPtr):
......@@ -265,17 +269,13 @@ void CMapLoaderGalaxy::spawnFoes(CMap &Map)
}
file.close();*/
// Add the Camera into the game scene
CCamera *camera = new CCamera(&Map,0,0);
m_ObjectPtr.push_back(camera);
// he we go to the adding objects
data_ptr = start_data;
for(size_t y=0 ; y<height ; y++)
{
for(size_t x=0 ; x<width ; x++)
{
addFoe(*data_ptr, x, y);
addFoe(Map, *data_ptr, x, y);
data_ptr++;
}
}
......@@ -284,21 +284,33 @@ void CMapLoaderGalaxy::spawnFoes(CMap &Map)
/**
* @brief Loads a foe given by the coordiantes
*/
void CMapLoaderGalaxy::addFoe(word foe, size_t x, size_t y)
void CMapLoaderGalaxy::addFoe(CMap &Map, word foe, size_t x, size_t y)
{
//x <<= CSF;
//y <<= CSF;
x <<= CSF;
y <<= CSF;
CObject *p_newfoe = NULL;
CCamera *camera = NULL;
switch(foe)
{
case 3:
// This is the player on map
// Spawn this player.
p_newfoe = new galaxy::CPlayerWM(&Map, x, y);
// Add the Camera into the game scene and attach it to this player
camera = new CCamera(&Map,x,y);
camera->attachToObject(*p_newfoe);
m_ObjectPtr.push_back(camera);
break;
default:
break;
}
if(p_newfoe)
m_ObjectPtr.push_back(p_newfoe);
}
CMapLoaderGalaxy::~CMapLoaderGalaxy()
......
......@@ -25,7 +25,7 @@ public:
bool gotoSignature(std::ifstream &MapFile);
bool loadMap(CMap &Map, Uint8 level);
void spawnFoes(CMap &Map);
void addFoe(word foe, size_t x, size_t y);
void addFoe(CMap &Map, word foe, size_t x, size_t y);
virtual ~CMapLoaderGalaxy();
private:
......
......@@ -82,7 +82,7 @@ void CPlayGameGalaxy::processInput()
*/
void CPlayGameGalaxy::processRendering()
{
g_pGfxEngine->getFont(0).drawFont(g_pVideoDriver->BlitSurface, "Press the arrows to scroll", 10, 10);
}
......
......@@ -9,6 +9,7 @@
#include "CMapLoaderGalaxy.h"
#include "../../sdl/CInput.h"
#include "../../sdl/CVideoDriver.h"
#include "../../StringUtils.h"
namespace galaxy {
......@@ -55,6 +56,17 @@ void CWorldMap::process()
(*obj)->draw();
}
std::string text1, text2, text3;
text1 = "Obj1- X:" + itoa((*m_ObjectPtr.begin())->getXPosition());
text1 += " Y:" + itoa((*m_ObjectPtr.begin())->getYPosition());
text2 = "Obj2- X:" + itoa((*m_ObjectPtr.begin())->getXPosition()+1);
text2 += " Y:" + itoa((*m_ObjectPtr.begin())->getYPosition()+1);
text3 = "Edge (" + itoa(m_Map.m_width<<CSF)+","+itoa(m_Map.m_height<<CSF) + ")";
g_pGfxEngine->getFont(0).drawFont(g_pVideoDriver->BlitSurface, text1, 10, 10);
g_pGfxEngine->getFont(0).drawFont(g_pVideoDriver->BlitSurface, text2, 10, 18);
g_pGfxEngine->getFont(0).drawFont(g_pVideoDriver->BlitSurface, text3, 10, 26);
}
void CWorldMap::processInput()
......@@ -65,22 +77,6 @@ void CWorldMap::processInput()
//if(g_pInput->getPressedCommand(IC_QUIT))
//m_endgame = true;
if(g_pInput->getHoldedCommand(IC_LEFT))
{
m_Map.scrollLeft();
}
else if(g_pInput->getHoldedCommand(IC_RIGHT))
{
m_Map.scrollRight();
}
if(g_pInput->getHoldedCommand(IC_UP))
{
m_Map.scrollUp();
}
else if(g_pInput->getHoldedCommand(IC_DOWN))
{
m_Map.scrollDown();
}
}
CWorldMap::~CWorldMap() {
......
......@@ -6,6 +6,8 @@
*/
#include "CPlayerWM.h"
#include "../../../common/CBehaviorEngine.h"
#include "../../../sdl/CInput.h"
namespace galaxy {
......@@ -13,6 +15,43 @@ CPlayerWM::CPlayerWM(CMap *pmap, Uint32 x, Uint32 y):
CObject(pmap, x, y, OBJ_PLAYER)
{
// TODO Auto-generated constructor stub
sprite=138;
CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
bboxX1 = rSprite.m_bboxX1; bboxX2 = rSprite.m_bboxX2;
bboxY1 = rSprite.m_bboxY1; bboxY2 = rSprite.m_bboxY2;
checkinitialCollisions();
}
/**
* The main process cycle for the player itself only on the map
*/
void CPlayerWM::process()
{
processWalking();
}
/*
* Processes the walking of the player on map here
*/
void CPlayerWM::processWalking()
{
size_t movespeed = 100;
// TODO: Implement animation speed!
if(g_pInput->getHoldedCommand(IC_LEFT))
moveLeft(movespeed);
if(g_pInput->getHoldedCommand(IC_RIGHT))
moveRight(movespeed);
if(g_pInput->getHoldedCommand(IC_UP))
moveUp(movespeed);
if(g_pInput->getHoldedCommand(IC_DOWN))
moveDown(movespeed);
if(g_pInput->getHoldedCommand(IC_STATUS))
solid = !solid;
}
......
......@@ -15,6 +15,8 @@ namespace galaxy {
class CPlayerWM : public CObject {
public:
CPlayerWM(CMap *pmap, Uint32 x, Uint32 y);
void process();
void processWalking();
virtual ~CPlayerWM();
};
......
......@@ -152,12 +152,9 @@ void CTileLoader::readGalaxyTileinfo(size_t NumUnMaskedTiles, size_t NumMaskedTi
TileMaskedProperties[j].bdown = m_data[j+2*NumUnMaskedTiles+2*NumMaskedTiles];
TileMaskedProperties[j].bleft = m_data[j+2*NumUnMaskedTiles+3*NumMaskedTiles];
//TileMaskedProperties[j].animationtime = m_data[j+2*NumUnMaskedTiles+4*NumMaskedTiles];
TileMaskedProperties[j].nextTile = static_cast<char>(m_data[j+2*NumUnMaskedTiles+4*NumMaskedTiles]);
TileMaskedProperties[j].behaviour = m_data[j+2*NumUnMaskedTiles+5*NumMaskedTiles];
//TileMaskedProperties[j].nextTile = static_cast<char>(m_data[j+2*NumUnMaskedTiles+6*NumMaskedTiles]);
TileMaskedProperties[j].animationtime = m_data[j+2*NumUnMaskedTiles+6*NumMaskedTiles];
TileMaskedProperties[j].nextTile = static_cast<char>(m_data[j+2*NumUnMaskedTiles+4*NumMaskedTiles]);
}
}
......
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