Sync commit
This commit is contained in:
parent
7b0560f6fd
commit
9d738f5707
14 changed files with 108 additions and 10 deletions
|
@ -46,7 +46,7 @@ set(SOURCES
|
|||
src/game/input/direction.cpp
|
||||
src/game/player/player.cpp
|
||||
src/game/player/player.hpp
|
||||
src/game/input/game_inputs.hpp)
|
||||
src/game/input/game_inputs.hpp src/game/world/world_view.cpp src/game/world/world_view.h src/utilities/smart_list.cpp src/utilities/smart_list.h)
|
||||
|
||||
set(PHYSICS_00_SOURCES
|
||||
src/prototypes/physics_00.cpp)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
// FPS
|
||||
#define FRAME_RATE 60
|
||||
#define FRAME_TIME sf::Time(sf::seconds(1.0f / FRAME_RATE))
|
||||
#define FRAME_TIME 1.0f / FRAME_RATE
|
||||
|
||||
// Window settings
|
||||
#define ANTIALIASINGLEVEL 8
|
||||
|
|
|
@ -32,7 +32,7 @@ void GridDebugLayer::draw(sf::RenderWindow *window) const
|
|||
}
|
||||
}
|
||||
|
||||
void GridDebugLayer::update() const
|
||||
void GridDebugLayer::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
~GridDebugLayer();
|
||||
|
||||
void draw(sf::RenderWindow *window) const override;
|
||||
void update() const override;
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
std::vector<GameObject*> marker;
|
||||
|
|
|
@ -12,7 +12,7 @@ public:
|
|||
GameObject();
|
||||
|
||||
virtual void draw(sf::RenderWindow *window) const = 0;
|
||||
virtual void update() const = 0;
|
||||
virtual void update() = 0;
|
||||
|
||||
TranslatedCoordinates coordinates;
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@ void InputMapper::processEvents()
|
|||
handleKeyPress(event.key);
|
||||
break;
|
||||
case sf::Event::KeyReleased:
|
||||
handleKeyRelease(event.key);
|
||||
break;
|
||||
case sf::Event::Closed:
|
||||
game->exit();
|
||||
|
@ -40,10 +41,34 @@ void InputMapper::handleKeyPress(sf::Event::KeyEvent event)
|
|||
return;
|
||||
}
|
||||
|
||||
// Move view
|
||||
// Handle direction
|
||||
auto direction = Direction::getDirection(event.code);
|
||||
if (direction != InputDirection::NONE)
|
||||
{
|
||||
game->actionController->moveView(direction);
|
||||
inputDirectionBuffer.push_back(direction);
|
||||
}
|
||||
}
|
||||
|
||||
InputDirection InputMapper::getInputDirection()
|
||||
{
|
||||
InputDirection direction = InputDirection::NONE;
|
||||
|
||||
for (InputDirection directionPart: inputDirectionBuffer)
|
||||
{
|
||||
direction = static_cast<InputDirection>(direction | directionPart);
|
||||
}
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
void InputMapper::handleKeyRelease(sf::Event::KeyEvent event)
|
||||
{
|
||||
// Handle direction
|
||||
auto direction = Direction::getDirection(event.code);
|
||||
if (direction != InputDirection::NONE)
|
||||
{
|
||||
// Remove direction from buffer
|
||||
inputDirectionBuffer.erase(std::remove(inputDirectionBuffer.begin(), inputDirectionBuffer.end(), direction),
|
||||
inputDirectionBuffer.end());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "../game.h"
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include "../../config.h"
|
||||
#include "direction.h"
|
||||
|
||||
class Game;
|
||||
|
||||
|
@ -17,10 +18,16 @@ public:
|
|||
|
||||
static void processEvents();
|
||||
|
||||
static InputDirection getInputDirection();
|
||||
|
||||
private:
|
||||
static inline Game *game = nullptr;
|
||||
|
||||
static inline std::vector<InputDirection> inputDirectionBuffer = std::vector<InputDirection>();
|
||||
|
||||
static void handleKeyPress(sf::Event::KeyEvent event);
|
||||
|
||||
static void handleKeyRelease(sf::Event::KeyEvent event);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ public:
|
|||
|
||||
void draw(sf::RenderWindow *window) const override;
|
||||
|
||||
void update() const override;
|
||||
void update() override;
|
||||
};
|
||||
|
||||
|
||||
|
|
29
src/game/world/world_view.cpp
Normal file
29
src/game/world/world_view.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "world_view.h"
|
||||
|
||||
WorldView::WorldView(Game *game)
|
||||
{
|
||||
this->game = game;
|
||||
view = game->window->getView();
|
||||
}
|
||||
|
||||
WorldView::~WorldView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void WorldView::draw(sf::RenderWindow *window) const
|
||||
{
|
||||
}
|
||||
|
||||
void WorldView::update()
|
||||
{
|
||||
auto moveDirection = InputMapper::getInputDirection();
|
||||
|
||||
if (moveDirection != InputDirection::NONE)
|
||||
{
|
||||
float stepSize = 100.0f * FRAME_TIME;
|
||||
auto delta = stepSize * Direction::getVector(moveDirection);
|
||||
this->view.move(delta);
|
||||
game->window->setView(this->view);
|
||||
}
|
||||
}
|
25
src/game/world/world_view.h
Normal file
25
src/game/world/world_view.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef HOLESOME_WORLD_VIEW_H
|
||||
#define HOLESOME_WORLD_VIEW_H
|
||||
|
||||
|
||||
#include "../game_object.h"
|
||||
#include "../game.h"
|
||||
|
||||
class WorldView : GameObject
|
||||
{
|
||||
public:
|
||||
explicit WorldView(Game *game);
|
||||
|
||||
~WorldView();
|
||||
|
||||
void draw(sf::RenderWindow *window) const override;
|
||||
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
sf::View view;
|
||||
Game *game;
|
||||
};
|
||||
|
||||
|
||||
#endif //HOLESOME_WORLD_VIEW_H
|
|
@ -15,7 +15,7 @@ void CircleObject::draw(sf::RenderWindow *window) const
|
|||
window->draw(circle);
|
||||
}
|
||||
|
||||
void CircleObject::update() const
|
||||
void CircleObject::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ public:
|
|||
CircleObject(int radius, sf::Color color);
|
||||
|
||||
void draw(sf::RenderWindow *window) const override;
|
||||
void update() const override;
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
int radius;
|
||||
|
|
1
src/utilities/smart_list.cpp
Normal file
1
src/utilities/smart_list.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "smart_list.h"
|
11
src/utilities/smart_list.h
Normal file
11
src/utilities/smart_list.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef HOLESOME_SMART_LIST_H
|
||||
#define HOLESOME_SMART_LIST_H
|
||||
|
||||
// TODO
|
||||
//class SmartList<T>
|
||||
//{
|
||||
//
|
||||
//};
|
||||
|
||||
|
||||
#endif //HOLESOME_SMART_LIST_H
|
Loading…
Reference in a new issue