
image.png

image.png

image.png
#include<stdio.h>
#include<stdlib.h> //清屏命令在这里。
#include <windows.h> //延时10毫秒-sleep,gotoxy函数
#include <iostream>
#include <conio.h> //getch()----不用按回车,就可以输入字符。
#include <graphics.h> //EasyX库,所使用的!
using namespace std;
//游戏画面尺寸
#define High 480
#define Width 640
void main()
{
initgraph(Width, High); //初始化画布
float ball_x, ball_y; //小球坐标
float ball_vx, ball_vy; //小球速度
float radius; //小球半径
ball_x = Width / 2;
ball_y = High / 2;
ball_vx = 1;
ball_vy = 1;
radius = 20;
BeginBatchDraw();
while (1)
{
//绘制黄线,绿色填充的圆
setcolor(YELLOW); //圆的线条为黄色
setfillcolor(GREEN); //圆内部位,绿色填充
fillcircle(ball_x, ball_y, radius); //画圆,圆心(100,100),半径20
FlushBatchDraw();
//延时
Sleep(3);
//绘制黑线,黑色填充的圆
setcolor(BLACK); //圆的线条为黄色
setfillcolor(BLACK); //圆内部位,绿色填充
fillcircle(ball_x, ball_y, radius); //画圆,圆心(100,100),半径20
ball_x = ball_x + ball_vx;
ball_y = ball_y + ball_vy;
//碰撞反弹
if ((ball_x <= radius) || (ball_x>=Width-radius)) //左右边界
{
ball_vx = -ball_vx;
}
if ((ball_y <= radius) || (ball_y >= High - radius)) //上下边界
{
ball_vy = -ball_vy;
}
}
EndBatchDraw();
closegraph();
}
网友评论