Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
<!-- next-header -->
## [Unreleased] - ReleaseDate

### Breaking changes

- `WindowDescriptor` has been renamed to `Window`
- You must new add `#[derive(Resource)]` above your `GameState` struct.
- It is no longer possible to use the unit type `()` instead of a `GameState` struct. Always create a `GameState` struct (it can be an empty struct with no fields).
- The `Timer` now takes a `TimerMode` enum variant instead of a `bool`. Use `TimerMode::Once` for a timer that runs once, or `TimerMode::Repeating` for a repeating timer.
- The following `KeyCode` variants have been renamed:
- `LShift` -> `ShiftLeft`
- `RShift` -> `ShiftRight`
- `LAlt` -> `AltLeft`
- `RAlt` -> `AltRight`
- `LBracket` -> `BracketLeft`
- `RBracket` -> `BracketRight`
- `LControl` -> `ControlLeft`
- `RControl` -> `ControlRight`
- `LShift` -> `ShiftLeft`
- `LWin` -> `SuperLeft`
- `RWin` -> `SuperRight`


### Improved

- Update bevy from 0.8 to 0.12
- Update bevy_prototype_lyon from 0.6 to 0.10
- Update ron from 0.7 to 0.8
- Fixed some inconsistent parameter names in examples
- Some examples' audio was turned down lower


## [5.2.1] - 2022-11-15

### Improved
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ exclude = [
]

