/**
This function is tasked with drawing the 8 points on a circle so that only 1/8th need be calculated.
\param screen the Screen
- \param pos This is the position to draw the points (not & because may want to have an added value pushed in)
+ \param wPos This is the world position to draw the points (not & because may want to have an added value pushed in)
+ \param pos This is the relative position to draw the points (not & because may want to have an added value pushed in)
\param color the color to be drawn
*/
void DrawCircle(SDL_Surface* screen, const Point2D wPos, const Point2D pos, Uint32 color){
}
else if(const CollisionCircle* col = dynamic_cast<const CollisionCircle*>(c)){
- ///col->collision(this, cPos, pos); \todo this flips a shit!!!!!!
+ ///col->collision(this, cPos, pos);/// \todo this flips a shit!!!!!!
}
return false;
\param pos the current sprite's position.
\return Returns true if any of the object's collision datas are colliding .
*/
- bool collision(const CollisionRectangle*, const Point2D cPos, const Point2D pos);/**< This does collision between Rectangles and Circles */
+ bool collision(const CollisionRectangle* c, const Point2D cPos, const Point2D pos);/**< This does collision between Rectangles and Circles */
virtual void draw(const Point2D& pos);/**< Draws the collision data to the screen */
};
#endif
int width;/**< Base width of the frame's image. \todo make this and animation's match or at least sync or delete*/
int height;/**< Base height of the frame's image. \todo make this and animation's match or at least sync or delete*/
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 */
+ Point2D animationPeg;/**< The offeset from position to place the image. Defaults to (0,0) */
vector<Collision*> collisionData;/**< The collision data for this sprite */
};
Game* Game::m_instance = NULL;
/** This function is called to create an instance of the class.
- Calling the constructor publicly is not allowed.
- The constructor is private and is only called by this Instance function.
+Calling the constructor publicly is not allowed.
+The constructor is private and is only called by this Instance function.
*/
Game* Game::game(){
if(!m_instance)
return m_instance;
}
-Game::Game() : mCurrentLevel(0), mScreen(0), ShowCollisions(false)
+Game::Game() : mCurrentLevel(0), mScreen(0), ShowCollisions(false), ShowFPS(false), startclock(0), deltaclock(0), currentFPS(0)
{
/** Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
mLevels.push_back(new Level(mScreen));
else
mLevels = l.levels;
-
+ // set start time for fps calc
+ startclock = SDL_GetTicks();
}
Game::~Game()
}
switch (event.type) {
- /** If the event is a click on the close button in the top
+ /** If the event is a click on the close button in the top
right corner of the window, we kill the application
- */
+ */
case SDL_QUIT:
done = 1;
break;
getCurrentLevel()->drawScene();
break;
- /** If our event reports a key being pressed down
- we process it
- */
- case SDL_KEYDOWN: {
- Uint8 *keys = SDL_GetKeyState(NULL);
- std::cout<<*keys<<std::endl;
- if (keys[SDLK_ESCAPE]) {
- done = 1;
- break;
- }
- if (keys[SDLK_F11]) {
- ShowCollisions = !ShowCollisions;
+ /** If our event reports a key being pressed down
+ we process it
+ */
+ case SDL_KEYDOWN:
+ {
+ Uint8 *keys = SDL_GetKeyState(NULL);
+ std::cout<<*keys<<std::endl;
+ if (keys[SDLK_ESCAPE]) {
+ done = 1;
+ break;
+ }
+ if (keys[SDLK_F11]) {
+ ShowCollisions = !ShowCollisions;
+ }
+ if (keys[SDLK_F12]) {
+ ShowFPS = !ShowFPS;
+ }
}
- }
default: /* fallthrough if the key wasn't escape or control*/
getCurrentLevel()->postEvent(event);
break;
}
getCurrentLevel()->update();
+ //obtain the current fps data.
+ deltaclock = SDL_GetTicks() - startclock;
+ startclock = SDL_GetTicks();
+ if ( deltaclock != 0 )
+ currentFPS = 1000 / deltaclock;
}
SDL_RemoveTimer(timer);
0, /* code */
0, /* data1 */
0 }; /* data2 */
- event.user = uevent;
+ event.user = uevent;
- SDL_PushEvent(&event);
+ SDL_PushEvent(&event);
- return interval;
+ return interval;
}
+
/** Decides whether or not to draw bounding boxes*/
bool ShowCollisions;
+ /** Decides whether or not to output FPS*/
+ bool ShowFPS;
+
/**
Gets the current level being played.
\return current level
/** Returns the main screen to allow for drawing */
SDL_Surface* Screen(){ return mScreen; }
+
+ /** Retrns the Current FPS of the game */
+ Uint32 getFPS() { return currentFPS;}
+
protected:
Game();
~Game();
void loadLevel(std::string levelName);/**< Loads a level by name. */
static Uint32 timerCallback(Uint32 interval, void* data);
+
+ //fps data calc
+ Uint32 startclock;
+ Uint32 deltaclock;
+ Uint32 currentFPS;
+
};
#endif
/** Will handle all movement and dynamic triggers. */
void Level::update(){
- /// \todo fix this too
+ /// \todo fix this behavior too
//mBehavior.update();
+ if(Game::game()->ShowFPS)
+ cout<<Game::game()->getFPS()<<endl;
+
//check collision with sun sprite
mSprites[0]->collisionWithSprite("sun");
}
{
public:
Level(SDL_Surface *screen);
+ /**
+ Level constructor
+ \param screen the Screen to be drawn to
+ \param name of the level
+ */
Level(SDL_Surface *screen, string name);
+ /**
+ Level constructor
+ \param screen the Screen to be drawn to
+ \param name of the level
+ \param behavior the Behavior for this level.
+ */
Level(SDL_Surface *screen, string name, string behavior);
~Level();
void drawScene();/**< Draws everything that is set to draw on the screen. */
Background* mBackground;/**< Pointer to the current Background. */
SDL_Surface *mScreen;/**< Pointer to the screen. */
//LevelBehavior mBehavior;/**< will be used to define the start actions, update, and leaving actions of the level */
- vector<Sprite*> mSprites;/**< Vector of all sprites on the level. \todo Maybe make into map? This should be a list of World objects once implemented. \todo add accessor or move to public*/
+ vector<Sprite*> mSprites;/**< Vector of all sprites on the level. \todo Maybe make into map? This should be a list of World objects once implemented. \todo add accessor or move to public \todo make a map by name (for collisions) \todo make a list ordered by Zorder (for drawing*/
map<string,Actor> mActors;/**< This level's actors. */
vector<Animation> mAnim;/**< This level's Animations */
void DrawIMG();/**< Draws an image to the screen. (Not used) */