predictCollisions func added to Game.cpp
This commit is contained in:
@ -21,10 +21,8 @@
|
||||
// #include "../ui/UIText.h"
|
||||
#include "../ui/UINineSlice.h"
|
||||
#include "../cjson/cJSON.h"
|
||||
#include "tmxparser.h"
|
||||
|
||||
|
||||
// Map* map;
|
||||
// tmxparser::TmxMap map;
|
||||
Manager manager;
|
||||
UINineSlice* my9Slice;
|
||||
UINineSlice* scoreboard9Slice;
|
||||
@ -71,6 +69,8 @@ int last_time;
|
||||
int current_time;
|
||||
int diff_time;
|
||||
|
||||
int Game::pTileX = 0;
|
||||
int Game::pTileY = 0;
|
||||
|
||||
std::string Game::BoolToString(bool b) {
|
||||
std::string myString;
|
||||
@ -332,11 +332,13 @@ void Game::update()
|
||||
camera.x = player.getComponent<TransformComponent>().position.x - camera.w/2 + player.getComponent<TransformComponent>().width/2;
|
||||
camera.y = player.getComponent<TransformComponent>().position.y - camera.h/2 + player.getComponent<TransformComponent>().height/2;
|
||||
|
||||
int pTileX = player.getComponent<TransformComponent>().position.x/gScale/tileMap.tileWidth;
|
||||
int pTileY = player.getComponent<TransformComponent>().position.y/gScale/tileMap.tileWidth;
|
||||
pTileX = player.getComponent<TransformComponent>().position.x/gScale/tileMap.tileWidth;
|
||||
pTileY = player.getComponent<TransformComponent>().position.y/gScale/tileMap.tileWidth;
|
||||
|
||||
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string(pTileX));
|
||||
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string(pTileY));
|
||||
player.getComponent<TransformComponent>().updateTilePosition(pTileX,pTileY);
|
||||
|
||||
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string((int)player.getComponent<TransformComponent>().tilePos.x));
|
||||
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string((int)player.getComponent<TransformComponent>().tilePos.y));
|
||||
int playerX = player.getComponent<TransformComponent>().position.x;
|
||||
int playerY = player.getComponent<TransformComponent>().position.y;
|
||||
|
||||
@ -451,3 +453,25 @@ void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blu
|
||||
SDL_SetRenderDrawColor(renderer, red, green, blue, 200);
|
||||
SDL_RenderDrawLine(renderer, srcpt.x, srcpt.y, destpt.x, destpt.y);
|
||||
}
|
||||
|
||||
int * predictCollisions(){
|
||||
static int boundaries[3];
|
||||
if (player.getComponent<TransformComponent>().velocity.x<0){
|
||||
// ====== For Each Row ====
|
||||
int i = 0;
|
||||
for (int r=Game::pTileY-1;r<=Game::pTileY+1;r++){
|
||||
// ====== For Each Tile (Column) =====
|
||||
for (int c=Game::pTileX;c>Game::pTileX-Game::camera.w/gameScene.getComponent<TileMapComponent>().tileWidth;c--){
|
||||
if(gameScene.getComponent<TileMapComponent>().colliders[r][c]>0){
|
||||
boundaries[i] = c*gameScene.getComponent<TileMapComponent>().tileWidth+gameScene.getComponent<TileMapComponent>().tileWidth;
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====== TODO: setup player moving in positive X, and Y axes =====
|
||||
|
||||
|
||||
return boundaries;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "Vector2D.h"
|
||||
#include "../assetmgr/AssetManager.h"
|
||||
#include "GameStateManager.h"
|
||||
#include "tmxparser.h"
|
||||
|
||||
class ColliderComponent;
|
||||
class AssetManager;
|
||||
@ -29,13 +30,17 @@ public:
|
||||
void update();
|
||||
void render();
|
||||
void clean();
|
||||
void printDebug(std::string debugInfo);
|
||||
// void printDebug(std::string debugInfo);
|
||||
static void drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blue);
|
||||
static int * predictCollisions();
|
||||
bool running() { return isRunning; }
|
||||
// static void AddTile(int srcX, int srcY, int xpos, int ypos);
|
||||
static SDL_Renderer *renderer;
|
||||
static SDL_Event event;
|
||||
// static std::vector<ColliderComponent*> colliders;
|
||||
// static tmxparser::TmxMap map;
|
||||
// gameScene;
|
||||
|
||||
static bool debugMenu;
|
||||
static bool isRunning;
|
||||
static bool debugCollisionBoxes;
|
||||
@ -48,6 +53,8 @@ public:
|
||||
static SDL_Rect levelMap;
|
||||
static AssetManager* assets;
|
||||
static GameStateManager* gsm;
|
||||
static int pTileX;
|
||||
static int pTileY;
|
||||
std::string BoolToString(bool b);
|
||||
enum groupLabels : std::size_t
|
||||
{
|
||||
|
Reference in New Issue
Block a user