Make the animator more official.
This commit is contained in:
parent
b87217ff90
commit
d0d3c8bc04
3 changed files with 20 additions and 15 deletions
16
animator.cpp
16
animator.cpp
|
@ -1,2 +1,18 @@
|
|||
#include "animator.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
void Animator::step(sf::Sprite& sprite, int rect_x, int rect_y, int rect_w, int rect_h) {
|
||||
if(playing) {
|
||||
count++;
|
||||
frame = ((count / 4) % max_frames);
|
||||
playing = frame != 0;
|
||||
}
|
||||
|
||||
sprite.setTextureRect(sf::IntRect({
|
||||
{rect_x + frame * width, rect_y},
|
||||
{rect_w, rect_h}}));
|
||||
}
|
||||
|
||||
void Animator::play() {
|
||||
playing = true;
|
||||
}
|
||||
|
|
18
animator.hpp
18
animator.hpp
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <fmt/core.h>
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
|
||||
struct Animator {
|
||||
int width = 0;
|
||||
|
@ -9,19 +9,7 @@ struct Animator {
|
|||
int frame = 0;
|
||||
bool playing = false;
|
||||
|
||||
inline void step(sf::Sprite& sprite, int rect_x, int rect_y, int rect_w, int rect_h) {
|
||||
if(playing) {
|
||||
count++;
|
||||
frame = ((count / 4) % max_frames);
|
||||
playing = frame != 0;
|
||||
}
|
||||
void step(sf::Sprite& sprite, int rect_x, int rect_y, int rect_w, int rect_h);
|
||||
|
||||
sprite.setTextureRect(sf::IntRect({
|
||||
{rect_x + frame * width, rect_y},
|
||||
{rect_w, rect_h}}));
|
||||
}
|
||||
|
||||
inline void play() {
|
||||
playing = true;
|
||||
}
|
||||
void play();
|
||||
};
|
||||
|
|
|
@ -50,6 +50,7 @@ executable('zedcaster', [
|
|||
'config.cpp',
|
||||
'texture.cpp',
|
||||
'raycaster.cpp',
|
||||
'animator.cpp',
|
||||
'stats.cpp',
|
||||
'main.cpp'
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue