-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBomb.cpp
52 lines (42 loc) · 1002 Bytes
/
Bomb.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @file Bomb.cpp
* @brief explosive device
* @author Josh Kennedy
*
* Kablam!
* Copyright (C) 2024 Josh Kennedy.
*/
#include "Bomb.hpp"
#include "Assets.hpp"
#include "Constants.hpp"
#include <SDL2/SDL.h>
Bomb::Bomb(float x, float y, float velocity)
: velocity(velocity), x(x), y(y), animation(Assets::getAnimation(BOMB)), active(true)
{
this->animation.setX(x);
this->animation.setY(y);
this->animation.play();
}
void Bomb::update(double deltaTime)
{
if (this->active)
{
this->animation.update(deltaTime);
this->y += this->velocity * deltaTime;
// TODO: Do we really need to check this here?
// Also, this should be if it goes past the player, not the screen
if (this->y > SCREEN_HEIGHT)
{
this->active = false;
}
this->animation.setX(this->x); // TODO: do we really need to update the x position every frame?
this->animation.setY(this->y);
}
}
void Bomb::render(SDL_Renderer* renderer)
{
if (this->active)
{
this->animation.render(renderer);
}
}