Sync commit

This commit is contained in:
Maximilian Giller 2023-05-09 20:50:50 +02:00
parent 7b0560f6fd
commit 9d738f5707
14 changed files with 108 additions and 10 deletions

View file

@ -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)

View file

@ -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

View file

@ -32,7 +32,7 @@ void GridDebugLayer::draw(sf::RenderWindow *window) const
}
}
void GridDebugLayer::update() const
void GridDebugLayer::update()
{
}

View file

@ -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;

View file

@ -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;
};

View file

@ -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());
}
}

View file

@ -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);
};

View file

@ -12,7 +12,7 @@ public:
void draw(sf::RenderWindow *window) const override;
void update() const override;
void update() override;
};

View 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);
}
}

View 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

View file

@ -15,7 +15,7 @@ void CircleObject::draw(sf::RenderWindow *window) const
window->draw(circle);
}
void CircleObject::update() const
void CircleObject::update()
{
}

View file

@ -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;

View file

@ -0,0 +1 @@
#include "smart_list.h"

View file

@ -0,0 +1,11 @@
#ifndef HOLESOME_SMART_LIST_H
#define HOLESOME_SMART_LIST_H
// TODO
//class SmartList<T>
//{
//
//};
#endif //HOLESOME_SMART_LIST_H