Merge branch 'master' of github.com:Allanis/LibD
This commit is contained in:
commit
abd57fcf78
@ -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,27 @@ void Player::Render(void) {
|
|||||||
_player->Draw();
|
_player->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::ProcessCollisions(void) {
|
||||||
|
// Process collisions with entities and actors.
|
||||||
|
// We should ensure we are not dead.
|
||||||
|
EntityCollisionTest();
|
||||||
|
ActorCollisionTest();
|
||||||
|
|
||||||
|
// Set all collision flags to false conditions
|
||||||
|
// then they will need to be proven in the test.
|
||||||
|
_notColliding = true;
|
||||||
|
_blueCollision = false;
|
||||||
|
bool onFloor = false;
|
||||||
|
|
||||||
|
// This is going to get messy, and I am going to have to play
|
||||||
|
// in KonoM's level stuff.
|
||||||
|
|
||||||
|
// We need a level manager class that will create a list of collidable
|
||||||
|
// entites/actors.
|
||||||
|
|
||||||
|
// I'll do this tomorrow now.
|
||||||
|
}
|
||||||
|
|
||||||
void Player::ProcessEvents(void) {
|
void Player::ProcessEvents(void) {
|
||||||
x = _player->GetX();
|
x = _player->GetX();
|
||||||
y = _player->GetY();
|
y = _player->GetY();
|
||||||
|
@ -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);
|
||||||
|
|
||||||
int GetX() { return x; }
|
int GetX() { return x; }
|
||||||
@ -27,4 +41,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;
|
||||||
};
|
};
|
||||||
|
@ -35,7 +35,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;
|
||||||
@ -85,7 +85,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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user