Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #define OLC_PGE_APPLICATION
  2. #include"olcPixelGameEngine.h"
  3. #include <random>
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <time.h>
  8. struct coord
  9. {
  10.     int x;
  11.     int y;
  12. };
  13.  
  14.  
  15. class animation : public olc::PixelGameEngine
  16. {
  17. public:
  18.     animation()
  19.     {
  20.         sAppName = "animation";
  21.     }
  22.  
  23.     //initialise some variables
  24.     float speed = 500.0;
  25.     //setting number of raindrops
  26.     coord rainDropPositions[120];
  27.     // setting number of the depthbuffer
  28.     coord dB[1304]; //dB, short for depthBuffer
  29.     void CreateRain()
  30.     {
  31.         int i = rainDrops;
  32.         if (rainDrops < maxRainDrops)
  33.         {
  34.             rainDropPositions[i].x = rand() % ScreenWidth();// spawn with random position on screen
  35.             rainDropPositions[i].y = 1; // spawn at top of screen
  36.             rainDrops++; // change value of rainDops by + 1
  37.         }
  38.     }
  39.  
  40.     void UpdateRain(float fElapsedTime)
  41.     {
  42.         //for every rainDrops
  43.         for (int i = 0;i < rainDrops; i++)
  44.         {
  45.             // move the rain downwards
  46.             rainDropPositions[i].y += fElapsedTime * speed;
  47.  
  48.             // if the raindrops are in the depthBuffer, draw them, else, spawn them somewhere at the top of the screen
  49.             if (dB[rainDropPositions[i].y].y < rainDropPositions[i].y)
  50.             {
  51.                 DrawSprite(rainDropPositions[i].x, rainDropPositions[i].y, sprTexRain, 1);
  52.             }
  53.             else
  54.             {
  55.                 //set y to top of screen and draw it at random x
  56.                 rainDropPositions[i].y = 1;
  57.                 rainDropPositions[i].x = rand() % ScreenWidth();
  58.                 DrawSprite(rainDropPositions[i].x, rainDropPositions[i].y, sprTexRain, 1);
  59.             }
  60.         }
  61.     }
  62.  
  63.  
  64.  
  65. private:
  66.     // set up sprites
  67.     olc::Sprite* sprTexAll;
  68.     olc::Sprite* sprTexRain;
  69.    
  70.     // initialise variables
  71.     int maxRainDrops = 120;
  72.     int rainDrops = 1;
  73.  
  74.     dB[4].y = 4;
  75.  
  76. public:
  77.     bool OnUserCreate() override
  78.     {
  79.         srand(time(0));
  80.         sprTexRain = new olc::Sprite("weiss hintergrund regentropfen.jpeg");
  81.         sprTexAll = new olc::Sprite("haus und hintergrund sukeesh projektlernen.jpeg");
  82.         return true;
  83.     }
  84.  
  85.     bool OnUserUpdate(float fElapsedTime) override
  86.     {
  87.          //Draw Main house
  88.          DrawSprite(0, 0, sprTexAll, 1);
  89.          // too obvious what this does ...?
  90.          CreateRain();
  91.          // move the rain
  92.          UpdateRain(fElapsedTime);
  93.          return true;
  94.     }
  95. };
  96.  
  97.  
  98.  
  99. int main()
  100. {
  101.     animation demo;
  102.     if (demo.Construct(1303, 733, 1, 1))
  103.         demo.Start();
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement