Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- using namespace std;
- struct player{
- double x, y, dx, dy;
- void move(){
- this->x += this->dx;
- this->dx += 0.0001;
- if(this->y>=19){
- this->y = 19;
- this->dy = 0;
- }else{
- this->dy += 0.2;
- this->y += this->dy;
- }
- }
- void jump(){
- if(this->y >= 19){
- this->dy = -1.6;
- }
- }
- int getRX(){ // Real X
- return (int)this->x;
- }
- int getSX(){ // Screen X
- return 20;
- }
- int getRY(){ // Real Y
- return (int)this->y;
- }
- int getSY(){ // Screen Y
- return (int)this->y;
- }
- };
- struct ananas{
- int x, w, h;
- void random(int x){
- this->h = rand()%3;
- this->w = rand()%3;
- this->x = x;
- }
- bool isAnanasHereReal(int x, int y){
- return (x >= this->x && x < this->x+this->w && y > 19 - this->h);
- }
- bool isAnanasHereScreen(int sx, int sy, player p){
- int x = p.x + sx - 20;
- int y = sy ;
- return this->isAnanasHereReal(x, y);
- }
- };
- const int a_count = 10;
- struct game{
- player p;
- ananas a[a_count];
- int last_ananas_x;
- void generate_ananases(){
- for(int i = 0; i < a_count; i++){
- int x = this->last_ananas_x+20+rand()%22;
- a[i].random(x);
- this->last_ananas_x = x;
- }
- }
- void init(){
- this->p.x = 0;
- this->p.y = 19;
- this->p.dx = 0.9;
- this->p.dy = 0;
- this->last_ananas_x = 50;
- this->generate_ananases();
- }
- void print(){
- }
- void loop(){
- this->p.move();
- //Если нажат пробел
- this->p.jump();
- this->print();
- }
- };
- int main()
- {
- game g;
- g.init();
- for(;;){
- g.loop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement