|
@@ -1,8 +1,7 @@
|
|
|
#include "Game.h"
|
|
|
#include "Engine.h"
|
|
|
+#include "data/List.h"
|
|
|
#include "input/Controller.h"
|
|
|
-#include "utils/List.h"
|
|
|
-#include "utils/Utils.h"
|
|
|
|
|
|
struct Line final {
|
|
|
Vector2 a;
|
|
@@ -57,8 +56,10 @@ static void addForce(const Vector2& force) {
|
|
|
}
|
|
|
|
|
|
static void addMovement() {
|
|
|
- physicsToggle = physicsToggle ^ Controller::start.wasReleased();
|
|
|
- float movement = Controller::right.isDown() - Controller::left.isDown();
|
|
|
+ physicsToggle =
|
|
|
+ physicsToggle ^ Window::Controls::wasReleased(Controller::start);
|
|
|
+ float movement = Window::Controls::isDown(Controller::right) -
|
|
|
+ Window::Controls::isDown(Controller::left);
|
|
|
float actualSpeed = SPEED * (1.0f - std::abs(steepness) * onGround);
|
|
|
if(physicsToggle) {
|
|
|
addForce(Vector2(actualSpeed, 0.0f) * movement);
|
|
@@ -186,14 +187,15 @@ static void applyGravity() {
|
|
|
|
|
|
static void handleJump() {
|
|
|
bool justJumped = false;
|
|
|
- if(Controller::a.isDown() && onGround) {
|
|
|
+ if(Window::Controls::isDown(Controller::a) && onGround) {
|
|
|
jumpPower = 15.0f;
|
|
|
onGround = false;
|
|
|
justJumped = true;
|
|
|
}
|
|
|
addForce(Vector2(0.0f, jumpPower));
|
|
|
jumpPower *= 0.9f;
|
|
|
- jumpPower *= Controller::a.isDown() && (velocity[1] > 0.0f || justJumped);
|
|
|
+ jumpPower *= Window::Controls::isDown(Controller::a) &&
|
|
|
+ (velocity[1] > 0.0f || justJumped);
|
|
|
}
|
|
|
|
|
|
static void relaunchProjectile() {
|
|
@@ -261,57 +263,40 @@ static void applyFriction() {
|
|
|
|
|
|
static void addLines() {
|
|
|
lines.clear();
|
|
|
- lines.add({{0.0f, 0.0f}, windowSize * Vector2(1.0f, 0.0f)});
|
|
|
- lines.add({{0.0f, 0.0f}, windowSize * Vector2(0.0f, 1.0f)});
|
|
|
- lines.add({windowSize, windowSize * Vector2(1.0f, 0.0f)});
|
|
|
- lines.add(
|
|
|
- {windowSize * Vector2(0.75f, 0.0f), windowSize * Vector2(1.0f, 0.5f)});
|
|
|
- lines.add({{0.0f, 30.0f}, {400.0f, 0.0f}});
|
|
|
- lines.add({{0.0f, 60.0f}, {300.0f, 0.0f}});
|
|
|
- lines.add({{0.0f, 90.0f}, {200.0f, 0.0f}});
|
|
|
- lines.add({{0.0f, 120.0f}, {100.0f, 0.0f}});
|
|
|
- lines.add({{100.0f, 180.0f}, {200.0f, 180.0f}});
|
|
|
-
|
|
|
- lines.add({{200.0f, 180.0f},
|
|
|
- {300.0f, 230.0f},
|
|
|
- Color4(0xF0, 0x00, 0x00, 0xFF),
|
|
|
- 0.2f});
|
|
|
- lines.add({{300.0f, 230.0f},
|
|
|
- {400.0f, 280.0f},
|
|
|
- Color4(0xC0, 0x00, 0x00, 0xFF),
|
|
|
- 0.4f});
|
|
|
- lines.add({{400.0f, 280.0f},
|
|
|
- {500.0f, 330.0f},
|
|
|
- Color4(0x90, 0x00, 0x00, 0xFF),
|
|
|
- 0.6f});
|
|
|
- lines.add({{500.0f, 330.0f},
|
|
|
- {600.0f, 380.0f},
|
|
|
- Color4(0x60, 0x00, 0x00, 0xFF),
|
|
|
- 0.8f});
|
|
|
-
|
|
|
- lines.add({{300.0f, 140.0f},
|
|
|
- {400.0f, 200.0f},
|
|
|
- Color4(0xF0, 0x00, 0x00, 0xFF),
|
|
|
- 0.2f});
|
|
|
- lines.add({{400.0f, 200.0f},
|
|
|
- {500.0f, 220.0f},
|
|
|
- Color4(0xC0, 0x00, 0x00, 0xFF),
|
|
|
- 0.4f});
|
|
|
- lines.add({{500.0f, 220.0f},
|
|
|
- {600.0f, 240.0f},
|
|
|
- Color4(0x90, 0x00, 0x00, 0xFF),
|
|
|
- 0.6f});
|
|
|
- lines.add({{600.0f, 240.0f},
|
|
|
- {700.0f, 260.0f},
|
|
|
- Color4(0x60, 0x00, 0x00, 0xFF),
|
|
|
- 0.8f});
|
|
|
-
|
|
|
- lines.add({{600.0f, 380.0f}, {1000.0f, 580.0f}});
|
|
|
+ lines.add(Line({0.0f, 0.0f}, windowSize * Vector2(1.0f, 0.0f)));
|
|
|
+ lines.add(Line({0.0f, 0.0f}, windowSize * Vector2(0.0f, 1.0f)));
|
|
|
+ lines.add(Line(windowSize, windowSize * Vector2(1.0f, 0.0f)));
|
|
|
+ lines.add(windowSize * Vector2(0.75f, 0.0f),
|
|
|
+ windowSize * Vector2(1.0f, 0.5f));
|
|
|
+ lines.add(Line({0.0f, 30.0f}, {400.0f, 0.0f}));
|
|
|
+ lines.add(Line({0.0f, 60.0f}, {300.0f, 0.0f}));
|
|
|
+ lines.add(Line({0.0f, 90.0f}, {200.0f, 0.0f}));
|
|
|
+ lines.add(Line({0.0f, 120.0f}, {100.0f, 0.0f}));
|
|
|
+ lines.add(Line({100.0f, 180.0f}, {200.0f, 180.0f}));
|
|
|
+
|
|
|
+ lines.add(Line({200.0f, 180.0f}, {300.0f, 230.0f},
|
|
|
+ Color4(0xF0, 0x00, 0x00, 0xFF), 0.2f));
|
|
|
+ lines.add(Line({300.0f, 230.0f}, {400.0f, 280.0f},
|
|
|
+ Color4(0xC0, 0x00, 0x00, 0xFF), 0.4f));
|
|
|
+ lines.add(Line({400.0f, 280.0f}, {500.0f, 330.0f},
|
|
|
+ Color4(0x90, 0x00, 0x00, 0xFF), 0.6f));
|
|
|
+ lines.add(Line({500.0f, 330.0f}, {600.0f, 380.0f},
|
|
|
+ Color4(0x60, 0x00, 0x00, 0xFF), 0.8f));
|
|
|
+
|
|
|
+ lines.add(Line({300.0f, 140.0f}, {400.0f, 200.0f},
|
|
|
+ Color4(0xF0, 0x00, 0x00, 0xFF), 0.2f));
|
|
|
+ lines.add(Line({400.0f, 200.0f}, {500.0f, 220.0f},
|
|
|
+ Color4(0xC0, 0x00, 0x00, 0xFF), 0.4f));
|
|
|
+ lines.add(Line({500.0f, 220.0f}, {600.0f, 240.0f},
|
|
|
+ Color4(0x90, 0x00, 0x00, 0xFF), 0.6f));
|
|
|
+ lines.add(Line({600.0f, 240.0f}, {700.0f, 260.0f},
|
|
|
+ Color4(0x60, 0x00, 0x00, 0xFF), 0.8f));
|
|
|
+
|
|
|
+ lines.add(Line({600.0f, 380.0f}, {1000.0f, 580.0f}));
|
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
|
- windowSize = Vector2(static_cast<float>(Engine::getSize().width),
|
|
|
- static_cast<float>(Engine::getSize().height));
|
|
|
+ windowSize = Engine::getSize().toFloat();
|
|
|
lastPosition = position;
|
|
|
acceleration = Vector2();
|
|
|
|
|
@@ -387,11 +372,11 @@ void Game::tick() {
|
|
|
void Game::render(float lag, Renderer& r) {
|
|
|
r.translateTo(0.0f, 0.0f)
|
|
|
.scale(1.0f, -1.0f)
|
|
|
- .translateY(Engine::getSize().height)
|
|
|
+ .translateY(Engine::getSize()[1])
|
|
|
.update();
|
|
|
r.drawRectangle(waterPosition, waterSize, Color4(0x00, 0x00, 0xFF, 0xFF));
|
|
|
|
|
|
- Vector2 pos = Utils::interpolate(lastPosition, position, lag);
|
|
|
+ Vector2 pos = Math::interpolate(lastPosition, position, lag);
|
|
|
|
|
|
r.push();
|
|
|
r.translateTo(0.0f, 0.0f)
|
|
@@ -400,7 +385,7 @@ void Game::render(float lag, Renderer& r) {
|
|
|
.translate(pos)
|
|
|
.translate(size * 0.5f)
|
|
|
.scale(1.0f, -1.0f)
|
|
|
- .translateY(Engine::getSize().height)
|
|
|
+ .translateY(Engine::getSize()[1])
|
|
|
.update();
|
|
|
r.drawRectangle(Vector2(), size, Color4(0xFF, 0x00, 0x00, 0xFF));
|
|
|
r.pop();
|
|
@@ -410,10 +395,10 @@ void Game::render(float lag, Renderer& r) {
|
|
|
r.push();
|
|
|
r.translateTo(0.0f, 0.0f)
|
|
|
.translate(size * 0.75f)
|
|
|
- .rotate(Utils::interpolate(lastAngle, angle, lag) + i)
|
|
|
+ .rotate(Math::interpolate(lastAngle, angle, lag) + i)
|
|
|
.translate(pos + size * 0.5f)
|
|
|
.scale(1.0f, -1.0f)
|
|
|
- .translateY(Engine::getSize().height)
|
|
|
+ .translateY(Engine::getSize()[1])
|
|
|
.update();
|
|
|
r.drawRectangle(Vector2(), size * 0.25f,
|
|
|
Color4(0xFF, 0x00, 0xFF, 0xFF));
|
|
@@ -422,7 +407,7 @@ void Game::render(float lag, Renderer& r) {
|
|
|
}
|
|
|
|
|
|
r.drawRectangle(
|
|
|
- Utils::interpolate(projectileLastPosition, projectilePosition, lag),
|
|
|
+ Math::interpolate(projectileLastPosition, projectilePosition, lag),
|
|
|
projectileSize, Color4(0xFF, 0xFF, 0x00, 0xFF));
|
|
|
|
|
|
for(const Line& line : lines) {
|
|
@@ -458,5 +443,5 @@ void Game::render(float lag, Renderer& r) {
|
|
|
}
|
|
|
|
|
|
bool Game::isRunning() {
|
|
|
- return !Controller::select.isDown();
|
|
|
+ return !Window::Controls::isDown(Controller::select);
|
|
|
}
|