Advertisement
Guest User

DinoC++StuctGame

a guest
Feb 25th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct player{
  8.     double x, y, dx, dy;
  9.    
  10.     void move(){
  11.         this->x += this->dx;
  12.         this->dx += 0.0001;
  13.         if(this->y>=19){
  14.             this->y = 19;
  15.             this->dy = 0;
  16.         }else{
  17.             this->dy += 0.2;
  18.             this->y += this->dy;
  19.         }
  20.     }
  21.     void jump(){
  22.         if(this->y >= 19){
  23.             this->dy = -1.6;
  24.         }
  25.     }
  26.     int getRX(){ // Real X
  27.         return (int)this->x;
  28.     }
  29.     int getSX(){ // Screen X
  30.         return 20;
  31.     }
  32.     int getRY(){ // Real Y
  33.         return (int)this->y;  
  34.     }
  35.     int getSY(){ // Screen Y
  36.         return (int)this->y;
  37.     }
  38. };
  39.  
  40. struct ananas{
  41.     int x, w, h;
  42.     void random(int x){
  43.         this->h = rand()%3;
  44.         this->w = rand()%3;
  45.         this->x = x;
  46.     }
  47.     bool isAnanasHereReal(int x, int y){
  48.         return (x >= this->x && x < this->x+this->w && y > 19 - this->h);
  49.     }
  50.     bool isAnanasHereScreen(int sx, int sy, player p){
  51.         int x = p.x + sx - 20;
  52.         int y = sy ;
  53.         return this->isAnanasHereReal(x, y);
  54.     }
  55. };
  56.  
  57. const int a_count = 10;
  58. struct game{
  59.     player p;
  60.     ananas a[a_count];
  61.     int last_ananas_x;
  62.     void generate_ananases(){
  63.         for(int i = 0; i < a_count; i++){
  64.             int x = this->last_ananas_x+20+rand()%22;
  65.             a[i].random(x);
  66.             this->last_ananas_x = x;
  67.         }
  68.     }
  69.     void init(){
  70.         this->p.x = 0;
  71.         this->p.y = 19;
  72.         this->p.dx = 0.9;
  73.         this->p.dy = 0;
  74.         this->last_ananas_x = 50;
  75.         this->generate_ananases();
  76.     }
  77.     void print(){
  78.        
  79.     }
  80.     void loop(){
  81.         this->p.move();
  82.         //Если нажат пробел
  83.             this->p.jump();
  84.         this->print();
  85.     }
  86. };
  87.  
  88. int main()
  89. {
  90.     game g;
  91.     g.init();
  92.     for(;;){
  93.         g.loop();
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement