summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/assets.cpp10
-rw-r--r--src/game/game.cpp8
-rw-r--r--src/game/game.hpp29
-rw-r--r--src/game/worldgen.cpp29
4 files changed, 63 insertions, 13 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp
index 32eff81..c20d77b 100644
--- a/src/game/assets.cpp
+++ b/src/game/assets.cpp
@@ -1,6 +1,6 @@
#include "game.hpp"
-namespace assets {
+namespace game::assets {
human_assets_t human;
sf::Texture tile_dirt;
@@ -13,8 +13,10 @@ void load(void)
human.legs_idle.load("assets/units/human/legs_idle", 2, 2);
human.legs_walking.load("assets/units/human/legs_walking", 2, 2);
- tile_dirt.loadFromFile("assets/tiles/dirt.png");
- tile_wall.loadFromFile("assets/tiles/wall.png");
+ world::register_tile(TILE_DIRT, 0);
+ world::register_tile(TILE_WALL, 1);
+ render::register_tile(TILE_DIRT, "assets/tiles/dirt.png");
+ render::register_tile(TILE_WALL, "assets/tiles/wall.png");
}
-} // namespace assets
+} // namespace game::assets
diff --git a/src/game/game.cpp b/src/game/game.cpp
index eb3966d..385a940 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -216,6 +216,8 @@ void state_t::start(void)
{
human_t *human;
+ world.generator = worldgen;
+
human = new human_t;
human->place(&world, v2f_t(0.5, 0.5));
units.insert(human);
@@ -267,4 +269,10 @@ void state_t::tick(double now_, double dt_)
unit->keep_moving(now, dt);
}
+bool load_assets(void)
+{
+ assets::load();
+ return true;
+}
+
} //namespace game
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 3e10bbb..5da6370 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -1,14 +1,25 @@
#include "../common.hpp"
-namespace assets {
- typedef struct {
- render::oriented_sprite_4M_t head_idle, body_idle;
- render::oriented_sprite_4M2_t legs_idle, legs_walking;
- } human_assets_t;
+namespace game {
+ enum {
+ TILE_NONE,
+ TILE_DIRT,
+ TILE_WALL
+ };
- extern human_assets_t human;
- extern sf::Texture tile_dirt;
- extern sf::Texture tile_wall;
+ void worldgen(world::tile_t *tile, world::tile_index_t x,
+ procgen::perlin_noise_t *perlin);
- void load(void);
+ namespace assets {
+ typedef struct {
+ render::oriented_sprite_4M_t head_idle, body_idle;
+ render::oriented_sprite_4M2_t legs_idle, legs_walking;
+ } human_assets_t;
+
+ extern human_assets_t human;
+ extern sf::Texture tile_dirt;
+ extern sf::Texture tile_wall;
+
+ void load(void);
+ }
};
diff --git a/src/game/worldgen.cpp b/src/game/worldgen.cpp
new file mode 100644
index 0000000..573d03b
--- /dev/null
+++ b/src/game/worldgen.cpp
@@ -0,0 +1,29 @@
+#include "game.hpp"
+
+namespace game {
+
+void worldgen(world::tile_t *tile, world::tile_index_t x,
+ procgen::perlin_noise_t *perlin)
+{
+ float waterlevel, height;
+
+ waterlevel = perlin->get(x, 1000.0f) * 0.3f +
+ perlin->get(x, 500.0f) * 0.1f;
+
+ height = perlin->get(x, 40.0f) * 0.6f +
+ perlin->get(x, 20.0f) * 0.25f +
+ perlin->get(x, 10.0f) * 0.2f +
+ perlin->get(x, 4.0f) * 0.1f +
+ perlin->get(x, 1.0f) * 0.05f;
+
+ if (height < waterlevel)
+ tile->type = TILE_WALL;
+ else if (height < waterlevel + 0.1)
+ tile->type = TILE_DIRT;
+ else if (perlin->get(x, 3.0f) > 0.0f)
+ tile->type = TILE_WALL;
+ else
+ tile->type = TILE_DIRT;
+}
+
+}