Merge branch 'master' of github.com:Allanis/LibD
This commit is contained in:
commit
abd57fcf78
@ -1,18 +1,38 @@
|
||||
#include "Player.h"
|
||||
|
||||
Player::Player(void) {
|
||||
PLAYER_SPEED = 15;
|
||||
_rotationAngle = 0.0f;
|
||||
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,27 @@ void Player::Render(void) {
|
||||
_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) {
|
||||
x = _player->GetX();
|
||||
y = _player->GetY();
|
||||
@ -42,4 +83,4 @@ void Player::ProcessEvents(void) {
|
||||
}
|
||||
|
||||
int Player::GetWidth() { return _player->GetWidth(); }
|
||||
int Player::GetHeight() { return _player->GetWidth(); }
|
||||
int Player::GetHeight() { return _player->GetWidth(); }
|
||||
|
@ -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);
|
||||
|
||||
int GetX() { return x; }
|
||||
@ -27,4 +41,12 @@ private:
|
||||
float PLAYER_SPEED;
|
||||
Sprite* _player;
|
||||
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);
|
||||
|
||||
_level->Load("../Data/Map/Ugly.tmx");
|
||||
_player->Prepare();
|
||||
_player->Update();
|
||||
|
||||
// Return success.
|
||||
return true;
|
||||
@ -85,7 +85,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