hzaba丶迹 hzaba丶迹
关注数: 33 粉丝数: 299 发帖数: 4,921 关注贴吧数: 270
有没有大佬看一下我这个程序哪有问题 我用easyx做了一个下一百层的代码,但是当球碰到板子的时候不能上升,直接穿下去了,有几个板子可以带着球上升,我不知道我的判断哪出来问题下面是代码 请大佬看看,谢谢 #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<graphics.h>#define High 640 #define Width 480 #define barNumber 5 int bar_x[barNumber],bar_y[barNumber]; //板子坐标 int bar_high,bar_width; //板子长宽 int radius; int ball_x,ball_y; //球坐标 int ball_v; //球速度 int bar_v; //板子速度 char input;void startup() //初始化 { bar_high = High/20; bar_width = Width/(barNumber-1); radius = 20; ball_x = Width/2; ball_y = radius; ball_v = 1; for(int i=0;i<barNumber;i++) { bar_x[i] = rand()%Width; bar_y[i] = rand()%High; } initgraph(Width,High); BeginBatchDraw(); }void show() { setcolor(RED); setfillcolor(RED); fillcircle(ball_x,ball_y,radius); setcolor(BLUE); setfillcolor(BLUE); int bar_left,bar_top,bar_right,bar_bottom; for(int i=0;i<barNumber;i++) { bar_left = bar_x[i] - bar_width/2; bar_top = bar_y[i] - bar_high/2; bar_right = bar_x[i] + bar_width/2; bar_bottom = bar_y[i] + bar_high/2; bar(bar_left,bar_top,bar_right,bar_bottom); } FlushBatchDraw(); Sleep(50); }void clean() { setcolor(BLACK); setfillcolor(BLACK); fillcircle(ball_x,ball_y,radius); int bar_left,bar_top,bar_right,bar_bottom; for(int i=0;i<barNumber;i++) { bar_left = bar_x[i] - bar_width/2; bar_top = bar_y[i] - bar_high/2; bar_right = bar_x[i] + bar_width/2; bar_bottom = bar_y[i] + bar_high/2; bar(bar_left,bar_top,bar_right,bar_bottom); }}void withinput() //输入相关 { if(kbhit()) { input = getch(); if(input=='a') ball_x = ball_x-15; if(input=='d') ball_x = ball_x+15; }}void withoutinput() //输入无关 { static int speed = 0; speed++; ball_y = ball_y + ball_v; for(int i=0;i<barNumber;i++) { if(ball_y==bar_y[i]-radius-bar_high/2+3 || ball_y==bar_y[i]-radius-bar_high/2-3) { if(ball_x>bar_x[i]-bar_width/2-5 && ball_x<bar_x[i]+bar_width/2+5) ball_v = -5; } else ball_v = 1; if(bar_y[i]>(-bar_high/2)-5) bar_y[i] = bar_y[i] - 5; else { bar_x[i] = rand()%Width; bar_y[i] = High - bar_high/2; } } }int main() { startup(); while(1) { clean(); withinput(); withoutinput(); show(); }}
首页 1 2 3 下一页