Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <cstddef>
#include <cstdint>

template <typename T, uint16_t N>
constexpr uint16_t arraySize(const T (&)[N]) { return N; }
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <cstdint>

namespace Engine
namespace SystemCore
{
struct SystemConfig
struct Configuration
{
// REQUIRED: modify this address to match the mac address of your PS3 controller
static constexpr char macAddress[] = "00:1b:fb:8e:87:ac";
Expand Down
6 changes: 3 additions & 3 deletions include/core/context-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include "engine/layer.h"
#include "engine/state-manager.h"
#include "engine/system-config.h"
#include "core/configuration.h"
#include "player/controller.h"
#include "lights/led-strip.h"
#include "display/display.h"

namespace Core
namespace SystemCore
{
class ContextManager
{
Expand All @@ -19,7 +19,7 @@ namespace Core

Engine::Layer *application = nullptr;
Engine::StateManager stateManager;
Engine::SystemConfig config;
SystemCore::Configuration config;
Player::Controller controller;
Lights::LedStrip leds;
Display::OledDisplay display;
Expand Down
2 changes: 1 addition & 1 deletion include/display/display-images.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Display
{
struct ImageInitLogo
{
inline static const unsigned char rawValues[] PROGMEM = {
static constexpr unsigned char rawValues[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00,
Expand Down
8 changes: 4 additions & 4 deletions include/display/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

#include "display/display-images.h"

// forward declaration because of ContextManager/OledDisplay circular dependency
namespace Core
namespace SystemCore
{
// forward declaration because of ContextManager/OledDisplay circular dependency
class ContextManager;
}

Expand All @@ -23,7 +23,7 @@ namespace Display
class OledDisplay
{
public:
OledDisplay(Core::ContextManager *contextManager);
OledDisplay(SystemCore::ContextManager *contextManager);
void updateDisplay();

private:
Expand All @@ -32,7 +32,7 @@ namespace Display
static constexpr int DISPLAY_ADDRESS = 0x3c;
Adafruit_SSD1306 display;

Core::ContextManager *contextManager;
SystemCore::ContextManager *contextManager;
ImageInitLogo initLogo;

char selectedOption(uint8_t index, uint8_t selectedOptionIndex) { return index == selectedOptionIndex ? '>' : ' '; };
Expand Down
2 changes: 1 addition & 1 deletion include/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Engine
void standbyControllerConnection();

private:
Core::ContextManager contextManager;
SystemCore::ContextManager contextManager;
uint32_t lastRender = 0;
void initializeEngine();
void renderLedStrip();
Expand Down
24 changes: 12 additions & 12 deletions include/engine/state-manager.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "games/recall/recall-state.h"
#include "games/phase-evasion/phase-evasion-state.h"
#include "games/demo/demo-state.h"
#include "scenes/canvas/canvas-state.h"
#include "games/recall/state.h"
#include "games/phase-evasion/state.h"
#include "games/demo/state.h"
#include "scenes/canvas/state.h"

namespace Engine
{
Expand Down Expand Up @@ -76,11 +76,11 @@ namespace Engine
const char *printGameName(uint8_t index);
const char *printSceneName(uint8_t index);

Games::RecallGameState &getRecallGameState() { return recallGameState; }
Games::PhaseEvasionGameState &getPhaseEvasionGameState() { return phaseEvasionGameState; }
Games::DemoGameState &getDemoGameState() { return demoGameState; }
Games::Recall::GameState &getRecallGameState() { return recallGameState; }
Games::PhaseEvasion::GameState &getPhaseEvasionGameState() { return phaseEvasionGameState; }
Games::Demo::GameState &getDemoGameState() { return demoGameState; }

Scenes::CanvasSceneState &getCanvasSceneState() { return canvasSceneState; }
Scenes::Canvas::SceneState &getCanvasSceneState() { return canvasSceneState; }

private:
SystemState systemState = SystemState::MenuHome;
Expand All @@ -89,10 +89,10 @@ namespace Engine
GameSelection userGameChoice = GameSelection::Demo;
SceneSelection userSceneChoice = SceneSelection::Canvas;

Games::RecallGameState recallGameState;
Games::PhaseEvasionGameState phaseEvasionGameState;
Games::DemoGameState demoGameState;
Games::Recall::GameState recallGameState;
Games::PhaseEvasion::GameState phaseEvasionGameState;
Games::Demo::GameState demoGameState;

Scenes::CanvasSceneState canvasSceneState;
Scenes::Canvas::SceneState canvasSceneState;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include "core/context-manager.h"
#include "engine/layer.h"
#include "games/demo/demo-player.h"
#include "games/demo/player.h"

namespace Games
namespace Games::Demo
{
class DemoCore : public Engine::Layer
class Controller : public Engine::Layer
{
public:
DemoCore(Core::ContextManager *ctx) : Engine::Layer{}, contextManager{ctx}, player1{DemoPlayer{ctx}}, player2{DemoPlayer{ctx}}
Controller(SystemCore::ContextManager *ctx) : Engine::Layer{}, contextManager{ctx}, player1{Player{ctx}}, player2{Player{ctx}}
{
contextManager->stateManager.getDemoGameState().reset();
}
Expand All @@ -21,9 +21,9 @@ namespace Games
void incrementHighScore();

private:
Core::ContextManager *contextManager;
DemoPlayer player1;
DemoPlayer player2;
SystemCore::ContextManager *contextManager;
Player player1;
Player player2;
static constexpr float speed = 4.0f;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
#include "core/context-manager.h"
#include "player/player.h"

namespace Games
namespace Games::Demo
{
class DemoPlayer : public Player::Player
class Player : public ::Player::Player
{
public:
DemoPlayer(Core::ContextManager *ctx) : contextManager{ctx}, Player::Player{ctx} {};
Player(SystemCore::ContextManager *ctx) : contextManager{ctx}, ::Player::Player{ctx} {};
void updatePlayer1LedBuffer();
void updatePlayer2LedBuffer();

private:
Core::ContextManager *contextManager;
SystemCore::ContextManager *contextManager;
static constexpr uint16_t width = 7;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <cstdint>

namespace Games
namespace Games::Demo
{
class DemoGameState
class GameState
{
public:
DemoGameState() : highScore{0}, currentScore{0} {}
GameState() : highScore{0}, currentScore{0} {}
void reset() { highScore = currentScore = 0; }
uint16_t highScore;
uint16_t currentScore;
Expand Down
31 changes: 31 additions & 0 deletions include/games/phase-evasion/controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "engine/layer.h"
#include "engine/timer.h"
#include "core/context-manager.h"
#include "games/phase-evasion/player.h"
#include "games/phase-evasion/flare.h"
#include "games/phase-evasion/flare-manager.h"

namespace Games::PhaseEvasion
{
class Controller : public Engine::Layer, private Engine::Timer
{
public:
Controller(SystemCore::ContextManager *ctx);
void nextEvent() override;
static constexpr uint16_t playerClearance = 20;

private:
SystemCore::ContextManager *contextManager;
GameState &state = contextManager->stateManager.getPhaseEvasionGameState();
Player player;
FlareManager flareManager;

void getUpdates();
void renderUserColor();
void renderFlare();
void checkCollision();
void checkGrowth();
};
}
30 changes: 30 additions & 0 deletions include/games/phase-evasion/flare-manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "games/phase-evasion/flare.h"

namespace Games::PhaseEvasion
{
class FlareManager : public Engine::Timer
{
public:
FlareManager() = default;
FlareManager(const FlareManager &) = delete;
FlareManager &operator=(const FlareManager &) = delete;

Flare &operator[](uint16_t index) { return flarePool[index]; }
const Flare &operator[](uint16_t index) const { return flarePool[index]; }

auto begin() { return flarePool.begin(); }
auto end() { return flarePool.end(); }
const auto begin() const { return flarePool.begin(); }
const auto end() const { return flarePool.end(); }

const size_t size() const;

void updatePositions();
void dispatch();

private:
std::array<Flare, 10> flarePool;
};
}
36 changes: 36 additions & 0 deletions include/games/phase-evasion/flare.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include "esp_system.h"

#include "common.h"

#include "engine/timer.h"
#include "core/configuration.h"
#include "lights/color.h"

namespace Games::PhaseEvasion
{
class Flare : public Engine::Timer
{
public:
Flare() : active{false},
color{Lights::Color::WhiteSmoke},
speed{0.0f},
positionFloat{SystemCore::Configuration::numLeds + width} {};

static constexpr uint16_t width = 10;
void updatePosition();
uint16_t getPosition() const { return static_cast<uint16_t>(positionFloat); }

const Lights::Color getColor() const { return color; }
bool isActive() const { return active; }
void activate(Lights::Color color, float speed);
void deactivate();

private:
bool active;
Lights::Color color;
float speed;
float positionFloat;
};
}
20 changes: 0 additions & 20 deletions include/games/phase-evasion/phase-evasion-core.h

This file was deleted.

18 changes: 0 additions & 18 deletions include/games/phase-evasion/phase-evasion-flare.h

This file was deleted.

17 changes: 0 additions & 17 deletions include/games/phase-evasion/phase-evasion-player.h

This file was deleted.

15 changes: 0 additions & 15 deletions include/games/phase-evasion/phase-evasion-state.h

This file was deleted.

Loading