-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlameThrower.cpp
48 lines (43 loc) · 1.74 KB
/
FlameThrower.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
#include <FlameThrower.h>
#include <TileGrid.h>
#include <Camera.h>
#include "FlameThrowerAnimations.h"
#include <Game.h>
#include <Scene.h>
#include "Time.h"
namespace actors {
FlameThrower::FlameThrower(const Vector8& location_grid, const uint8_t& fire_offset) : position_grid(location_grid), fire_offset(fire_offset)
{
animation_player.set_animation(&animations::flamethrower_idle);
}
void FlameThrower::update()
{
if (animation_player.animation_ptr == &animations::flamethrower_idle && ((gametime::framecount - fire_offset) & 0b111111) == 0)
{
animation_player.set_animation(&animations::flamethrower_shoot);
}
else if (animation_player.animation_ptr == &animations::flamethrower_shoot)
{
const auto current_time = gametime::framecount - animation_player.start_frame;
const auto shoot_animation_duration = animations::flamethrower_shoot.get_animation_duration();
const auto half_shoot_animation_duration = shoot_animation_duration >> 1;
if (current_time == half_shoot_animation_duration)
{
Game::scene.shoot_fireball(Vector16((position_grid.x << tile_size_pow2) + 8, (position_grid.y << tile_size_pow2) + 8), direction::up);
}
else if (current_time == shoot_animation_duration)
{
animation_player.set_animation(&animations::flamethrower_idle);
}
}
}
Rectangle FlameThrower::measure(const Camera& camera) const
{
const auto position_screen = camera.to_screen(VectorI(position_grid.x << tile_size_pow2, position_grid.y << tile_size_pow2));
return animation_player.get_cropped_sprite_bounds(position_screen.x, position_screen.y);
}
void FlameThrower::render(const uint8_t& layer, const Rectangle& part, int x, int y, uint16_t* slice_buffer) const
{
animation_player.render(part, x, y, slice_buffer);
}
}