-
Notifications
You must be signed in to change notification settings - Fork 1
/
main-1.cpp
executable file
·81 lines (63 loc) · 1.42 KB
/
main-1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Eternity Intro
*
* Jon Vlachoyiannis
* 8/12/2005
*/
#include <stdio.h>
#define ALLEGRO_STATICLINK
#define USE_CONSOLE
#include <allegro.h>
#define NUMOFSNOW 500 // number of snowflakes
typedef struct {
int x, y;
int layer;
}particles_t;
particles_t Snow[NUMOFSNOW];
void InitSnow()
{
for (int i=0; i < NUMOFSNOW; i++)
{
Snow[i].x = rand() % 320;
Snow[i].y = rand() % 200;
Snow[i].layer = rand() % 3; // number of layers
}
}
void DrawSnow()
{
for (int i=0; i < NUMOFSNOW; i++)
putpixel(screen, Snow[i].x, Snow[i].y, Snow[i].layer * 2 + 20);
}
void UpdateSnow()
{
for (int i=0; i < NUMOFSNOW; i++)
{
Snow[i].y += Snow[i].layer; // higher layer moves faster
Snow[i].layer = rand() % 3; // number of layers
if ( Snow[i].y > 199 )
Snow[i].y = 0;
Snow[i].x = (Snow[i].x + (2 - rand()%4)) % 320; // move left right but always between 320
}
}
int main()
{
allegro_init();
install_keyboard();
set_color_depth(8);
//if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 200, 0, 0)<0)
if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 320, 200, 0, 0)<0)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Failed to initialize video mode\n %s\n",allegro_error);
}
InitSnow();
while ((!key[KEY_ESC])&&(!key[KEY_SPACE]))
{
UpdateSnow();
clear_bitmap(screen);
DrawSnow();
vsync();
}
return 1;
}
END_OF_MAIN();