Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(kbhit())
- {
- ch=getch();
- if(ch=='e'){break;} //exit
- if(ch=='d') //move right
- {
- ax=1;
- if(vx<vellim){vx=vx+ax*dt;}
- dx=vx*dt;
- x+=dx;
- s_mario(x,y); //This function draws the character at the appropriate place
- }
- if(ch=='a') //move left
- {
- ax=-1;
- if(vx>-vellim){vx=vx+ax*dt;}
- dx=vx*dt;
- x+=dx;
- s_mario(x,y);
- }
- if(ch=='w'&&jumpkey==0) //jump
- {
- vy=60;
- jumpkey=1;
- }
- }
- if(jumpkey==1)
- {
- vy=vy-g;
- dy=vy*dt;
- y-=dy*0.1;
- if(y>400){y=399;vy=0;jumpkey=0;}
- s_mario(x,y);
- }
- if(!kbhit())
- { vx*=c;
- dx=vx*dt;
- x+=dx;
- s_mario(x,y);
- delay(5);
- }
Add Comment
Please, Sign In to add comment