Skip to content

Commit

Permalink
SpriteHandler_examples.h:
Browse files Browse the repository at this point in the history
* Finalized the background image.
* Slight improvements of ship.
* Improved stars color distribution.
* More stars.
* Increased the motion span of the flying creature.
  • Loading branch information
razterizer committed Oct 19, 2024
1 parent 8d41fd4 commit 9cd595d
Showing 1 changed file with 52 additions and 32 deletions.
84 changes: 52 additions & 32 deletions Examples/SpriteHandler_examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace sprite_handler
sprite0->set_sprite_bg_colors(0,
-2, -2, -2, -2, -2,
-2, -2, 13, -2, -2,
-2, 7, 7, 7, -2,
1, 7, 7, 7, 1,
-2, -2, 14, -2, -2
);
sprite0->init_frame(1);
Expand All @@ -63,7 +63,7 @@ namespace sprite_handler
sprite0->set_sprite_bg_colors(1,
-2, -2, -2, -2, -2,
-2, -2, 13, -2, -2,
-2, 7, 7, 7, -2,
1, 7, 7, 7, 1,
-2, -2, 4, -2, -2
);
sprite0->init_frame(2);
Expand All @@ -82,7 +82,7 @@ namespace sprite_handler
sprite0->set_sprite_bg_colors(2,
-2, -2, -2, -2, -2,
-2, -2, 13, -2, -2,
-2, 7, 7, 7, -2,
1, 7, 7, 7, 1,
-2, -2, -2, -2, -2
);
sprite0->func_frame_to_texture = [](int anim_frame)
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace sprite_handler
};
}

for (int s_idx = 0; s_idx < 16; ++s_idx)
for (int s_idx = 0; s_idx < 20; ++s_idx)
{
auto* sprite3 = sprh.create_sprite("star" + std::to_string(s_idx));
sprite3->pos.r = rnd::rand_int(0, sh.num_rows()-1);
Expand All @@ -165,13 +165,13 @@ namespace sprite_handler
sprite3->init_frame(0);
char star_ch = rnd::rand_select<char>({ '.', '+' });
sprite3->set_sprite_chars(0, star_ch);
sprite3->set_sprite_fg_colors(0, rnd::rand_select<Color>({ Color::White, Color::White, Color::White, Color::White, Color::Yellow, Color::Yellow, Color::Red, Color::Blue, Color::Blue }));
sprite3->set_sprite_fg_colors(0, rnd::rand_select<Color>({ Color::White, Color::White, Color::White, Color::White, Color::White, Color::Yellow, Color::Yellow, Color::Yellow, Color::Red, Color::Blue, Color::Blue, Color::Blue }));
sprite3->set_sprite_bg_colors(0, Color::Transparent2);
sprite3->init_frame(1);
sprite3->set_sprite_chars(1, star_ch);
sprite3->set_sprite_fg_colors(1, Color::Black);
sprite3->set_sprite_bg_colors(1, Color::Transparent2);
const int max_twinkle = 40;
const int max_twinkle = 100;
int twinkle_offs = rnd::rand_int(0, max_twinkle);
sprite3->func_frame_to_texture = [twinkle_offs](int anim_frame)
{
Expand All @@ -194,7 +194,7 @@ namespace sprite_handler
R"( )",
R"( )",
R"(::::::: )",
R"(~~~.~=.:::: )",
R"(~~~.~=.::%% )",
R"(ou.~~~~~,.~%%%% )",
R"(898o.~~~+~~~~o8%%% )",
R"(9883o..,~~~~ooO9Wm** )",
Expand All @@ -215,18 +215,27 @@ namespace sprite_handler
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 4, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11, 15, 15, 13, 13, 15, 15, 7, 7, 3, 7, 3, 3, 5, 13, 13, 5, 15, 11, 11, 15, 4, 12, 12, 4, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11, 7, 7, 15, 13, 15, 15, 5, 7, 3, 3, 7, 13, 13, 13, 5, 5, 13, 3, 13, 13, 13, 4, 12, 4, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3, 7, 15, 13, 15, 15, 7, 3, 3, 7, 7, 7, 13, 13, 5, 5, 13, 13, 13, 15, 15, 15, 15, 15, 11, 3, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
); // G:11, DG:3, DC:7, C:15, B:13, DB:5, DC:7, DG:3, G:11

/*
C:15 : '~', 'w', ','
B:13 : 'o', '9', '"', '='
DB:5 : 'O', 'p', '*'
DC:7 : 'S', '0', '<', '>', '%', '+', 'u'
DG:3 : 'W', '6', '8', '.'
G:11 : 'i', 'M', '3', 'm', ':'
*/
sprite4->set_sprite_bg_colors(0,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
Expand All @@ -237,19 +246,30 @@ namespace sprite_handler
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2
8, 16, 16, 16, 8, 7, 3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
7, 7, 7, 8, 7, 15, 8, 3, 13, 13, 13, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
7, 3, 8, 7, 7, 7, 7, 7, 8, 8, 7, 3, 13, 13, 13, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11, 11, 11, 7, 8, 7, 7, 7, 8, 7, 7, 7, 7, 7, 11, 3, 13, 13, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11, 11, 11, 3, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 11, 11, 11, 15, 7, 7, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11, 3, 11, 7, 8, 7, 7, 8, 7, 7, 7, 15, 15, 7, 11, 7, 11, 15, 11, 15, 7, 7, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11, 13, 7, 8, 8, 7, 7, 7, 7, 7, 15, 11, 7, 7, 11, 11, 7, 15, 15, 7, 8, 5, 13, 7, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11, 11, 7, 8, 7, 8, 7, 7, 8, 15, 15, 11, 11, 7, 7, 7, 15, 15, 7, 7, 7, 5, 13, 5, 7, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
3, 7, 7, 7, 7, 7, 7, 15, 15, 11, 15, 13, 11, 11, 7, 7, 11, 7, 15, 15, 7, 5, 13, 13, 5, 7, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
3, 13, 5, 7, 7, 7, 7, 3, 15, 11, 11, 15, 11, 11, 7, 11, 11, 7, 11, 7, 7, 7, 5, 13, 5, 7, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11, 15, 7, 7, 7, 7, 15, 11, 11, 15, 13, 13, 7, 7, 11, 11, 11, 7, 7, 7, 7, 7, 7, 3, 3, 11, 3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2
);

/*
B:13 : 'S', '6'
DB:5 : '0'
C:15 : '%', 'm', 'w'
DC:7 : '~', 'o'
G:11 : '8', 'W', 'O', 'M', '9'
DG:3 : '3', 'p', 'i'
LG:8 : '>', '<', '+', '.', ','
*/

// ///////////////////////////////////////////////////////////
// LET's GO ! //
// ///////////////////////////////////////////////////////////
Expand All @@ -267,8 +287,8 @@ namespace sprite_handler

int anim_frame = (i + 3)*44 + (j + 5);
auto t = static_cast<float>(anim_frame)/(23.f*45.f);
sprite1->pos.c = math::roundI(20.f + 6.f*std::cos(math::c_2pi * 7.13 * t));
sprite1->pos.r = math::roundI(10.f + 4*std::sin(math::c_2pi * 10 * t));
sprite1->pos.c = math::roundI(20.f + 10.f*std::cos(math::c_2pi * 7.13 * t));
sprite1->pos.r = math::roundI(10.f + 5*std::sin(math::c_2pi * 10 * t));

for (int a_idx = 0; a_idx < asteroids.size(); ++a_idx)
{
Expand Down

0 comments on commit 9cd595d

Please sign in to comment.