{
//variables
string buffer,file;
- vector<int> transparency;
+ int transparency[3];
int pause;
animFile="ArtAssets/Sprites/"+animFile;
//file
}
else
{
+ /** File name */
file=temp;
+ /** Pause time */
value>>pause;
+ /** transparency #'s R G B */
for(int i=0; i<3;++i)
{
int num;
value>>num;
if(num >= 0 && num<=255)
- transparency.push_back(num);
+ transparency[i] = num;///< \todo check to see if this is being stupid.
+ else
+ {
+ transparency[i] = 0;
+ cout<<"Invalid value!"<<endl;
+ }
}
+ /** AnimationPeg */
+ double x=0.0, y=0.0;
+ value>>x;
+ value>>y;
+
+ /** Collision data */
+ char c;
+ value>>c;
+ while(c != ')'){
+ if(c == 'n')
+ continue;
+ else if(c == 'c')
+ {
+ double xOffset = 0.0, yOffset = 0.0;
+ value>>xOffset;
+ value>>yOffset;
+ double radius;
+ value>>radius;
+ mAnim[count].bounds.push_back(CollisionCircle(Point2D(xOffset, yOffset), radius));
+ }
+ else if(c == 'r')
+ {
+ double xOffset = 0.0, yOffset = 0.0;
+ value>>xOffset;
+ value>>yOffset;
+ double width = 0.0 , height = 0.0;
+ value>>width;
+ value>>height;
+ mAnim[count].bounds.push_back(CollisionRectangle(Point2D(xOffset, yOffset), width, height));
+ }
+ value>>c;
+ }
+
+ /** Load image for Frame */
SDL_Surface *temp=NULL;
- if((temp = LoadImage("Sprites/"+file)) == NULL) return -1;
+ if((temp = LoadImage("Sprites/"+file)) == NULL) return -1;//Load image for Frame
/** Set transparent color */
SDL_SetColorKey(temp, SDL_SRCCOLORKEY, SDL_MapRGB(temp->format, transparency[0], transparency[1], transparency[2]));
+
/** Loads image into animation */
mAnim[count].image = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
+
/** sets frame delay and makes sure height and width are correct */
mAnim[count].pause = pause;
if(!mW) mW = mAnim[count].image->w;
if(!mH) mH = mAnim[count].image->h;
+
+ /** Set the animation Peg*/
+ mAnim[count].animationPeg = Point2D(x,y);
+
count++;
}
}
-#ifndef SPRITEBASE
-#define SPRITEBASE
-#include "Collision.h"
+#ifndef ANIMATION
+#define ANIMATION
+#include "Frame.h"
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
-#include <vector>
using std::vector;
-struct SpriteFrame{
- SDL_Surface *image;/**< Pointer to an image. */
- int pause;/**< Tells the amount of time to pause between this frame and the next. */
- int width;/**< Base width of the frame's image. */
- int height;/**< Base height of the frame's image. */
- vector<Point2D> hotSpots;/**< Hot spots that can be used for locating objects on the sprite default is tagged to center of the sprite \todo implement default*/
- Point2D animationPeg;/**< The offeset from position to place the image. Defaults to (0,0) \todo implement */
- vector<Collision> bounds;/**< The collision data for this sprite */
-};
-
/**
An Animation
public:
Animation(std::string animFile);
int loadAnimation(std::string animFile);/**< Loads the Animations from a file in the specified format. */
- SpriteFrame *mAnim;/**< Pointer to the current animation. */
+ SpriteFrame *mAnim;/**< Pointer to the current animation. As an array of SpriteFrames */
int mBuilt,/**< Using as a bool */
mNumFrames,/**< Number of frames in this Animation */
mW,/**< Animation's current width */
#Number of Frames
#ArtAssets/ milisec Transparency
-#filename pause r g b
+#filename pause r g b xOffset yOffset ( collisionType <Circle has offset, radius | rectangle has offset, width, height>
NumFrames: 4
-sun1.bmp 20 0 0 255
-sun2.bmp 20 0 0 255
-sun3.bmp 20 0 0 255
-sun4.bmp 20 0 0 255
+sun1.bmp 20 0 0 255 0.0 0.0 ( n )
+sun2.bmp 20 0 0 255 0.0 0.0 ( n )
+sun3.bmp 20 0 0 255 0.0 0.0 ( n )
+sun4.bmp 20 0 0 255 0.0 0.0 ( n )
#Number of Frames
#ArtAssets/ milisec Transparency
-#filename pause r g b
+#filename pause r g b xOffset yOffset
NumFrames: 9
-viking1.bmp 50 0 255 0
-viking2.bmp 50 0 255 0
-viking3.bmp 50 0 255 0
-viking4.bmp 50 0 255 0
-viking5.bmp 50 0 255 0
-viking6.bmp 50 0 255 0
-viking7.bmp 50 0 255 0
-viking8.bmp 50 0 255 0
-viking9.bmp 50 0 255 0
+viking1.bmp 50 0 255 0 0.0 0.0 ( n )
+viking2.bmp 50 0 255 0 0.0 0.0 ( n )
+viking3.bmp 50 0 255 0 0.0 0.0 ( n )
+viking4.bmp 50 0 255 0 0.0 0.0 ( n )
+viking5.bmp 50 0 255 0 0.0 0.0 ( n )
+viking6.bmp 50 0 255 0 0.0 0.0 ( n )
+viking7.bmp 50 0 255 0 0.0 0.0 ( n )
+viking8.bmp 50 0 255 0 0.0 0.0 ( n )
+viking9.bmp 50 0 255 0 0.0 0.0 ( n )
--- /dev/null
+#include "Collision.h"
+
+bool CollisionRectangle::collision(CollisionRectangle &c){
+}
+bool CollisionRectangle::collision(CollisionCircle &c){
+}
+bool CollisionCircle::collision(CollisionRectangle &c){
+}
+bool CollisionCircle::collision(CollisionCircle &c){
+}
+
class Collision
{
public:
- Collision();
+ Collision():pos(0.0,0.0){}
Point2D pos;/**< The position of the center of the collision data */
- virtual bool rectColl(Collision &c);/**< Check collision with Rectangle */
- virtual bool circColl(Collision &c);/**< Check collision with Circle */
+ virtual bool collision(CollisionRectangle &c);/**< Check collision with Rectangle */
+ virtual bool collision(CollisionCircle &c);/**< Check collision with Circle */
/// \todo See this http://www.metanetsoftware.com/technique/tutorialA.html
protected:
string name;///< Name of this behavior \todo make this actually be useful
class CollisionRectangle : public Collision
{
public:
- CollisionRectangle();
- int width;
- int height;
+ CollisionRectangle():width(1.0),height(1.0){};
+ CollisionRectangle(Point2D pt, double w, double h):width(w),height(h){ pos = pt;}
+ double width;/**< Rectangle's width */
+ double height;/**< Rectangle's height */
+
+ bool collision(CollisionRectangle &c);/**< Check collision with Rectangle */
+ bool collision(CollisionCircle &c);/**< Check collision with Circle */
};
/**
{
public:
CollisionCircle();
- int radius;/**< The raidus of the circle */
+ CollisionCircle(Point2D pt, double r):radius(r){ pos = pt; }
+ double radius;/**< The raidus of the circle */
+
+ bool collision(CollisionRectangle &c);/**< Check collision with Rectangle */
+ bool collision(CollisionCircle &c);/**< Check collision with Circle */
};
#endif
--- /dev/null
+#ifndef FRAME
+#define FRAME
+#include "Collision.h"
+#include <string>
+#include <SDL/SDL.h>
+#include <SDL/SDL_image.h>
+#include <vector>
+
+struct SpriteFrame{
+ SDL_Surface *image;/**< Pointer to an image. */
+ int pause;/**< Tells the amount of time to pause between this frame and the next. */
+ int width;/**< Base width of the frame's image. */
+ int height;/**< Base height of the frame's image. */
+ vector<Point2D> hotSpots;/**< Hot spots that can be used for locating objects on the sprite default is tagged to center of the sprite \todo implement default*/
+ Point2D animationPeg;/**< The offeset from position to place the image. Defaults to (0,0) \todo implement */
+ vector<Collision> bounds;/**< The collision data for this sprite */
+};
+
+#endif
\ No newline at end of file
{
if(mAnimating == 1) {
if(mLastUpdate+mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame].pause*mSpeed<SDL_GetTicks()) {
+ //obtain current peg
+ Point2D ppos = mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame].animationPeg;
mActor.mFrame++;
- if(mActor.mFrame > mActor.mAnimations[mActor.mCurrentAnimation]->mNumFrames-1) mActor.mFrame=0;
+ if(mActor.mFrame > mActor.mAnimations[mActor.mCurrentAnimation]->mNumFrames-1)
+ mActor.mFrame=0;
+ //obtain next peg
+ Point2D npos = mActor.mAnimations[mActor.mCurrentAnimation]->mAnim[mActor.mFrame].animationPeg;
+ //move current position to difference of two
+ mPos.add(ppos - npos);
mLastUpdate = SDL_GetTicks();
}
}
Point2D sub(Point2D pt);/**< Subtracts the value of the point from this \return This after modification*/
Point2D mult(double d);/**< Multiplies the values of this by i \return This after modificaiton*/
Point2D div(double d);/**< Divides the values of this by i \return This after modificaiton*/
-
+ Point2D operator+ (Point2D& pt){ return Point2D(x + pt.x, y + pt.y); }
+ Point2D operator- (Point2D& pt){ return Point2D(x - pt.x, y - pt.y); }
+ Point2D operator+= (Point2D& pt){ return add(pt); }
+ Point2D operator-= (Point2D& pt){ sub(pt); }
};
/** Just for more logical names for sizes of objects*/