Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <iostream>
  3. #include <whycpp/application_listener.h>
  4. #include <whycpp/whycpp.h>
  5. #include <whycpp/drawing.h>
  6. #include <whycpp/time.h>
  7. #include <cmath>
  8. #include <vector>
  9. #include <whycpp/color.h>
  10. #include <whycpp/buttons.h>
  11. #include <whycpp/input.h>
  12. #include <whycpp/palette.h>
  13. #include <whycpp/lifecycle.h>
  14. #include "../cmake-build-debug/whycpp-src/include/whycpp/buttons.h"
  15.  
  16. class Enemy {
  17. public:
  18. double Ex = 50;
  19. int Ey = 25;
  20. int Esp = 0; //enemy speed
  21. int height = 15;
  22. int width = 15;
  23. int check = 1;
  24.  
  25.  
  26. Enemy(double Ex_, int Ey_, int Esp_) : Ex(Ex_), Ey(Ey_), Esp(Esp_) {}
  27.  
  28. void Update(Context &ctx) {
  29. DrawRectFill(ctx, Ex, static_cast<int>(Ey), height, width, PALETTE[3]);
  30. DrawRectFill(ctx, Ex+25, static_cast<int>(Ey), height, width, PALETTE[3]);
  31. DrawRectFill(ctx, Ex+50, static_cast<int>(Ey), height, width, PALETTE[3]);
  32. DrawRectFill(ctx, Ex+75, static_cast<int>(Ey), height, width, PALETTE[3]);
  33. DrawRectFill(ctx, Ex+100, static_cast<int>(Ey), height, width, PALETTE[3]);
  34. DrawRectFill(ctx, Ex+125, static_cast<int>(Ey), height, width, PALETTE[3]);
  35. DrawRectFill(ctx, Ex-25, static_cast<int>(Ey), height, width, PALETTE[3]);
  36. DrawRectFill(ctx, Ex+150, static_cast<int>(Ey), height, width, PALETTE[3]);
  37. // if (IsPressed(ctx, Button::KEY_SPACE)){
  38. // check+=1;
  39. // }
  40. // if (Ex <= 236) {
  41. // if ((check % 2 == 0) && (check <= 100)) {
  42. // Ex += 1;
  43. // check+=1;
  44. // }
  45. // }
  46. // else if(Ex>= 10){
  47. // if (check % 2 == 0) {
  48. // Ex -= 1;
  49. // }
  50. // }
  51.  
  52. }
  53. };
  54.  
  55. class Player {
  56. public:
  57. double x = 100;
  58. int y = 125;
  59. int sp = 100;
  60. int height = 15;
  61. int width = 15;
  62.  
  63. Player(double x, int y, int sp) : x(x), y(y), sp(sp) {}
  64.  
  65. void Update(Context &ctx) {
  66. DrawRectFill(ctx, static_cast<int>(x), y, height, width, PALETTE[2]);
  67. if (IsPressed(ctx, Button::KEY_LEFT)) {
  68. if (x >= 10) {
  69. x -= sp * GetDelta(ctx);
  70. }
  71. }
  72. if (IsPressed(ctx, Button::KEY_RIGHT)) {
  73. if (x <= 236)
  74. x += sp * GetDelta(ctx);
  75. }
  76. if (IsPressed(ctx, Button::KEY_ESCAPE)) {
  77. ExitApp(ctx);
  78. }
  79. }
  80. };
  81.  
  82. class Game : public ApplicationListener {
  83. public:
  84. Player *player = nullptr;
  85. Enemy *enemy = nullptr;
  86.  
  87. void OnCreate(Context &context) override {
  88. enemy = new Enemy(50, 25, 10);
  89. player = new Player(115, 125, 100);
  90. }
  91.  
  92. void OnRender(Context &ctx) override {
  93. DrawClearScreen(ctx, PALETTE[1]);
  94. player->Update(ctx);
  95. enemy->Update(ctx);
  96. }
  97. };
  98.  
  99. int main(int argc, char *argv[]) {
  100. RunApp<Game>();
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement