daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <whycpp/application_listener.h>
  3. #include <whycpp/whycpp.h>
  4. #include <whycpp/drawing.h>
  5. #include <whycpp/time.h>
  6. #include <cmath>
  7. #include <vector>
  8. #include <whycpp/color.h>
  9. #include <whycpp/buttons.h>
  10. #include <whycpp/input.h>
  11. #include <whycpp/palette.h>
  12. #include <whycpp/lifecycle.h>
  13. #include <vector>
  14.  
  15. class GameObject {
  16. public:
  17.     virtual void Update(Context &ctx) = 0;
  18. };
  19.  
  20.  
  21. class Container {
  22. public:
  23.     std::vector<GameObject*> gameObjects;
  24.  
  25.     void Add(GameObject* go) {
  26.         gameObjects.push_back(go);
  27.     }
  28. };
  29.  
  30. class Bomb: public GameObject {
  31. public:
  32.     float x;
  33.     float y;
  34.     float width;
  35.     float height;
  36.     const RGBA color = PALETTE[16];
  37.  
  38.     Bomb(float x, float y, float width, float height, Container* container) : x(x), y(y), width(width), height(height)  {}
  39.  
  40.     void Update(Context &ctx) override {
  41.  
  42.     }
  43. };
  44.  
  45.  
  46. class Man: public GameObject {
  47. public:
  48.     float x;
  49.     float y;
  50.     float width;
  51.     float height;
  52.     float ms;
  53.     Container *container;
  54.  
  55.     const RGBA color = PALETTE[6];
  56.  
  57.     Man(float x, float y, float width, float height, float ms, Container *container) : x(x), y(y), width(width),
  58.                                                                                        height(height),
  59.                                                                                        ms(ms), container(container) {}
  60.  
  61.  
  62.  
  63.     void Update(Context &ctx) override {
  64.         ProcessInput(ctx);
  65.         Draw(ctx);
  66.     }
  67.  
  68.     void Draw(Context &ctx) {
  69.         DrawRectFill(ctx, x, y, width, height, color);
  70.     }
  71.  
  72.     void ProcessInput(Context &ctx) {
  73.         if (IsPressed(ctx, Button::KEY_W)) {
  74.             y-=ms;
  75.         }
  76.         if (IsPressed(ctx, Button::KEY_S)) {
  77.             y+=ms;
  78.         }
  79.         if (IsPressed(ctx, Button::KEY_D)) {
  80.             x+=1;
  81.         }
  82.         if (IsPressed(ctx, Button::KEY_A)) {
  83.             x-=1;
  84.         }
  85.         if (IsPressed(ctx, Button::KEY_SPACE)) {
  86.            container->Add(new Bomb(x,y,6,6,container));
  87.         }
  88.     }
  89.  
  90. };
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. class Bomberman : public ApplicationListener {
  107.     Container* container;
  108.  
  109. public :
  110.     void OnCreate(Context &ctx)override {
  111.         container = new Container();
  112.         container->Add(new Man(10, 10, 12, 12,1, container));
  113.     }
  114.     void OnRender(Context &ctx) override {
  115.         DrawClearScreen(ctx, PALETTE[6]);
  116.         DrawRectFill(ctx, 0, 0, 256, 144, PALETTE[1]);
  117.  
  118.         for (auto obj: container->gameObjects) {
  119.             obj->Update(ctx);
  120.         }
  121.     }
  122. };
  123.  
  124.  
  125.  
  126. int main(int argc, char *argv[]){
  127.     RunApp<Bomberman>(ApplicationConfig(256, 144, "Bomberman", false));
  128.     return 0;
  129. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top