The Game Engine  1
Background Class Reference

The Background. More...

#include <Background.h>

+ Inheritance diagram for Background:
+ Collaboration diagram for Background:

Public Member Functions

 Background (string name="default", string filename="bg.bmp", bool wrap=true, Point2D ScreenPosition=Point2D())
 Initializes the Background. More...
 
 ~Background ()
 
void draw ()
 Draw background. More...
 
void update ()
 Update to run each loop. More...
 
string getName ()
 Returns name. More...
 
void setName (string name)
 Set Name. More...
 
int load (string name="default")
 Loads a Bacground by name. More...
 
Size2D getPosition ()
 Obtains the Background's position. More...
 
Point2D getBasePos ()
 Obtain Base Pos for drawing. More...
 
Point2D getCenterPos ()
 Obtain Center Pos for Collisions. More...
 
virtual WorldObjectType getType ()
 This provides a simple interface to determine types of objects. More...
 
void setWrap (bool tf)
 Obtains the Background's position. More...
 
bool getWrap ()
 Returns whether the background wraps or not. More...
 
void drawCollisions ()
 Draws CollisionObject data for the Object (from outside) More...
 
- Public Member Functions inherited from WorldObject
 WorldObject (std::string name, Point2D pos=Point2D(), int z=0)
 
void drawCollisions (vector< CollisionObject * > &vec, const Point2D &pos)
 Draws CollisionObject data for the Object. More...
 
virtual void runBehavior ()
 Behavior that WorldObject follows. More...
 
void setPosition (double x, double y)
 Sets the WorldObject's x an y coordinate. More...
 
void setPosition (Point2D pos)
 Sets the WorldObject's x an y coordinate. More...
 
void setBasePosition (double x, double y)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setBasePosition (Point2D pos)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setCenterPosition (double x, double y)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setCenterPosition (Point2D pos)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void move (double dx=0.0, double dy=0.0)
 Move by given amount NOTE: This is an instantaneous movement by a given amount and does not correspond to physics which is set to do the updated amount per second. More...
 
virtual void move (Point2D direction)
 Moves the WorldObject relative to the current pos. More...
 
virtual void moveTowards (Point2D direction)
 Move towards a given coordinate (path finding) More...
 
Point2D getPosition ()
 Gets the WorldObject's position. More...
 
void setTransparency (float f)
 Sets the WorldObject's transparency. More...
 
float getTransparency ()
 Gets the WorldObject's transparency. More...
 
void setAngle (float a)
 Sets the WorldObject's angle in degrees. More...
 
float getAngle ()
 Gets the WorldObject's angle. More...
 
void setVelocity (Point2D vel)
 Sets the WorldObject's velocity as a vector (will set MaxVelocity if needed) More...
 
void setVelocity (double xVel, double yVel)
 Sets the WorldObject's velocity from coordinates (will set MaxVelocity if needed) More...
 
Point2D getVelocity ()
 Gets the WorldObject's Velocity. More...
 
void setMaxVelocity (Point2D vel)
 Sets the WorldObject's MaxVelocity (magnitude) from (x,y) and transforms into a magnitude. More...
 
void setMaxVelocity (double vel, Point2D dir)
 Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified. More...
 
void setMaxSpeed (double vel)
 Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified. More...
 
Point2D getMaxVelocity ()
 Gets the WorldObject's Max Velocity. More...
 
double getMaxSpeed ()
 Gets the WorldObject's Max Speed. More...
 
double getMaxSpeedSquared ()
 Gets the WorldObject's Max Speed Squared (cheaper operation). More...
 
void setAcceleration (Point2D accel)
 Sets the WorldObject's Acceleration in (x,y) coords. More...
 
Point2D getAcceleration ()
 Gets the WorldObject's Acceleration. More...
 
void setZOrder (int i)
 
int getZOrder ()
 
std::string getName ()
 returns the WorldObject's name More...
 
bool operator< (WorldObject &rhs)
 Sort worldObjects. More...
 

Protected Attributes

Texture mBackground
 Background Texture. More...
 
int width
 Width of the background. More...
 
int height
 Height of the background. More...
 
bool wrapping
 Flag to determine whether or not a background should wrap. More...
 
vector< CollisionObject * > collisionData
 The collision data for this Background. More...
 
- Protected Attributes inherited from WorldObject
std::string mName
 WorldObject's name. More...
 
Point2D mPos
 The current (x,y) position. More...
 
Point2D mVelocity
 The current velocity vector. More...
 
Point2D mMaxVelocity
 The max velocity is the max possible velocity where lengthis the speed. More...
 
