1111
1212#include " bitmap.hpp"
1313#include " color.hpp"
14+ #include " game.hpp"
1415#include " game_components.hpp"
1516#include " point.hpp"
1617#include " size.hpp"
2223
2324
2425namespace lefticus ::my_awesome_game {
25- Game_Map make_map ()// NOLINT congetive complexity
26- {
27- Game_Map map{ Size{ 10 , 10 } };// NOLINT magic numbers
28-
29- auto solid_draw = []([[maybe_unused]] Vector2D_Span<Color> &pixels,
30- [[maybe_unused]] const Game &game,
31- [[maybe_unused]] Point map_location) {
32- for (std::size_t cur_x = 0 ; cur_x < pixels.size ().width ; ++cur_x) {
33- for (std::size_t cur_y = 0 ; cur_y < pixels.size ().height ; ++cur_y) {
34- if (cur_x == 0 || cur_y == 0 || cur_x == pixels.size ().width - 1 || cur_y == pixels.size ().height - 1 ) {
35- pixels.at (Point{ cur_x, cur_y }) = Color{ 128 , 128 , 128 , 255 };// NOLINT Magic numbers
36- } else {
37- switch ((game.clock .count () / 1000 ) % 2 ) {// NOLINT Magic numbers
38- case 0 :
39- pixels.at (Point{ cur_x, cur_y }) = Color{ 255 , 255 , 255 , 255 };// NOLINT Magic numbers
40- break ;
41- case 1 :// NOLINT Magic Numbers
42- pixels.at (Point{ cur_x, cur_y }) = Color{ 200 , 240 , 240 , 255 };// NOLINT Magic numbers
43- break ;
44- }
45- }
46- }
47- }
48- };
49-
50- auto cannot_enter = [](const Game &, Point, Direction) -> bool { return false ; };
51-
52- auto empty_draw = []([[maybe_unused]] Vector2D_Span<Color> &pixels,
53- [[maybe_unused]] const Game &game,
54- [[maybe_unused]] Point map_location) {
55- for (std::size_t cur_x = 0 ; cur_x < pixels.size ().width ; ++cur_x) {
56- for (std::size_t cur_y = 0 ; cur_y < pixels.size ().height ; ++cur_y) {
57- pixels.at (Point{ cur_x, cur_y }) = Color{ 10 , 10 , 10 , 255 };// NOLINT Magic numbers
58- }
59- }
60- };
61-
62- for (std::size_t cur_x = 0 ; cur_x < map.locations .size ().width ; ++cur_x) {
63- for (std::size_t cur_y = 0 ; cur_y < map.locations .size ().height ; ++cur_y) {
64- map.locations .at (Point{ cur_x, cur_y }).draw = empty_draw;
65- }
66- }
67-
68- map.locations .at (Point{ 2 , 3 }).draw = solid_draw;
69- map.locations .at (Point{ 2 , 3 }).can_enter = cannot_enter;
70- map.locations .at (Point{ 1 , 4 }).draw = solid_draw;
71- map.locations .at (Point{ 1 , 4 }).can_enter = cannot_enter;
72- map.locations .at (Point{ 0 , 2 }).draw = solid_draw;
73- map.locations .at (Point{ 0 , 2 }).can_enter = [](const Game &, Point, Direction direction) {
74- return direction == Direction::South;
75- };
76-
77-
78- return map;
79- }
80-
81- Game make_game ()
82- {
83- Game retval;
84- retval.maps .emplace (" main" , make_map ());
85- retval.current_map = " main" ;
86- retval.tile_size = Size{ 8 , 8 };// NOLINT Magic Number
87-
88- Character player;
89- player.draw = [player_bitmap = load_png (" player.png" )]([[maybe_unused]] Vector2D_Span<Color> &pixels,
90- [[maybe_unused]] const Game &game,
91- [[maybe_unused]] Point map_location) {
92- // with with a fully saturated red at 50% alpha
93- for (std::size_t cur_x = 0 ; cur_x < pixels.size ().width ; ++cur_x) {
94- for (std::size_t cur_y = 0 ; cur_y < pixels.size ().height ; ++cur_y) {
95- pixels.at (Point{ cur_x, cur_y }) += player_bitmap.at (Point{ cur_x, cur_y });
96- }
97- }
98- };
99-
100-
101- retval.player = player;
102-
103- return retval;
104- }
10526
10627
10728void draw (Bitmap &viewport, Point map_center, const Game &game, const Game_Map &map)
@@ -203,6 +124,9 @@ void game_iteration_canvas()
203124
204125 if (game.maps .at (game.current_map ).can_enter_from (game, location, from)) {
205126 game.player .map_location = location;
127+ auto action = game.maps .at (game.current_map ).locations .at (location).action ;
128+
129+ if (action) { action (game, location, from); }
206130 }
207131 }
208132 }();
@@ -229,11 +153,11 @@ void game_iteration_canvas()
229153 last_time = new_time;
230154
231155 // now actually draw the game elements
232- return ftxui::hbox ({ bm | ftxui::border,
156+ return ftxui::vbox ({ ftxui:: hbox ({ bm | ftxui::border,
233157 ftxui::vbox ({ ftxui::text (" Frame: " + std::to_string (counter)),
234158 ftxui::text (" FPS: " + std::to_string (fps)),
235159 ftxui::text (" Character: " + last_character),
236- small_bm | ftxui::border }) });
160+ small_bm | ftxui::border }) }), ftxui::text ( " Message: " + game. last_message )}) ;
237161 };
238162
239163 auto container = ftxui::Container::Vertical ({});
0 commit comments