[dependencies]
bevy = { version = "0.8.1", default-features = false, features = [
bevy = { version = "0.12.1", default-features = false, features = [
"bevy_audio",
"bevy_gilrs",
"bevy_gltf",
"bevy_render",
"bevy_text",
"bevy_winit",
"render",
"png",
"hdr",
"mp3",
"x11",
"vorbis",
] }
bevy_prototype_lyon = "0.6"
ron = "0.7"
bevy_prototype_lyon = "0.10.0"
ron = "0.8"
serde = { version = "1.0", features = [ "derive" ] }

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Write your game!
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,
}
Expand All @@ -78,7 +79,7 @@ Write your game!
// 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, 1.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);
Expand Down
5 changes: 4 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ Configuration goes in `release.toml`
# First, choose `major`, `minor`, or `patch` for the level to release

# Next, run the command in dry-run mode
$ cargo release -vv LEVEL
$ cargo release -v LEVEL

# Then do it for real with the same level
$ cargo release --execute LEVEL

# Then publish an updated tutorial
$ script/publish_tutorial
```
5 changes: 3 additions & 2 deletions examples/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::path::PathBuf;

use rusty_engine::prelude::*;

#[derive(Resource)]
struct GameState {
circle_radius: f32,
scale: f32,
Expand Down Expand Up @@ -70,7 +71,7 @@ fn main() {
// Start with the "game" part
let mut game = Game::new();
game.show_colliders = true;
game.window_settings(WindowDescriptor {
game.window_settings(Window {
title: "Collider Creator".into(),
..Default::default()
});
Expand Down Expand Up @@ -153,7 +154,7 @@ fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
let location = (((location / game_state.scale) * 2.0).round() * 0.5) * game_state.scale;
if engine
.keyboard_state
.pressed_any(&[KeyCode::RShift, KeyCode::LShift])
.pressed_any(&[KeyCode::ShiftLeft, KeyCode::ShiftRight])
{
sprite.change_last_collider_point(location);
} else {
Expand Down
13 changes: 8 additions & 5 deletions examples/collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use rusty_engine::prelude::*;

const ROTATION_SPEED: f32 = 3.0;

#[derive(Resource)]
struct GameState {}

fn main() {
let mut game = Game::new();
let msg2 = game.add_text(
Expand All @@ -15,7 +18,7 @@ fn main() {
msg2.font_size = 20.0;
msg2.translation.y = 340.0;

let mut race_car = game.add_sprite("Player", SpritePreset::RacingCarGreen);
let race_car = game.add_sprite("Player", SpritePreset::RacingCarGreen);
race_car.translation = Vec2::new(0.0, 0.0);
race_car.rotation = UP;
race_car.layer = 100.0;
Expand All @@ -28,20 +31,20 @@ fn main() {
break 'outer;
}
let sprite_preset = sprite_presets_iter.next().unwrap();
let mut sprite = game.add_sprite(format!("{:?}", sprite_preset), sprite_preset);
let sprite = game.add_sprite(format!("{:?}", sprite_preset), sprite_preset);
sprite.translation = Vec2::new(x as f32, (-y) as f32);
sprite.collision = true;
}
}

let mut text = game.add_text("collision text", "");
let text = game.add_text("collision text", "");
text.translation = Vec2::new(0.0, -200.0);

game.add_logic(logic);
game.run(());
game.run(GameState {});
}

fn logic(engine: &mut Engine, _: &mut ()) {
fn logic(engine: &mut Engine, _: &mut GameState) {
// If a collision event happened last frame, print it out and play a sound
for collision_event in engine.collision_events.drain(..) {
let text = engine.texts.get_mut("collision text").unwrap();
Expand Down
3 changes: 2 additions & 1 deletion examples/game_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rusty_engine::prelude::*;

// You can name your game state struct whatever you want, and it can contain many different types as
// its fields
#[derive(Resource)]
struct MyCustomGameStateStuff {
// Use a timer to tell when to start/stop turning
change_timer: Timer,
Expand All @@ -20,7 +21,7 @@ fn main() {
let _ = game.add_sprite("Race Car", SpritePreset::RacingCarGreen);

let initial_game_state = MyCustomGameStateStuff {
change_timer: Timer::from_seconds(1.0, true),
change_timer: Timer::from_seconds(1.0, TimerMode::Repeating),
turning: false,
};

Expand Down
18 changes: 11 additions & 7 deletions examples/keyboard_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use rusty_engine::prelude::*;

#[derive(Resource)]
struct GameState {}

fn main() {
let mut game = Game::new();

let mut race_car = game.add_sprite("Race Car", SpritePreset::RacingCarGreen);
let race_car = game.add_sprite("Race Car", SpritePreset::RacingCarGreen);
race_car.translation = Vec2::new(0.0, 0.0);
race_car.rotation = UP;
race_car.scale = 1.0;
Expand All @@ -17,19 +20,20 @@ fn main() {
text.translation.y = 250.0;

game.add_logic(logic);
game.run(());
game.run(GameState {});
}

fn logic(game_state: &mut Engine, _: &mut ()) {
fn logic(engine: &mut Engine, _: &mut GameState) {
// Get the race car sprite
let race_car = game_state.sprites.get_mut("Race Car").unwrap();
let race_car = engine.sprites.get_mut("Race Car").unwrap();

// Loop through any keyboard input that hasn't been processed this frame
for keyboard_event in &game_state.keyboard_events {
for keyboard_event in &engine.keyboard_events {
if let KeyboardInput {
scan_code: _,
key_code: Some(key_code),
state: ButtonState::Pressed,
window: _,
} = keyboard_event
{
// Handle various keypresses. The extra keys are for the Dvorak keyboard layout. ;-)
Expand All @@ -50,8 +54,8 @@ fn logic(game_state: &mut Engine, _: &mut ()) {

// Clamp the translation so that the car stays on the screen
race_car.translation = race_car.translation.clamp(
-game_state.window_dimensions * 0.5,
game_state.window_dimensions * 0.5,
-engine.window_dimensions * 0.5,
engine.window_dimensions * 0.5,
);
}
}
Expand Down
23 changes: 13 additions & 10 deletions examples/keyboard_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ use std::f32::consts::PI;

use rusty_engine::prelude::*;

#[derive(Resource)]
struct GameState {}

fn main() {
let mut game = Game::new();

let mut race_car = game.add_sprite("Race Car", SpritePreset::RacingCarGreen);
let race_car = game.add_sprite("Race Car", SpritePreset::RacingCarGreen);
race_car.translation = Vec2::new(0.0, 0.0);
race_car.rotation = UP;
race_car.scale = 1.0;
Expand All @@ -19,20 +22,20 @@ fn main() {
text.translation.y = 250.0;

game.add_logic(logic);
game.run(());
game.run(GameState {});
}

fn logic(game_state: &mut Engine, _: &mut ()) {
fn logic(engine: &mut Engine, _: &mut GameState) {
// Compute how fast we should move, rotate, and scale
let move_amount = 200.0 * game_state.delta_f32;
let rotation_amount = PI * game_state.delta_f32;
let scale_amount = 1.0 * game_state.delta_f32;
let move_amount = 200.0 * engine.delta_f32;
let rotation_amount = PI * engine.delta_f32;
let scale_amount = 1.0 * engine.delta_f32;

// Get the race car sprite
let race_car = game_state.sprites.get_mut("Race Car").unwrap();
let race_car = engine.sprites.get_mut("Race Car").unwrap();

// Handle keyboard input
let ks = &mut game_state.keyboard_state;
let ks = &mut engine.keyboard_state;
if ks.pressed_any(&[KeyCode::W, KeyCode::Up, KeyCode::Comma]) {
race_car.translation.y += move_amount;
}
Expand Down Expand Up @@ -67,7 +70,7 @@ fn logic(game_state: &mut Engine, _: &mut ()) {

// Clamp the translation so that the car stays on the screen
race_car.translation = race_car.translation.clamp(
-game_state.window_dimensions * 0.5,
game_state.window_dimensions * 0.5,
-engine.window_dimensions * 0.5,
engine.window_dimensions * 0.5,
);
}
7 changes: 5 additions & 2 deletions examples/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

use rusty_engine::prelude::*;

#[derive(Resource)]
struct GameState {}

fn main() {
let mut game = Game::new();

let mut layer = 0.0;
let preset_iterator = SpritePreset::variant_iter().peekable();
for (x, sprite_preset) in (-300..=600).step_by(30).zip(preset_iterator) {
let mut sprite = game.add_sprite(format!("{:?}", sprite_preset), sprite_preset);
let sprite = game.add_sprite(format!("{:?}", sprite_preset), sprite_preset);
sprite.translation = Vec2::new(x as f32, (-x) as f32);
sprite.layer = layer; // 0.0 is the bottom (back) layer. 999.0 is the top (front) layer.
layer += 1.0;
}

// We don't do anything after game setup, so our game logic can be an empty closure
game.run(());
game.run(GameState {});
}
10 changes: 6 additions & 4 deletions examples/level_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use rusty_engine::prelude::*;

#[derive(Resource)]
struct GameState {
current_label: String,
// Use an incrementing index (converted to a string) for the unique label of the sprites
Expand Down Expand Up @@ -77,7 +78,7 @@ Z - Print out Rust code of current level
let game_state = GameState::default();

// Get our first sprite onto the board
let mut curr_sprite = game.add_sprite("0".to_string(), SpritePreset::RacingCarRed);
let curr_sprite = game.add_sprite("0".to_string(), SpritePreset::RacingCarRed);
//curr_sprite.scale = 0.5;
curr_sprite.layer = MAX_LAYER;

Expand All @@ -98,14 +99,15 @@ fn logic(engine: &mut Engine, game_state: &mut GameState) {
scan_code: _,
key_code: Some(key_code),
state,
window: _,
} = keyboard_event
{
if *state == ButtonState::Pressed {
match key_code {
KeyCode::Z | KeyCode::Semicolon => {
print_level = true;
}
KeyCode::LShift | KeyCode::RShift => {
KeyCode::ShiftLeft | KeyCode::ShiftRight => {
game_state.shift_pressed = true;
}
KeyCode::R | KeyCode::P => {
Expand All @@ -127,7 +129,7 @@ fn logic(engine: &mut Engine, game_state: &mut GameState) {
}
} else {
match key_code {
KeyCode::LShift | KeyCode::RShift => {
KeyCode::ShiftLeft | KeyCode::ShiftRight => {
game_state.shift_pressed = false;
}
_ => {}
Expand All @@ -139,7 +141,7 @@ fn logic(engine: &mut Engine, game_state: &mut GameState) {
// Print out the level?
if print_level {
println!(
"---------------\n\nuse rusty_engine::prelude::*;\n\nstruct GameState {{}}\n\nfn main() {{\n let mut game = Game::new();\n"
"---------------\n\nuse rusty_engine::prelude::*;\n\n#[derive(Resource)]\nstruct GameState {{}}\n\nfn main() {{\n let mut game = Game::new();\n"
);
for sprite in engine.sprites.values() {
if sprite.label == game_state.current_label {
Expand Down
7 changes: 5 additions & 2 deletions examples/mouse_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use rusty_engine::prelude::*;

const ORIGIN_LOCATION: (f32, f32) = (0.0, -200.0);

#[derive(Resource)]
struct GameState {}

fn main() {
let mut game = Game::new();

Expand Down Expand Up @@ -35,10 +38,10 @@ fn main() {
msg2.translation.y = 275.0;

game.add_logic(logic);
game.run(());
game.run(GameState {});
}

fn logic(engine: &mut Engine, _: &mut ()) {
fn logic(engine: &mut Engine, _: &mut GameState) {
if let Some(sprite) = engine.sprites.get_mut("Race Car") {
// Use mouse button events to rotate. Every click rotates the sprite by a fixed amount
for mouse_button_input in &engine.mouse_button_events {
Expand Down
Loading