double mMaxSpeed
 The max Speed if MaxVelocity is 0 to store val. More...
 
Point2D mAcceleration
 The current acceleration vector. More...
 
bool mVisible
 Determine if Object should be visible. More...
 
float mTransparency
 Transparency! More...
 
float mAngle
 Angle of rotation. More...
 
float mScale
 Scale for the sprit. More...
 
int ZOrder
 Stacking order. Determines what draws on top. (subsorted by position) More...
 
long mLastUpdate
 Number that indicates when the Object has last updated. Overflows in about 24 days so no worries. More...
 
long mLastDraw
 Number that indicates when the Object has last updated. Overflows in about 24 days so no worries. More...
 
bool mUnused
 Determines whether or not this object's update function should run. More...
 
Behavior mBehavior
 Behavior to act each loop if !mUnused. More...
 

Additional Inherited Members

- Public Types inherited from WorldObject
enum  WorldObjectType {
  SPRITE, BACKGROUND, MENU, TEXT,
  PARTICLESYSTEM
}
 This is to be used for Type checking so as to make no need for dynamic_cast and it's inefficiency. More...
 

Detailed Description

The Background.

This class is tasked with the following:

  • Loading the background
    • Drawing the background
    • Storing and drawing Map Bounds
    • Handling Tile-based Maps
      Todo:
      allow tiled bgs and have them blit to a single surface / texture when loaded

Definition at line 23 of file Background.h.

Constructor & Destructor Documentation

Background::Background ( string  name = "default",
string  filename = "bg.bmp",
bool  wrap = true,
Point2D  ScreenPosition = Point2D() 
)

Initializes the Background.

Parameters
nameName of the background for reference in the program
filenameName of the file in ArtAssets
wrapWhether you want the background to tile or not
ScreenPositionPosition on the screen where the background should begin to draw.

Definition at line 6 of file Background.cpp.

+ Here is the call graph for this function:

Background::~Background ( )

Definition at line 14 of file Background.cpp.

Member Function Documentation

void Background::draw ( )
virtual

Draw background.

Implements WorldObject.

Definition at line 20 of file Background.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Background::drawCollisions ( )
virtual

Draws CollisionObject data for the Object (from outside)

Reimplemented from WorldObject.

Definition at line 131 of file Background.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point2D Background::getBasePos ( )
inlinevirtual

Obtain Base Pos for drawing.

Implements WorldObject.

Definition at line 89 of file Background.h.

Point2D Background::getCenterPos ( )
inlinevirtual

Obtain Center Pos for Collisions.

Implements WorldObject.

Definition at line 94 of file Background.h.

string Background::getName ( )
inline

Returns name.

Returns
Name of the Background

Definition at line 66 of file Background.h.

Size2D Background::getPosition ( )
inline

Obtains the Background's position.

Returns
Current position of the Background's top left corner

Definition at line 84 of file Background.h.

virtual WorldObjectType Background::getType ( )
inlinevirtual

This provides a simple interface to determine types of objects.

Returns the name of the Class and Descendants i.e. Something inheriting from Sprite would look like Sprite:Thing

Implements WorldObject.

Definition at line 99 of file Background.h.

bool Background::getWrap ( )

Returns whether the background wraps or not.

Returns
Wrapping

Definition at line 127 of file Background.cpp.

int Background::load ( string  name = "default")

Loads a Bacground by name.

Parameters
nameName of the background to load (defaults to default)

Load image for Frame

Set transparent color

Loads image into animation

Definition at line 58 of file Background.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Background::setName ( string  name)
inline

Set Name.

Parameters
nameName for the Background

Definition at line 72 of file Background.h.

void Background::setWrap ( bool  tf)

Obtains the Background's position.

Returns
Current position of the Background's top left corner

Definition at line 123 of file Background.cpp.

void Background::update ( )
virtual

Update to run each loop.

Reimplemented from WorldObject.

Definition at line 52 of file Background.cpp.

+ Here is the call graph for this function:

Member Data Documentation

vector<CollisionObject*> Background::collisionData
protected

The collision data for this Background.

Todo:
implement collisions

Definition at line 34 of file Background.h.

int Background::height
protected

Height of the background.

Definition at line 30 of file Background.h.

Texture Background::mBackground
protected

Background Texture.

Definition at line 26 of file Background.h.

int Background::width
protected

Width of the background.

Definition at line 28 of file Background.h.

bool Background::wrapping
protected

Flag to determine whether or not a background should wrap.

Definition at line 32 of file Background.h.


The documentation for this class was generated from the following files: