Nimbin[12]?SDL & Graphics / SDL_Game_CPP / src/inventory/weapon.hpp

SDL_Game_CPP git · main

SDL game in C++

sdl game c++ · first commit 2026-03-24 · last commit 2026-03-24 (8 months ago) · synced 1 hour ago · upstream: codeberg.org/Studying_at_HsNR/SDL_Game_CPP

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/SDL_Game_CPP.gitwget https://git.christianimmanuel.de/sdl-graphics/SDL_Game_CPP/archive/SDL_Game_CPP.tar.gz
src/inventory/weapon.hpp 1.2 KB · 57 lines raw
#pragma once

#include "defaults/defaults.hpp"

#include <string>
#include <vector>
#include <unordered_map>
#include <SDL3_image/SDL_image.h>

enum class WeaponType {
    KNIFE,
    LONGSWORD,
    SWORD,
    SPEER,
    HAMMER,
    BOW,
    SHIELD,
};

enum class WeaponMaterial {
    WOOD,
    BONE
};
struct WeaponTileSet {
    SDL_Texture*  texture;
    SDL_Point size;
    WeaponMaterial material;
};

struct WeaponSet {
    size_t   weapon_tileset_id;
    SDL_FRect tileset_position;
    WeaponType type;
    float demage;
    float speed;
};

extern std::vector<WeaponTileSet> weapon_sets;
extern std::vector<WeaponSet>     weapons;

class Weapon {
    size_t         weapon_index = (size_t)-1;

    static void AddWeaponFromTileset(size_t tileset_id, WeaponType type,
                            float demage, float speed, float x, float y, float w, float h);
public:
    WeaponType     type     = WeaponType::SWORD;
    WeaponMaterial material = WeaponMaterial::WOOD;
    SDL_FPoint     dimension = {30.0f, 16.0f};
    bool flip = false;

    Weapon(WeaponType type, WeaponMaterial material);

    static void Init(SDL_Renderer* renderer);

    void Draw(SDL_Renderer* renderer, float x, float y);
};