You can now stab stuff with a sword.

master
Zed A. Shaw 3 months ago
parent ad38f575a3
commit d397c02d38
  1. BIN
      assets/cinqueda_1-512.png
  2. 14
      main.cpp
  3. 5
      texture.cpp
  4. 1
      texture.hpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

@ -31,6 +31,12 @@ void draw_gui(sf::RenderWindow &window, sf::Text &text, Stats &stats) {
window.draw(text);
}
void draw_weapon(sf::RenderWindow &window, sf::Sprite *weapon, float rotation) {
weapon->setPosition({SCREEN_WIDTH/2,SCREEN_HEIGHT/2});
weapon->setRotation(sf::degrees(rotation));
window.draw(*weapon);
}
int main() {
sf::RenderWindow window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Ray Caster Game Thing");
@ -55,6 +61,7 @@ int main() {
window.close();
};
float rotation = -30.0f;
Stats stats;
window.setVerticalSyncEnabled(VSYNC);
@ -68,6 +75,7 @@ int main() {
stats.sample(1/elapsed.count());
draw_gui(window, text, stats);
draw_weapon(window, rayview.$textures.sword.sprite, rotation);
window.display();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
@ -86,6 +94,12 @@ int main() {
stats.reset();
}
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
rotation = -30.0f;
} else {
rotation = -10.0f;
}
window.handleEvents(onClose);
}

@ -32,8 +32,11 @@ void TexturePack::load_textures() {
sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-256.png");
sprite_texture->setSmooth(false);
sf::Sprite* sf_sprite = new sf::Sprite(*sprite_texture);
sprites.push_back({4.0, 3.55, 6, sf_sprite, sprite_texture});
sword.sprite_texture = new sf::Texture("assets/cinqueda_1-512.png");
sword.sprite_texture->setSmooth(false);
sword.sprite = new sf::Sprite(*sword.sprite_texture);
}
Image& TexturePack::get_texture(size_t num) {

@ -28,6 +28,7 @@ struct TexturePack {
std::vector<Sprite> sprites;
Image floor;
Image ceiling;
Sprite sword;
void load_textures();
std::vector<uint32_t> load_image(std::string filename);

Loading…
Cancel
Save