Arch Game Engine  0.2
object.cpp
1 #include <math.h>
2 #include "object.h"
3 #include "collision.h"
4 
5 Object::Object() {
6  objsImage=false;
7  objsColor.a = 255;
8 }
9 Object::~Object() {}
10 
11 void Object::center(int w, int h) {
12  setDestCoord((w/2)-(getDestW()/2), (h/2)-(getDestH()/2));
13 }
14 
15 void Object::setName(string s) {
16  name = s;
17 }
18 string Object::getName() {
19  return name;
20 }
21 
23  Collision col;
24  Object obj;
25  obj.setDest(getPos());
26  if(col.isTouching(obj, screen)) {
27  displayable = true;
28  } else {
29  displayable = false;
30  }
31 }
32 
33 void Object::centerOn(Input i) {
34  setDestCoord(i.getMouseX()-(getDestW()/2), i.getMouseY()-(getDestH()/2));
35 }
36 
37 void Object::centerOn(int cx, int cy) {
38  setPosCoord(cx-(getDestW()/2), cy-(getDestH()/2));
39 }
40 
42  double angle = atan2(o.getDestY() - getDestY(), o.getDestX() - getDestX());
43  double c = cos(angle) * getSpeed();
44  double s = sin(angle) * getSpeed();
45  setVelX(c);
46  setVelY(s);
47 }
48 
49 void Object::setVelTo(int x, int y) {
50  double angle = atan2(y-getDestY(), x-getDestX());
51  double c = cos(angle) * getSpeed();
52  double s = sin(angle) * getSpeed();
53  setVelX(c);
54  setVelY(s);
55 }
56 
58  double angle = atan2(o.getDestY() - getDestY(), o.getDestX() - getDestX()) * (180/PI);
59  setAngle(angle);
60 }
61 
62 void Object::lookAt(Input i) {
63  Object tmp;
64  tmp.setDestCoord(i.getMouseX(), i.getMouseY());
65  lookAt(tmp);
66 }
67 
68 void Object::centerOn(Object obj) {
69  centerOn(obj.getDestX()-(obj.getDestW()/2), obj.getDestY()-(obj.getDestH()/2));
70 }
71 
72 void Object::rotateAngle(int rot) {
73  setAngle(getAngle()+rot);
74 }
75 
76 void Object::moveToVel() {
77  moveDest(getVelX(), getVelY());
78 }
This class stores information for an Object in the game.
Definition: object.h:12
void setDest(SDL_Rect i)
Set the destination with a given SDL_Rect.
Definition: object.h:74
double getAngle() const
Get the Object&#39;s angle.
Definition: object.h:60
virtual void checkDisplayable(Object screen)
Checks if the Object is in the given screen.
Definition: object.cpp:22
SDL_Rect getPos() const
Get the position of the Object in the world.
Definition: object.h:70
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
Class used for calculating different types of collision between given Objects.
Definition: collision.h:7
void lookAt(Object o)
Set the object&#39;s angle towards another object.
Definition: object.cpp:57
bool isTouching(Object a, Object b)
Check if two objects are touching.
Definition: collision.cpp:7
void setVelTo(Object o)
Set the object&#39;s velocity toward another object.
Definition: object.cpp:41
void setAngle(double a)
Set the angle.
Definition: object.h:62