Game.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "Game.h"
  2. #include "rendering/Renderer.h"
  3. #include "rendering/wrapper/GLFW.h"
  4. #include "utils/String.h"
  5. float x = 0.0f;
  6. float y = 0.0f;
  7. float lastX = 0.0f;
  8. float lastY = 0.0f;
  9. float playerWidth = 80.0f;
  10. float playerHeight = 80.0f;
  11. float width = 800.0f;
  12. float height = 480.0f;
  13. float motionY = 0.0f;
  14. bool onGround = false;
  15. Game::Game(const Controller& c, const Clock& fps, const Clock& tps) : controller(c), fps(fps), tps(tps) {
  16. }
  17. void Game::tick() {
  18. /*lastX = x;
  19. lastY = y;
  20. if(controller.isDown(Button::LEFT)) {
  21. x -= 7;
  22. }
  23. if(controller.isDown(Button::RIGHT)) {
  24. x += 7;
  25. }
  26. if(controller.isDown(Button::A) && onGround) {
  27. motionY = -15.0f;
  28. onGround = false;
  29. }
  30. motionY += 0.5f;
  31. y += motionY;
  32. if(y > height - playerHeight) {
  33. y = height - playerHeight;
  34. motionY = 0.0f;
  35. onGround = true;
  36. }
  37. while(x > width) {
  38. x -= width + playerWidth;
  39. lastX -= width + playerWidth;
  40. }
  41. while(x < -playerWidth) {
  42. x += width + playerWidth;
  43. lastX += width + playerWidth;
  44. }*/
  45. }
  46. void Game::render(float lag, Renderer& renderer) const {
  47. renderer.translateTo(0.0f, 0.0f).update();
  48. renderer.drawRectangle(lastX + (x - lastX) * lag, lastY + (y - lastY) * lag, playerWidth, playerHeight, 0xFF0000FF);
  49. renderer.translateTo(0.0f, 0.0f).scale(4).update();
  50. String s("&900A");
  51. s.append(": ").append(controller.getDownTime(0)).append(" ");
  52. renderer.drawString(0, 10, s);
  53. }
  54. bool Game::isRunning() const {
  55. return true;//!controller.isDown(Button::SELECT);
  56. }