Skip to content

Commit

Permalink
Update to Rust 2024 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
ollej committed Feb 20, 2025
1 parent e94ae5d commit c8748a2
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
authors = ["Olle Wreede <olle@wreede.se>"]
edition = "2021"
edition = "2024"
name = "bunner-macroquad"
version = "0.5.0"
version = "0.6.0"

[dependencies]
macroquad = { version = "0.4", features = ["audio"] }
Expand Down
2 changes: 1 addition & 1 deletion src/active_row.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{child::Child, position::Position, WIDTH};
use crate::{WIDTH, child::Child, position::Position};
use macroquad::rand;

pub trait ActiveRow: Sized {
Expand Down
6 changes: 3 additions & 3 deletions src/bunner.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::{
child::Child, player_direction::PlayerDirection, player_state::PlayerState, position::Position,
resources::Resources, row::Row, splat::Splat, HEIGHT, WIDTH,
HEIGHT, WIDTH, child::Child, player_direction::PlayerDirection, player_state::PlayerState,
position::Position, resources::Resources, row::Row, splat::Splat,
};
use macroquad::{
audio::play_sound_once,
color::colors::WHITE,
experimental::collections::storage,
input::KeyCode,
texture::{draw_texture, Texture2D},
texture::{Texture2D, draw_texture},
};
use std::collections::VecDeque;

Expand Down
2 changes: 1 addition & 1 deletion src/car.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{actor::Actor, mover::Mover, position::Position, resources::Resources};
use macroquad::{
audio::play_sound_once,
prelude::{collections::storage, draw_texture, WHITE},
prelude::{WHITE, collections::storage, draw_texture},
rand::{self, ChooseRandom},
};
use std::collections::HashSet;
Expand Down
4 changes: 2 additions & 2 deletions src/dirt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
child::Child, position::Position, resources::Resources, road::Road, row::Row, water::Water,
ROW_HEIGHT,
ROW_HEIGHT, child::Child, position::Position, resources::Resources, road::Road, row::Row,
water::Water,
};
use macroquad::{audio::play_sound_once, prelude::collections::storage, rand, texture::Texture2D};

Expand Down
2 changes: 1 addition & 1 deletion src/drawing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::resources::Resources;
use macroquad::prelude::{collections::storage, draw_texture, WHITE};
use macroquad::prelude::{WHITE, collections::storage, draw_texture};

