Skip to content

Commit

Permalink
upgrade to Bevy 0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhu committed Dec 13, 2024
1 parent e6c1f4f commit afe5455
Show file tree
Hide file tree
Showing 39 changed files with 2,868 additions and 1,864 deletions.
2,523 changes: 2,088 additions & 435 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ version = "0.1.3"
edition = "2021"

[dependencies]
bevy_asset_loader = { version = "0.21.0", features = [
bevy_asset_loader = { version = "0.22.0", features = [
"2d",
"standard_dynamic_assets",
] }
bevy_kira_audio = { version = "0.20.0", features = ["ogg","mp3", "wav"] }
bevy_kira_audio = { version = "0.21.0", features = ["ogg","mp3", "wav"] }
rand = "0.9.0-alpha.2"
bevy-parallax = "0.10.0"
bevy_embedded_assets = "0.11.0"
bevy_prototype_lyon = "0.12.0"
#bevy-parallax = "0.10.0"
bevy_prototype_lyon = "0.13.0"
serde = "1.0.210"
serde_json = "1.0.128"
uuid = "1.11.0"
bevy_pkv = "0.11.1"
sys-locale = "0.3"
bevy_pkv = "0.12.0"
#sys-locale = "0.3"
#bevy_rapier2d = "0.27.0"
# Compile low-severity logs out of native builds for performance.
log = { version = "0.4", features = [
Expand All @@ -38,7 +36,7 @@ leafwing-input-manager = "0.15.1"
#bevy_common_assets = "0.11.0"

[dependencies.bevy]
version = "0.14.2"
version = "0.15.0"
# Disable the default features if there are any that you do not want
default-features = false
# https://docs.rs/crate/bevy/latest/features
Expand All @@ -61,6 +59,7 @@ features = [
"bevy_ui",
"wayland",#对Linux系统支持,也可以选择x11
#"bevy_winit",#启用wayland也就启动winit了
"bevy_window",
"default_font",
"hdr",
"multi_threaded",
Expand All @@ -75,7 +74,7 @@ features = [
# https://github.com/bevyengine/bevy/tree/main/examples#webgl2-and-webgpu
# https://github.com/jgayfer/bevy_light_2d/pull/7
"webgpu",
# "x11",
"x11",
]

[features]
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ ______

# 3. 开发指南
## 3.1 游戏引擎
Game Engine:[Bevy](https://bevyengine.org/)
- Game Engine:[Bevy](https://bevyengine.org/)
- 目前支持0.14.2和0.15.0两个版本的不同分支

## 3.2 游戏模板
- 使用`cargo generate thebevyflock/bevy_new_2d`生成的[bevy_new_2d 游戏模板](https://github.com/TheBevyFlock/bevy_new_2d)
-[ASCII Space Shooter](https://github.com/JamesHDuffield/ascii-rust)开源项目Copy核心逻辑代码
Expand Down
5 changes: 2 additions & 3 deletions src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
},
components::abilities::{AbilitiesResource, AbilityDescriptionsResource, ActivateAbilityEvent},
components::character::CharactersResource,
components::input::PlayerAction,
components::player::{InputRestrictionsAtSpawn, PlayersResource},
screens::AppStates,
};
Expand All @@ -30,10 +29,10 @@ use bevy_asset_loader::loading_state::LoadingState;
use bevy_asset_loader::prelude::{
ConfigureLoadingState, LoadingStateAppExt, StandardDynamicAssetCollection,
};
use leafwing_input_manager::prelude::InputManagerPlugin;
// use leafwing_input_manager::prelude::InputManagerPlugin;

pub(super) fn plugin(app: &mut App) {
app.add_plugins(InputManagerPlugin::<PlayerAction>::default());
// app.add_plugins(InputManagerPlugin::<PlayerAction>::default());
app.add_event::<ActivateAbilityEvent>();
app.add_loading_state(
LoadingState::new(AppStates::Loading)
Expand Down
14 changes: 7 additions & 7 deletions src/components/abilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ pub enum AbilitySlotIDComponent {
Two,
}
/// Component for tracking ability cooldowns
#[derive(Component, Deserialize, Clone)]
#[derive(Component, Clone)]
pub struct AbilityCooldownComponent {
/// Stored seperately so that it can used with the player's cooldown multiplier
/// Stored separately so that it can be used with the player's cooldown multiplier
/// to set the duration of the cooldown timer
pub base_cooldown_time: f32,
/// Tracks a cooldown for an ability
Expand Down Expand Up @@ -123,7 +123,7 @@ pub struct ChargeAbilityData {

/// Stores ability values unique to the charge ability
/// Which applies an external impulse and damage reduction to the player
#[derive(Component, Deserialize, Clone)]
#[derive(Component, Clone)]
pub struct ChargeAbilityComponent {
/// Tracks how long the player has been charging, stops charging when completed
pub action_timer: Timer,
Expand Down Expand Up @@ -158,7 +158,7 @@ struct ChargeAbilityComponentData {
/// Standard weapon bundle for spawning entity as a child of player component
#[derive(Bundle, Clone)]
pub struct StandardWeaponAbilityBundle {
/// Slot ID that that the ability occupies
/// Slot ID that the ability occupies
slot: AbilitySlotIDComponent,
/// Tracks cooldown time
cooldown: AbilityCooldownComponent,
Expand All @@ -180,7 +180,7 @@ impl From<&StandardWeaponAbilityData> for StandardWeaponAbilityBundle {
/// Stores minimum data required to instantiate
#[derive(Deserialize)]
pub struct StandardWeaponAbilityData {
/// Slot ID that that the ability occupies
/// Slot ID that the ability occupies
slot: AbilitySlotIDComponent,
/// Base cooldown duration, before player's multiplier
base_cooldown_time: f32,
Expand All @@ -206,8 +206,8 @@ pub struct StandardWeaponAbilityComponent {
pub despawn_time_multiplier: f32,
/// Multiplied by the player's projectile size to get size of fired projectile
pub size_multiplier: f32,
/// Multiplied by the the player's projectile_count and rounded to nearest integer
/// to get number of projetctiles fired
/// Multiplied by the player's projectile_count and rounded to nearest integer
/// to get number of projectiles fired
pub count_multiplier: f32,
/// Sound that plays when the ability is activated
pub sound: SoundEffectType,
Expand Down
6 changes: 3 additions & 3 deletions src/components/character.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::components::abilities::{SlotOneAbilityType, SlotTwoAbilityType};
use crate::components::health::HealthComponent;
use crate::components::health::Health;
use crate::components::spawnable::SpawnPosition;
use bevy::math::Vec2;
use bevy::prelude::Resource;
Expand Down Expand Up @@ -80,9 +80,9 @@ pub struct Character {
pub cooldown_multiplier: f32,
}

impl From<&Character> for HealthComponent {
impl From<&Character> for Health {
fn from(character: &Character) -> Self {
HealthComponent::new(
Health::new(
character.health,
character.shields,
character.shields_recharge_rate,
Expand Down
91 changes: 0 additions & 91 deletions src/components/enemies.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::components::input::ButtonActionType;
use crate::components::player::PlayerInput;
use bevy::prelude::{Entity, Event};

Expand All @@ -7,17 +6,6 @@ use bevy::prelude::{Entity, Event};
#[derive(Event)]
pub struct AnimationCompletedEvent(pub Entity);

#[derive(Event, Clone, PartialEq, Eq, Copy, Debug)]
pub struct ButtonActionEvent {
pub action: ButtonActionType,
}

impl From<ButtonActionType> for ButtonActionEvent {
fn from(value: ButtonActionType) -> Self {
ButtonActionEvent { action: value }
}
}

/// Stores the index (likely 0 or 1) of the player that joined an n-player game.
#[derive(Event)]
pub struct PlayerJoinEvent {
Expand Down
44 changes: 20 additions & 24 deletions src/components/health.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use crate::gameplay::effects::HitFlash;
use crate::gameplay::gamelogic::{DespawnWithScene, ExplodesOnDespawn, Targettable, WillTarget};
use crate::gameplay::gamelogic::{ExplodesOnDespawn, Targettable, WillTarget};
use crate::gameplay::physics::{Collider, Physics};
use crate::ship::engine::Engine;
use bevy::prelude::*;

// Bundles
#[derive(Bundle, Default)]
pub struct FighterBundle {
pub sprite: SpriteBundle,
pub physics: Physics,
pub engine: Engine,
pub health: HealthComponent,
pub collider: Collider,
pub targettable: Targettable,
pub will_target: WillTarget,
pub despawn_with_scene: DespawnWithScene,
pub explodes_on_despawn: ExplodesOnDespawn,
pub hit_flash: HitFlash,
}
#[derive(Component, Default)]
#[require(
Sprite,
Physics,
Engine,
Health,
Collider,
Targettable,
WillTarget,
ExplodesOnDespawn,
HitFlash
)]
pub struct Spacecraft;

#[derive(Component)]
pub struct Seeker(pub Entity);
Expand All @@ -26,7 +26,7 @@ pub struct Seeker(pub Entity);
pub struct Owner(pub Entity);

#[derive(Component)]
pub struct HealthComponent {
pub struct Health {
pub health: usize,
pub shields: usize,
pub max_health: usize,
Expand All @@ -36,19 +36,15 @@ pub struct HealthComponent {
pub shields_recharge_timer: Timer,
}

impl Default for HealthComponent {
impl Default for Health {
fn default() -> Self {
HealthComponent::new(100, 100, 2.0)
Health::new(100, 100, 2.0)
}
}

impl HealthComponent {
pub fn new(
max_health: usize,
max_shield: usize,
shields_recharge_rate: f32,
) -> HealthComponent {
HealthComponent {
impl Health {
pub fn new(max_health: usize, max_shield: usize, shields_recharge_rate: f32) -> Health {
Health {
health: max_health,
max_health,
shields: max_shield,
Expand Down
Loading

0 comments on commit afe5455

Please sign in to comment.