|
@@ -3,22 +3,65 @@
|
|
#include "rendering/wrapper/GLFWWrapper.h"
|
|
#include "rendering/wrapper/GLFWWrapper.h"
|
|
#include "utils/String.h"
|
|
#include "utils/String.h"
|
|
|
|
|
|
|
|
+float x = 0.0f;
|
|
|
|
+float y = 0.0f;
|
|
|
|
+float lastX = 0.0f;
|
|
|
|
+float lastY = 0.0f;
|
|
|
|
+float playerWidth = 80.0f;
|
|
|
|
+float playerHeight = 80.0f;
|
|
|
|
+
|
|
|
|
+float width = 800.0f;
|
|
|
|
+float height = 480.0f;
|
|
|
|
+
|
|
|
|
+float motionY = 0.0f;
|
|
|
|
+bool onGround = false;
|
|
|
|
+
|
|
Game::Game(const Controller& c, const Clock& fps, const Clock& tps) : controller(c), fps(fps), tps(tps) {
|
|
Game::Game(const Controller& c, const Clock& fps, const Clock& tps) : controller(c), fps(fps), tps(tps) {
|
|
}
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
void Game::tick() {
|
|
|
|
+ lastX = x;
|
|
|
|
+ lastY = y;
|
|
|
|
+ if(controller.isDown(Button::LEFT)) {
|
|
|
|
+ x -= 7;
|
|
|
|
+ }
|
|
|
|
+ if(controller.isDown(Button::RIGHT)) {
|
|
|
|
+ x += 7;
|
|
|
|
+ }
|
|
|
|
+ if(controller.isDown(Button::A) && onGround) {
|
|
|
|
+ motionY = -15.0f;
|
|
|
|
+ onGround = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ motionY += 0.5f;
|
|
|
|
+ y += motionY;
|
|
|
|
+
|
|
|
|
+ if(y > height - playerHeight) {
|
|
|
|
+ y = height - playerHeight;
|
|
|
|
+ motionY = 0.0f;
|
|
|
|
+ onGround = true;
|
|
|
|
+ }
|
|
|
|
+ while(x > width) {
|
|
|
|
+ x -= width + playerWidth;
|
|
|
|
+ lastX -= width + playerWidth;
|
|
|
|
+ }
|
|
|
|
+ while(x < -playerWidth) {
|
|
|
|
+ x += width + playerWidth;
|
|
|
|
+ lastX += width + playerWidth;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void Game::render(float lag, Renderer& renderer) const {
|
|
void Game::render(float lag, Renderer& renderer) const {
|
|
- (void) lag;
|
|
|
|
- renderer.translateTo(0.0f, 0.0f).scale(4.0f).update();
|
|
|
|
|
|
+ renderer.translateTo(0.0f, 0.0f).scale(4).update();
|
|
for(uint i = 0; i < controller.getButtonAmount(); i++) {
|
|
for(uint i = 0; i < controller.getButtonAmount(); i++) {
|
|
String s(controller.getName(i));
|
|
String s(controller.getName(i));
|
|
- s.append(": ").append(controller.wasReleased(i)).append(" ").append(controller.getDownTime(i)).append("öüäÖÜÄÖß");
|
|
|
|
|
|
+ s.append(": ").append(controller.wasReleased(i)).append(" ").append(controller.getDownTime(i));
|
|
renderer.drawString(0, 10 * i, s);
|
|
renderer.drawString(0, 10 * i, s);
|
|
}
|
|
}
|
|
|
|
+ renderer.translateTo(0.0f, 0.0f).update();
|
|
|
|
+ renderer.drawRectangle(lastX + (x - lastX) * lag, lastY + (y - lastY) * lag, playerWidth, playerHeight, 0x0000FFFF);
|
|
}
|
|
}
|
|
|
|
|
|
bool Game::isRunning() const {
|
|
bool Game::isRunning() const {
|
|
- return true;
|
|
|
|
|
|
+ return !controller.isDown(Button::SELECT);
|
|
}
|
|
}
|