removed public name from sprite. (may need to make mName public or add accessors)
Created Behavior class to use in place of function pointers (so that there is only one level class and it has a behavior instead)
--- /dev/null
+#ifndef BEHAVIOR
+#define BEHAVIOR
+#include "Sprite.h"
+#include "Background.h"
+#include <vector>
+#include <map>
+#include <string>
+
+using std::vector;
+using std::string;
+
+/**
+ This is an action that a Behavior, Sprite, or other object can have.
+
+ This class is tasked with the following:
+ - being a parent container for actions.
+ */
+
+class Behavior
+{
+public:
+ Behavior();
+ Behavior(string Name):name(Name);
+ virtual void load();/**< Loading Behavior*/
+ virtual void update();/**< Update Behavior*/
+ virtual void unload();/**< Delete Behavior*/
+protected:
+ string name;/**< Name of this behavior */
+};
+#endif
for (size_t i = 0; i < mLevels.size(); ++i) {
delete mLevels[i];
}
- delete mScreen;
+ /// \todo Does this even need to be here or will closing the program unallocate the mem?
+ //delete mScreen;
}
Level* Game::getCurrentLevel()
break;
}
- ///\todo This needs to be changed to where every single key-press is registered at once and put into a list of sorts and then events on keys is handled elsewhere to allow multi-keypresses and for better program flow.
switch (event.type) {
/** If the event is a click on the close button in the top
right corner of the window, we kill the application
virtual void drawScene();/**< Draws everything that is set to draw on the screen. */
void LoadBG(string name);/**< Loads the Background. */
virtual void postEvent(SDL_Event event);/**< Passes along SDL events */
- virtual void update();/**< Loop that runs every game frame that calculates movement, placement, etc. */
+ virtual void update();/**< Loop that runs every game frame that calculates movement, placement, etc. as well as obtains key strokes (limited by keyboard hardware)*/
void addSprite(Sprite* sp);///< add a Sprite to the list of sprites
void removeSprite(Sprite* sp);///< remove the Sprite sp from the list of sprites
void addActor(string name, Actor actor);///< add a Actor to the list of sprites
public:
LevelWorld(SDL_Surface *screen);
void drawScene();/**< Draws everything that is set to draw on the screen. */
- void update();/**< Loop that runs every game frame that calculates movement, placement, etc.*/
-
+ void update();/**< Loop that runs every game frame that calculates movement, placement, etc. as well as obtains key strokes (limited by keyboard hardware)*/
};
#endif
#include <iostream>
using std::cout;
using std::endl;
-Sprite::Sprite(SDL_Surface *screen, std::string name, Actor actor) :
+Sprite::Sprite(SDL_Surface *screen, std::string name, Actor actor, int z) :
mDrawn(0),
mVisible(true),
mLastUpdate(0),
mActor(actor),
- mScreen(screen)
- /** \todo implement name and mName seee if I even need both of them. */
+ mScreen(screen),
+ ZOrder(z)
{
/** \todo Later add a part that adds name to list of level sprites
Game.Level.SpriteList.pushback(name);
class Sprite
{
public:
- Sprite(SDL_Surface *screen, std::string name, Actor actor);
+ Sprite(SDL_Surface *screen, std::string name, Actor actor, int z = 0);
void setAnimation(int animation){ mActor.mCurrentAnimation = animation; }/**< changes to the specified animation beginning at 0. */
int getAnimation(){ return mActor.mCurrentAnimation; }/**< returns active animation. */
void setFrame(int frame) { mActor.mFrame = frame; }/**< cahnges to the specified frame of the animation beginning at 0. */
void startAnim() {mAnimating = 1;}/**< Causes the animation to play. */
void stopAnim() {mAnimating = 0;}/**< Causes the animation to stop. */
void rewind() {mActor.mFrame = 0;}/**< Resets the Sprite's animation to the first frame. */
- std::string name;
void draw();/**< draws Sprite. */
void xadd(int num) {mPos.x += num;}/**< Increase X coordiante by a given amount. */
void yadd(int num) {mPos.y += num;}/**< Increase y coordinate by a given amount. */
return compatible_image;
}
+Point2D::Point2D (const SizeD& copy){
+ x = copy.w;
+ y = copy.h;
+}
+
double Point2D::length(){
- return sqrt(x*x + y*y);///< \todo find math.sqrt
+ return sqrt(x*x + y*y);
+}
+
+Point2D Point2D::unitVec(){
+ double len = length();///< \todo optimize
+ return Point2D((x/len), (y/len));
}
Point2D Point2D::add(Point2D pt){
x = copy.x;
y = copy.y;
}
- Point2D (/*const SizeD& copy*/int i);///< Copy object \todo make SizeD work here
+ Point2D (const SizeD& copy);///< Copy object
/** \todo add typical vector functionality like length, nomal vectors etc. */
double x;/**< x position */
double length();/**< The length of the Point (from origin)
\return length of the vector/point
*/
+ Point2D unitVec();/**< The unit vector of the Point (from origin)
+ \return length of the vector/point
+ */
Point2D add(Point2D pt);/**< Adds the value of the point to this \return This after modificaiton*/
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*/