naval_swarm/src/types.hpp

82 lines
1.7 KiB
C++

#include "const.hpp"
#include <SDL3/SDL.h>
#include <SDL3_image/SDL_image.h>
#include <iostream>
struct Angle360 {
private:
int value{0};
void normalize() {
value %= 360;
if (value < 0)
value += 360; // Handle negative values
}
public:
// Constructor
Angle360(int val = 0) : value(val) { normalize(); }
// Assignment operator
Angle360 &operator=(int val) {
value = val;
normalize();
return *this;
}
// Compound assignment
Angle360 &operator+=(int rhs) {
value += rhs;
normalize();
return *this;
}
Angle360 &operator-=(int rhs) {
value -= rhs;
normalize();
return *this;
}
// Type conversion
operator int() const { return value; }
// Stream output
friend std::ostream &operator<<(std::ostream &os, const Angle360 &a) {
return os << a.value;
}
};
struct Entity {
private:
SDL_FRect m_position;
SDL_FPoint m_offset{0, 0}; // Default offset
public:
// Direct access reference with auto-sync
SDL_FRect &position() { return m_position; }
const SDL_FRect &position() const { return m_position; }
// Computed central position (always fresh)
SDL_FRect Central_position() const {
return {m_position.x + m_offset.x, m_position.y + m_offset.y, m_position.w,
m_position.h};
}
// Set offset values
void set_offset(float x, float y) { m_offset = {x, y}; }
// --- Existing members ---
SDL_FRect Tposition;
bool gotoT;
SDL_Texture *texture;
SDL_Rect srcRect;
float speed = 250.0f;
Angle360 angle;
};
struct Camera {
SDL_FRect view = {0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT};
bool followPlayer = false;
float speed = 500.0f;
float smoothness = 0.1f;
};