-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgameobject.cpp
More file actions
74 lines (59 loc) · 1.63 KB
/
Copy pathgameobject.cpp
File metadata and controls
74 lines (59 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "gameobject.h"
GameObject::GameObject(Vector2 pos, Vector2 velocity, int width, int height, Color color) {
this->position = pos;
this->velocity = velocity;
this->ogVel = velocity;
this->type = "rect";
this->dimension[0] = width;
this->dimension[1] = height;
this->color = color;
this->objectRect = Rectangle{ pos.x, pos.y, static_cast<float>(width), static_cast<float>(height) };
}
GameObject::GameObject(Vector2 pos, float radius, Vector2 velocity, Color color) {
this->position = pos;
this->radius = radius;
this->velocity = velocity;
this->type = "circle";
this->color = color;
this->ogVel = velocity;
}
void GameObject::ReDef() {
if (type == "rect") {
objectRect = Rectangle{ position.x, position.y, objectRect.width, objectRect.height };
}
}
void GameObject::Draw() {
if (type == "rect") {
DrawRectangleRec(objectRect, color);
}
if (type == "circle") {
DrawCircle(position.x, position.y, radius, color);
}
}
void GameObject::SetVelocity(Vector2 newVelocity) {
velocity = newVelocity;
}
void GameObject::Move() {
position.x += velocity.x * GetFrameTime();
position.y += velocity.y * GetFrameTime();
}
void GameObject::SetMoveUp() {
velocity.x = 0;
velocity.y = ogVel.y * -1;
}
void GameObject::SetMoveDown() {
velocity.x = 0;
velocity.y = ogVel.y*1;
}
void GameObject::SetMoveLeft() {
velocity.y = 0;
velocity.x = ogVel.x * -1;
}
void GameObject::SetMoveRight() {
velocity.x = ogVel.x;
velocity.y = 0;
}
void GameObject::Update() {
ReDef();
Draw();
}