pub enum NumberAlign {
Left,
Expand Down
2 changes: 1 addition & 1 deletion src/eagle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{actor::Actor, position::Position, resources::Resources};
use macroquad::prelude::{collections::storage, draw_texture, WHITE};
use macroquad::prelude::{WHITE, collections::storage, draw_texture};

pub struct Eagle {
position: Position,
Expand Down
39 changes: 20 additions & 19 deletions src/game.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
actor::Actor, bunner::Bunner, eagle::Eagle, grass::Grass, player_state::PlayerState,
position::Position, resources::Resources, row::Row, row::RowSound, HEIGHT, ROW_HEIGHT,
HEIGHT, ROW_HEIGHT, actor::Actor, bunner::Bunner, eagle::Eagle, grass::Grass,
player_state::PlayerState, position::Position, resources::Resources, row::Row, row::RowSound,
};
use macroquad::{
audio::{play_sound, set_sound_volume, stop_sound, PlaySoundParams},
prelude::{clear_background, collections::storage, KeyCode, BLACK},
audio::{PlaySoundParams, play_sound, set_sound_volume, stop_sound},
prelude::{BLACK, KeyCode, clear_background, collections::storage},
rand::gen_range,
};
use std::collections::{HashMap, HashSet, VecDeque};
Expand All @@ -30,13 +30,16 @@ impl Game {
}

pub fn update(&mut self, input_queue: VecDeque<KeyCode>) {
if let Some(bunner) = &self.bunner {
// Scroll faster if the player is close to the top of the screen. Limit scroll speed to
// between 1 and 3 pixels per frame.
self.scroll_pos -=
1.max(3.min(self.scroll_pos + HEIGHT - bunner.position.y) / (HEIGHT / 4));
} else {
self.scroll_pos -= 1;
match &self.bunner {
Some(bunner) => {
// Scroll faster if the player is close to the top of the screen. Limit scroll speed to
// between 1 and 3 pixels per frame.
self.scroll_pos -=
1.max(3.min(self.scroll_pos + HEIGHT - bunner.position.y) / (HEIGHT / 4));
}
_ => {
self.scroll_pos -= 1;
}
}

// Remove rows that have scrolled past the bottom of the screen.
Expand Down Expand Up @@ -101,18 +104,16 @@ impl Game {
}

pub fn game_over(&self) -> bool {
if let Some(bunner) = &self.bunner {
bunner.state != PlayerState::Alive && bunner.timer < 0
} else {
false
match &self.bunner {
Some(bunner) => bunner.state != PlayerState::Alive && bunner.timer < 0,
_ => false,
}
}

pub fn score(&self) -> u32 {
if let Some(bunner) = &self.bunner {
0.max((-320 - bunner.min_y as i32) / 40) as u32
} else {
0
match &self.bunner {
Some(bunner) => 0.max((-320 - bunner.min_y as i32) / 40) as u32,
_ => 0,
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/global_state.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{
HEIGHT, WIDTH,
bunner::Bunner,
drawing::{display_number, NumberAlign, NumberColor},
drawing::{NumberAlign, NumberColor, display_number},
game::Game,
position::Position,
resources::Resources,
state::State,
HEIGHT, WIDTH,
};
use macroquad::{
audio::{play_sound, set_sound_volume, PlaySoundParams, Sound},
audio::{PlaySoundParams, Sound, play_sound, set_sound_volume},
color::colors::WHITE,
experimental::collections::storage,
input::KeyCode,
Expand Down
6 changes: 3 additions & 3 deletions src/grass.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
child::Child, hedge::Hedge, hedge_mask::HedgeMask, hedge_row::HedgeRow, hedge_tile::HedgeTile,
position::Position, resources::Resources, road::Road, row::Row, water::Water, ROW_HEIGHT,
WIDTH,
ROW_HEIGHT, WIDTH, child::Child, hedge::Hedge, hedge_mask::HedgeMask, hedge_row::HedgeRow,
hedge_tile::HedgeTile, position::Position, resources::Resources, road::Road, row::Row,
water::Water,
};
use macroquad::{audio::play_sound_once, prelude::collections::storage, rand, texture::Texture2D};

Expand Down
6 changes: 3 additions & 3 deletions src/hedge.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
actor::Actor, hedge_row::HedgeRow, hedge_tile::HedgeTile, position::Position,
resources::Resources, TILE_WIDTH,
TILE_WIDTH, actor::Actor, hedge_row::HedgeRow, hedge_tile::HedgeTile, position::Position,
resources::Resources,
};
use macroquad::prelude::{collections::storage, draw_texture, WHITE};
use macroquad::prelude::{WHITE, collections::storage, draw_texture};

#[derive(Clone)]
pub struct Hedge {
Expand Down
8 changes: 2 additions & 6 deletions src/log.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{actor::Actor, mover::Mover, position::Position, resources::Resources};
use macroquad::{
prelude::{collections::storage, draw_texture, WHITE},
prelude::{WHITE, collections::storage, draw_texture},
rand::gen_range,
};

Expand Down Expand Up @@ -45,11 +45,7 @@ impl Actor for Log {
}

fn width(&self) -> i32 {
if self.image_index == 0 {
84
} else {
138
}
if self.image_index == 0 { 84 } else { 138 }
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

use macroquad::{
audio::{self, Sound},
input::{is_key_pressed, utils::*, KeyCode},
input::{KeyCode, is_key_pressed, utils::*},
time::get_frame_time,
window::{next_frame, Conf},
window::{Conf, next_frame},
};

use bunner_macroquad::{
global_state::GlobalState, resources::Resources, FPS_120, FPS_30, FPS_60, HEIGHT, TITLE, WIDTH,
FPS_30, FPS_60, FPS_120, HEIGHT, TITLE, WIDTH, global_state::GlobalState, resources::Resources,
};

use std::error;
Expand Down
2 changes: 1 addition & 1 deletion src/pavement.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{child::Child, resources::Resources, road::Road, row::Row, ROW_HEIGHT};
use crate::{ROW_HEIGHT, child::Child, resources::Resources, road::Road, row::Row};
use macroquad::{audio::play_sound_once, prelude::collections::storage, texture::Texture2D};

#[derive(Clone)]
Expand Down
4 changes: 2 additions & 2 deletions src/rail.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
child::Child, player_state::PlayerState, position::Position, resources::Resources, road::Road,
row::Row, train::Train, water::Water, HEIGHT, ROW_HEIGHT, WIDTH,
HEIGHT, ROW_HEIGHT, WIDTH, child::Child, player_state::PlayerState, position::Position,
resources::Resources, road::Road, row::Row, train::Train, water::Water,
};

use macroquad::{
Expand Down
4 changes: 2 additions & 2 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// The file naming actually helps, since "map" textures don't have an index.

use macroquad::{
audio::{self, load_sound, Sound},
prelude::{collections::storage, coroutines::start_coroutine, load_texture, Texture2D, *},
audio::{self, Sound, load_sound},
prelude::{Texture2D, collections::storage, coroutines::start_coroutine, load_texture, *},
};
use std::error;

Expand Down
7 changes: 4 additions & 3 deletions src/road.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
active_row::ActiveRow, actor::Actor, car::Car, car::CarSound, car::TrafficSound, child::Child,
grass::Grass, mover::Mover, pavement::Pavement, player_state::PlayerState, position::Position,
rail::Rail, resources::Resources, row::Row, row::RowSound, ROW_HEIGHT, WIDTH,
ROW_HEIGHT, WIDTH, active_row::ActiveRow, actor::Actor, car::Car, car::CarSound,
car::TrafficSound, child::Child, grass::Grass, mover::Mover, pavement::Pavement,
player_state::PlayerState, position::Position, rail::Rail, resources::Resources, row::Row,
row::RowSound,
};

use macroquad::{
Expand Down
4 changes: 2 additions & 2 deletions src/row.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{child::Child, player_state::PlayerState, position::Position, WIDTH};
use crate::{WIDTH, child::Child, player_state::PlayerState, position::Position};
use macroquad::{
color::colors::WHITE,
texture::{draw_texture, Texture2D},
texture::{Texture2D, draw_texture},
};

pub trait Row {
Expand Down
2 changes: 1 addition & 1 deletion src/splat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
actor::Actor, player_direction::PlayerDirection, position::Position, resources::Resources,
};
use macroquad::prelude::{collections::storage, draw_texture, WHITE};
use macroquad::prelude::{WHITE, collections::storage, draw_texture};

#[derive(Clone)]
pub struct Splat {
Expand Down
2 changes: 1 addition & 1 deletion src/train.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{actor::Actor, position::Position, resources::Resources};
use macroquad::{
prelude::{collections::storage, draw_texture, WHITE},
prelude::{WHITE, collections::storage, draw_texture},
rand::ChooseRandom,
};

Expand Down
4 changes: 2 additions & 2 deletions src/water.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
active_row::ActiveRow, child::Child, dirt::Dirt, log::Log, player_state::PlayerState,
position::Position, resources::Resources, row::Row, row::RowSound, ROW_HEIGHT, WIDTH,
ROW_HEIGHT, WIDTH, active_row::ActiveRow, child::Child, dirt::Dirt, log::Log,
player_state::PlayerState, position::Position, resources::Resources, row::Row, row::RowSound,
};
use macroquad::{
audio::play_sound_once,
Expand Down

0 comments on commit c8748a2

Please sign in to comment.