Commit 3dbdd61e authored by Gerhard Stein's avatar Gerhard Stein

Scrubs can be shot again. Animation have been improved alot now. I think now...

Scrubs can be shot again. Animation have been improved alot now. I think now it's perfect and much less code and variables.
parent f2639890
......@@ -177,7 +177,6 @@ bool CMap::changeTile(Uint16 x, Uint16 y, Uint16 t)
if( setTile( x, y, t ) )
{
m_Tilemaps.at(1).drawTile(mp_scrollsurface, (x<<4)&511, (y<<4)&511, t);
registerAnimation( (x<<4)&511, (y<<4)&511, 0, t );
return true;
}
return false;
......@@ -317,13 +316,11 @@ void CMap::redrawAt(int mx, int 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(1).drawTile(mp_scrollsurface, (mx<<4)&511, (my<<4)&511, fg);
registerAnimation( (mx<<4)&511, (my<<4)&511, bg, fg );
}
else
{
size_t fg = m_Plane[1].getMapDataAt(mx, my);
m_Tilemaps.at(1).drawTile(mp_scrollsurface, (mx<<4)&511, (my<<4)&511, fg);
registerAnimation( (mx<<4)&511, (my<<4)&511, 0, fg );
}
}
......@@ -353,7 +350,6 @@ void CMap::drawAll()
m_Tilemaps.at(0).drawTile(mp_scrollsurface, ((x<<4)+m_mapxstripepos)&511,((y<<4)+m_mapystripepos)&511, bg);
if(fg)
m_Tilemaps.at(1).drawTile(mp_scrollsurface, ((x<<4)+m_mapxstripepos)&511,((y<<4)+m_mapystripepos)&511, fg);
registerAnimation( ((x<<4)+m_mapxstripepos)&511,((y<<4)+m_mapystripepos)&511, bg, fg );
}
}
}
......@@ -366,7 +362,6 @@ void CMap::drawAll()
Uint32 fg = m_Plane[1].getMapDataAt(x+m_mapx, y+m_mapy);
m_Tilemaps.at(1).drawTile(mp_scrollsurface, ((x<<4)+m_mapxstripepos)&511,((y<<4)+m_mapystripepos)&511, fg);
registerAnimation( ((x<<4)+m_mapxstripepos)&511,((y<<4)+m_mapystripepos)&511, 0, fg );
}
}
}
......@@ -391,7 +386,6 @@ void CMap::drawHstripe(unsigned int y, unsigned int mpy)
m_Tilemaps.at(0).drawTile(mp_scrollsurface, ((x<<4)+m_mapxstripepos)&511, y, bg);
if(fg)
m_Tilemaps.at(1).drawTile(mp_scrollsurface, ((x<<4)+m_mapxstripepos)&511, y, fg);
registerAnimation( ((x<<4)+m_mapxstripepos)&511, y, bg, fg );
}
}
else
......@@ -400,7 +394,6 @@ void CMap::drawHstripe(unsigned int y, unsigned int mpy)
{
Uint32 fg = m_Plane[1].getMapDataAt(x+m_mapx, mpy);
m_Tilemaps.at(1).drawTile(mp_scrollsurface, ((x<<4)+m_mapxstripepos)&511, y, fg);
registerAnimation( ((x<<4)+m_mapxstripepos)&511, y, 0, fg );
}
}
}
......@@ -425,7 +418,6 @@ void CMap::drawVstripe(unsigned int x, unsigned int mpx)
m_Tilemaps.at(0).drawTile(mp_scrollsurface, x, ((y<<4)+m_mapystripepos)&511, bg);
if(fg)
m_Tilemaps.at(1).drawTile(mp_scrollsurface, x, ((y<<4)+m_mapystripepos)&511, fg);
registerAnimation( x, ((y<<4)+m_mapystripepos)&511, bg, fg );
}
}
else
......@@ -435,7 +427,6 @@ void CMap::drawVstripe(unsigned int x, unsigned int mpx)
Uint32 fg = m_Plane[1].getMapDataAt(mpx, y+m_mapy);
m_Tilemaps.at(1).drawTile(mp_scrollsurface, x, ((y<<4)+m_mapystripepos)&511, fg);
registerAnimation( x, ((y<<4)+m_mapystripepos)&511, 0, fg );
}
}
}
......@@ -445,49 +436,10 @@ void CMap::drawVstripe(unsigned int x, unsigned int mpx)
/////////////////////////
// searches for animated tiles at the map position (X,Y) and
// unregisters them from animtiles
/**
* auxiliary list predictor which finds elements at some coordinates
*/
class CMap::usedCoord
{
public:
usedCoord(size_t x, size_t y): m_x(x), m_y(y) {};
bool operator() (const stAnimationSlot& value)
{ return (m_x == value.x && m_y == value.y ); }
private : size_t m_x,m_y;
};
void CMap::deAnimate(int x, int y)
{
const int px = ((m_mapxstripepos+((x-m_mapx)<<4))&511);
const int py = ((m_mapystripepos+((y-m_mapy)<<4))&511);
m_AnimationSlots.remove_if(usedCoord(px, py));
}
// Draw an animated tile. If it's not animated draw it anyway
void CMap::drawAnimatedTile(SDL_Surface *dst, Uint16 mx, Uint16 my, Uint16 tile)
{
CTileProperties &TileProperty = g_pBehaviorEngine->getTileProperties(1).at(tile);
if(TileProperty.animationtime)
{ // animate animated tile
std::list<stAnimationSlot>::iterator slot = m_AnimationSlots.begin();
for( ; slot != m_AnimationSlots.end() ; slot++ )
{
if( (slot->x == static_cast<size_t>(mx+m_scrollx_buf)) &&
(slot->y == static_cast<size_t>(my+m_scrolly_buf)) )
{
m_Tilemaps.at(1).drawTile( dst, mx, my, slot->fgtile );
}
}
}
else
{ // Unanimated tile
m_Tilemaps.at(1).drawTile( dst, mx, my, tile );
}
m_Tilemaps.at(1).drawTile( dst, mx, my, tile );
}
void CMap::animateAllTiles()
......@@ -496,91 +448,94 @@ void CMap::animateAllTiles()
m_animtiletimer++;
// Go throught the list and just draw all the tiles that need to be animated
std::list<stAnimationSlot>::iterator slot = m_AnimationSlots.begin();
if(m_Background)
{
for( ; slot != m_AnimationSlots.end() ; slot++ )
{ // Get the right property of the tile
CTileProperties &TilePropertiesBG =
g_pBehaviorEngine->getTileProperties(0).at(slot->bgtile);
CTileProperties &TilePropertiesFG =
g_pBehaviorEngine->getTileProperties(1).at(slot->fgtile);
m_Tilemaps.at(0).drawTile( mp_scrollsurface, slot->x, slot->y, slot->bgtile);
if(slot->fgtile)
m_Tilemaps.at(1).drawTile( mp_scrollsurface, slot->x, slot->y, slot->fgtile);
// get the next tile which will be drawn in the next animation cycle
if(TilePropertiesBG.animationtime)
if( (m_animtiletimer % TilePropertiesBG.animationtime) == 0)
slot->bgtile += TilePropertiesBG.nextTile;
if(TilePropertiesFG.animationtime)
if( (m_animtiletimer % TilePropertiesFG.animationtime) == 0)
slot->fgtile += TilePropertiesFG.nextTile;
}
}
else
{
for( ; slot != m_AnimationSlots.end() ; slot++ )
{ // Get the right property of the tile
CTileProperties &TilePropertiesFG =
g_pBehaviorEngine->getTileProperties(1).at(slot->fgtile);
m_Tilemaps.at(1).drawTile( mp_scrollsurface, slot->x, slot->y, slot->fgtile);
Uint32 num_h_tiles = mp_scrollsurface->h/16;
Uint32 num_v_tiles = mp_scrollsurface->w/16;
if(num_v_tiles+m_mapx >= m_width)
num_v_tiles = m_width-m_mapx;
// get the next tile which will be drawn in the next animation cycle
if(TilePropertiesFG.animationtime)
if( (m_animtiletimer % TilePropertiesFG.animationtime) == 0)
slot->fgtile += TilePropertiesFG.nextTile;
}
}
}
if(num_h_tiles+m_mapy >= m_height)
num_h_tiles = m_height-m_mapy;
// register the tiles which has to be animated
void CMap::registerAnimation(Uint32 x, Uint32 y, size_t bg, size_t fg)
{
// first check if some of the Animation slots are out of place and remove them
m_AnimationSlots.remove_if(usedCoord(x, y));
CTileProperties &TilePropertyFG =
g_pBehaviorEngine->getTileProperties(1).at(fg);
// we just drew an animated tile which we will now register
if( m_Background )
if(m_Background)
{
CTileProperties &TilePropertyBG =
g_pBehaviorEngine->getTileProperties(0).at(bg);
if( TilePropertyBG.animationtime && m_Background )
std::vector<CTileProperties> &backTileProperties =
g_pBehaviorEngine->getTileProperties(0);
std::vector<CTileProperties> &frontTileProperties =
g_pBehaviorEngine->getTileProperties(1);
word *p_back_tile = m_Plane[0].getMapDataPtr();
word *p_front_tile = m_Plane[1].getMapDataPtr();
for( size_t y=0 ; y<m_height ; y++)
{
stAnimationSlot NewAnimationSlot;
NewAnimationSlot.x = x;
NewAnimationSlot.y = y;
NewAnimationSlot.bgtile = bg;
NewAnimationSlot.fgtile = fg;
m_AnimationSlots.push_back(NewAnimationSlot);
for( size_t x=0 ; x<m_width ; x++)
{
bool draw = false;
CTileProperties &back_tile = backTileProperties[*p_back_tile];
if( back_tile.animationtime && (m_animtiletimer % back_tile.animationtime == 0) )
{
*p_back_tile += back_tile.nextTile;
draw = true;
}
p_back_tile++;
CTileProperties &front_tile = frontTileProperties[*p_front_tile];
if( front_tile.animationtime && (m_animtiletimer % front_tile.animationtime == 0) )
{
*p_front_tile += front_tile.nextTile;
draw = true;
}
p_front_tile++;
if( draw && x >= m_mapx && y >= m_mapy &&
x < m_mapx + num_v_tiles && y < m_mapy + num_h_tiles )
{
Uint16 bg = m_Plane[0].getMapDataAt(x,y);
Uint16 fg = m_Plane[1].getMapDataAt(x,y);
const Uint16 loc_x = (((x-m_mapx)<<4)+m_mapxstripepos)&511;
const Uint16 loc_y = (((y-m_mapy)<<4)+m_mapystripepos)&511;
m_Tilemaps.at(0).drawTile(mp_scrollsurface, loc_x, loc_y, bg);
if(fg)
m_Tilemaps.at(1).drawTile(mp_scrollsurface, loc_x, loc_y, fg);
}
}
}
}
if( TilePropertyFG.animationtime )
else
{
stAnimationSlot NewAnimationSlot;
NewAnimationSlot.x = x;
NewAnimationSlot.y = y;
NewAnimationSlot.bgtile = bg;
NewAnimationSlot.fgtile = fg;
m_AnimationSlots.push_back(NewAnimationSlot);
std::vector<CTileProperties> &frontTileProperties =
g_pBehaviorEngine->getTileProperties(1);
word *p_front_tile = m_Plane[1].getMapDataPtr();
for( size_t y=0 ; y<m_height ; y++)
{
for( size_t x=0 ; x<m_width ; x++)
{
bool draw = false;
CTileProperties &front_tile = frontTileProperties[*p_front_tile];
if( front_tile.animationtime && (m_animtiletimer % front_tile.animationtime == 0) )
{
*p_front_tile += front_tile.nextTile;
draw = true;
}
p_front_tile++;
if( draw && x >= m_mapx && y >= m_mapy &&
x < m_mapx + num_v_tiles && y < m_mapy + num_h_tiles )
{
Uint16 fg = m_Plane[1].getMapDataAt(x,y);
const Uint16 loc_x = (((x-m_mapx)<<4)+m_mapxstripepos)&511;
const Uint16 loc_y = (((y-m_mapy)<<4)+m_mapystripepos)&511;
m_Tilemaps.at(1).drawTile(mp_scrollsurface, loc_x, loc_y, fg);
}
}
}
}
}
void CMap::cleanup()
{
if(!m_AnimationSlots.empty())
m_AnimationSlots.clear();
}
CMap::~CMap() {
}
......
......@@ -51,10 +51,8 @@ public:
bool changeTile(Uint16 x, Uint16 y, Uint16 t);
// Animation methods
void deAnimate(int x, int y);
void drawAnimatedTile(SDL_Surface *dst, Uint16 mx, Uint16 my, Uint16 tile);
void animateAllTiles();
void registerAnimation(Uint32 x, Uint32 y, size_t bg, size_t fg);
unsigned int getlevelat(unsigned int x, unsigned int y) {
return m_objectlayer[x>>4][y>>4]; }
......@@ -63,7 +61,6 @@ public:
word *getForegroundData();
word *getBackgroundData();
void cleanup();
virtual ~CMap();
Sint16 m_scrollx_buf; // Amount to move surface in X.
......@@ -100,13 +97,13 @@ private:
SDL_Surface *mp_scrollsurface;
std::vector<CTilemap> &m_Tilemaps;
class usedCoord;
/*class usedCoord;
struct stAnimationSlot{
size_t x, y;
size_t bgtile, fgtile;
};
};*/
std::list<stAnimationSlot> m_AnimationSlots;
//std::list<stAnimationSlot> m_AnimationSlots;
Uint8 m_animtiletimer;
......
......@@ -59,14 +59,6 @@ m_blinktime(0)
checkinitialCollisions();
}
/*bool CObject::spawn(int x0, int y0, object_t otype, int Episode, direction_t dirof)
{
// Check for collision points when object is spawn. Later only collision basing on movements will be checked
// object could not be created
g_pLogFile->ftextOut("Object of type %d could not be created at %d,%d (out of object slots)<br>",otype,x,y);
return false;
}*/
void CObject::setupObjectType(int Episode)
{
switch(m_type)
......
......@@ -48,7 +48,6 @@ bool CPlayer::getGoodie(int px, int py)
(TileProperty[tile].behaviour == 27 || TileProperty[tile].behaviour == 28) ) // All pickupable items
{ // pick up the goodie, i.e. erase it from the map
mp_Map->changeTile(px, py, TileProperty[tile].chgtile);
if (TileProperty[tile].animationtime) mp_Map->deAnimate(px, py);
}
else if (TileProperty[tile].behaviour == 1) // Lethal (Deadly) Behavoir
{ // whoah, this "goodie" isn't so good...
......@@ -271,7 +270,6 @@ bool CPlayer::showGameHint(int mpx, int mpy)
return false;
}
mp_Map->setTile(mpx, mpy+1, 432,true);
mp_Map->deAnimate(mpx<<STC, (mpy+1)<<STC);
}
hintused = true;
return true;
......
......@@ -41,7 +41,6 @@ void CPlayGameGalaxy::loadLevel()
// TODO: Lets load the main map for now and create process for this
CMapLoaderGalaxy MapLoader(m_ExeFile);
m_Map.cleanup();
m_Map.setScrollSurface(g_pVideoDriver->getScrollSurface());
MapLoader.loadMap(m_Map, m_Level); // Map Level?
......
......@@ -106,7 +106,7 @@ void CScrub::process()
canbezapped = 0;
}
// die if shot
if (HealthPoints <= 0 && state==SCRUB_DYING )
if (HealthPoints <= 0 && state!=SCRUB_DYING )
{
solid=true;
state = SCRUB_DYING;
......
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