diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-16 10:02:05 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-16 10:02:05 -0500 |
commit | a34396730c8d993fea84a454690bd13ea9a9b403 (patch) | |
tree | 5f226ee45acaa7070a1bb821df3320e907a9ecb2 | |
parent | 8ffb27ab09ff567a159e5be5a243fd3967084977 (diff) | |
download | dispatcher-a34396730c8d993fea84a454690bd13ea9a9b403.tar.gz dispatcher-a34396730c8d993fea84a454690bd13ea9a9b403.tar.bz2 dispatcher-a34396730c8d993fea84a454690bd13ea9a9b403.zip |
Started implementing pushing, but not really
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/entity.h | 22 | ||||
-rw-r--r-- | src/level.h | 8 | ||||
-rw-r--r-- | src/main.cpp | 12 | ||||
-rw-r--r-- | src/renderer.cpp | 6 | ||||
-rw-r--r-- | src/simulation.cpp | 2 | ||||
-rw-r--r-- | src/tileset.h | 2 |
7 files changed, 38 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore index 378eac2..7b90e02 100644 --- a/.gitignore +++ b/.gitignore | |||
@@ -1 +1,2 @@ | |||
1 | build | 1 | build |
2 | build-intrinsic | ||
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 @@ | |||
3 | 3 | ||
4 | #include "vector.h" | 4 | #include "vector.h" |
5 | 5 | ||
6 | enum class ColliderType { | ||
7 | player, | ||
8 | train, | ||
9 | other | ||
10 | }; | ||
11 | |||
12 | enum class Direction { | ||
13 | none, | ||
14 | left, | ||
15 | right, | ||
16 | up, | ||
17 | down | ||
18 | }; | ||
19 | |||
6 | class Entity { | 20 | class Entity { |
7 | public: | 21 | public: |
8 | 22 | ||
@@ -14,17 +28,23 @@ public: | |||
14 | vec2s gridPos; | 28 | vec2s gridPos; |
15 | 29 | ||
16 | // Movement | 30 | // Movement |
31 | Direction shouldMoveTo = Direction::none; | ||
17 | bool moving = false; | 32 | bool moving = false; |
18 | vec2s destPos; | 33 | vec2s destPos; |
19 | double movementTween = 0.0; | 34 | double movementTween = 0.0; |
20 | double speed = 0.0; // Tiles per second | 35 | double speed = 0.0; // Tiles per second |
21 | 36 | ||
22 | // Player | 37 | // Player |
23 | bool player = false; | 38 | bool controllable = false; |
24 | 39 | ||
25 | // Collision | 40 | // Collision |
41 | ColliderType colliderType = ColliderType::other; | ||
42 | |||
26 | bool playerCanPush = false; | 43 | bool playerCanPush = false; |
27 | bool trainCanPush = false; | 44 | bool trainCanPush = false; |
45 | |||
46 | // Temp | ||
47 | int colorVal = 25; | ||
28 | 48 | ||
29 | }; | 49 | }; |
30 | 50 | ||
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: | |||
12 | size_ = LEVEL_SIZE; | 12 | size_ = LEVEL_SIZE; |
13 | 13 | ||
14 | tiles_.resize(size_.w() * size_.h()); | 14 | tiles_.resize(size_.w() * size_.h()); |
15 | |||
16 | for (size_t y = 0; y < size_.h(); y++) | ||
17 | { | ||
18 | for (size_t x = 0; x < size_.w(); x++) | ||
19 | { | ||
20 | tiles_[x+y*size_.w()] = rand() % 10; | ||
21 | } | ||
22 | } | ||
23 | } | 15 | } |
24 | 16 | ||
25 | const vec2s& getSize() const | 17 | 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**) | |||
19 | entity.gridPos.y() = 5; | 19 | entity.gridPos.y() = 5; |
20 | entity.size = TILE_SIZE; | 20 | entity.size = TILE_SIZE; |
21 | entity.speed = 3.0; | 21 | entity.speed = 3.0; |
22 | entity.player = true; | 22 | entity.controllable = true; |
23 | entity.colliderType = ColliderType::player; | ||
24 | entity.colorVal = 180; | ||
25 | |||
26 | Simulation::id_type crateId = sim.emplaceEntity(); | ||
27 | Entity& crate = sim.getEntity(crateId); | ||
28 | crate.gridPos.x() = 4; | ||
29 | crate.gridPos.y() = 5; | ||
30 | crate.size = TILE_SIZE; | ||
31 | crate.speed = 4.0; | ||
32 | crate.playerCanPush = true; | ||
23 | 33 | ||
24 | bool quit = false; | 34 | bool quit = false; |
25 | 35 | ||
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) | |||
61 | { | 61 | { |
62 | for (size_t x = 0; x < level.getSize().w(); x++) | 62 | for (size_t x = 0; x < level.getSize().w(); x++) |
63 | { | 63 | { |
64 | int val = level.at(x, y) * 10; | 64 | int val = 255 - level.at(x, y) * 10; |
65 | 65 | ||
66 | SDL_SetRenderDrawColor(ren_.get(), val, val, 0, 255); | 66 | SDL_SetRenderDrawColor(ren_.get(), val, val, val, 255); |
67 | 67 | ||
68 | SDL_Rect rect { | 68 | SDL_Rect rect { |
69 | static_cast<int>(x * TILE_SIZE.w()), | 69 | static_cast<int>(x * TILE_SIZE.w()), |
@@ -80,7 +80,7 @@ void Renderer::render(const Simulation& sim) | |||
80 | { | 80 | { |
81 | const Entity& entity = sim.getEntity(id); | 81 | const Entity& entity = sim.getEntity(id); |
82 | 82 | ||
83 | SDL_SetRenderDrawColor(ren_.get(), 100, 100, 100, 255); | 83 | SDL_SetRenderDrawColor(ren_.get(), entity.colorVal, entity.colorVal, 65, 255); |
84 | 84 | ||
85 | SDL_Rect rect { | 85 | SDL_Rect rect { |
86 | static_cast<int>(entity.pos.x()), | 86 | static_cast<int>(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( | |||
12 | Entity& entity = entities_.at(id); | 12 | Entity& entity = entities_.at(id); |
13 | 13 | ||
14 | // Control | 14 | // Control |
15 | if (entity.player && | 15 | if (entity.controllable && |
16 | !entity.moving) | 16 | !entity.moving) |
17 | { | 17 | { |
18 | if (keystate[SDL_SCANCODE_LEFT] && | 18 | 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: | |||
6 | 6 | ||
7 | bool canPlayerMoveTo(size_t tile) const | 7 | bool canPlayerMoveTo(size_t tile) const |
8 | { | 8 | { |
9 | return (tile % 2 == 1); | 9 | return true; |
10 | } | 10 | } |
11 | }; | 11 | }; |
12 | 12 | ||