[Add] Half way through axis aligned bounding box implementation.
This commit is contained in:
parent
11367621ef
commit
b360a2a894
@ -3,16 +3,36 @@
|
||||
Player::Player(void) {
|
||||
PLAYER_SPEED = 15;
|
||||
_rotationAngle = 0.0f;
|
||||
_allowCollision = true;
|
||||
_notColliding = false;
|
||||
_blueCollision = false;
|
||||
|
||||
// Loading of sprites and collision details.
|
||||
_player->LoadSprite("../Data/Img/Player.png");
|
||||
// This should be directed to a collision sheet.
|
||||
_collisionBound = new AABB();
|
||||
_collisionBound->CreateAABBFromSprite("../Data/Img/Player.png");
|
||||
|
||||
_environmentCollisionBound = new AABB();
|
||||
_environmentCollisionBound->SetMin(_collisionBound->GetMin().x, _collisionBound->GetMax().y - 50.0f);
|
||||
_environmentCollisionBound->SetMax(_collisionBound->GetMax());
|
||||
}
|
||||
|
||||
Player::~Player(void) {
|
||||
delete _player;
|
||||
delete _collisionBound;
|
||||
}
|
||||
|
||||
void Player::Prepare(void) {
|
||||
_player = new Sprite();
|
||||
void Player::Update(void) {
|
||||
// Position and collision bound with the player.
|
||||
_collisionBound->SetPositionOffset(_player->GetX(), _player->GetY());
|
||||
_environmentCollisionBound->SetPositionOffset(_player->GetX, _player->GetY());
|
||||
|
||||
_player->LoadSprite("../Data/Img/Player.png");
|
||||
// Time to process the collisions.
|
||||
ProcessCollisions();
|
||||
|
||||
// Process events here.
|
||||
ProcessEvents();
|
||||
}
|
||||
|
||||
void Player::Render(void) {
|
||||
@ -20,6 +40,10 @@ void Player::Render(void) {
|
||||
_player->Draw();
|
||||
}
|
||||
|
||||
void Player::ProcessCollisions(void) {
|
||||
|
||||
}
|
||||
|
||||
void Player::ProcessEvents(void) {
|
||||
x = _player->GetX();
|
||||
y = _player->GetY();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "../Sprite/Sprite.h"
|
||||
#include "../Collision/AABB.h"
|
||||
#include "../Global/Globals.h"
|
||||
#include "../System/Debug.h"
|
||||
#include "../IO/Input.h"
|
||||
@ -12,8 +13,21 @@ public:
|
||||
Player(void);
|
||||
~Player(void);
|
||||
|
||||
void Prepare(void);
|
||||
void Update(void);
|
||||
void Render(void);
|
||||
|
||||
// --- Collision stuff.
|
||||
|
||||
// Process the collisions and reactions.
|
||||
void ProcessCollisions(void);
|
||||
// Entity collision test.
|
||||
void EntityCollisionTest(void);
|
||||
// Actor(NPCS).
|
||||
void ActorCollisionTest(void);
|
||||
AABB* GetAABB(void);
|
||||
|
||||
bool GetInBlueCollision(void);
|
||||
|
||||
void ProcessEvents(void);
|
||||
|
||||
private:
|
||||
@ -22,4 +36,12 @@ private:
|
||||
float PLAYER_SPEED;
|
||||
Sprite* _player;
|
||||
float _rotationAngle;
|
||||
|
||||
// --- Collisions.
|
||||
bool _allowCollision;
|
||||
bool _notColliding;
|
||||
bool _blueCollision;
|
||||
|
||||
AABB* _collisionBound;
|
||||
AABB* _environmentCollisionBound;
|
||||
};
|
||||
|
@ -32,7 +32,7 @@ bool Game::Init(void) {
|
||||
glAlphaFunc(GL_GREATER, 0.1f);
|
||||
|
||||
_level->Load("../Data/Map/Ugly.tmx");
|
||||
_player->Prepare();
|
||||
_player->Update();
|
||||
|
||||
// Return success.
|
||||
return true;
|
||||
@ -64,7 +64,7 @@ void Game::Shutdown(void) {
|
||||
}
|
||||
|
||||
void Game::ProcessEvents(void) {
|
||||
_player->ProcessEvents();
|
||||
// Should not need this, as the game class has no events to process..
|
||||
}
|
||||
|
||||
void Game::OnResize(int width, int height) {
|
||||
|
Loading…
Reference in New Issue
Block a user