-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollider-component.cpp
More file actions
38 lines (32 loc) · 1.1 KB
/
collider-component.cpp
File metadata and controls
38 lines (32 loc) · 1.1 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
#include <iostream>
#include "collider-component.hpp"
#include "collision.hpp"
#include "game.hpp"
#include "defs.hpp"
//Collision ColliderComponent::c;
ColliderComponent::ColliderComponent(int t, int x_off, int y_off) {
type = t;
x_offset = x_off;
y_offset = y_off;
}
ColliderComponent::ColliderComponent(int t) {
type = t;
}
void ColliderComponent::draw(Entity* entity) {
SDL_SetRenderDrawColor(Game::renderer, 255, 0, 0, 255);
SDL_Rect e = {Game::camera->xpos + collider.x, Game::camera->ypos + collider.y, collider.w, collider.h};
SDL_RenderDrawRect(Game::renderer, &e);
}
void ColliderComponent::init(Entity* entity) {
collider.x = entity->xpos + x_offset;
collider.y = entity->ypos + y_offset;
collider.w = entity->width - x_offset;
collider.h = entity->height - y_offset;
}
void ColliderComponent::update(Entity *entity) {
leftCollision = rightCollision = topCollision = bottomCollision = false;
collider.x = entity->xpos + x_offset;
collider.y = entity->ypos + y_offset;
collider.w = entity->width - x_offset;
collider.h = entity->height - y_offset;
}