summary refs log tree commit diff stats
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/map_collision.cpp29
-rw-r--r--src/components/map_collision.h3
-rw-r--r--src/components/map_render.cpp1
-rw-r--r--src/components/physics_body.cpp1
-rw-r--r--src/components/player_physics.cpp1
5 files changed, 30 insertions, 5 deletions
diff --git a/src/components/map_collision.cpp b/src/components/map_collision.cpp index 9afa6f8..9adad26 100644 --- a/src/components/map_collision.cpp +++ b/src/components/map_collision.cpp
@@ -1,11 +1,14 @@
1#include "map_collision.h" 1#include "map_collision.h"
2#include "map.h" 2#include "map.h"
3#include "game.h" 3#include "game.h"
4#include "consts.h"
4 5
5MapCollisionComponent::MapCollisionComponent(const Map& map) : map(map) 6MapCollisionComponent::MapCollisionComponent(const Map& map) : map(map)
6{ 7{
7 addCollision(-6, 0, GAME_WIDTH, Direction::left, (map.getLeftMap() == nullptr) ? Collision::Type::wrap : Collision::Type::teleport); 8 addCollision(-6, 0, GAME_HEIGHT, Direction::left, collisionFromMoveType(map.getLeftMoveType()));
8 addCollision(GAME_WIDTH+6, 0, GAME_WIDTH, Direction::right, (map.getRightMap() == nullptr) ? Collision::Type::reverse : Collision::Type::teleport); 9 addCollision(GAME_WIDTH+6, 0, GAME_HEIGHT, Direction::right, collisionFromMoveType(map.getRightMoveType()));
10 addCollision(-7, 0, GAME_WIDTH, Direction::up, collisionFromMoveType(map.getUpMoveType()));
11 addCollision(GAME_HEIGHT+6, 0, GAME_WIDTH, Direction::down, collisionFromMoveType(map.getDownMoveType()));
9 12
10 for (int i=0; i<MAP_WIDTH*MAP_HEIGHT; i++) 13 for (int i=0; i<MAP_WIDTH*MAP_HEIGHT; i++)
11 { 14 {
@@ -186,13 +189,20 @@ void MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli
186 { 189 {
187 if (dir == Direction::left) 190 if (dir == Direction::left)
188 { 191 {
189 game.loadMap(*map.getLeftMap(), std::make_pair(GAME_WIDTH-collider.size.first/2, old_position.second)); 192 game.loadMap(game.getMap(map.getLeftMapID()), std::make_pair(GAME_WIDTH-collider.size.first/2, old_position.second));
190 } else if (dir == Direction::right) 193 } else if (dir == Direction::right)
191 { 194 {
192 game.loadMap(*map.getRightMap(), std::make_pair(-collider.size.first/2, old_position.second)); 195 game.loadMap(game.getMap(map.getRightMapID()), std::make_pair(-collider.size.first/2, old_position.second));
196 } else if (dir == Direction::up)
197 {
198 game.loadMap(game.getMap(map.getUpMapID()), std::make_pair(old_position.first, GAME_HEIGHT-collider.size.second/2));
199 } else if (dir == Direction::down)
200 {
201 game.loadMap(game.getMap(map.getDownMapID()), std::make_pair(old_position.first, -collider.size.second/2));
193 } 202 }
194 } else if (collision.type == Collision::Type::reverse) 203 } else if (collision.type == Collision::Type::reverse)
195 { 204 {
205 // TODO reverse
196 if (dir == Direction::right) 206 if (dir == Direction::right)
197 { 207 {
198 collider.position.first = collision.axis - collider.size.first; 208 collider.position.first = collision.axis - collider.size.first;
@@ -209,3 +219,14 @@ void MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli
209 game.playerDie(); 219 game.playerDie();
210 } 220 }
211} 221}
222
223MapCollisionComponent::Collision::Type MapCollisionComponent::collisionFromMoveType(Map::MoveType type)
224{
225 switch (type)
226 {
227 case Map::MoveType::Wall: return Collision::Type::wall;
228 case Map::MoveType::Wrap: return Collision::Type::wrap;
229 case Map::MoveType::Warp: return Collision::Type::teleport;
230 case Map::MoveType::ReverseWarp: return Collision::Type::reverse;
231 }
232}
diff --git a/src/components/map_collision.h b/src/components/map_collision.h index 3b718b6..18b9397 100644 --- a/src/components/map_collision.h +++ b/src/components/map_collision.h
@@ -2,9 +2,9 @@
2#define MAP_COLLISION_H 2#define MAP_COLLISION_H
3 3
4#include "entity.h" 4#include "entity.h"
5#include "map.h"
5#include <list> 6#include <list>
6 7
7class Map;
8class Game; 8class Game;
9 9
10class MapCollisionComponent : public Component { 10class MapCollisionComponent : public Component {
@@ -35,6 +35,7 @@ class MapCollisionComponent : public Component {
35 35
36 void addCollision(double axis, double lower, double upper, Direction dir, Collision::Type type); 36 void addCollision(double axis, double lower, double upper, Direction dir, Collision::Type type);
37 void processCollision(Game& game, Entity& collider, Collision collision, Direction dir, std::pair<double, double> old_position); 37 void processCollision(Game& game, Entity& collider, Collision collision, Direction dir, std::pair<double, double> old_position);
38 Collision::Type collisionFromMoveType(Map::MoveType type);
38 39
39 std::list<Collision> left_collisions; 40 std::list<Collision> left_collisions;
40 std::list<Collision> right_collisions; 41 std::list<Collision> right_collisions;
diff --git a/src/components/map_render.cpp b/src/components/map_render.cpp index 10c5db8..45766e1 100644 --- a/src/components/map_render.cpp +++ b/src/components/map_render.cpp
@@ -1,6 +1,7 @@
1#include "map_render.h" 1#include "map_render.h"
2#include "map.h" 2#include "map.h"
3#include "game.h" 3#include "game.h"
4#include "consts.h"
4 5
5MapRenderComponent::MapRenderComponent(const Map& map) : screen(GAME_WIDTH, GAME_HEIGHT) 6MapRenderComponent::MapRenderComponent(const Map& map) : screen(GAME_WIDTH, GAME_HEIGHT)
6{ 7{
diff --git a/src/components/physics_body.cpp b/src/components/physics_body.cpp index 72f2fd8..acbdc5d 100644 --- a/src/components/physics_body.cpp +++ b/src/components/physics_body.cpp
@@ -1,5 +1,6 @@
1#include "physics_body.h" 1#include "physics_body.h"
2#include "game.h" 2#include "game.h"
3#include "consts.h"
3 4
4void PhysicsBodyComponent::receive(Game&, Entity&, const Message& msg) 5void PhysicsBodyComponent::receive(Game&, Entity&, const Message& msg)
5{ 6{
diff --git a/src/components/player_physics.cpp b/src/components/player_physics.cpp index e366d6e..1d14f35 100644 --- a/src/components/player_physics.cpp +++ b/src/components/player_physics.cpp
@@ -1,6 +1,7 @@
1#include "player_physics.h" 1#include "player_physics.h"
2#include "muxer.h" 2#include "muxer.h"
3#include "game.h" 3#include "game.h"
4#include "consts.h"
4 5
5#define JUMP_VELOCITY(h, l) (-2 * (h) / (l)) 6#define JUMP_VELOCITY(h, l) (-2 * (h) / (l))
6#define JUMP_GRAVITY(h, l) (2 * ((h) / (l)) / (l)) 7#define JUMP_GRAVITY(h, l) (2 * ((h) / (l)) / (l))