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
//! Rusty Engine is a simple, 2D game engine for those who are learning Rust. Create simple game
//! prototypes using straightforward Rust code without any advanced game engine concepts! It works
//! on macOS, Linux, and Windows. Rusty Engine is a simplification wrapper over
//! [Bevy](https://bevyengine.org/), which I encourage you to use directly for more serious game
//! engine needs.
//!
//! # Quick Start Example
//!
//! You start by importing `rusty_engine::prelude::*`, define your own `GameState` struct,
//! create a [`Game`](crate::game::Game), set up your game, and then call
//! [`Game::run`](crate::game::Game::run).
//!
//! ```no_run
//! use rusty_engine::prelude::*;
//!
//! // Define a struct to hold custom data for your game (it can be a lot more complicated than this one!)
//! #[derive(Resource)]
//! struct GameState {
//! health: i32,
//! }
//!
//! fn main() {
//! // Create a game
//! let mut game = Game::new();
//! // Set up your game. `Game` exposes all of the methods and fields of `Engine`.
//! let sprite = game.add_sprite("player", SpritePreset::RacingCarBlue);
//! sprite.scale = 2.0;
//! game.audio_manager.play_music(MusicPreset::Classy8Bit, 0.1);
//! // Add one or more functions with logic for your game. When the game is run, the logic
//! // functions will run in the order they were added.
//! game.add_logic(game_logic);
//! // Run the game, with an initial state
//! let initial_game_state = GameState { health: 100 };
//! game.run(initial_game_state);
//! }
//!
//! // Your game logic functions can be named anything, but the first parameter is always a
//! // `&mut Engine`, and the second parameter is a mutable reference to your custom game
//! // state struct (`&mut GameState` in this case).
//! //
//! // This function will be run once each frame.
//! fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
//! // The `Engine` contains all sorts of built-in goodies.
//! // Get access to the player sprite...
//! let player = engine.sprites.get_mut("player").unwrap();
//! // Rotate the player...
//! player.rotation += std::f32::consts::PI * engine.delta_f32;
//! // Damage the player if it is out of bounds...
//! if player.translation.x > 100.0 {
//! game_state.health -= 1;
//! }
//! }
//! ```
//!
//! # Asset Licenses
//!
//! All assets included with this game engine have the appropriate license described and linked to
//! in a `README.md` file in the same directory as the source files. In most cases, the license is
//! [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/)--meaning you may do
//! whatever you wish with the asset.
//!
//! One notable exception is some of the music files, which are under a different license and
//! include specific attribution requirements that must be met in order to be used legally when
//! distributed. Please see
//! [this `README.md` file](https://github.com/CleanCut/rusty_engine/tree/main/assets/audio/music)
//! for more information.
//!
// Public prelude
// Used in our public constants
use ;
// Screen directions
/// The rotation (in radians) for a sprite to face right
pub const RIGHT: f32 = 0.0;
/// The rotation (in radians) for a sprite to face left
pub const LEFT: f32 = PI;
/// The rotation (in radians) for a sprite to face up
pub const UP: f32 = FRAC_PI_2;
/// The rotation (in radians) for a sprite to face down
pub const DOWN: f32 = PI + FRAC_PI_2;
// Compass directions
/// The rotation (in radians) for a sprite to face north
pub const NORTH: f32 = FRAC_PI_2;
/// The rotation (in radians) for a sprite to face north east
pub const NORTH_EAST: f32 = FRAC_PI_4;
/// The rotation (in radians) for a sprite to face east
pub const EAST: f32 = 0.0;
/// The rotation (in radians) for a sprite to face south east
pub const SOUTH_EAST: f32 = PI + FRAC_PI_2 + FRAC_PI_4;
/// The rotation (in radians) for a sprite to face south
pub const SOUTH: f32 = PI + FRAC_PI_2;
/// The rotation (in radians) for a sprite to face south west
pub const SOUTH_WEST: f32 = PI + FRAC_PI_4;
/// The rotation (in radians) for a sprite to face west
pub const WEST: f32 = PI;
/// The rotation (in radians) for a sprite to face north west
pub const NORTH_WEST: f32 = FRAC_PI_2 + FRAC_PI_4;