|
|
@ -1,7 +1,8 @@ |
|
|
|
#include "player.h" |
|
|
|
#include "player.h" |
|
|
|
|
|
|
|
|
|
|
|
Player::Player(EntityManager* entityManager, Camera *camera, float x, float y) { |
|
|
|
Player::Player(EntityManager* entityManager, Map *map, Camera *camera, float x, float y) { |
|
|
|
this->entityManager = entityManager; |
|
|
|
this->entityManager = entityManager; |
|
|
|
|
|
|
|
this->map = map; |
|
|
|
this->camera = camera; |
|
|
|
this->camera = camera; |
|
|
|
|
|
|
|
|
|
|
|
this->Load("data/gfx/player.png"); |
|
|
|
this->Load("data/gfx/player.png"); |
|
|
@ -11,7 +12,7 @@ Player::Player(EntityManager* entityManager, Camera *camera, float x, float y) { |
|
|
|
|
|
|
|
|
|
|
|
void Player::Update(sf::RenderWindow* window, InputManager inputManager) { |
|
|
|
void Player::Update(sf::RenderWindow* window, InputManager inputManager) { |
|
|
|
// Store currect location of the player for the Camera to use
|
|
|
|
// Store currect location of the player for the Camera to use
|
|
|
|
sf::Vector2f cameraPosition = sf::Vector2f(this->getPosition().x, this->getPosition().y); |
|
|
|
sf::Vector2f playerPosition = sf::Vector2f(this->getPosition().x, this->getPosition().y);; |
|
|
|
|
|
|
|
|
|
|
|
// Update player velocity
|
|
|
|
// Update player velocity
|
|
|
|
this->velocity.x = inputManager.IsPressed(InputManager::Right) * this->speed - |
|
|
|
this->velocity.x = inputManager.IsPressed(InputManager::Right) * this->speed - |
|
|
@ -20,77 +21,79 @@ void Player::Update(sf::RenderWindow* window, InputManager inputManager) { |
|
|
|
inputManager.IsPressed(InputManager::Up) * this->speed; |
|
|
|
inputManager.IsPressed(InputManager::Up) * this->speed; |
|
|
|
|
|
|
|
|
|
|
|
// Update camera position
|
|
|
|
// Update camera position
|
|
|
|
// VERSION 1!
|
|
|
|
//|------------|--------------|------------|
|
|
|
|
// if(this->getPosition().x + 16 > window->getSize().x / 2) {
|
|
|
|
//| 1 | 2 | 1 |
|
|
|
|
// this->camera->MoveCamera(window, sf::Vector2f(this->velocity.x, 0));
|
|
|
|
//| | | |
|
|
|
|
// }
|
|
|
|
//|------------x--------------|------------|
|
|
|
|
// else {
|
|
|
|
//| 3 | 4 | 3 |
|
|
|
|
// camera->SetCenter(window, sf::Vector2f(window->getSize().x / 2, window->getSize().y / 2));
|
|
|
|
//| | | |
|
|
|
|
// }
|
|
|
|
//|------------|--------------y------------|
|
|
|
|
|
|
|
|
//| 1 | 2 | 1 |
|
|
|
|
|
|
|
|
//| | | |
|
|
|
|
|
|
|
|
//|------------|--------------|------------|
|
|
|
|
|
|
|
|
|
|
|
|
// if(this->getPosition().y + 16 > window->getSize().y / 2) {
|
|
|
|
// Get window center start and end
|
|
|
|
// this->camera->MoveCamera(window, sf::Vector2f(0, this->velocity.y));
|
|
|
|
// x on map scetch
|
|
|
|
// }
|
|
|
|
sf::Vector2f windowCenterStart = sf::Vector2f(window->getSize().x / 2, window->getSize().y / 2); |
|
|
|
// else {
|
|
|
|
// y on map scetch
|
|
|
|
// camera->SetCenter(window, sf::Vector2f(window->getSize().x / 2, window->getSize().y / 2));
|
|
|
|
sf::Vector2f windowCenterEnd = sf::Vector2f(map->width * map->tilewidth - windowCenterStart.x, |
|
|
|
// }
|
|
|
|
map->height * map->tileheight - windowCenterStart.y); |
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// VERSION 2!
|
|
|
|
// If Player is in the center (4)
|
|
|
|
// if(this->getPosition().x < window->getSize().x / 2
|
|
|
|
if(playerPosition.x > windowCenterStart.x |
|
|
|
// && this->getPosition().y < window->getSize().y / 2) {
|
|
|
|
&& playerPosition.y > windowCenterStart.y |
|
|
|
// camera->SetCenter(window, sf::Vector2f(window->getSize().x / 2, window->getSize().y / 2));
|
|
|
|
&& playerPosition.x < windowCenterEnd.x |
|
|
|
// }
|
|
|
|
&& playerPosition.y < windowCenterEnd.y) { |
|
|
|
|
|
|
|
camera->SetCenter(window, sf::Vector2f(playerPosition.x, playerPosition.y)); |
|
|
|
// if(this->getPosition().x> window->getSize().x / 2
|
|
|
|
|
|
|
|
// && this->getPosition().y> window->getSize().y / 2) {
|
|
|
|
|
|
|
|
// //this->camera->MoveCamera(window, sf::Vector2f(this->velocity.x, this->velocity.y));
|
|
|
|
|
|
|
|
// camera->SetCenter(window, sf::Vector2f(this->getPosition().x, this->getPosition().y));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else if(this->getPosition().x> window->getSize().x / 2) {
|
|
|
|
|
|
|
|
// this->camera->MoveCamera(window, sf::Vector2f(this->velocity.x, 0));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else if(this->getPosition().y> window->getSize().y / 2) {
|
|
|
|
|
|
|
|
// this->camera->MoveCamera(window, sf::Vector2f(0, this->velocity.y));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// VERSION 3!
|
|
|
|
|
|
|
|
if(this->getPosition().x < window->getSize().x / 2 |
|
|
|
|
|
|
|
&& this->getPosition().y < window->getSize().y / 2) { |
|
|
|
|
|
|
|
camera->SetCenter(window, sf::Vector2f(window->getSize().x / 2, window->getSize().y / 2)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(this->getPosition().x> window->getSize().x / 2 |
|
|
|
// If Player is in the edge (2,3)
|
|
|
|
&& this->getPosition().y> window->getSize().y / 2) { |
|
|
|
// Middle Top
|
|
|
|
//this->camera->MoveCamera(window, sf::Vector2f(this->velocity.x, this->velocity.y));
|
|
|
|
else if(playerPosition.x > windowCenterStart.x |
|
|
|
camera->SetCenter(window, sf::Vector2f(this->getPosition().x, this->getPosition().y)); |
|
|
|
&& playerPosition.x < windowCenterEnd.x |
|
|
|
|
|
|
|
&& playerPosition.y < windowCenterStart.y) { |
|
|
|
|
|
|
|
camera->SetCenter(window, sf::Vector2f(playerPosition.x, windowCenterStart.y)); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
// Middle Bottom
|
|
|
|
if(this->getPosition().x> window->getSize().x / 2) { |
|
|
|
else if(playerPosition.x > windowCenterStart.x |
|
|
|
this->camera->MoveCamera(window, sf::Vector2f(this->velocity.x, 0)); |
|
|
|
&& playerPosition.x < windowCenterEnd.x |
|
|
|
} |
|
|
|
&& playerPosition.y > windowCenterEnd.y) { |
|
|
|
|
|
|
|
camera->SetCenter(window, sf::Vector2f(playerPosition.x, windowCenterEnd.y)); |
|
|
|
if(this->getPosition().y> window->getSize().y / 2) { |
|
|
|
} |
|
|
|
this->camera->MoveCamera(window, sf::Vector2f(0, this->velocity.y)); |
|
|
|
// Middle Left
|
|
|
|
} |
|
|
|
else if(playerPosition.y > windowCenterStart.y |
|
|
|
|
|
|
|
&& playerPosition.y < windowCenterEnd.y |
|
|
|
|
|
|
|
&& playerPosition.x < windowCenterStart.x) { |
|
|
|
|
|
|
|
camera->SetCenter(window, sf::Vector2f(windowCenterStart.x, playerPosition.y)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Middle Right
|
|
|
|
|
|
|
|
else if(playerPosition.y > windowCenterStart.y |
|
|
|
|
|
|
|
&& playerPosition.y < windowCenterEnd.y |
|
|
|
|
|
|
|
&& playerPosition.x > windowCenterEnd.x) { |
|
|
|
|
|
|
|
camera->SetCenter(window, sf::Vector2f(windowCenterEnd.x, playerPosition.y)); |
|
|
|
} |
|
|
|
} |
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// VERSION 4!
|
|
|
|
|
|
|
|
// @Todo
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sf::Vertex2f tempPlayerLoc;
|
|
|
|
// If Player is in one of the corners (1)
|
|
|
|
// if(playerLoc.x != edge X)
|
|
|
|
// Top Left
|
|
|
|
// {
|
|
|
|
else if(playerPosition.x < windowCenterStart.x |
|
|
|
// tempPlayerLoc.x = playerLoc.x
|
|
|
|
&& playerPosition.y < windowCenterStart.y) { |
|
|
|
// }
|
|
|
|
camera->SetCenter(window, sf::Vector2f(windowCenterStart.x, windowCenterStart.y)); |
|
|
|
// if(playerLoc.y != edge Y)
|
|
|
|
} |
|
|
|
// {
|
|
|
|
// Top Right
|
|
|
|
// tempPlayerLoc.y = playerLoc.y
|
|
|
|
else if(playerPosition.x > windowCenterEnd.x |
|
|
|
// }
|
|
|
|
&& playerPosition.y < windowCenterStart.y) { |
|
|
|
// view->setCenter(playerLoc)
|
|
|
|
camera->SetCenter(window, sf::Vector2f(windowCenterEnd.x, windowCenterStart.y)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Bottom Left
|
|
|
|
|
|
|
|
else if(playerPosition.x < windowCenterStart.x |
|
|
|
|
|
|
|
&& playerPosition.y > windowCenterEnd.y) { |
|
|
|
|
|
|
|
camera->SetCenter(window, sf::Vector2f(windowCenterStart.x, windowCenterEnd.y)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Bottom Right
|
|
|
|
|
|
|
|
else if(playerPosition.x > windowCenterEnd.x |
|
|
|
|
|
|
|
&& playerPosition.y > windowCenterEnd.y) { |
|
|
|
|
|
|
|
camera->SetCenter(window, sf::Vector2f(windowCenterEnd.x, windowCenterEnd.y)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Player::~Player() |
|
|
|
Player::~Player() |
|
|
|