Two Demos With Source And Gfx


otaco

Still Fresh
Joined
Sep 14, 2007
Messages
91
Location
Germany, Weimar
Website
www.otaco.de
Since I'm very busy with my current project for the Pandora, there is no time for some stuff I worked on in the past. So I post two concept demos here, maybe somebody is interested to use some of the code or the images (asteriods, explosions, ... as image sequences) for their own projects.
alien_aster.gif

Read the README.TXT within the archives for the demo controls.

Here it comes:

Project_gp2x.zip.jpg


Download: Project_gp2x.zip win32, with source


SDLE_Race_Race.zip.jpg


Download: SDLE_Race_Race.zip.zip win32, with source (This is the Thundercooperfalconbird Project which was originally made for the gp2x)


Both Demos make use of my SDLE Sprite Engine, which I'm not able to provide at the moment, but game mechanics of the demos are coded in the source files in the archives.
 
Last edited by a moderator:
The second image is pretty hot :)

How is the smoke trail done? Particle engine of sorts, using coloured sprites as fit particles and alpha blending them atop each other? (Thats how I've been experimenting of late..)

jeff
 
Last edited by a moderator:
'skeezix' said:
The second image is pretty hot :)

How is the smoke trail done? Particle engine of sorts, using coloured sprites as fit particles and alpha blending them atop each other? (Thats how I've been experimenting of late..)

jeff
Since SDL can't really scale or rotate stuff efficiently all the alpha blending and sizing is made in the animation. Download the demo and look in the data folder (I think its the data/kaboom folder).

I wrote myself an abstraction for frame based sprites here is the header:

CODE

#ifndef SDLE_ANIMSPRITE_H
#define SDLE_ANIMSPRITE_H

#include <SDL.h>

#include <Sprite.h>
#include <ParticleSprite.h>
#include <Point.h>

#include <vector>


namespace SDLE
{


/// Animated Sprite with n Frames

class AnimSprite: public ParticleSprite
{
public:
/// class constructor
//AnimSprite();
/// class constructor
AnimSprite(SDL_Surface* member);
/// class constructor
AnimSprite(const std::vector<SDL_Surface*>& frames);

/// class destructor
virtual ~AnimSprite();

/// add one frame to the end of the sequence
void addFrame(SDL_Surface* member);

/// add frames to the end of the sequence
void addFrames(const std::vector<SDL_Surface*>& frames);

/// set animation to a defined frame
void setFrameNum(int frameNum);

/// set speed of the Animation (in animframes per frame, can be < 0.0 and negative)
void setAnimSpeed(float fpf);

/// get lenght of this animation
int getAnimLength();

/// get the frame container of this animsprite
std::vector<SDL_Surface*>& getFrames();


/// framestep
void animStep();


protected:

/// anim frames per animStep
float _fpf;

/// current frame number in float to support fpf in < 1.0
float _frameNum;

/// current frame number
int _frameNumInt;

/// pointer to the frames
std::vector<SDL_Surface*> _frames;




};


} // SDLE

#endif // SDLE_ANIMSPRITE_H




Here is the implementation:

CODE


#include <AnimSprite.h>


namespace SDLE
{


///////////////////////////////////////////////////////////////////////////////


/// class constructor

AnimSprite::AnimSprite(SDL_Surface* member):
ParticleSprite(member),
_fpf(1.0),
_frameNum(0.0),
_frameNumInt(0),
_frames()
{
_lifeTime = -1;
}

///////////////////////////////////////////////////////////////////////////////


/// class constructor

AnimSprite::AnimSprite(const std::vector<SDL_Surface*>& frames):
ParticleSprite(0),
_fpf(1.0),
_frameNum(0.0),
_frameNumInt(0),
_frames()
{
_lifeTime = -1;
addFrames(frames);

setMember(_frames[0]);
}


///////////////////////////////////////////////////////////////////////////////


/// class destructor

/* virtual */
AnimSprite::~AnimSprite()
{
//_frames.clear();
}


///////////////////////////////////////////////////////////////////////////////


/// add one frame to the end of the sequence

void
AnimSprite::addFrame(SDL_Surface* member)
{
_frames.push_back(member);

// set frame 1 for member
if (_frames.size())
{
setMember(_frames[0]);
}
}


///////////////////////////////////////////////////////////////////////////////


/// add frames to the end of the sequence

void
AnimSprite::addFrames(const std::vector<SDL_Surface*>& frames)
{
for (unsigned int i=0; i!=frames.size(); ++i)
{
_frames.push_back(frames);
}

// set frame 1 for member
if (_frames.size())
{
setMember(_frames[0]);
}
}


///////////////////////////////////////////////////////////////////////////////


/// set animation to a defined frame

void
AnimSprite::setFrameNum(int frameNum)
{
_frameNum = frameNum;

if (_frames.size())
{
_frameNumInt = int(_frameNum) % (_frames.size());
setMember(_frames[_frameNumInt]);
}

}


///////////////////////////////////////////////////////////////////////////////


/// set speed of the animation

void
AnimSprite::setAnimSpeed(float fpf)
{
_fpf = fpf;
}


///////////////////////////////////////////////////////////////////////////////


/// set speed of the animation

int
AnimSprite::getAnimLength()
{
return _frames.size()-1;
}


///////////////////////////////////////////////////////////////////////////////


/// get the frame container of this animsprite

std::vector<SDL_Surface*>&
AnimSprite::getFrames()
{
return _frames;
}


///////////////////////////////////////////////////////////////////////////////


/// draw the sprite to a destination surface

void
AnimSprite::animStep()
{

_frameNum = _frameNum + _fpf;

if (_frames.size())
{
_frameNumInt = int(_frameNum) % (_frames.size());
setMember(_frames[_frameNumInt]);
}

}


///////////////////////////////////////////////////////////////////////////////



} // /namespace SDLE
 
Last edited by a moderator:
Back
Top