Have a barely working animation thing that animates the evil eye when you click a button.
This commit is contained in:
parent
51c1e04f61
commit
b87217ff90
7 changed files with 35 additions and 2 deletions
2
animator.cpp
Normal file
2
animator.cpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "animator.hpp"
|
||||||
|
#include "constants.hpp"
|
27
animator.hpp
Normal file
27
animator.hpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
struct Animator {
|
||||||
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
|
int max_frames = 0;
|
||||||
|
size_t count = 0;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprite.setTextureRect(sf::IntRect({
|
||||||
|
{rect_x + frame * width, rect_y},
|
||||||
|
{rect_w, rect_h}}));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void play() {
|
||||||
|
playing = true;
|
||||||
|
}
|
||||||
|
};
|
|
@ -9,7 +9,7 @@
|
||||||
"armored_knight": "assets/armored_knight_1-256.png",
|
"armored_knight": "assets/armored_knight_1-256.png",
|
||||||
"sword": "assets/cinqueda_1-512.png",
|
"sword": "assets/cinqueda_1-512.png",
|
||||||
"barrel": "assets/wood_barrel_large-256.png",
|
"barrel": "assets/wood_barrel_large-256.png",
|
||||||
"evil_eye": "assets/evil_eye_test-256.png",
|
"evil_eye": "assets/evil_eye-sprites.png",
|
||||||
"peasant_girl": "assets/undead_peasant-256.png",
|
"peasant_girl": "assets/undead_peasant-256.png",
|
||||||
"floor": "assets/floor_tile_test-256.png",
|
"floor": "assets/floor_tile_test-256.png",
|
||||||
"ceiling": "assets/ceiling_test-256.png"
|
"ceiling": "assets/ceiling_test-256.png"
|
||||||
|
|
BIN
assets/evil_eye-sprites.png
Normal file
BIN
assets/evil_eye-sprites.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 316 KiB |
1
main.cpp
1
main.cpp
|
@ -96,6 +96,7 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
|
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
|
||||||
|
rayview.$anim.play();
|
||||||
rotation = -30.0f;
|
rotation = -30.0f;
|
||||||
} else {
|
} else {
|
||||||
rotation = -10.0f;
|
rotation = -10.0f;
|
||||||
|
|
|
@ -150,8 +150,9 @@ void Raycaster::sprite_casting() {
|
||||||
int texY = ((d * textureHeight) / spriteHeight) / textureHeight;
|
int texY = ((d * textureHeight) / spriteHeight) / textureHeight;
|
||||||
|
|
||||||
sf_sprite->setScale({sprite_w, sprite_h});
|
sf_sprite->setScale({sprite_w, sprite_h});
|
||||||
sf_sprite->setTextureRect(sf::IntRect({texX, texY}, {texX_end - texX, textureHeight}));
|
$anim.step(*sf_sprite, texX, texY, texX_end - texX, textureHeight);
|
||||||
sf_sprite->setPosition({x, y});
|
sf_sprite->setPosition({x, y});
|
||||||
|
|
||||||
$window.draw(*sf_sprite);
|
$window.draw(*sf_sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "texture.hpp"
|
#include "texture.hpp"
|
||||||
#include <SFML/System/Clock.hpp>
|
#include <SFML/System/Clock.hpp>
|
||||||
|
#include "animator.hpp"
|
||||||
|
|
||||||
using matrix::Matrix;
|
using matrix::Matrix;
|
||||||
using RGBA = uint32_t;
|
using RGBA = uint32_t;
|
||||||
|
@ -43,6 +44,7 @@ struct Raycaster {
|
||||||
std::vector<int> spriteOrder;
|
std::vector<int> spriteOrder;
|
||||||
std::vector<double> spriteDistance;
|
std::vector<double> spriteDistance;
|
||||||
std::vector<double> ZBuffer; // width
|
std::vector<double> ZBuffer; // width
|
||||||
|
Animator $anim{256, 256, 10, 0};
|
||||||
|
|
||||||
Raycaster(sf::RenderWindow& window, Matrix &map, int width, int height);
|
Raycaster(sf::RenderWindow& window, Matrix &map, int width, int height);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue