mFrames = new SpriteFrame[mNumFrames];
mBuilt = 1;
//read out frames
- for(unsigned int i=0; i<doc.size(); i++){
+ for(unsigned int i=0; i<doc.size(); i++) {
/** File name */
file=doc[i]["file"].to<string>();
double x=doc[i]["offset"]["x"].to<double>();
double y=doc[i]["offset"]["y"].to<double>();
/** Collision data */
- for(unsigned int j=0; j<doc[i]["collision"].size();j++){
- if(doc[i]["collision"][j]["type"].to<string>()=="circle"){
+ for(unsigned int j=0; j<doc[i]["collision"].size();j++) {
+ if(doc[i]["collision"][j]["type"].to<string>()=="circle") {
double xOffset = doc[i]["collision"][j]["offset"]["x"].to<double>();
double yOffset = doc[i]["collision"][j]["offset"]["y"].to<double>();
double radius = doc[i]["collision"][j]["radius"].to<double>();
mFrames[count].collisionData.push_back(new CollisionCircle(Point2D(xOffset, yOffset), radius));
}
- else if(doc[i]["collision"][j]["type"].to<string>()=="rectangle"){
+ else if(doc[i]["collision"][j]["type"].to<string>()=="rectangle") {
double xOffset = doc[i]["collision"][j]["offset"]["x"].to<double>();
double yOffset = doc[i]["collision"][j]["offset"]["y"].to<double>();
double width = doc[i]["collision"][j]["width"].to<double>();
// /** Collision data */
// char c;
// value>>c;
- // if(c == '('){
+ // if(c == '(') {
// value>>c;
- // while(c != ')'){
- // if(c == 'n'){
+ // while(c != ')') {
+ // if(c == 'n') {
// value>>c;
// continue;
// }
//Methods
int loadAnimation(std::string animFile);/**< Loads the Animations from a file in the specified format. */
- bool operator==(Animation a){return mName==a.mName;}
- bool operator!=(Animation a){return mName!=a.mName;}
+ bool operator==(Animation a) {return mName==a.mName;}
+ bool operator!=(Animation a) {return mName!=a.mName;}
};
#endif
load(filename);
cout<<"background \""<<mName<<"\" created"<<endl;
}
-void Background::draw(){
+void Background::draw() {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1, 1, 1, mTransparency);
glLoadIdentity();
}
-void Background::update(){
+void Background::update() {
}
-int Background::load(std::string filename){
+int Background::load(std::string filename) {
/** Load image for Frame */
SDL_Surface *temp=NULL;
if((temp = LoadImage("Backgrounds/"+filename)) == NULL) return -1;//Load image for Frame
return 0;
}
-void Background::setWrap(bool tf){
+void Background::setWrap(bool tf) {
wrapping=tf;
}
-bool Background::getWrap(){
+bool Background::getWrap() {
return wrapping;
}
-void Background::drawCollisions(){
+void Background::drawCollisions() {
WorldObject::drawCollisions(collisionData, mPos);
}
);
void draw();/**< Draw background. */
void update();/**< Update to run each loop */
- string getName(){ return mName; }/** Returns name. */
- void setName(string name){ mName = name; }/** Set Name. */
+ string getName() { return mName; }/** Returns name. */
+ void setName(string name) { mName = name; }/** Set Name. */
int load(string name="default");///< Loads a Bacground by name.
- SizeD getPosition(){return mPos;}
+ SizeD getPosition() {return mPos;}
void setWrap(bool tf);
bool getWrap();
void drawCollisions();/**< Draws Collision data for the Object (from outside) */
void DrawPixel(SDL_Surface *screen, int x, int y, Uint32 c)
{
//keep in bounds
- if(x>0 && y>0 && x < screen->w && y < screen->h){
+ if(x>0 && y>0 && x < screen->w && y < screen->h) {
Uint32 color = c&0xFFFFFF;
//Uint32 color1 = SDL_MapRGB(screen->format, c&0xff, c&0xFF00, c&0xFF0000);
switch (screen->format->BytesPerPixel)
\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){
+void DrawCircle(SDL_Surface* screen, const Point2D wPos, const Point2D pos, Uint32 color) {
DrawPixel(screen, int(wPos.x + pos.x), int(wPos.y + pos.y), color);
DrawPixel(screen, int(wPos.x - pos.x), int(wPos.y + pos.y), color);
DrawPixel(screen, int(wPos.x + pos.x), int(wPos.y - pos.y), color);
\param end This is the end position to draw the point (not & because may want to have an added value pushed in)
\param color the color to be drawn
*/
-void DrawLine(SDL_Surface* screen, const Point2D start, Point2D end, Uint32 color){
+void DrawLine(SDL_Surface* screen, const Point2D start, Point2D end, Uint32 color) {
Slock(screen);
//values for calculation and max values
int x,y;//start as low vals used for algorithm
int xMax, yMax;
//if the end point is lower swap em
- if(end.y < start.y){
+ if(end.y < start.y) {
x = (int)end.x;
y = (int)end.y;
xMax = (int)start.x;
int sum = 2 * dY + dX;
DrawPixel(screen, x, y, color);
- while( x < xMax){
- if(sum < 0){
+ while( x < xMax) {
+ if(sum < 0) {
sum += 2 * dX;
y++;
}
}
}
else {
- while(y < yMax){
+ while(y < yMax) {
DrawPixel(screen, x, y, color);
y++;
}
Sulock(screen);
}
-void CollisionRectangle::draw(const Point2D& pos){
+void CollisionRectangle::draw(const Point2D& pos) {
Point2D nPos = pos + mPos;
//top
Point2D startPos = nPos + Point2D(-width/2, -height/2);
DrawLine(Game::game()->Screen(), startPos, endPos, color);
}
-void CollisionCircle::draw(const Point2D& pos){
+void CollisionCircle::draw(const Point2D& pos) {
Slock(Game::game()->Screen());
int x=0,y=(int)radius;///<The relative x,y pos
int midpt = 1-(int)radius;///<the midpt of the circle
//draw pts
DrawCircle(Game::game()->Screen(), pos + mPos, Point2D(x,y), color);
//calculate other points
- while(x<y){
+ while(x<y) {
x++;
if(midpt<0)
midpt += 2 * x + 1;
Sulock(Game::game()->Screen());
}
-bool Collision::checkCollisions(const vector<Collision*>& c, const Point2D cPos, const Point2D pos){
- for(unsigned int i=0; i < c.size(); i++){
+bool Collision::checkCollisions(const vector<Collision*>& c, const Point2D cPos, const Point2D pos) {
+ for(unsigned int i=0; i < c.size(); i++) {
if(collision(c[i], cPos, pos))//if any are true return true then and there
return true;
}
}
bool CollisionRectangle::collision(const Collision *c, const Point2D cPos, const Point2D pos) const {
- if(const CollisionRectangle* rec = dynamic_cast<const CollisionRectangle*>(c)){
+ if(const CollisionRectangle* rec = dynamic_cast<const CollisionRectangle*>(c)) {
///check rect vs rect really just axis aligned box check (simpler)
double r1Left = -width/2 + mPos.x + pos.x;
double r1Right = width/2 + mPos.x + pos.x;
bool outsideY = r1Bottom < r2Top || r1Top > r2Bottom;
return !(outsideY || outsideX);
}
- else if(dynamic_cast<const CollisionCircle*>(c)){
+ else if(dynamic_cast<const CollisionCircle*>(c)) {
return c->collision(this, cPos, pos);
}
//if something breaks bad
if (const CollisionRectangle* r = dynamic_cast<const CollisionRectangle*>(c)) {
collision(r, cPos, pos);///call the circle rect fn
}
- else if(const CollisionCircle* col = dynamic_cast<const CollisionCircle*>(c)){
+ else if(const CollisionCircle* col = dynamic_cast<const CollisionCircle*>(c)) {
///check circle vs circle
if(((col->mPos + cPos) - (mPos + pos)).length() <= (col->radius + radius))
return true;
class Collision
{
public:
- Collision():mPos(0.0,0.0),color(0xFF00FF00){ }
+ Collision():mPos(0.0,0.0),color(0xFF00FF00) { }
Point2D mPos;/**< The position of the center of the collision data */
/**
Check collision with objects
class CollisionRectangle : public Collision
{
public:
- CollisionRectangle():width(1.0),height(1.0){};
- CollisionRectangle(Point2D pt, double w, double h):width(w),height(h){ mPos = pt;}
+ CollisionRectangle():width(1.0),height(1.0) {};
+ CollisionRectangle(Point2D pt, double w, double h):width(w),height(h) { mPos = pt;}
double width;/**< Rectangle's width */
double height;/**< Rectangle's height */
/**
{
public:
CollisionCircle();
- CollisionCircle(Point2D pt, double r) : radius(r){ mPos = pt; }
+ CollisionCircle(Point2D pt, double r) : radius(r) { mPos = pt; }
double radius; /**< The raidus of the circle */
/**
This does collision between Rectangles and Circles
using namespace std;
-Font::Font( FontType t, int s ) : type(t), size(s), count(1){
+Font::Font( FontType t, int s ) : type(t), size(s), count(1) {
// Load a font
fontFile = type==English ? "FreeSans.ttf" : "Japanese.ttf";
font = TTF_OpenFont(fontFile.c_str(), size);
cerr << "TTF_OpenFont() Failed: " << TTF_GetError() << endl;
}
-Font::Font( int s ) : type(English), size(s), count(1){
+Font::Font( int s ) : type(English), size(s), count(1) {
// Load a font
fontFile = "FreeSans.ttf";
font = TTF_OpenFont(fontFile.c_str(), size);
}
-Font::~Font(){
+Font::~Font() {
TTF_CloseFont(font);
}
-void Font::setSize(int s){
- if(s!=size){
+void Font::setSize(int s) {
+ if(s!=size) {
TTF_CloseFont(font);
font = TTF_OpenFont(fontFile.c_str(), s);
}
Calling the constructor publicly is not allowed.
The constructor is private and is only called by this Instance function.
*/
-Game* Game::game(){
+Game* Game::game() {
if(!m_instance)
m_instance = new Game;
return m_instance;
return mCurrentLevel;
}
-void Game::setCurrentLevel(string name){
- if(mCurrentLevel<0){
+void Game::setCurrentLevel(string name) {
+ if(mCurrentLevel<0) {
loadCurrentLevel(name);
return;
}
else
{
mLevels[mCurrentLevel]->unload();
- for(unsigned int i=0, count = mLevels.size(); i < count; i++){
- if(mLevels[i]->getName() == name){
+ for(unsigned int i=0, count = mLevels.size(); i < count; i++) {
+ if(mLevels[i]->getName() == name) {
mCurrentLevel=i;
return;
}
cout<<"Level "<<name<<" does not exist."<<endl;
}
-void Game::loadCurrentLevel(string name){
- for(unsigned int i=0, count = mLevels.size(); i < count; i++){
- if(mLevels[i]->getName() == name){
+void Game::loadCurrentLevel(string name) {
+ for(unsigned int i=0, count = mLevels.size(); i < count; i++) {
+ if(mLevels[i]->getName() == name) {
LoadingLevel = mLevels[i];
this->mLevels[i]->load();
LoadingLevel = NULL;
void run();
/** Returns the main screen to allow for drawing */
- SDL_Surface* Screen(){ return mScreen; }
+ SDL_Surface* Screen() { return mScreen; }
/** Retrns the Current FPS of the game */
Uint32 getFPS() { return currentFPS; }
class HUD
{
public:
- HUD(){}
+ HUD() {}
//
// TextScroller scroller;
// TextFader fader;
void Level::DrawCollisions()
{
- if(Game::game()->ShowCollisions){
+ if(Game::game()->ShowCollisions) {
mBackground->drawCollisions();
for (size_t i=0; i<mWorldObjects.size(); ++i) {
mWorldObjects[i]->drawCollisions();
}
/** Will handle all movement and dynamic triggers. */
-void Level::update(){
+void Level::update() {
sort(mWorldObjects.begin(),mWorldObjects.end());
if (Loaded)
{
unload();
return;
}
- for(unsigned int i=0, size = mWorldObjects.size(); i<size; i++){
+ for(unsigned int i=0, size = mWorldObjects.size(); i<size; i++) {
if (!mWinCondition())
mWorldObjects[i]->update();
else
return;
}
}
- for(unsigned int i=0, size = ToRemove.size(); i<size; i++){
+ for(unsigned int i=0, size = ToRemove.size(); i<size; i++) {
{
// Try to remove from mWorldObjects,
// if failed see if it's currently pending add
bool removed=false;
- for(vector<WorldObject* >::iterator ptr = mWorldObjects.begin(); ptr != mWorldObjects.end(); ptr++){
- if(*ptr == ToRemove[i]){
+ for(vector<WorldObject* >::iterator ptr = mWorldObjects.begin(); ptr != mWorldObjects.end(); ptr++) {
+ if(*ptr == ToRemove[i]) {
delete *ptr;
mWorldObjects.erase(ptr);
removed=true;
break;
}
}
- if(removed){
- for(vector<Sprite* >::iterator ptr = mSprites.begin(); ptr != mSprites.end(); ptr++){
- if(*ptr == ToRemove[i]){
+ if(removed) {
+ for(vector<Sprite* >::iterator ptr = mSprites.begin(); ptr != mSprites.end(); ptr++) {
+ if(*ptr == ToRemove[i]) {
mSprites.erase(ptr);
removed=true;
break;
}
}
} else{
- for(vector<WorldObject* >::iterator ptr = ToAdd.begin(); ptr != ToAdd.end(); ptr++){
- if(*ptr == ToRemove[i]){
+ for(vector<WorldObject* >::iterator ptr = ToAdd.begin(); ptr != ToAdd.end(); ptr++) {
+ if(*ptr == ToRemove[i]) {
ToAdd.erase(ptr);
break;
}
}
}
ToRemove.clear();
- for(unsigned int i=0, size = ToAdd.size(); i<size; i++){
+ for(unsigned int i=0, size = ToAdd.size(); i<size; i++) {
mWorldObjects.push_back(ToAdd[i]);
if(Sprite* sp = dynamic_cast<Sprite*>(ToAdd[i]))
mSprites.push_back(sp);
}
}
-void Level::load(){
+void Level::load() {
clearData();
mLoadBehavior();
/// \todo Add menu
Loaded = true;
}
-void Level::unload(){
+void Level::unload() {
mUnloadBehavior();
clearData();
Loaded = false;
}
-void Level::clearData(){
+void Level::clearData() {
/// \todo stop and delete sound
//clear WorldObjects
- for(unsigned int i=0,size=mWorldObjects.size(); i<size; i++){
+ for(unsigned int i=0,size=mWorldObjects.size(); i<size; i++) {
delete mWorldObjects[i];
}
mWorldObjects.clear();
//clear textures
int count = mTextures.size();
vector<GLuint> texts = vector<GLuint>();
- for(map<string, Texture>::iterator it = mTextures.begin(),end=mTextures.end();it!=end;it++){
+ for(map<string, Texture>::iterator it = mTextures.begin(),end=mTextures.end();it!=end;it++) {
glDeleteTextures(1, &it->second);
}
mTextures.clear();
}
-void Level::addSprite(Sprite* sp){
+void Level::addSprite(Sprite* sp) {
ToAdd.push_back(sp);
}
-Sprite* Level::getSprite(string name){
- for(int i=0, count=mSprites.size(); i < count; i++){
- if(mSprites[i]->getName()==name){
+Sprite* Level::getSprite(string name) {
+ for(int i=0, count=mSprites.size(); i < count; i++) {
+ if(mSprites[i]->getName()==name) {
return mSprites[i];
}
}
return NULL;
}
-void Level::removeSprite(Sprite* sp){
+void Level::removeSprite(Sprite* sp) {
ToRemove.push_back(sp);
}
-void Level::addAnimation(Animation anim){
+void Level::addAnimation(Animation anim) {
mAnims.push_back(anim);
}
-Animation* Level::getAnimation(string name){
- for(int i=0, count=mAnims.size(); i < count; i++){
- if(mAnims[i].mName==name){
+Animation* Level::getAnimation(string name) {
+ for(int i=0, count=mAnims.size(); i < count; i++) {
+ if(mAnims[i].mName==name) {
return &mAnims[i];
}
}
return NULL;
}
-void Level::removeAnimation(Animation anim){
- for(vector<Animation>::iterator ptr = mAnims.begin(); ptr != mAnims.end(); ptr++){
- if(*ptr == anim){
+void Level::removeAnimation(Animation anim) {
+ for(vector<Animation>::iterator ptr = mAnims.begin(); ptr != mAnims.end(); ptr++) {
+ if(*ptr == anim) {
mAnims.erase(ptr);
return;
}
}
}
-void Level::addActor(string name, Actor actor){
+void Level::addActor(string name, Actor actor) {
mActors.insert(make_pair(name, actor));
}
-void Level::removeActor(string name){
+void Level::removeActor(string name) {
mActors.erase(name);
}
-Sprite* Level::findSpriteByName(string name){
+Sprite* Level::findSpriteByName(string name) {
/// \todo make this return a list of all sprites with the same name (or make it specifiable)
- for(unsigned int i=0; i < mSprites.size(); i++){
+ for(unsigned int i=0; i < mSprites.size(); i++) {
if(mSprites[i]->getName()==name)//find the sprite with the same name
return mSprites[i];
}
return NULL;//if a sprite wasn't found return null
}
-Font* Level::getFont( int s = 24, FontType t = English){
+Font* Level::getFont( int s = 24, FontType t = English) {
map<int, Font*> font = t == English ? mFonts[0] : mFonts[1];
map<int, Font*>::iterator it = font.find(s);
//if the font doesn't exist
- if(it!=font.end()){
+ if(it!=font.end()) {
//create it
Font* f = new Font(t,s);
font[s] = f;
}
}
-void Level::closeFont( Font* f){
+void Level::closeFont( Font* f) {
map<int, Font*> font = f->type == English ? mFonts[0] : mFonts[1];
map<int, Font*>::iterator it = font.find(f->size);
- if(it != font.end()){
+ if(it != font.end()) {
//if we're here we have a font
Font* f = it->second;
//decrement the count of texts using the font
f->count--;
//if there are none left
- if(f->count==0){
+ if(f->count==0) {
//delete it
font.erase(it);
}
void removeAnimation(Animation anim);/**< remove an Actor to the list of sprites \param anim The actor to add */
void addActor(string name, Actor actor);/**< add a Actor to the list of sprites \param name Name of the actor \param actor The actor to add */
void removeActor(string name);/**< remove the Actor sp from the list of sprites \param name Name of the actor to remove */
- string getName(){ return mName; }/**< returns the current level's name \return Level's name */
- void setBackground(Background* b){mBackground=b;}/**< sets the current level's background \param b Background */
- Background* getBackground(){return mBackground;}/**< gets the current level's name \return Level's Background */
+ string getName() { return mName; }/**< returns the current level's name \return Level's name */
+ void setBackground(Background* b) {mBackground=b;}/**< sets the current level's background \param b Background */
+ Background* getBackground() {return mBackground;}/**< gets the current level's name \return Level's Background */
Sprite* findSpriteByName(string name);/**< returns the first Sprite with a given name \param name Name of the sprite to return \return Pointer to the requested sprite */
bool Loaded;/**< Shows if the level has loaded or not (level changing) */
void Unload();/**< What should be done when this level is left (not deleted) */
#include "SDL_ttf.h"
///\file LevelFns.h this file should contain all Behaviors for Levels
-void LevelWorldLoad(){
+void LevelWorldLoad() {
Level* l = Game::game()->LoadingLevel;
SDL_Surface* screen = Game::game()->Screen();
sun->setSpeed(1);
}
-void LevelWorldUpdate(){
+void LevelWorldUpdate() {
Level* LevelWorld = Game::game()->getCurrentLevel();
Sprite* player = LevelWorld->getSprite("viking1");
Background* bg = LevelWorld->getBackground();
Uint8 *keys = SDL_GetKeyState(NULL);
- if(player){
+ if(player) {
if ( keys[SDLK_LEFT] ) { player->xadd(-1); }
if ( keys[SDLK_RIGHT] ) { player->xadd(1); }
if ( keys[SDLK_UP] ) { player->yadd(-1); }
if ( keys[SDLK_DOWN] ) { player->yadd(1); }
}
- if(bg){
+ if(bg) {
if ( keys[SDLK_a] ) { bg->xadd(-1); }
if ( keys[SDLK_d] ) { bg->xadd(1); }
if ( keys[SDLK_w] ) { bg->yadd(-1); }
///\file LoadResources.cpp this file should contain implementations for loading resources
-void Game::LoadResources(){
+void Game::LoadResources() {
mLevels.push_back(new Level("World", NeverEnd, LevelWorldLoad, LevelWorldUpdate));
}
mLastUpdate = SDL_GetTicks();
}
}
- if(mVisible == true){
+ if(mVisible == true) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1, 1, 1, mTransparency);
}
}
-void Sprite::update(){
+void Sprite::update() {
mBehavior();
}
-vector<Collision*>& Sprite::getCollisionData(){
+vector<Collision*>& Sprite::getCollisionData() {
return mActor.mAnimations[mActor.mCurrentAnimation]->mFrames[mActor.mFrame].collisionData;
}
-void Sprite::drawCollisions(){
+void Sprite::drawCollisions() {
//get the frame for readability
SpriteFrame frame = mActor.mAnimations[mActor.mCurrentAnimation]->mFrames[mActor.mFrame];
//center the location
WorldObject::drawCollisions(frame.collisionData, pt);
}
-Sprite* Sprite::collisionWithSprite(string name){
+Sprite* Sprite::collisionWithSprite(string name) {
//get the frame for readability
SpriteFrame* frame = getAnimation();
//get the first sprite with this name
{
public:
Sprite(std::string name, Actor actor);
- void setAnimation(int animation){ mActor.mCurrentAnimation = animation; }/**< changes to the specified animation beginning at 0. */
- SpriteFrame* getAnimation(){ return &mActor.mAnimations[mActor.mCurrentAnimation]->mFrames[mActor.mFrame]; }/**< returns active animation. (actually the current frame within the animation) \todo see if this is slower maybe undo */
+ void setAnimation(int animation) { mActor.mCurrentAnimation = animation; }/**< changes to the specified animation beginning at 0. */
+ SpriteFrame* getAnimation() { return &mActor.mAnimations[mActor.mCurrentAnimation]->mFrames[mActor.mFrame]; }/**< returns active animation. (actually the current frame within the animation) \todo see if this is slower maybe undo */
void setFrame(int frame) { mActor.mFrame = frame; }/**< cahnges to the specified frame of the animation beginning at 0. */
int getFrame() { return mActor.mFrame; }/**< returns active frame. */
void setSpeed(float speed) { mSpeed = speed; }/**< sets the Sprite's speed. */
float getSpeed() { return mSpeed;}/**< returns a Sprite's current speed. */
- void toggleAnim(){ mAnimating = !mAnimating; }/**< Pauses or resumes an animation. */
+ void toggleAnim() { mAnimating = !mAnimating; }/**< Pauses or resumes an animation. */
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. */
#include <GL/gl.h>
using namespace std;
-Text::Text(string filename, FontType t, int s, SDL_Color c, int w, int h ) : WorldObject(filename), mFont(Game::game()->getCurrentLevel()->getFont(s, t)), color(c), width(w), height(h){
+Text::Text(string filename, FontType t, int s, SDL_Color c, int w, int h ) : WorldObject(filename), mFont(Game::game()->getCurrentLevel()->getFont(s, t)), color(c), width(w), height(h) {
}
-Text::Text(string name, string t, int s, SDL_Color c, int w, int h) : WorldObject(name), text(t), mFont(Game::game()->getCurrentLevel()->getFont(s, (FontType)0)), color(c), width(w), height(h){
+Text::Text(string name, string t, int s, SDL_Color c, int w, int h) : WorldObject(name), text(t), mFont(Game::game()->getCurrentLevel()->getFont(s, (FontType)0)), color(c), width(w), height(h) {
}
-Text::~Text(){
+Text::~Text() {
Game::game()->getCurrentLevel()->closeFont(mFont);
}
glDeleteTextures(1, &texture);
}
-void Text::update(){
+void Text::update() {
}
\ No newline at end of file
#include "fns.h"
-void WorldObject::drawCollisions(){}
+void WorldObject::drawCollisions() {}
-void WorldObject::drawCollisions(vector<Collision*> &vec, const Point2D& pos){
- for(unsigned int i=0; i < vec.size(); i++){
+void WorldObject::drawCollisions(vector<Collision*> &vec, const Point2D& pos) {
+ for(unsigned int i=0; i < vec.size(); i++) {
vec[i]->draw(pos);
}
}
void yset(int y) {mPos.y = y;}/**< Sets the Sprite's y coordinate. */
void setPosition(int x, int y) {mPos.x = x; mPos.y = y;}/**< Sets the Sprite's x an y coordinate. */
Point2D getPosition() { return mPos; }/**< Gets the Sprite's position */
- void setTransparency(float f){ mTransparency = f>1?1:f<0?0:f;}/**< Sets the Sprite's transparency. \param f The sprite's transparancy [0,1] other values will be force set */
- float getTransparency(){return mTransparency;}/**< Gets the Sprite's transparency. */
- void setAngle(float a){ mAngle = a; while(a>360)a-=360;}/**< Sets the Sprite's angle in degrees. \param a Angle in degrees */
- float getAngle(){return mAngle;}/**< Gets the Sprite's angle. */
+ void setTransparency(float f) { mTransparency = f>1?1:f<0?0:f;}/**< Sets the Sprite's transparency. \param f The sprite's transparancy [0,1] other values will be force set */
+ float getTransparency() {return mTransparency;}/**< Gets the Sprite's transparency. */
+ void setAngle(float a) { mAngle = a; while(a>360)a-=360;}/**< Sets the Sprite's angle in degrees. \param a Angle in degrees */
+ float getAngle() {return mAngle;}/**< Gets the Sprite's angle. */
void setZOrder(int i) { ZOrder=i; }
int getZOrder() { return ZOrder; }
- std::string getName(){ return mName; }/**< returns the Sprite's name */
- bool operator<(WorldObject &rhs){ return ZOrder < rhs.getZOrder(); }
+ std::string getName() { return mName; }/**< returns the Sprite's name */
+ bool operator<(WorldObject &rhs) { return ZOrder < rhs.getZOrder(); }
protected:
std::string mName;/**< Sprite's name */
return compatible_image;
}
-Point2D::Point2D (const SizeD& copy){
+Point2D::Point2D (const SizeD& copy) {
x = copy.w;
y = copy.h;
}
-double Point2D::length(){
+double Point2D::length() {
return sqrt(x*x + y*y);
}
-Point2D Point2D::unitVec(){
+Point2D Point2D::unitVec() {
double len = length();///< \todo optimize
return Point2D((x/len), (y/len));
}
-Point2D Point2D::add(Point2D pt){
+Point2D Point2D::add(Point2D pt) {
x += pt.x;
y += pt.y;
return *this;
}
-Point2D Point2D::sub(Point2D pt){
+Point2D Point2D::sub(Point2D pt) {
x -= pt.x;
y -= pt.y;
return *this;
}
-Point2D Point2D::mult(double d){
+Point2D Point2D::mult(double d) {
x *= d;
y *= d;
return *this;
}
-Point2D Point2D::div(double d){
+Point2D Point2D::div(double d) {
x /= d;
y /= d;
return *this;
}
-unsigned int nextPow2(unsigned int i){
+unsigned int nextPow2(unsigned int i) {
i--;
i |= i>>1; //handle 2 bit numbers
i |= i>>2; //handle 4 bit numbers
///Behaviors use functions that take nothing and return nothing
typedef void (*Behavior) ();
///As the name denotes, this just simply does nothing
-static void DoNothing(){}
+static void DoNothing() {}
///A function that determines state of level completion
typedef bool (*Condition) ();
///Condition that is always false
-static bool NeverEnd(){return false;}
+static bool NeverEnd() {return false;}
///Texture name
typedef GLuint Texture;
///deg/rad
{
public:
friend class SizeD;
- Point2D ():x(0),y(0){}
- Point2D (double X, double Y):x(X),y(Y){}
+ Point2D ():x(0),y(0) {}
+ Point2D (double X, double Y):x(X),y(Y) {}
Point2D (const Point2D& copy)///< Copy object
{
x = copy.x;
Point2D div(double d);/**< Divides the values of this by i \return This after modificaiton*/
Point2D operator+ (const Point2D& pt) const { return Point2D(x + pt.x, y + pt.y); }
Point2D operator- (const Point2D& pt) const { return Point2D(x - pt.x, y - pt.y); }
- Point2D operator+= (Point2D& pt){ return add(pt); }
- Point2D operator-= (Point2D& pt){ return sub(pt); }
+ Point2D operator+= (Point2D& pt) { return add(pt); }
+ Point2D operator-= (Point2D& pt) { return sub(pt); }
friend ostream &operator<<(ostream &out, Point2D p) //output
{
out<<"("<<p.x<<","<<p.y<<")";
{
public:
friend class Pont2D;
- SizeD ():w(0),h(0){}
- SizeD (double width, double height):w(width),h(height){}
+ SizeD ():w(0),h(0) {}
+ SizeD (double width, double height):w(width),h(height) {}
SizeD (const SizeD& copy)
{
w = copy.w;