到目前为止,我已经让我的程序显示一组在屏幕上随机出现的不同颜色的像素。我想知道是否有可能让像素向下移动,有点像你在宇宙飞船的太空中向前移动。这是我的程序到目前为止,它非常简单,但我需要它。
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>
int main() {
int gd = DETECT, gm;
int i, x, y;
initgraph(&gd, &gm, "C:\\TC\\BGI");
initwindow(1200, 768);
/* color 500 random pixels on screen */
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,1);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,2);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,3);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,4);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,5);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,6);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,7);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,8);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,9);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,9);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,10);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,11);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,12);
}
for(i=0; i<=125; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,13);
}
for(i=0; i<=100; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,14);
}
for(i=0; i<=900; i++) {
x=rand()%getmaxx();
y=rand()%getmaxy();
putpixel(x,y,15);
}
getch();
closegraph();
return 0;
}
任何帮助将不胜感激。
您需要生成一次背景图像,然后多次显示它,屏幕清晰并在两者之间进行转换。
struct COORD {
unsigned short x;
unsigned short y;
};
COORD stars[STAR_COUNT];
for(int star = 0; STAR_COUNT > star; ++star)
{
stars[star].x = rand() % SCREEN_WIDTH;
stars[star].y = rand() % SCREEN_HEIGHT;
}
然后可能为每个框架执行以下操作:
for(int star = 0; STAR_COUNT > star; ++star)
{
--stars[star].x;
--stars[nstar].y;
}