Skip to content

Commit

Permalink
Merge pull request #901 from Ghabry/weather
Browse files Browse the repository at this point in the history
Make snow effect less heavy and replace snowflake graphic
  • Loading branch information
fdelapena committed Jun 21, 2016
2 parents f020b5c + 7c3b6b6 commit 38c9ea0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/game_screen.cpp
Expand Up @@ -204,7 +204,7 @@ void Game_Screen::InitSnowRain() {
if (!snowflakes.empty()) if (!snowflakes.empty())
return; return;


static const int num_snowflakes[3] = {100, 200, 300}; static const int num_snowflakes[3] = {50, 100, 150};


for (int i = 0; i < num_snowflakes[data.weather_strength]; i++) { for (int i = 0; i < num_snowflakes[data.weather_strength]; i++) {
Snowflake f; Snowflake f;
Expand All @@ -223,9 +223,9 @@ void Game_Screen::UpdateSnowRain(int speed) {
for (it = snowflakes.begin(); it != snowflakes.end(); ++it) { for (it = snowflakes.begin(); it != snowflakes.end(); ++it) {
Snowflake& f = *it; Snowflake& f = *it;
f.y += (uint8_t)speed; f.y += (uint8_t)speed;
f.life++; f.life -= 5;
if (f.life > snowflake_life) if (f.life < 10)
f.life = 0; f.life = 255;
} }
} }


Expand Down
44 changes: 26 additions & 18 deletions src/weather.cpp
Expand Up @@ -82,17 +82,25 @@ void Weather::Draw() {
} }
} }


static const uint8_t snow_image[] = { static const uint8_t snow_image[] =
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, {
0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00,
0x00, 0x04, 0x02, 0x03, 0x00, 0x00, 0x00, 0xd4, 0x9f, 0x76, 0xed, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x09, 0x50, 0x4c, 0x54, 0x45, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x03, 0x00, 0x00, 0x00, 0x80, 0x98, 0x10, 0x17,
0xc0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0x0d, 0x6d, 0xd7, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x06, 0x50, 0x4c, 0x54, 0x45, 0xff, 0x00, 0x00,
0x00, 0x00, 0x01, 0x74, 0x52, 0x4e, 0x53, 0x00, 0x40, 0xe6, 0xd8, 0xff, 0xff, 0xff, 0x41, 0x1d, 0x34, 0x11, 0x00, 0x00, 0x00, 0x09,
0x66, 0x00, 0x00, 0x00, 0x0e, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0a, 0xf0, 0x00, 0x00, 0x0a,
0x63, 0x10, 0x61, 0xc8, 0x04, 0x42, 0x11, 0x00, 0x03, 0xf0, 0x00, 0xf0, 0x01, 0x42, 0xac, 0x34, 0x98, 0x00, 0x00, 0x00, 0x07, 0x74,
0xfb, 0xb6, 0xa8, 0xf1, 0xda, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x49, 0x4d, 0x45, 0x07, 0xe0, 0x05, 0x1e, 0x16, 0x12, 0x02, 0x2c,
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 0xe7, 0xd0, 0xc3, 0x00, 0x00, 0x00, 0x2b, 0x74, 0x45, 0x58, 0x74,
0x43, 0x72, 0x65, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x54, 0x69,
0x6d, 0x65, 0x00, 0x44, 0x69, 0x20, 0x33, 0x31, 0x20, 0x4d, 0x61,
0x69, 0x20, 0x32, 0x30, 0x31, 0x36, 0x20, 0x30, 0x30, 0x3a, 0x31,
0x35, 0x3a, 0x31, 0x35, 0x20, 0x2b, 0x30, 0x31, 0x30, 0x30, 0xc0,
0x15, 0x68, 0x2f, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54,
0x08, 0x5b, 0x63, 0x10, 0x64, 0x10, 0x04, 0x00, 0x00, 0x48, 0x00,
0x23, 0xf5, 0x3f, 0xea, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45,
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
}; };


static const uint8_t rain_image[] = { static const uint8_t rain_image[] = {
Expand Down Expand Up @@ -137,25 +145,25 @@ void Weather::DrawSnow() {
} }


static const int wobble[2][18] = { static const int wobble[2][18] = {
{-1,-1, 0, 1, 0, 1, 1, 0,-1,-1, 0, 1, 0, 1, 1, 0,-1, 0}, {-1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{-1,-1, 0, 0, 1, 1, 0,-1,-1, 0, 1, 0, 1, 1, 0,-1, 0, 0} {-1,-1, 0, 0, 1, 1, 0,-1,-1, 0, 1, 0, 1, 1, 0,-1, 0, 0}
}; };


Rect rect = snow_bitmap->GetRect(); Rect rect = snow_bitmap->GetRect();


const std::vector<Game_Screen::Snowflake>& snowflakes = Main_Data::game_screen->GetSnowflakes(); const std::vector<Game_Screen::Snowflake>& snowflakes = Main_Data::game_screen->GetSnowflakes();


std::vector<Game_Screen::Snowflake>::const_iterator it; std::vector<Game_Screen::Snowflake>::iterator it;
for (it = snowflakes.begin(); it != snowflakes.end(); ++it) { for (const Game_Screen::Snowflake& f : snowflakes) {
const Game_Screen::Snowflake& f = *it; if (f.life < 0) {
if (f.life > snowflake_visible)
continue; continue;
int x = f.x - f.y/2; }
int x = f.x - f.y / 4;
int y = f.y; int y = f.y;
int i = (y / 2) % 18; int i = (y / 2) % 18;
x += wobble[0][i]; x += wobble[0][i];
y += wobble[1][i]; y += wobble[1][i];
weather_surface->Blit(x, y, *snow_bitmap, rect, 192); weather_surface->Blit(x, y, *snow_bitmap, rect, f.life);
} }


dirty = true; dirty = true;
Expand Down

0 comments on commit 38c9ea0

Please sign in to comment.