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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! # Game Development Framework
//!
//! This module provides specialized tools and utilities for developing terminal-based games
//! with MinUI. It includes systems for sprite management, collision detection, map handling,
//! and game loop utilities that complement the core UI framework.
//!
//! ## Overview
//!
//! The game module bridges the gap between MinUI's widget-based UI system and the specific
//! needs of game development. While MinUI handles rendering, input, and basic UI components,
//! the game module adds game-specific concepts like sprites, tiles, collision detection,
//! and frame-rate management.
//!
//! ## Core Components
//!
//! ### Tiles and Sprites
//! - [`tile`] - Tile-based graphics and behaviors for grid-based games
//! - [`sprite`] - Sprite management with movement and animation support
//!
//! ### World Management
//! - [`map`] - Map and level layout management systems
//! - [`collision`] - Collision detection between game objects
//!
//! ### Game Loop
//! - [`game_loop`] - Frame rate management, timing, and game state utilities
//!
//! ## Game Development Patterns
//!
//! ### Fixed Timestep Games
//! Perfect for turn-based games, roguelikes, and puzzle games where timing isn't critical:
//!
//! ```rust
//! use minui::prelude::*;
//!
//! struct GameState {
//! player_x: u16,
//! player_y: u16,
//! }
//!
//! let mut app = App::new(GameState { player_x: 5, player_y: 5 })?;
//!
//! app.run(
//! |state, event| {
//! match event {
//! Event::Character('q') => false, // Quit
//! Event::KeyUp => { state.player_y = state.player_y.saturating_sub(1); true }
//! Event::KeyDown => { state.player_y += 1; true }
//! Event::KeyLeft => { state.player_x = state.player_x.saturating_sub(1); true }
//! Event::KeyRight => { state.player_x += 1; true }
//! _ => true,
//! }
//! },
//! |state, window| {
//! window.write_str(state.player_y, state.player_x, "@")?;
//! Ok(())
//! }
//! )?;
//! # Ok::<(), minui::Error>(())
//! ```
//!
//! ### Real-time Games
//! For action games, arcade-style games, and smooth animation:
//!
//! ```rust
//! use minui::prelude::*;
//! use std::time::Duration;
//!
//! struct ActionGame {
//! player_x: f32,
//! player_y: f32,
//! velocity_x: f32,
//! velocity_y: f32,
//! }
//!
//! let mut app = App::new(ActionGame {
//! player_x: 40.0,
//! player_y: 12.0,
//! velocity_x: 0.0,
//! velocity_y: 0.0,
//! })?
//! .with_tick_rate(Duration::from_millis(16)); // ~60 FPS
//!
//! app.run(
//! |state, event| {
//! match event {
//! Event::Tick => {
//! // Update physics
//! state.player_x += state.velocity_x;
//! state.player_y += state.velocity_y;
//!
//! // Apply friction
//! state.velocity_x *= 0.9;
//! state.velocity_y *= 0.9;
//! true
//! }
//! Event::Character('w') => { state.velocity_y -= 0.5; true }
//! Event::Character('s') => { state.velocity_y += 0.5; true }
//! Event::Character('a') => { state.velocity_x -= 0.5; true }
//! Event::Character('d') => { state.velocity_x += 0.5; true }
//! Event::Character('q') => false,
//! _ => true,
//! }
//! },
//! |state, window| {
//! window.write_str(state.player_y as u16, state.player_x as u16, "◉")?;
//! Ok(())
//! }
//! )?;
//! # Ok::<(), minui::Error>(())
//! ```
//!
//! ## Game Types Supported
//!
//! The MinUI game framework is particularly well-suited for:
//!
//! ### Classic Terminal Games
//! - **Roguelikes**: Dungeon crawlers with procedural generation
//! - **Text Adventures**: Interactive fiction with rich narratives
//! - **MUDs/RPGs**: Multi-user dungeons and role-playing games
//!
//! ### Puzzle Games
//! - **Tetris-style**: Block-falling puzzle games
//! - **Sokoban**: Box-pushing puzzle games
//! - **Word Games**: Crosswords, word searches, text-based puzzles
//!
//! ### Arcade Games
//! - **Snake**: Classic snake game with smooth movement
//! - **Pong**: Simple paddle and ball games
//! - **Space Invaders**: Scrolling shoot-em-up style games
//!
//! ### Strategy Games
//! - **Turn-based Strategy**: Chess, checkers, tactical games
//! - **Tower Defense**: Real-time strategy with tower placement
//! - **4X Games**: Explore, expand, exploit, exterminate strategy games
//!
//! ## Implementation Status
//!
//! The game module is currently in early development with placeholder implementations.
//! The framework provides the foundation for game development, but specific game
//! utilities are planned for future releases.
//!
//! ## Future Enhancements
//!
//! Planned features for the game module include:
//! - Entity-Component-System (ECS) architecture
//! - Physics simulation and collision detection
//! - Sound system integration (where supported)
//! - Save/load system for game state
//! - Networking support for multiplayer games
//! - Procedural generation utilities