Have a barely working animation thing that animates the evil eye when you click a button.

master
Zed A. Shaw 1 month ago
parent 51c1e04f61
commit b87217ff90
  1. 2
      animator.cpp
  2. 27
      animator.hpp
  3. 2
      assets/config.json
  4. BIN
      assets/evil_eye-sprites.png
  5. 1
      main.cpp
  6. 3
      raycaster.cpp
  7. 2
      raycaster.hpp

@ -0,0 +1,2 @@
#include "animator.hpp"
#include "constants.hpp"

@ -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",
"sword": "assets/cinqueda_1-512.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",
"floor": "assets/floor_tile_test-256.png",
"ceiling": "assets/ceiling_test-256.png"

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

@ -96,6 +96,7 @@ int main() {
}
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
rayview.$anim.play();
rotation = -30.0f;
} else {
rotation = -10.0f;

@ -150,8 +150,9 @@ void Raycaster::sprite_casting() {
int texY = ((d * textureHeight) / spriteHeight) / textureHeight;
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});
$window.draw(*sf_sprite);
}
}

@ -12,6 +12,7 @@
#include <memory>
#include "texture.hpp"
#include <SFML/System/Clock.hpp>
#include "animator.hpp"
using matrix::Matrix;
using RGBA = uint32_t;
@ -43,6 +44,7 @@ struct Raycaster {
std::vector<int> spriteOrder;
std::vector<double> spriteDistance;
std::vector<double> ZBuffer; // width
Animator $anim{256, 256, 10, 0};
Raycaster(sf::RenderWindow& window, Matrix &map, int width, int height);

Loading…
Cancel
Save