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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ run. Return `false` to abort running any later functions during the frame.
`fn somename(engine_state: &mut EngineState, game_state: &mut GameState) -> bool`, where `GameState`
is the user-defined struct passed to `rusty_engine::init!()`, or `()` if nothing was passed in.
- `.play_sfx()` now takes a volume level from `0.0` to `1.0` as a second argument, e.g. `.play_sfx(SfxPreset::Congratulations, 1.0)`
- `TextActor` has been renamed to `Text` to eliminate the confusing "actor" terminology.
`TextActor::text` is now `Text::value` for similar reasons.

### Other Changes

- `AudioManager::music_playing()` will return whether or not music is currently playing (accessible
through `EngineState:audio_manager`)
- Custom fonts may now be set on a `TextActor` at creation time.
`EngineState::add_text_actor_with_font` was added for a convenience. The font specified should be
- Custom fonts may now be set on a `Text` at creation time.
`EngineState::add_text_with_font` was added for a convenience. The font specified should be
a `.ttf` or `.otf` file stored in `assets/fonts`
- Custom sounds may now be played via `AudioManager::play_music` and `AudioManager::play_sfx` by
specifying a path to a sound file relative to `assets/audio`.
Expand Down
12 changes: 6 additions & 6 deletions examples/collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ROTATION_SPEED: f32 = 3.0;
fn main() {
let mut game = Game::new();

let msg2 = game.add_text_actor(
let msg2 = game.add_text(
"instructions",
"Move the car around with your mouse. Rotate it by holding left/right mouse buttons. Scale it with the mousewheel.",
);
Expand All @@ -33,8 +33,8 @@ fn main() {
}
}

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

game.add_logic(logic);
game.run(());
Expand All @@ -43,14 +43,14 @@ fn main() {
fn logic(engine_state: &mut EngineState, _: &mut ()) -> bool {
// If a collision event happened last frame, print it out and play a sound
for event in engine_state.collision_events.drain(..) {
let text_actor = engine_state.text_actors.get_mut("collision text").unwrap();
let text = engine_state.texts.get_mut("collision text").unwrap();
match event.state {
CollisionState::Begin => {
text_actor.text = format!("{:?}", event.pair);
text.value = format!("{:?}", event.pair);
engine_state.audio_manager.play_sfx(SfxPreset::Switch1, 1.0)
}
CollisionState::End => {
text_actor.text = "".into();
text.value = "".into();
engine_state.audio_manager.play_sfx(SfxPreset::Switch2, 1.0)
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/keyboard_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
race_car.scale = 1.0;

let instructions = "Discrete Movement with Keyboard Events\n==============================\nChange translation (move): w a s d / arrows\nChange Rotation: z c\nChange Scale: + -";
let text = game.add_text_actor("instructions", instructions);
let text = game.add_text("instructions", instructions);
text.translation.y = 250.0;

game.add_logic(logic);
Expand Down
2 changes: 1 addition & 1 deletion examples/keyboard_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
race_car.scale = 1.0;

let instructions = "Smooth movement with KeyboardState Example\n====================================\nChange translation (move): w a s d / arrows\nChange Rotation: z c\nChange Scale: + -";
let text = game.add_text_actor("instructions", instructions);
let text = game.add_text("instructions", instructions);
text.translation.y = 250.0;

game.add_logic(logic);
Expand Down
4 changes: 2 additions & 2 deletions examples/mouse_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ fn main() {
anchor.translation = ORIGIN_LOCATION.into();
anchor.layer = 0.0;

let msg = game.add_text_actor("relative message", "Relative Mouse Motion Indicator");
let msg = game.add_text("relative message", "Relative Mouse Motion Indicator");
msg.translation.y = -300.0;
msg.font_size = 20.0;

let msg2 = game.add_text_actor(
let msg2 = game.add_text(
"instructions",
"Discrete Movement with Mouse Events\n==============================\nMove the car around with your mouse.\nRotate it by clicking left/right mouse buttons.\nScale it with the mousewheel.",
);
Expand Down
4 changes: 2 additions & 2 deletions examples/mouse_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ fn main() {
anchor.translation = ORIGIN_LOCATION.into();
anchor.layer = 0.0;

let msg = game.add_text_actor("relative message", "Relative Mouse Motion Indicator");
let msg = game.add_text("relative message", "Relative Mouse Motion Indicator");
msg.translation.y = -300.0;
msg.font_size = 20.0;

let msg2 = game.add_text_actor(
let msg2 = game.add_text(
"instructions",
"Smooth Movement with Mouse State\n==============================\nMove the car around with your mouse.\nRotate it by holding left/right mouse buttons.\nScale it with the mousewheel.",
);
Expand Down
4 changes: 2 additions & 2 deletions examples/music.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ rusty_engine::init!();

fn main() {
let mut game = Game::new();
let msg = game.add_text_actor(
let msg = game.add_text(
"msg",
"You can play looping music presets that are included in the asset pack. For example:",
);
msg.translation.y = 50.0;

let msg2 = game.add_text_actor_with_font(
let msg2 = game.add_text_with_font(
"msg2",
"engine_state.audio_manager.play_music(MusicPreset::Classy8Bit, 1.0);",
"FiraMono-Medium.ttf",
Expand Down
6 changes: 3 additions & 3 deletions examples/music_sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rusty_engine::init!(GameState);

fn main() {
let mut game = Game::new();
let msg = game.add_text_actor(
let msg = game.add_text(
"msg",
"Press any key to advance to the next music selection.\n\nIf you are not running with \"--release\", it may take several seconds for each song to load!",
);
Expand Down Expand Up @@ -36,8 +36,8 @@ fn logic(engine_state: &mut EngineState, game_state: &mut GameState) -> bool {
.nth(game_state.music_index)
.unwrap();
engine_state.audio_manager.play_music(music_preset, 1.0);
// And make a text actor saying what song we're playing
let note1 = engine_state.add_text_actor("note1", format!("Looping: {:?}", music_preset));
// And make text saying what song we're playing
let note1 = engine_state.add_text("note1", format!("Looping: {:?}", music_preset));
note1.font_size = 75.0;
}
true
Expand Down
6 changes: 3 additions & 3 deletions examples/scenarios/car_shoot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() {
for i in 0..25 {
game_state.cars_left.push(i);
}
let cars_left = game.add_text_actor("cars left", "Cars left: 25");
let cars_left = game.add_text("cars left", "Cars left: 25");
cars_left.translation = Vec2::new(540.0, -320.0);

game.add_logic(game_logic);
Expand Down Expand Up @@ -119,8 +119,8 @@ fn game_logic(engine_state: &mut EngineState, game_state: &mut GameState) -> boo
game_state.spawn_timer = Timer::from_seconds(thread_rng().gen_range(0.1..1.25), false);
// Get the next car
if let Some(i) = game_state.cars_left.pop() {
let cars_left = engine_state.text_actors.get_mut("cars left").unwrap();
cars_left.text = format!("Cars left: {}", i);
let cars_left = engine_state.texts.get_mut("cars left").unwrap();
cars_left.value = format!("Cars left: {}", i);
let label = format!("car{}", i);
let car_choices = vec![
RacingCarBlack,
Expand Down
10 changes: 5 additions & 5 deletions examples/scenarios/extreme_drivers_ed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ fn main() {
game.audio_manager.play_music(MusicPreset::Classy8Bit, 0.5);

// Stuff used to keep and display score
let score_text = game.add_text_actor("score_text", "Score: 0");
let score_text = game.add_text("score_text", "Score: 0");
score_text.translation = Vec2::new(-10.0, 82.0);
score_text.font_size = 24.0;

Expand All @@ -833,7 +833,7 @@ const TURN_RATE: f32 = 3.0;
const ACCELERATION_RATE: f32 = 100.0;

fn logic(engine_state: &mut EngineState, game_state: &mut GameState) -> bool {
let score_text = engine_state.text_actors.get_mut("score_text").unwrap();
let score_text = engine_state.texts.get_mut("score_text").unwrap();

// if game_state.won {
// for actor in game_state.actors.values_mut() {
Expand Down Expand Up @@ -917,7 +917,7 @@ fn logic(engine_state: &mut EngineState, game_state: &mut GameState) -> bool {
.audio_manager
.play_sfx(SfxPreset::Confirmation1, 1.0);
game_state.score += 1;
score_text.text = format!("Score: {}", game_state.score);
score_text.value = format!("Score: {}", game_state.score);
if game_state.score >= game_state.win_amount {
game_state.won = true;
}
Expand All @@ -926,7 +926,7 @@ fn logic(engine_state: &mut EngineState, game_state: &mut GameState) -> bool {

// Crash!
game_state.crashed = true;
//game_state.add_text_actor("crashed", "You crashed. You fail. :-(");
//game_state.add_text("crashed", "You crashed. You fail. :-(");
engine_state.audio_manager.play_sfx(SfxPreset::Jingle3, 1.0);
engine_state.audio_manager.stop_music();
}
Expand All @@ -935,7 +935,7 @@ fn logic(engine_state: &mut EngineState, game_state: &mut GameState) -> bool {
engine_state
.audio_manager
.play_sfx(SfxPreset::Congratulations, 1.0);
let mut you_win = engine_state.add_text_actor("you win", "You Win!");
let mut you_win = engine_state.add_text("you win", "You Win!");
you_win.font_size = 120.0;
you_win.translation.y = -50.0;
}
Expand Down
8 changes: 4 additions & 4 deletions examples/scenarios/road_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
}

// Create the health message
let health_message = game.add_text_actor("health_message", "Health: 5");
let health_message = game.add_text("health_message", "Health: 5");
health_message.translation = Vec2::new(550.0, 320.0);

game.add_logic(game_ends);
Expand Down Expand Up @@ -117,20 +117,20 @@ fn game_logic(engine_state: &mut EngineState, game_state: &mut GameState) -> boo
}

// Deal with collisions
let health_message = engine_state.text_actors.get_mut("health_message").unwrap();
let health_message = engine_state.texts.get_mut("health_message").unwrap();
for event in engine_state.collision_events.drain(..) {
// We don't care if obstacles collide with each other or collisions end
if !event.pair.either_contains("player1") || event.state.is_end() {
continue;
}
if game_state.health_amount > 0 {
game_state.health_amount -= 1;
health_message.text = format!("Health: {}", game_state.health_amount);
health_message.value = format!("Health: {}", game_state.health_amount);
engine_state.audio_manager.play_sfx(SfxPreset::Impact3, 0.5);
}
}
if game_state.health_amount == 0 {
let game_over = engine_state.add_text_actor("game over", "Game Over");
let game_over = engine_state.add_text("game over", "Game Over");
game_over.font_size = 128.0;
engine_state.audio_manager.stop_music();
engine_state.audio_manager.play_sfx(SfxPreset::Jingle3, 0.5);
Expand Down
4 changes: 2 additions & 2 deletions examples/sfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ rusty_engine::init!();

fn main() {
let mut game = Game::new();
let msg = game.add_text_actor(
let msg = game.add_text(
"msg",
"You can play sound effect presets that are included in the asset pack. For example:",
);
msg.translation.y = 50.0;

let msg2 = game.add_text_actor_with_font(
let msg2 = game.add_text_with_font(
"msg2",
"engine_state.audio_manager.play_sfx(SfxPreset::Jingle1, 1.0);",
"FiraMono-Medium.ttf",
Expand Down
12 changes: 6 additions & 6 deletions examples/sfx_sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ fn main() {
game_state.end_timer =
Timer::from_seconds((SfxPreset::variant_iter().len() as f32) * 2.0 + 1.0, false);

let mut msg = game.add_text_actor("msg", "Playing sound effects!");
let mut msg = game.add_text("msg", "Playing sound effects!");
msg.translation = Vec2::new(0.0, 100.0);
msg.font_size = 60.0;

let mut sfx_label = game.add_text_actor("sfx_label", "");
let mut sfx_label = game.add_text("sfx_label", "");
sfx_label.translation = Vec2::new(0.0, -100.0);
sfx_label.font_size = 90.0;

Expand All @@ -43,8 +43,8 @@ fn logic(engine_state: &mut EngineState, game_state: &mut GameState) -> bool {
let sfx = SfxPreset::variant_iter().nth(i).unwrap();
engine_state.audio_manager.play_sfx(sfx, 1.0);
// Update the text to show which sound effect we are playing
let sfx_label = engine_state.text_actors.get_mut("sfx_label").unwrap();
sfx_label.text = format!("{:?}", sfx);
let sfx_label = engine_state.texts.get_mut("sfx_label").unwrap();
sfx_label.value = format!("{:?}", sfx);
}
}

Expand All @@ -54,8 +54,8 @@ fn logic(engine_state: &mut EngineState, game_state: &mut GameState) -> bool {
.tick(engine_state.delta)
.just_finished()
{
let sfx_label = engine_state.text_actors.get_mut("sfx_label").unwrap();
sfx_label.text = "That's all! Press Esc to quit.".into();
let sfx_label = engine_state.texts.get_mut("sfx_label").unwrap();
sfx_label.value = "That's all! Press Esc to quit.".into();
}
true
}
4 changes: 2 additions & 2 deletions examples/sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ rusty_engine::init!();

fn main() {
let mut game = Game::new();
let msg = game.add_text_actor(
let msg = game.add_text(
"msg",
"You can add your own sound files to the assets/audio directory (or its\nsubdirectories) and play them by relative path. For example:",
);
msg.translation.y = 100.0;

let msg2 = game.add_text_actor_with_font(
let msg2 = game.add_text_with_font(
"msg2",
"engine_state.audio_manager.play_sfx(\"sfx/congratulations.ogg\", 1.0);",
"FiraMono-Medium.ttf",
Expand Down
6 changes: 3 additions & 3 deletions examples/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ fn main() {
let mut actor = game.add_actor(&actor_string, actor_preset);
actor.translation = Vec2::new(x as f32, (-y) as f32);

let mut text_actor = game.add_text_actor(&actor_string, &actor_string);
text_actor.translation = Vec2::new(x as f32, (-y - 75) as f32);
text_actor.font_size = 22.0;
let mut text = game.add_text(&actor_string, &actor_string);
text.translation = Vec2::new(x as f32, (-y - 75) as f32);
text.font_size = 22.0;
}
}

Expand Down
18 changes: 9 additions & 9 deletions examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ rusty_engine::init!(GameState);

fn main() {
let mut game = Game::new();
let fps = game.add_text_actor_with_font("fps", "FPS: ", "FiraMono-Medium.ttf");
let fps = game.add_text_with_font("fps", "FPS: ", "FiraMono-Medium.ttf");
fps.translation = Vec2::new(0.0, 250.0);
fps.font_size = 60.0;

let zoom_msg = game.add_text_actor(
let zoom_msg = game.add_text(
"zoom_msg",
"Changing font size re-renders the text smoothly at a different size,\nbut using this technique for animation is both jittery (character kerning) and expensive.",
);
zoom_msg.font_size = 35.0;
zoom_msg.translation = Vec2::new(0.0, 150.0);

let font_msg = game.add_text_actor_with_font(
let font_msg = game.add_text_with_font(
"font_msg",
"You can choose a font at creation time by providing the filename of a font stored in assets/fonts.\n\"FiraSans-Bold.ttf\" is the default. \"FiraMono-Medium.ttf\" is also included in the asset pack.",
"FiraMono-Medium.ttf",
);
font_msg.font_size = 20.0;
font_msg.translation.y = 0.0;

let msg = game.add_text_actor("msg", "Changing the text's translation, rotation*, and scale* is fast,\n so feel free to do that a lot.");
let msg = game.add_text("msg", "Changing the text's translation, rotation*, and scale* is fast,\n so feel free to do that a lot.");
msg.font_size = 24.0;
msg.translation.y = -150.0;

let msg2 = game.add_text_actor("msg2", "*Changing rotation and scale will not work until Bevy 0.6 is released,\nbut changing the translation works great already!");
let msg2 = game.add_text("msg2", "*Changing rotation and scale will not work until Bevy 0.6 is released,\nbut changing the translation works great already!");
msg2.font_size = 20.0;

let game_state = GameState {
Expand All @@ -43,15 +43,15 @@ fn main() {

fn game_logic(engine_state: &mut EngineState, game_state: &mut GameState) -> bool {
if game_state.timer.tick(engine_state.delta).just_finished() {
let mut fps = engine_state.text_actors.get_mut("fps").unwrap();
fps.text = format!("FPS: {:.1}", 1.0 / engine_state.delta_f32);
let mut fps = engine_state.texts.get_mut("fps").unwrap();
fps.value = format!("FPS: {:.1}", 1.0 / engine_state.delta_f32);
}

let msg2 = engine_state.text_actors.get_mut("msg2").unwrap();
let msg2 = engine_state.texts.get_mut("msg2").unwrap();
msg2.translation.x = 50.0 * (engine_state.time_since_startup_f64 * 0.5).sin() as f32;
msg2.translation.y = 50.0 * (engine_state.time_since_startup_f64 * 0.5).cos() as f32 - 275.0;

let msg3 = engine_state.text_actors.get_mut("zoom_msg").unwrap();
let msg3 = engine_state.texts.get_mut("zoom_msg").unwrap();
msg3.font_size = 10.0 * (engine_state.time_since_startup_f64 * 0.5).cos() as f32 + 25.0;
true
}
1 change: 0 additions & 1 deletion examples/transform.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//
use rusty_engine::prelude::*;

rusty_engine::init!();
Expand Down
2 changes: 1 addition & 1 deletion examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
cursor_visible: false,
..Default::default() // for the rest of the options, see https://docs.rs/bevy/0.5.0/bevy/window/struct.WindowDescriptor.html
});
let _ = game.add_text_actor(
let _ = game.add_text(
"message",
"This is a heavily-customized window.\nYou may resize it a little bit.\nPress Esc to exit.",
);
Expand Down
Loading