Finish the engine upgrade
Some checks failed
Basic checks / Basic build-and-test supertask (push) Failing after 2m1s
Some checks failed
Basic checks / Basic build-and-test supertask (push) Failing after 2m1s
Events have been replaced with Messages, import paths have been updated for new engine module layout, and minor API changes have been matched.
This commit is contained in:
2534
Cargo.lock
generated
2534
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ license = "AGPL-3.0-only"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.17"
|
||||
bevy-inspector-egui = "0.32"
|
||||
bevy-inspector-egui = "0.34"
|
||||
bevy_rapier2d = "0.32"
|
||||
rand = "0.9"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use bevy::color::Color;
|
||||
|
||||
pub const WINDOW_SIZE: bevy::prelude::Vec2 = bevy::prelude::Vec2::new(800.0, 600.0);
|
||||
pub const WINDOW_SIZE: (u32, u32) = (800, 600);
|
||||
|
||||
pub const UI_BUTTON_NORMAL: Color = Color::srgb(0.15, 0.15, 0.15); // Button color when it's just hanging out
|
||||
pub const UI_BUTTON_HOVERED: Color = Color::srgb(0.25, 0.25, 0.25); // ... when it's hovered
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
//! Compile-time configurables can be found in the [`config`] module.
|
||||
|
||||
pub mod config;
|
||||
mod messages;
|
||||
mod machinery;
|
||||
mod messages;
|
||||
mod objects;
|
||||
mod physics;
|
||||
mod resources;
|
||||
@@ -182,7 +182,7 @@ fn input_ship_shoot(
|
||||
|
||||
// If the weapon is ready and the player presses the trigger,
|
||||
// spawn a bullet & reset the timer.
|
||||
if weapon.finished() && keyboard_input.pressed(KeyCode::Space) {
|
||||
if weapon.is_finished() && keyboard_input.pressed(KeyCode::Space) {
|
||||
weapon.reset();
|
||||
// Derive bullet velocity, add to the ship's velocity
|
||||
let bullet_vel = (ship_pos.rotation * Vec3::X).xy() * BULLET_SPEED;
|
||||
|
||||
@@ -8,7 +8,12 @@ use std::time::Duration;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{WorldSize, messages::{AsteroidDestroy, SpawnAsteroid}, objects::AsteroidSize, resources::Score};
|
||||
use crate::{
|
||||
WorldSize,
|
||||
messages::{AsteroidDestroy, SpawnAsteroid},
|
||||
objects::AsteroidSize,
|
||||
resources::Score,
|
||||
};
|
||||
|
||||
/// Asteroid spawning parameters and state.
|
||||
///
|
||||
@@ -38,7 +43,7 @@ impl AsteroidSpawner {
|
||||
/// Update the asteroid spawn timer in the [`AsteroidSpawner`] resource, and
|
||||
/// spawns any asteroids that are due this frame.
|
||||
pub fn tick_asteroid_manager(
|
||||
mut events: EventWriter<SpawnAsteroid>,
|
||||
mut events: MessageWriter<SpawnAsteroid>,
|
||||
mut spawner: ResMut<AsteroidSpawner>,
|
||||
time: Res<Time>,
|
||||
play_area: Res<WorldSize>,
|
||||
@@ -140,7 +145,7 @@ pub fn operate_sparklers(sparklers: Query<(&mut Visibility, &mut Sparkler)>, tim
|
||||
///
|
||||
/// Refreshing the HUD element is done by [crate::widgets::operate_ui] (a private function)
|
||||
pub fn update_scoreboard(
|
||||
mut destroy_events: EventReader<AsteroidDestroy>,
|
||||
mut destroy_events: MessageReader<AsteroidDestroy>,
|
||||
mut scoreboard: ResMut<Score>,
|
||||
) {
|
||||
for _event in destroy_events.read() {
|
||||
|
||||
@@ -8,7 +8,7 @@ fn main() {
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
canvas: Some("#game-canvas".to_owned()),
|
||||
resolution: WindowResolution::new(WINDOW_SIZE.x, WINDOW_SIZE.y),
|
||||
resolution: WindowResolution::new(WINDOW_SIZE.0, WINDOW_SIZE.1),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//! Asteroids, the player's ship, and such.
|
||||
|
||||
use bevy::{
|
||||
camera::visibility::Visibility,
|
||||
ecs::{
|
||||
component::Component,
|
||||
entity::Entity,
|
||||
@@ -11,9 +12,9 @@ use bevy::{
|
||||
system::{Commands, Query, Res, ResMut, Single},
|
||||
},
|
||||
math::{Vec2, Vec3, Vec3Swizzles},
|
||||
mesh::Mesh2d,
|
||||
prelude::{Deref, DerefMut},
|
||||
render::{mesh::Mesh2d, view::Visibility},
|
||||
sprite::MeshMaterial2d,
|
||||
sprite_render::MeshMaterial2d,
|
||||
state::state::NextState,
|
||||
time::{Timer, TimerMode},
|
||||
transform::components::Transform,
|
||||
@@ -23,8 +24,8 @@ use bevy_rapier2d::prelude::{ActiveCollisionTypes, ActiveEvents, Collider, Senso
|
||||
use crate::{
|
||||
AngularVelocity, GameAssets, GameState, Lives,
|
||||
config::{ASTEROID_LIFETIME, DEBRIS_LIFETIME, SHIP_FIRE_RATE},
|
||||
messages::{AsteroidDestroy, BulletDestroy, ShipDestroy, SpawnAsteroid},
|
||||
machinery::{Lifetime, Sparkler},
|
||||
messages::{AsteroidDestroy, BulletDestroy, ShipDestroy, SpawnAsteroid},
|
||||
physics::{Velocity, Wrapping},
|
||||
};
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ pub(crate) fn wrap_entities(
|
||||
/// | Bullet & Bullet | Nothing. Bullets won't collide with each other (and probably can't under normal gameplay conditions) |
|
||||
/// | Bullet & Ship | Nothing. The player shouldn't be able to shoot themselves (and the Flying Saucer hasn't been impl.'d, so it's bullets don't count) |
|
||||
pub fn collision_listener(
|
||||
mut collisions: BufferedReader<CollisionEvent>,
|
||||
mut collisions: MessageReader<CollisionEvent>,
|
||||
mut ship_writer: MessageWriter<messages::ShipDestroy>,
|
||||
mut asteroid_writer: MessageWriter<messages::AsteroidDestroy>,
|
||||
mut bullet_writer: MessageWriter<messages::BulletDestroy>,
|
||||
|
||||
@@ -10,9 +10,9 @@ use bevy::{
|
||||
Vec2,
|
||||
primitives::{Circle, Triangle2d},
|
||||
},
|
||||
mesh::Mesh,
|
||||
prelude::{Deref, DerefMut, Reflect, ReflectResource},
|
||||
render::mesh::Mesh,
|
||||
sprite::ColorMaterial,
|
||||
sprite_render::ColorMaterial,
|
||||
};
|
||||
use bevy_inspector_egui::InspectorOptions;
|
||||
use bevy_inspector_egui::inspector_options::ReflectInspectorOptions;
|
||||
@@ -42,12 +42,14 @@ impl From<Lives> for String {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: consider switching this to use a u32 pair like the Window settings
|
||||
// thing now does.
|
||||
#[derive(Deref, DerefMut, Resource)]
|
||||
pub struct WorldSize(Vec2);
|
||||
|
||||
impl Default for WorldSize {
|
||||
fn default() -> Self {
|
||||
WorldSize(Vec2::new(WINDOW_SIZE.x, WINDOW_SIZE.y))
|
||||
WorldSize(Vec2::new(WINDOW_SIZE.0 as f32, WINDOW_SIZE.1 as f32))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ fn button_bundle(text: &str) -> impl Bundle {
|
||||
margin: UiRect::all(Val::Px(5.0)),
|
||||
..default()
|
||||
},
|
||||
BorderColor(Color::BLACK),
|
||||
BorderColor::all(Color::BLACK),
|
||||
BorderRadius::MAX,
|
||||
BackgroundColor(UI_BUTTON_NORMAL),
|
||||
children![(
|
||||
@@ -152,7 +152,7 @@ fn spawn_menu(mut commands: Commands) {
|
||||
cmds.spawn((
|
||||
Text::new("Robert's Bad Asteroids Game"),
|
||||
TextFont::from_font_size(50.0),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(Justify::Center),
|
||||
TextShadow::default(),
|
||||
));
|
||||
cmds.spawn((
|
||||
@@ -247,7 +247,7 @@ fn animate_get_ready_widget(
|
||||
bar_segment.width = Val::Percent(100.0 * (1.0 - timer.fraction()));
|
||||
|
||||
// If the timer has expired, change state to playing.
|
||||
if timer.finished() {
|
||||
if timer.is_finished() {
|
||||
game_state.set(GameState::Playing);
|
||||
}
|
||||
}
|
||||
@@ -274,14 +274,14 @@ fn operate_buttons(
|
||||
(Changed<Interaction>, With<Button>),
|
||||
>,
|
||||
mut game_state: ResMut<NextState<GameState>>,
|
||||
mut app_exit_events: EventWriter<AppExit>,
|
||||
mut app_exit_events: MessageWriter<AppExit>,
|
||||
) {
|
||||
// TODO: Better colors. These are taken from the example and they're ugly.
|
||||
for (interaction, mut color, mut border_color, menu_action) in &mut interactions {
|
||||
match *interaction {
|
||||
Interaction::Pressed => {
|
||||
*color = UI_BUTTON_PRESSED.into();
|
||||
border_color.0 = DARK_GRAY.into();
|
||||
border_color.set_all(DARK_GRAY);
|
||||
match menu_action {
|
||||
ButtonMenuAction::ToMainMenu => {
|
||||
game_state.set(GameState::TitleScreen);
|
||||
@@ -296,11 +296,11 @@ fn operate_buttons(
|
||||
}
|
||||
Interaction::Hovered => {
|
||||
*color = UI_BUTTON_HOVERED.into();
|
||||
border_color.0 = WHITE.into();
|
||||
border_color.set_all(WHITE);
|
||||
}
|
||||
Interaction::None => {
|
||||
*color = UI_BUTTON_NORMAL.into();
|
||||
border_color.0 = BLACK.into();
|
||||
border_color.set_all(BLACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user