Fix bug in update
This commit is contained in:
parent
f9caf21322
commit
ec5c6b2bec
48
src/main.cpp
48
src/main.cpp
@ -7,29 +7,46 @@
|
|||||||
#include <SDL3/SDL_video.h>
|
#include <SDL3/SDL_video.h>
|
||||||
#include <sand.h>
|
#include <sand.h>
|
||||||
|
|
||||||
constexpr uint16_t WIDTH = 128;
|
constexpr uint16_t WIDTH = 256;
|
||||||
constexpr uint16_t HEIGHT = 128;
|
constexpr uint16_t HEIGHT = 256;
|
||||||
|
|
||||||
constexpr int WINDOW_WIDTH = 1024;
|
constexpr int WINDOW_WIDTH = 1024;
|
||||||
constexpr int WINDOW_HEIGHT = 1024;
|
constexpr int WINDOW_HEIGHT = 1024;
|
||||||
|
|
||||||
uint8_t lookup[][3]
|
uint8_t lookup[][3]
|
||||||
= { { 0, 0, 0 }, { 50, 0, 0 }, { 100, 100, 100 }, { 200, 200, 200 } };
|
= { { 0, 0, 0 }, { 50, 0, 0 }, { 100, 100, 100 }, { 100, 100, 100 } };
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
auto rb = sand::TypeBuilder()
|
auto rb = sand::TypeBuilder()
|
||||||
.add_type("offgrid")
|
.add_type("offgrid")
|
||||||
.add_type("air")
|
.add_type("air")
|
||||||
.add_type("stone1")
|
.add_type("stone1", "stone2")
|
||||||
.add_type("stone2")
|
.add_type("stone2", "stone1")
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
rb.add_rule("air", "stone1")
|
rb.add_rule("air", "stone2")
|
||||||
.top_middle([](const auto& t) { return t == "stone1"; });
|
.top_middle([](const auto& t) { return t == "stone1"; });
|
||||||
|
rb.add_rule("air", "stone1")
|
||||||
|
.top_middle([](const auto& t) { return t == "stone2"; });
|
||||||
|
rb.add_rule("air", "stone2")
|
||||||
|
.top_right([](const auto& t) { return t == "stone1"; })
|
||||||
|
.middle_right([](const auto& t) { return t != "air"; });
|
||||||
|
rb.add_rule("air", "stone1")
|
||||||
|
.top_left([](const auto& t) { return t == "stone2"; })
|
||||||
|
.middle_left([](const auto& t) { return t != "air"; });
|
||||||
|
|
||||||
rb.add_rule("stone1", "air")
|
rb.add_rule("stone1", "air")
|
||||||
.bottom_middle([](const auto& t) { return t == "air"; });
|
.bottom_middle([](const auto& t) { return t == "air"; });
|
||||||
|
rb.add_rule("stone1", "air")
|
||||||
|
.bottom_left([](const auto& t) { return t == "air"; })
|
||||||
|
.bottom_middle([](const auto& t) { return t != "air"; });
|
||||||
|
|
||||||
|
rb.add_rule("stone2", "air")
|
||||||
|
.bottom_middle([](const auto& t) { return t == "air"; });
|
||||||
|
rb.add_rule("stone2", "air")
|
||||||
|
.bottom_right([](const auto& t) { return t == "air"; })
|
||||||
|
.bottom_middle([](const auto& t) { return t != "air"; });
|
||||||
|
|
||||||
auto s = rb.build(WIDTH, HEIGHT, "air");
|
auto s = rb.build(WIDTH, HEIGHT, "air");
|
||||||
|
|
||||||
@ -60,15 +77,20 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
float x, y;
|
float x, y;
|
||||||
int state;
|
int state;
|
||||||
if (time > 0.008 && (state = SDL_GetMouseState(&x, &y)))
|
if (time > 1 / 1000.0f)
|
||||||
{
|
{
|
||||||
int ix = x * WIDTH / WINDOW_WIDTH;
|
time = 0;
|
||||||
int iy = y * HEIGHT / WINDOW_HEIGHT;
|
s.update();
|
||||||
|
|
||||||
if (ix >= 0 && ix < WIDTH && iy >= 0 && iy < HEIGHT)
|
if ((state = SDL_GetMouseState(&x, &y)))
|
||||||
{
|
{
|
||||||
time = 0;
|
int ix = x * WIDTH / WINDOW_WIDTH;
|
||||||
s.set(ix, iy, state == 1 ? "stone1" : "stone2");
|
int iy = y * HEIGHT / WINDOW_HEIGHT;
|
||||||
|
|
||||||
|
if (ix >= 0 && ix < WIDTH && iy >= 0 && iy < HEIGHT)
|
||||||
|
{
|
||||||
|
s.set(ix, iy, state == 1 ? "stone1" : "stone2");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,8 +107,6 @@ int main(int argc, char** argv)
|
|||||||
SDL_BlitSurfaceScaled(surface, nullptr, SDL_GetWindowSurface(window),
|
SDL_BlitSurfaceScaled(surface, nullptr, SDL_GetWindowSurface(window),
|
||||||
nullptr, SDL_SCALEMODE_NEAREST);
|
nullptr, SDL_SCALEMODE_NEAREST);
|
||||||
SDL_UpdateWindowSurface(window);
|
SDL_UpdateWindowSurface(window);
|
||||||
|
|
||||||
s.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_DestroySurface(surface);
|
SDL_DestroySurface(surface);
|
||||||
|
|||||||
@ -291,7 +291,7 @@ void Sand::update()
|
|||||||
|
|
||||||
if (i < width - 1 && j > 0)
|
if (i < width - 1 && j > 0)
|
||||||
{
|
{
|
||||||
neighbors += get(i + 1, j);
|
neighbors += get(i + 1, j - 1);
|
||||||
}
|
}
|
||||||
neighbors <<= 16;
|
neighbors <<= 16;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user