如何使它看起来像正在下的雪

How to make it look like falling snow?

本文关键字:何使它 看起来      更新时间:2023-10-16

我试着让它看起来像是在下雪,但到处都是雪,我必须从库图形中制作雪花。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();
}