, world(block_types, wc)
, spawn_index(world.Chunks().MakeIndex(wc.spawn, 3))
, player(*world.AddPlayer(config.player.name))
+, spawn_player(false)
, hud(env, config, player)
, manip(env, player.GetEntity())
, input(world, player, manip)
if (save.Exists(player)) {
save.Read(player);
} else {
- // TODO: spawn
+ spawn_player = true;
}
}
}
-void MasterState::OnEnter() {
- env.state.Push(&preload);
- env.window.GrabMouse();
+void MasterState::OnResume() {
+ if (spawn_index.MissingChunks() > 0) {
+ env.state.Push(&preload);
+ }
+ if (config.input.mouse) {
+ env.window.GrabMouse();
+ }
+ if (spawn_player) {
+ // TODO: spawn
+ spawn_player = false;
+ }
+}
+
+void MasterState::OnPause() {
+ env.window.ReleaseMouse();
}
);
~MasterState();
- void OnEnter() override;
+ void OnResume() override;
+ void OnPause() override;
void Handle(const SDL_Event &) override;
void Update(int dt) override;
World world;
ChunkIndex &spawn_index;
Player &player;
+ bool spawn_player;
HUD hud;
InteractiveManipulator manip;
DirectInput input;
namespace blank {
+class BlockLookup;
class ChunkIndex;
class Player {
void SetInventorySlot(int i) noexcept { inv_slot = i; }
int GetInventorySlot() const noexcept { return inv_slot; }
+ bool SuitableSpawn(BlockLookup &) const noexcept;
+
void Update(int dt);
private:
}
+bool Player::SuitableSpawn(BlockLookup &spawn_block) const noexcept {
+ if (!spawn_block || spawn_block.GetType().collide_block) {
+ return false;
+ }
+
+ BlockLookup head_block(spawn_block.Next(Block::FACE_UP));
+ if (!head_block || head_block.GetType().collide_block) {
+ return false;
+ }
+
+ return true;
+}
+
void Player::Update(int dt) {
chunks.Rebase(entity.ChunkCoords());
}