-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameobjects.cpp
More file actions
41 lines (32 loc) · 1.02 KB
/
Copy pathgameobjects.cpp
File metadata and controls
41 lines (32 loc) · 1.02 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
#include "lib.h"
#include <string>
#include <unordered_map>
GameObject::GameObject(
Coordinate new_position, Coordinate new_size, RGBA new_fill
) {
position = new_position;
size = new_size;
fill = new_fill;
}
void GameObject::update(std::unordered_map<std::string, int>*) {};
bool GameObject::is_colliding(GameObject* target) {
// Check if the current object is colliding with the target object
// For simplicity, let's assume collision detection based on bounding boxes
// Calculate the bounding boxes for both objects
int left1 = position.x;
int right1 = position.x + size.x;
int top1 = position.y;
int bottom1 = position.y + size.y;
int left2 = target->position.x;
int right2 = target->position.x + target->size.x;
int top2 = target->position.y;
int bottom2 = target->position.y + target->size.y;
// Check for collision
return (
right1 >= left2
&& left1 <= right2
&& bottom1 >= top2
&& top1 <= bottom2
);
}
GameObject::~GameObject() {}