easyx小游戏
#include "stdafx.h" int main(){ srand(time(NULL)); initgraph(640,480); int user_x=20,user_y=400,block_x=0,block_y=0; block_y=rand()%100; char ch; int t=clock(); for(;;){ circle(user_x,user_y,15); if(_kbhit()){ ch=_getch(); if(ch=='W')user_y-=10; } else if(clock()-t>100){ t=clock(); user_y+=10; if(user_y>480)user_y=480; block_x-=10; } cleardevice(); rectangle(block_x,480-block_y,block_x+20,480); //block_x-=10; if(block_x==0)block_x=480,block_y=rand()%100; if(block_x==user_x && 480-block_y<user_y)goto lose; if(user_y<350)user_y=350; } lose: cleardevice(); TCHAR st[]=_T("GAME OVER"); outtextxy(200,200,st); for(;;); closegraph(); return 0; closegraph(); }
注:stdafx包括:
游戏目标:不让小球碰到柱子
游戏截图: