From a34396730c8d993fea84a454690bd13ea9a9b403 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 16 Feb 2019 10:02:05 -0500 Subject: Started implementing pushing, but not really --- src/entity.h | 22 +++++++++++++++++++++- src/level.h | 8 -------- src/main.cpp | 12 +++++++++++- src/renderer.cpp | 6 +++--- src/simulation.cpp | 2 +- src/tileset.h | 2 +- 6 files changed, 37 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/entity.h b/src/entity.h index d99680f..8d28b98 100644 --- a/src/entity.h +++ b/src/entity.h @@ -3,6 +3,20 @@ #include "vector.h" +enum class ColliderType { + player, + train, + other +}; + +enum class Direction { + none, + left, + right, + up, + down +}; + class Entity { public: @@ -14,17 +28,23 @@ public: vec2s gridPos; // Movement + Direction shouldMoveTo = Direction::none; bool moving = false; vec2s destPos; double movementTween = 0.0; double speed = 0.0; // Tiles per second // Player - bool player = false; + bool controllable = false; // Collision + ColliderType colliderType = ColliderType::other; + bool playerCanPush = false; bool trainCanPush = false; + + // Temp + int colorVal = 25; }; diff --git a/src/level.h b/src/level.h index 3d6fb87..6224c15 100644 --- a/src/level.h +++ b/src/level.h @@ -12,14 +12,6 @@ public: size_ = LEVEL_SIZE; tiles_.resize(size_.w() * size_.h()); - - for (size_t y = 0; y < size_.h(); y++) - { - for (size_t x = 0; x < size_.w(); x++) - { - tiles_[x+y*size_.w()] = rand() % 10; - } - } } const vec2s& getSize() const diff --git a/src/main.cpp b/src/main.cpp index 1b74143..4dce6a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,17 @@ int main(int, char**) entity.gridPos.y() = 5; entity.size = TILE_SIZE; entity.speed = 3.0; - entity.player = true; + entity.controllable = true; + entity.colliderType = ColliderType::player; + entity.colorVal = 180; + + Simulation::id_type crateId = sim.emplaceEntity(); + Entity& crate = sim.getEntity(crateId); + crate.gridPos.x() = 4; + crate.gridPos.y() = 5; + crate.size = TILE_SIZE; + crate.speed = 4.0; + crate.playerCanPush = true; bool quit = false; diff --git a/src/renderer.cpp b/src/renderer.cpp index 2916dd6..64b3a8e 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -61,9 +61,9 @@ void Renderer::render(const Simulation& sim) { for (size_t x = 0; x < level.getSize().w(); x++) { - int val = level.at(x, y) * 10; + int val = 255 - level.at(x, y) * 10; - SDL_SetRenderDrawColor(ren_.get(), val, val, 0, 255); + SDL_SetRenderDrawColor(ren_.get(), val, val, val, 255); SDL_Rect rect { static_cast(x * TILE_SIZE.w()), @@ -80,7 +80,7 @@ void Renderer::render(const Simulation& sim) { const Entity& entity = sim.getEntity(id); - SDL_SetRenderDrawColor(ren_.get(), 100, 100, 100, 255); + SDL_SetRenderDrawColor(ren_.get(), entity.colorVal, entity.colorVal, 65, 255); SDL_Rect rect { static_cast(entity.pos.x()), diff --git a/src/simulation.cpp b/src/simulation.cpp index 3079f56..7dfc83c 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -12,7 +12,7 @@ void Simulation::tick( Entity& entity = entities_.at(id); // Control - if (entity.player && + if (entity.controllable && !entity.moving) { if (keystate[SDL_SCANCODE_LEFT] && diff --git a/src/tileset.h b/src/tileset.h index 552b2f8..610a710 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -6,7 +6,7 @@ public: bool canPlayerMoveTo(size_t tile) const { - return (tile % 2 == 1); + return true; } }; -- cgit 1.4.1