Skip to content

Commit

Permalink
Add broadphasing debug prints and reset key instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstarkov committed May 8, 2020
1 parent dccec91 commit 7b4e16c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Entity {
private:

public:
AABB oldHitbox;
Entity(AABB hitbox, Vec2D vel = {}, Vec2D accel = {}) : hitbox(hitbox), velocity(vel), acceleration(accel) {}
Entity(Vec2D vel = {}, Vec2D accel = {}) : velocity(vel), acceleration(accel) {}
void update();
Expand Down
20 changes: 16 additions & 4 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ SDL_Window* Game::window = nullptr;
SDL_Renderer* Game::renderer = nullptr;
bool Game::running = false;
std::vector<Entity*> Game::entities;
std::vector<AABB> Game::broadphase;

Game::Game() {
tm = TextureManager::getInstance();
ih = InputHandler::getInstance();
player = Player::getInstance();
Entity* box0 = new Entity(AABB(120, 200, 40, 40));
Entity* box1 = new Entity(AABB(100, 400, 400, 32));
Entity* box1 = new Entity(AABB(100, 400, 400, 64));
Entity* box2 = new Entity(AABB(200, 300, 32, 100));
Entity* box3 = new Entity(AABB(264, 300, 32, 100));
Entity* box4 = new Entity(AABB(350, 200, 100, 32));
Entity* box5 = new Entity(AABB(550, 480, 100, 32));
entities.push_back(box0);
entities.push_back(box1);
entities.push_back(box2);
entities.push_back(box3);
Expand All @@ -40,6 +39,11 @@ void Game::init() {
std::cout << "SDL window failed to init" << std::endl;
}
running = true;
instructions();
}

void Game::instructions() {
std::cout << "Press 'r' to reset block position" << std::endl;
}

void Game::update() {
Expand All @@ -49,15 +53,23 @@ void Game::update() {

void Game::render() {
SDL_RenderClear(renderer); // clear screen
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_SetRenderDrawColor(renderer, 255, 50, 100, 255);
SDL_RenderDrawRect(renderer, player->getHitbox().AABBtoRect());
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
for (auto entity : entities) {
SDL_RenderDrawRect(renderer, entity->getHitbox().AABBtoRect());
}
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
for (auto aabb : broadphase) {
//SDL_RenderDrawRect(renderer, aabb.AABBtoRect());
}
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
//SDL_RenderDrawRect(renderer, player->oldHitbox.AABBtoRect());
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderPresent(renderer); // display
broadphase.clear();
SDL_Delay(0);
}

void Game::loop() {
Expand Down
2 changes: 2 additions & 0 deletions src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class Game {
Player* player;
void update();
void render();
void instructions();
public:
static std::vector<Entity*> entities;
static std::vector<AABB> broadphase;
Game();
static Game* getInstance() {
if (!instance) {
Expand Down

0 comments on commit 7b4e16c

Please sign in to comment.