[Add] Half way through axis aligned bounding box implementation.

This commit is contained in:
Rtch90 2012-04-12 01:55:07 +01:00
parent 11367621ef
commit b360a2a894
3 changed files with 54 additions and 8 deletions

View File

@ -3,16 +3,36 @@
Player::Player(void) { Player::Player(void) {
PLAYER_SPEED = 15; PLAYER_SPEED = 15;
_rotationAngle = 0.0f; _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) { Player::~Player(void) {
delete _player; delete _player;
delete _collisionBound;
} }
void Player::Prepare(void) { void Player::Update(void) {
_player = new Sprite(); // 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) { void Player::Render(void) {
@ -20,6 +40,10 @@ void Player::Render(void) {
_player->Draw(); _player->Draw();
} }
void Player::ProcessCollisions(void) {
}
void Player::ProcessEvents(void) { void Player::ProcessEvents(void) {
x = _player->GetX(); x = _player->GetX();
y = _player->GetY(); y = _player->GetY();

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "../Sprite/Sprite.h" #include "../Sprite/Sprite.h"
#include "../Collision/AABB.h"
#include "../Global/Globals.h" #include "../Global/Globals.h"
#include "../System/Debug.h" #include "../System/Debug.h"
#include "../IO/Input.h" #include "../IO/Input.h"
@ -12,8 +13,21 @@ public:
Player(void); Player(void);
~Player(void); ~Player(void);
void Prepare(void); void Update(void);
void Render(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); void ProcessEvents(void);
private: private:
@ -22,4 +36,12 @@ private:
float PLAYER_SPEED; float PLAYER_SPEED;
Sprite* _player; Sprite* _player;
float _rotationAngle; float _rotationAngle;
// --- Collisions.
bool _allowCollision;
bool _notColliding;
bool _blueCollision;
AABB* _collisionBound;
AABB* _environmentCollisionBound;
}; };

View File

@ -32,7 +32,7 @@ bool Game::Init(void) {
glAlphaFunc(GL_GREATER, 0.1f); glAlphaFunc(GL_GREATER, 0.1f);
_level->Load("../Data/Map/Ugly.tmx"); _level->Load("../Data/Map/Ugly.tmx");
_player->Prepare(); _player->Update();
// Return success. // Return success.
return true; return true;
@ -64,7 +64,7 @@ void Game::Shutdown(void) {
} }
void Game::ProcessEvents(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) { void Game::OnResize(int width, int height) {