-
Notifications
You must be signed in to change notification settings - Fork 0
/
projectile.cpp
38 lines (33 loc) · 1.02 KB
/
projectile.cpp
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 "projectile.hpp"
#include "defs.hpp"
Projectile::Projectile(int x, int y, float v) {
n_xpos = xpos = x;
n_ypos = ypos = y;
velocity = v;
generateTag();
init();
}
Projectile::Projectile(int x, int y, int p, float v) {
n_xpos = xpos = x;
n_ypos = ypos = y;
parent = p;
velocity = v;
generateTag();
init();
}
void Projectile::init() {
width = TILESHEET_SIZE * SCALING;
height = TILESHEET_SIZE * SCALING;
addComponent<ColliderComponent>(COLLIDER_COMPONENT, PROJECTILE);
addComponent<GraphicsComponent>(GRAPHICS_COMPONENT, SDL_Rect { 13 * TILESHEET_SIZE, 0 * TILESHEET_SIZE, TILESHEET_SIZE, TILESHEET_SIZE});
addComponent<PhysicsComponent>(PHYSICS_COMPONENT);
getComponent<PhysicsComponent>(PHYSICS_COMPONENT).xvel = velocity;
getComponent<PhysicsComponent>(PHYSICS_COMPONENT).yvel = 0;
}
void Projectile::draw() {
drawComponents();
}
void Projectile::update() {
getComponent<PhysicsComponent>(PHYSICS_COMPONENT).applyNormalForce();
updateComponents();
}