| 838 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2011 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emCORE.
|
|
|
7 |
//
|
|
|
8 |
// emCORE is free software: you can redistribute it and/or
|
|
|
9 |
// modify it under the terms of the GNU General Public License as
|
|
|
10 |
// published by the Free Software Foundation, either version 2 of the
|
|
|
11 |
// License, or (at your option) any later version.
|
|
|
12 |
//
|
|
|
13 |
// emCORE is distributed in the hope that it will be useful,
|
|
|
14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
16 |
// See the GNU General Public License for more details.
|
|
|
17 |
//
|
|
|
18 |
// You should have received a copy of the GNU General Public License along
|
|
|
19 |
// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include "emcoreapp.h"
|
|
|
25 |
#include "main.h"
|
|
|
26 |
#include "settings.h"
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
struct snowflake
|
|
|
30 |
{
|
|
|
31 |
int x;
|
|
|
32 |
int y;
|
|
|
33 |
uint8_t opacity[4];
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
static struct snowflake snow_flakes[150];
|
|
|
38 |
static int snow_velocity_x;
|
|
|
39 |
static int snow_velocity_y;
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
void snow_init()
|
|
|
43 |
{
|
|
|
44 |
int i;
|
|
|
45 |
snow_velocity_x = (rand() % 11) - 5;
|
|
|
46 |
snow_velocity_y = rand() % 21;
|
|
|
47 |
for (i = 0; i < ARRAYLEN(snow_flakes); i++)
|
|
|
48 |
{
|
|
|
49 |
snow_flakes[i].x = rand() % (176 << 4);
|
|
|
50 |
snow_flakes[i].y = rand() % (132 << 4);
|
|
|
51 |
snow_flakes[i].opacity[0] = rand() & 0xff;
|
|
|
52 |
snow_flakes[i].opacity[1] = rand() & 0xff;
|
|
|
53 |
snow_flakes[i].opacity[2] = rand() & 0xff;
|
|
|
54 |
snow_flakes[i].opacity[3] = rand() & 0xff;
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
void render_snow()
|
|
|
59 |
{
|
|
|
60 |
int i;
|
|
|
61 |
if (!settings.snow) return;
|
|
|
62 |
snow_velocity_x += (rand() % 3) - 1;
|
|
|
63 |
if (snow_velocity_x > 2) snow_velocity_x = 2;
|
|
|
64 |
if (snow_velocity_x < -2) snow_velocity_x = -2;
|
|
|
65 |
snow_velocity_y += (rand() % 3) - 1;
|
|
|
66 |
if (snow_velocity_y > 15) snow_velocity_y = 15;
|
|
|
67 |
if (snow_velocity_y < 10) snow_velocity_y = 10;
|
|
|
68 |
for (i = 0; i < ARRAYLEN(snow_flakes) * settings.snow / SETTINGS_SNOW_MAX; i++)
|
|
|
69 |
{
|
|
|
70 |
snow_flakes[i].x += snow_velocity_x + (rand() % 7) - 3;
|
|
|
71 |
if (snow_flakes[i].x < 0) snow_flakes[i].x += (176 << 4);
|
|
|
72 |
if (snow_flakes[i].x >= (176 << 4)) snow_flakes[i].x -= (176 << 4);
|
|
|
73 |
snow_flakes[i].y += snow_velocity_y + (rand() % 7) - 3;
|
|
|
74 |
if (snow_flakes[i].y < 0) snow_flakes[i].y += (132 << 4);
|
|
|
75 |
if (snow_flakes[i].y >= (132 << 4)) snow_flakes[i].y -= (132 << 4);
|
|
|
76 |
int x = snow_flakes[i].x >> 4;
|
|
|
77 |
int y = snow_flakes[i].y >> 4;
|
|
|
78 |
int x2 = x < 175 ? x + 1 : 0;
|
|
|
79 |
int y2 = y < 131 ? y + 1 : 0;
|
|
|
80 |
int o0 = (snow_flakes[i].opacity[0] << 24) | 0xffffff;
|
|
|
81 |
int o1 = (snow_flakes[i].opacity[1] << 24) | 0xffffff;
|
|
|
82 |
int o2 = (snow_flakes[i].opacity[2] << 24) | 0xffffff;
|
|
|
83 |
int o3 = (snow_flakes[i].opacity[3] << 24) | 0xffffff;
|
|
|
84 |
ui->blendcolor(1, 1, o0, framebuf, x, y, 176, framebuf, x, y, 176);
|
|
|
85 |
ui->blendcolor(1, 1, o1, framebuf, x2, y, 176, framebuf, x2, y, 176);
|
|
|
86 |
ui->blendcolor(1, 1, o2, framebuf, x, y2, 176, framebuf, x, y2, 176);
|
|
|
87 |
ui->blendcolor(1, 1, o3, framebuf, x2, y2, 176, framebuf, x2, y2, 176);
|
|
|
88 |
}
|
|
|
89 |
}
|