Arch Game Engine  0.2
object.h
1 #ifndef OBJECT_H
2 #define OBJECT_H
3 #define PI 3.14159265358979323846
4 
5 #include "image.h"
6 #include "input.h"
7 #include <SDL2/SDL.h>
8 
9 class Collision;
10 
12 class Object {
13 private:
14  Image img;
15  Input i;
16  SDL_Rect frame, dest, pos, buff, movedBuff;
17  double angle;
18  string name;
19  double x, y, velX, velY, speed;
20  bool displayable;
21  bool gravity;
22  bool objsImage;
23  struct color { Uint8 r, g, b, a; };
24  color objsColor;
25 public:
26  Object();
27  ~Object();
28  SDL_Rect getBuff() const {return buff;}
29  SDL_Rect getMovedBuff() const {return movedBuff;}
30  void actGravity(bool g) {gravity=g;}
32  void setDisplayable(bool d) { displayable = d; }
34  bool isDisplayable(Object screen) { checkDisplayable(screen); return displayable; }
36  virtual void checkDisplayable(Object screen);
38  void setCoord(double x, double y) { setX(x); setY(y); }
40  void setX(double sx) { x = sx; }
42  void setY(double sy) { y = sy; }
44  void move(double x, double y) { moveX(x); moveY(y); }
46  void moveX(double mx) { x += mx; }
48  void moveY(double my) { y += my; }
50  double getX() const { return x; }
52  double getY() const { return y; }
54  Image getImage() const { return img; }
56  void setImage(Image i) { img = i; objsImage=true; }
58  void setImage(string file, SDL_Renderer* ren) { img.loadImage(file, ren); objsImage=true; }
60  double getAngle() const { return angle; }
62  void setAngle(double a) { angle = a; }
64  void center(int w, int h);
66  SDL_Rect getFrame() const { return frame; }
68  SDL_Rect getDest() const { return dest; }
70  SDL_Rect getPos() const { return pos; }
72  void setFrame(SDL_Rect i) { frame = i; }
74  void setDest(SDL_Rect i) { buff=dest; if(movedBuff.x!=buff.x && movedBuff.y!=buff.y) {movedBuff=buff;} dest = i; }
76  void setPos(SDL_Rect i) { pos = i; }
78  void setFrame(int x, int y, int w, int h) { setFrameCoord(x, y); setFrameSize(w, h); }
80  void setFrameCoord(int x, int y) { setFrameX(x); setFrameY(y); }
82  void setFrameSize(int w, int h) { setFrameW(w); setFrameH(h); }
84  void setFrameX(int x) { frame.x = x; }
86  void setVelTo(Object o);
88  void lookAt(Object o);
90  void setFrameY(int y) { frame.y = y; }
91  void setFrameW(int w) { frame.w = w; }
92  void setFrameH(int h) { frame.h = h; }
93  int getFrameX() const { return frame.x; }
94  int getFrameY() const { return frame.y; }
95  int getFrameW() const { return frame.w; }
96  int getFrameH() const { return frame.h; }
97  void setDest(int x, int y, int w, int h) { buff=dest; if(movedBuff.x!=buff.x || movedBuff.y!=buff.y) {movedBuff=buff;} setDestCoord(x, y); setDestSize(w, h); }
98  void setDestCoord(int x, int y) { setDestX(x); setDestY(y); }
99  void setDestSize(int w, int h) { setDestW(w); setDestH(h); }
100  void setDestX(int x) { buff=dest; if(movedBuff.x!=buff.x || movedBuff.y!=buff.y) {movedBuff=buff;} dest.x = x; }
101  void setDestY(int y) { buff=dest; if(movedBuff.x!=buff.x || movedBuff.y!=buff.y) {movedBuff=buff;} dest.y = y; }
102  void setDestW(int w) { buff=dest; if(movedBuff.x!=buff.x || movedBuff.y!=buff.y) {movedBuff=buff;} dest.w = w; }
103  void setDestH(int h) { buff=dest; if(movedBuff.x!=buff.x || movedBuff.y!=buff.y) {movedBuff=buff;} dest.h = h; }
104  int getDestX() const { return dest.x; }
105  int getDestY() const { return dest.y; }
106  int getDestW() const { return dest.w; }
107  int getDestH() const { return dest.h; }
108  void setPos(int x, int y, int w, int h) { setPosCoord(x, y); setPosSize(w, h); }
109  void setPosCoord(int x, int y) { setPosX(x); setPosY(y); }
110  void setPosSize(int w, int h) { setPosW(w); setPosH(h); }
111  void setPosX(int x) { pos.x = x; }
112  void setPosY(int y) { pos.y = y; }
113  void setPosW(int w) { pos.w = w; }
114  void setPosH(int h) { pos.h = h; }
115  int getPosX() const { return pos.x; }
116  int getPosY() const { return pos.y; }
117  int getPosW() const { return pos.w; }
118  int getPosH() const { return pos.h; }
119  void moveFrame(int x, int y) { moveFrameX(x); moveFrameY(y); }
120  void moveFrameX(int x) { frame.x += x; }
121  void moveFrameY(int y) { frame.y += y; }
122  void moveDest(int x, int y) { moveDestX(x); moveDestY(y); }
123  void moveDestX(int x) { buff=dest; if(movedBuff.x!=buff.x || movedBuff.y!=buff.y) {movedBuff=buff;} dest.x += x; }
124  void moveDestY(int y) { buff=dest; if(movedBuff.x!=buff.x || movedBuff.y!=buff.y) {movedBuff=buff;} dest.y += y; }
125  void movePos(int x, int y) { movePosX(x); movePosY(y); }
126  void movePosX(int x) { pos.x += x; }
127  void movePosY(int y) { pos.y += y; }
128  double getVelX() { return velX; }
129  double getVelY() { return velY; }
130  void setVelX(double vx) { velX = vx; }
131  void setVelY(double vy) { velY = vy; }
132  void setVelTo(int x, int y);
133  double getSpeed() { return speed; }
134  void setSpeed(double s) { speed = s; }
135  void setName(string s);
136  string getName();
137  void centerOn(Input i);
138  void centerOn(int cx, int cy);
139  void centerOn(Object obj);
140  void lookAt(Input i);
141  color red = {0xff,0,0,0xff};
142  color green = {0,0xff,0,0xff};
143  color blue = {0,0,0xff,0xff};
144  void setColor(color c) {objsColor = c;}
145  void setColor(Uint8 r, Uint8 g, Uint8 b) {objsColor.r=r;objsColor.g=g;objsColor.b=b;}
146  void setTransparency(Uint8 a) {objsColor.a = a;}
147  bool imageSet() const {return objsImage;}
148  color getColor() const {return objsColor;}
149  void rotateAngle(int rot);
150  void moveToVel();
151 };
152 
153 #endif //OBJECT_H
154 
This class stores information for an Object in the game.
Definition: object.h:12
double getY() const
Get the current y coordinate.
Definition: object.h:52
void setImage(Image i)
Set the Object&#39;s Image with a given Image.
Definition: object.h:56
void setFrameY(int y)
Set the y coordinate of the frame.
Definition: object.h:90
void setDisplayable(bool d)
This sets if you want the Object to visible on the screen by passing in a boolean.
Definition: object.h:32
void setY(double sy)
Set the y coordinate with a given y.
Definition: object.h:42
double getX() const
Get the current x coordinate.
Definition: object.h:50
void moveY(double my)
Move along the y coordinate with a given y amount.
Definition: object.h:48
void setFrame(SDL_Rect i)
Set the frame with a given SDL_Rect.
Definition: object.h:72
void loadImage(string file, SDL_Renderer *ren)
Load in either a BMP or PNG file with the path and renderer.
Definition: image.cpp:5
void setDest(SDL_Rect i)
Set the destination with a given SDL_Rect.
Definition: object.h:74
SDL_Rect getDest() const
Get the destination for the Object to be displayed on screen.
Definition: object.h:68
void setCoord(double x, double y)
Set the coordinate of the Object with a given x and y.
Definition: object.h:38
double getAngle() const
Get the Object&#39;s angle.
Definition: object.h:60
void setFrame(int x, int y, int w, int h)
Set the frame with a given x and y coordinate and width and height.
Definition: object.h:78
virtual void checkDisplayable(Object screen)
Checks if the Object is in the given screen.
Definition: object.cpp:22
bool isDisplayable(Object screen)
Check if the Object is displayable by seeing if it is in a given screen.
Definition: object.h:34
void setX(double sx)
Set the x coordinate with a given x.
Definition: object.h:40
void move(double x, double y)
Move along the x and y coordinate with a given x and y amount.
Definition: object.h:44
SDL_Rect getPos() const
Get the position of the Object in the world.
Definition: object.h:70
void setFrameSize(int w, int h)
Set the size of the frame with a width and height.
Definition: object.h:82
Image getImage() const
Get the Object&#39;s Image.
Definition: object.h:54
void center(int w, int h)
Center the Object based on a width and height.
Definition: object.cpp:11
Class for checking and storing keyboard and mouse input.
Definition: input.h:9
void setImage(string file, SDL_Renderer *ren)
Give the path and renderer to create the Object&#39;s Image.
Definition: object.h:58
Class used for calculating different types of collision between given Objects.
Definition: collision.h:7
Class for loading in SDL Textures.
Definition: image.h:11
SDL_Rect getFrame() const
Get the frame that the Object parses from the Image.
Definition: object.h:66
void setPos(SDL_Rect i)
Set the position with a given SDL_Rect.
Definition: object.h:76
void lookAt(Object o)
Set the object&#39;s angle towards another object.
Definition: object.cpp:57
void setFrameCoord(int x, int y)
Set the x and y coordinate of the frame.
Definition: object.h:80
void setVelTo(Object o)
Set the object&#39;s velocity toward another object.
Definition: object.cpp:41
void setFrameX(int x)
Set the x coordinate of the frame.
Definition: object.h:84
void setAngle(double a)
Set the angle.
Definition: object.h:62
void moveX(double mx)
Move along the x coordinate with a given x amount.
Definition: object.h:46