如何使它看起来像正在下的雪
How to make it look like falling snow?
我试着让它看起来像是在下雪,但到处都是雪,我必须从库图形中制作雪花。h。我不知道如何让它移动,但我已经添加了x和y。对于int speed
,我不知道该如何使用它,我从其他代码中看到,这些代码来自球的移动。这个代码是我的任务用的,你们能帮我吗?
#include <graphics.h>
class Snow
{
private:
int x,y;
int color;
int speed;
public:
Snow(int _x, int _y, int _color, int _speed)
{
x=_x;
y=_y;
color=_color;
speed=_speed;
}
int getColor()
{
return color;
}
int getSpeed()
{
return speed;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
void setX(int value)
{
//x=rand();
x=value;
}
void setY (int value)
{
//y=rand();
y=value;
}
void setColor(int value)
{
color=value;
}
void setSpeed(int value)
{
speed=value;
}
void draw()
{
setcolor(color);
setfillstyle(SOLID_FILL,color);
fillellipse(x,y,2,2);
}
void undraw()
{
setcolor(BLACK);
fillellipse(x,y,2,2);
}
void move()
{
undraw();
x=rand() % getmaxwidth();
y=rand() % getmaxheight();
draw();
}
};
int main()
{
int screenWidth = getmaxwidth();
int screenHeight = getmaxheight();
initwindow(screenWidth, screenHeight, "Snowy day");
Snow p1(0,0,WHITE,10);
while (!kbhit())
{
delay(100);
p1.move();
}
return 0;
}
您应该在移动函数中使用速度。例如:
void move() {
undraw();
x=rand() % getmaxwidth();
// fall
y += speed;
draw();
}
相关文章:
- std::vector的包装器,使数组的结构看起来像结构的数组
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 如何使它看起来像正在下的雪
- 如何用逗号分隔输出?如何改进此代码以使其看起来更体面?
- 为什么这个结构的大小是 40,而它看起来应该是 12/24?
- 我需要将阵列样式的邻接矩阵转换为矢量样式(以使其看起来更好)
- 结构化绑定:当某些内容看起来像引用并且行为类似于引用,但它不是引用时
- 如何使QTextEdit看起来被禁用
- 我应该如何使 std::filesystem 看起来符合 Visual Studio 2015 的标准
- 使标题看起来像它们在不同的文件夹中
- 我的 vscode 的控制台输出看起来很奇怪,如何解决它
- 如何使Qtabbar中的选定选项卡在悬停而不悬停时看起来相同
- 字符串流问题,我认为我的代码看起来不错,但它显示奇怪的符号
- DirectX透明纹理-使植物看起来很好看
- C++成员函数未声明错误时(当它看起来是错误时)
- 什么是UMThunkStubAMD64,为什么它看起来是一个瓶颈
- 是否可以使用现有API修改windows功能区控件,使其看起来更像MS Word 2010中的功能区
- 如何将按钮添加到任务栏后使窗口看起来对称
- 如何将一个大矩形分割成N个小矩形,使其看起来随机
- visualstudio2010-如何制作一个正在等待某个事件的c++程序,使其看起来响应迅速