Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define OLC_PGE_APPLICATION
- #include"olcPixelGameEngine.h"
- #include <random>
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- struct coord
- {
- int x;
- int y;
- };
- class animation : public olc::PixelGameEngine
- {
- public:
- animation()
- {
- sAppName = "animation";
- }
- //initialise some variables
- float speed = 500.0;
- //setting number of raindrops
- coord rainDropPositions[120];
- // setting number of the depthbuffer
- coord dB[1304]; //dB, short for depthBuffer
- void CreateRain()
- {
- int i = rainDrops;
- if (rainDrops < maxRainDrops)
- {
- rainDropPositions[i].x = rand() % ScreenWidth();// spawn with random position on screen
- rainDropPositions[i].y = 1; // spawn at top of screen
- rainDrops++; // change value of rainDops by + 1
- }
- }
- void UpdateRain(float fElapsedTime)
- {
- //for every rainDrops
- for (int i = 0;i < rainDrops; i++)
- {
- // move the rain downwards
- rainDropPositions[i].y += fElapsedTime * speed;
- // if the raindrops are in the depthBuffer, draw them, else, spawn them somewhere at the top of the screen
- if (dB[rainDropPositions[i].y].y < rainDropPositions[i].y)
- {
- DrawSprite(rainDropPositions[i].x, rainDropPositions[i].y, sprTexRain, 1);
- }
- else
- {
- //set y to top of screen and draw it at random x
- rainDropPositions[i].y = 1;
- rainDropPositions[i].x = rand() % ScreenWidth();
- DrawSprite(rainDropPositions[i].x, rainDropPositions[i].y, sprTexRain, 1);
- }
- }
- }
- private:
- // set up sprites
- olc::Sprite* sprTexAll;
- olc::Sprite* sprTexRain;
- // initialise variables
- int maxRainDrops = 120;
- int rainDrops = 1;
- dB[4].y = 4;
- public:
- bool OnUserCreate() override
- {
- srand(time(0));
- sprTexRain = new olc::Sprite("weiss hintergrund regentropfen.jpeg");
- sprTexAll = new olc::Sprite("haus und hintergrund sukeesh projektlernen.jpeg");
- return true;
- }
- bool OnUserUpdate(float fElapsedTime) override
- {
- //Draw Main house
- DrawSprite(0, 0, sprTexAll, 1);
- // too obvious what this does ...?
- CreateRain();
- // move the rain
- UpdateRain(fElapsedTime);
- return true;
- }
- };
- int main()
- {
- animation demo;
- if (demo.Construct(1303, 733, 1, 1))
- demo.Start();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement