Arch Game Engine  0.2
physics-tmp.cpp
1 #include "physics-tmp.h"
2 
3 Physics::Physics() {}
4 Physics::~Physics() {}
5 
6 
7 //Sample function, read more about it in the header file
9  int speed = 3; //eventually you will be able to retrieve the speed from the object like: object.getSpeed(), until then it is hardcoded
10  //Note: I am not the best at math so this will be very rudimentary
11  if(cur.getDestX() > des.getDestX()) { //is the destination to the left
12  if(cur.getDestY() > des.getDestY()) { //is the destination below
13  cur.setDestX(cur.getDestX()-speed); //move to the left
14  cur.setDestY(cur.getDestY()-speed); //move down
15  } else if(cur.getDestY() == des.getDestY()) { //is the destination at the same y
16  cur.setDestX(cur.getDestX()-speed); //move to the left
17  } else { //or is the destination above
18  cur.setDestX(cur.getDestX()-speed); //move to the left
19  cur.setDestY(cur.getDestY()+speed); //move up
20  }
21  } else if(cur.getDestX() == des.getDestX()) { //is the destination at the same x value
22  if(cur.getDestY() > des.getDestY()) { //is the destination below
23  cur.setDestY(cur.getDestY()-speed); //move down
24  } else if(cur.getDestY() == des.getDestY()) { //is the destination at the same y
25  //the destination is where the object is...
26  } else { //or is the destination above
27  cur.setDestY(cur.getDestY()+speed); //move up
28  }
29  } else { //or is the destination to the right
30  if(cur.getDestY() > des.getDestY()) { //is the destination below
31  cur.setDestX(cur.getDestX()+speed); //move to the left
32  cur.setDestY(cur.getDestY()-speed); //move down
33  } else if(cur.getDestY() == des.getDestY()) { //is the destination at the same y
34  cur.setDestX(cur.getDestX()+speed); //move to the left
35  } else { //or is the destination above
36  cur.setDestX(cur.getDestX()+speed); //move to the left
37  cur.setDestY(cur.getDestY()+speed); //move up
38  }
39  }
40  return cur; //in game code for how this function will be called: ship.setDest(this, blackhole);
41  //there is also a chance this code is wrong :), I haven't tested it out, but it builds
42 }
This class stores information for an Object in the game.
Definition: object.h:12
Object moveTowards(Object cur, Object des)
Returns modified first Object that is moving towards the second object (I THINK). ...
Definition: physics-tmp.cpp:8