|
|
|
|
|
|
|
#ifndef PARTICLES_H
|
|
|
|
#define PARTICLES_H
|
|
|
|
|
|
|
|
#include <SDL2/SDL_events.h>
|
|
|
|
#include <SDL2/SDL_pixels.h>
|
|
|
|
#include <SDL2/SDL_render.h>
|
|
|
|
#include <SDL2/SDL_surface.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace pengine {
|
|
|
|
|
|
|
|
enum class ParticleID {
|
|
|
|
BASIC = 0,
|
|
|
|
SAND = 1,
|
|
|
|
WATER = 2,
|
|
|
|
STEAM = 3,
|
|
|
|
LAVA = 4,
|
|
|
|
ROCK = 5
|
|
|
|
};
|
|
|
|
|
|
|
|
class PixelColour {
|
|
|
|
public:
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
Uint8 b;
|
|
|
|
Uint8 g;
|
|
|
|
Uint8 r;
|
|
|
|
Uint8 a;
|
|
|
|
};
|
|
|
|
Uint32 pixel;
|
|
|
|
};
|
|
|
|
Uint32 get_pixelcol();
|
|
|
|
SDL_Color get_sdlcol();
|
|
|
|
PixelColour(short r, short g, short b, short a);
|
|
|
|
PixelColour(short r, short g, short b);
|
|
|
|
PixelColour(const Uint8[3]);
|
|
|
|
PixelColour(SDL_Color c);
|
|
|
|
PixelColour(Uint32 c);
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class State { SOLID, LIQUID, GAS };
|
|
|
|
|
|
|
|
struct particle_data {
|
|
|
|
double density;
|
|
|
|
bool liquid;
|
|
|
|
double temperature;
|
|
|
|
double boiling_point;
|
|
|
|
double melting_point;
|
|
|
|
double freezing_point;
|
|
|
|
ParticleID gas_state;
|
|
|
|
ParticleID liquid_state;
|
|
|
|
ParticleID solid_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Particle;
|
|
|
|
|
|
|
|
class Grid {
|
|
|
|
public:
|
|
|
|
Particle **grid;
|
|
|
|
Uint32 *pixels;
|
|
|
|
int xsize;
|
|
|
|
int ysize;
|
|
|
|
|
|
|
|
Grid(int xs, int ys);
|
|
|
|
virtual ~Grid();
|
|
|
|
Grid &operator=(Grid o);
|
|
|
|
|
|
|
|
void update();
|
|
|
|
void clear();
|
|
|
|
void update_texture();
|
|
|
|
void add_particle_at(int x, int y, ParticleID p);
|
|
|
|
void erase_particle_at(int x, int y);
|
|
|
|
|
|
|
|
bool move_particle(int xa, int ya, int xb, int yb);
|
|
|
|
int swap_particle(int xa, int ya, int xb, int yb);
|
|
|
|
bool inside_grid(int x, int y);
|
|
|
|
Particle *get_particle(int x, int y);
|
|
|
|
void replace_particle(int x, int y, Particle *new_particle);
|
|
|
|
// std::vector<Particle *> get_particles_near(int x, int y);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Particle {
|
|
|
|
public:
|
|
|
|
struct particle_data data;
|
|
|
|
|
|
|
|
bool updated = false;
|
|
|
|
enum ParticleID id;
|
|
|
|
virtual void update(Grid *const, int x, int y) = 0;
|
|
|
|
virtual PixelColour get_colour() = 0;
|
|
|
|
Particle(ParticleID id) : id{id} {};
|
|
|
|
virtual std::string get_name() = 0;
|
|
|
|
virtual ~Particle() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BasicParticle : public Particle {
|
|
|
|
protected:
|
|
|
|
bool update_temperature(Grid *const g, int x, int y);
|
|
|
|
State get_state();
|
|
|
|
|
|
|
|
public:
|
|
|
|
BasicParticle();
|
|
|
|
BasicParticle(ParticleID id);
|
|
|
|
struct particle_data default_data(ParticleID id);
|
|
|
|
void update(Grid *const, int x, int y) override;
|
|
|
|
PixelColour get_colour() override;
|
|
|
|
std::string get_name() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Sand : public BasicParticle {
|
|
|
|
|
|
|
|
public:
|
|
|
|
void update(Grid *const, int x, int y) override;
|
|
|
|
Sand() : BasicParticle(ParticleID::SAND){};
|
|
|
|
Sand(ParticleID id) : BasicParticle(id){};
|
|
|
|
};
|
|
|
|
|
|
|
|
class Water : public BasicParticle {
|
|
|
|
public:
|
|
|
|
void update(Grid *const, int x, int y) override;
|
|
|
|
Water() : BasicParticle(ParticleID::WATER){};
|
|
|
|
Water(ParticleID id) : BasicParticle(id){};
|
|
|
|
};
|
|
|
|
|
|
|
|
class Steam : public BasicParticle {
|
|
|
|
public:
|
|
|
|
void update(Grid *const, int x, int y) override;
|
|
|
|
Steam() : BasicParticle(ParticleID::STEAM){};
|
|
|
|
};
|
|
|
|
|
|
|
|
class Lava : public Water {
|
|
|
|
public:
|
|
|
|
void update(Grid *const, int x, int y) override;
|
|
|
|
Lava();
|
|
|
|
};
|
|
|
|
|
|
|
|
class Rock : public Sand {
|
|
|
|
public:
|
|
|
|
void update(Grid *const, int x, int y) override;
|
|
|
|
Rock();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace pengine
|
|
|
|
#endif
|