回复 2楼 风过无痕1989
这是目前写到的代码:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main (void)
{
//设置窗口大小
float width,height;
width =1200;
height =700;
initgraph(width,height);
float ball_x,ball_y,radius,g;
//球的初始位置
radius=30;
ball_x=width/4;
ball_y=height-radius;
float g=1.7;
//重力
float ball_v=0;
float ball_vx=0;
while(1)
{
if(kbhit())
{
char input=_getch();
if (input==' ')
//按空格跳跃
ball_v=-40 ;
if(input=='z')
ball_vx=-40;
if(input=='x')
ball_vx=40;
//左右跳跃
}
//小球速度位置改变
ball_v=ball_v+g;
ball_y=ball_y+ball_v;
ball_x=ball_x+ball_vx;
//限制小球不掉落地面
if(ball_y>=height-radius)
{
ball_v=0;
ball_y=height-radius;
}
cleardevice();//清空画面
fillcircle(ball_x,ball_y,radius);//填充小球
float q,w,e,r;
q=3*width/4;
w=height/3;
e=3*width/4+50;
r=height;
fillrectangle(q,w,e,r);//填充方块
Sleep(20);
}
_getch();
return 0;
}