proper collision
This commit is contained in:
parent
83e312894b
commit
553ab7c1df
10 changed files with 143 additions and 8 deletions
32
include/collision.hpp
Normal file
32
include/collision.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
#include "map.hpp"
|
||||
#include <SDL.h>
|
||||
#include <map>
|
||||
|
||||
struct PCollisionRect {
|
||||
SDL_Rect rect;
|
||||
};
|
||||
|
||||
struct PCollisionInfo {
|
||||
bool isSolid = false;
|
||||
};
|
||||
|
||||
struct PCollisionDatabase {
|
||||
std::map<std::string, PCollisionInfo> tileInfo;
|
||||
};
|
||||
|
||||
/*
|
||||
* Called once, generates a list of tiles which are solid, and which ones are
|
||||
* not solid
|
||||
*/
|
||||
void PPopulateCollisionDb();
|
||||
|
||||
/*
|
||||
* Check if we can move to the given position in the map
|
||||
*/
|
||||
bool PCanMoveTo(int x, int y);
|
||||
|
||||
/*
|
||||
* Build a list of PCollisionRects from the given map
|
||||
*/
|
||||
void PBuildCollisionFromMap(Map *map);
|
|
@ -15,6 +15,8 @@ struct Map {
|
|||
int mapHeight;
|
||||
int mapScaleX; // Rendering scale
|
||||
int mapScaleY; // Rendering scale
|
||||
int mapPlayerSpawnX;
|
||||
int mapPlayerSpawnY;
|
||||
|
||||
MapData data;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include <SDL.h>
|
||||
#include <string>
|
||||
|
||||
enum PPlayerFacingDirection { Up, Down, Left, Right };
|
||||
|
@ -13,3 +14,4 @@ struct PPlayer {
|
|||
};
|
||||
|
||||
void PRenderPlayer(PPlayer *player);
|
||||
SDL_Rect PGetPlayerRect(PPlayer *player);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "assets.hpp"
|
||||
#include "collision.hpp"
|
||||
#include "config.hpp"
|
||||
#include "player.hpp"
|
||||
#include <SDL.h>
|
||||
|
@ -8,7 +9,10 @@ struct GlobalState {
|
|||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Rect camera;
|
||||
|
||||
PPlayer player;
|
||||
PCollisionDatabase collisionDb;
|
||||
std::vector<PCollisionRect> collisions;
|
||||
PhoenixAssets assets;
|
||||
int scale = 20;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue