Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define _WIN32_WINNT 0x0500 //needed by gotoXY function only.
- #include "Windows.h" //needed by gotoXY function only.
- using namespace std;
- //gotoXY function, puts the cursor to x,y coordinate
- void gotoXY(int x, int y)
- {
- static HANDLE h = NULL;
- if(!h)
- h = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD c = { x, y };
- SetConsoleCursorPosition(h,c);
- }
- //main function
- int main()
- {
- float x=0,y=0,vx,vy,g,fs;
- printf(" Enter the Horizontal Velocity ( Recommended Value : 2.5 ) = ");
- scanf("%f",&vx);
- printf(" Enter the Vertical Velocity ( Recommended Value : 2.5 ) = ");
- scanf("%f",&vy);
- printf(" Enter the Gravity ( Recommended Value : 0.5 ) = ");
- scanf("%f",&g);
- printf(" Enter the Friction ( Recommended Value : 0.025 ) = ");
- scanf("%f",&fs);
- while(1){
- if(GetAsyncKeyState(VK_UP) != 0){ //reset
- system("CLS");
- x=0;
- y=0;
- printf(" Enter the Horizontal Velocity ( Recommended Value : 2.5 ) = ");
- scanf("%f",&vx);
- printf(" Enter the Vertical Velocity ( Recommended Value : 2.5 ) = ");
- scanf("%f",&vy);
- printf(" Enter the Gravity ( Recommended Value : 0.5 ) = ");
- scanf("%f",&g);
- printf(" Enter the Friction ( Recommended Value : 0.025 ) = ");
- scanf("%f",&fs);
- }
- //update
- vy+=g;
- x+=vx;
- y+=vy;
- //check & fix
- if(y+vy>24)
- y=24;
- if((y<15 && y+vy>15 ) || (y>15 && y+vy<15) )
- y=15;
- if(x+vx>78)
- x=78;
- else if(x+vx<0)
- x=0;
- if(y==24 && vx!=0){
- if(vx>0)
- vx-=fs;
- else if(vx<0)
- vx+=fs;
- }
- if(y>=24 || (x>=10 && x<=35 && y==15))
- vy*=-1;
- if(x>=78 || x<=0)
- vx*=-1;
- //draw
- system("CLS");
- if(x>=0 && x<=78 && y<=24 && y>=0){
- gotoXY(x,y);
- printf("O");
- }
- for(int i=10;i<=35;i++){
- gotoXY(i,15);
- printf("*");
- }
- gotoXY(1,1);
- printf(" x = %f , vx = %f // y = %f , vy = %f\n\n Reset : Up Arrow // Tolga Ay - http://about.me/tolga.ay", x,vx,y,vy);
- Sleep(40);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement