美文网首页
网易c++------课时38---简单动画

网易c++------课时38---简单动画

作者: heiqimingren | 来源:发表于2020-11-11 19:30 被阅读0次
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();
}


相关文章

网友评论

      本文标题:网易c++------课时38---简单动画

      本文链接:https://www.haomeiwen.com/subject/iyzepktx.html