diff --git a/src/entity/dropped_item.rs b/src/entity/dropped_item.rs index 8d39d5c5..d907fdb1 100644 --- a/src/entity/dropped_item.rs +++ b/src/entity/dropped_item.rs @@ -8,7 +8,6 @@ use bevy::core::FrameCount; use bevy::prelude::*; use bevy_aseprite_ultra::prelude::*; use bevy_rapier2d::prelude::*; -use rand::random; #[derive(Component)] pub struct DroppedItemEntity { @@ -27,12 +26,9 @@ struct InteractionMarker; pub fn spawn_dropped_item( commands: &mut Commands, assets: &Res, - x: f32, - y: f32, + position: Vec2, item_type: InventoryItem, ) { - let tx = x; - let ty = y; let icon = match item_type { InventoryItem::Spell(spell) => { let props = spell_to_props(spell); @@ -85,11 +81,7 @@ pub fn spawn_dropped_item( }, EntityDepth, InheritedVisibility::default(), - Transform::from_translation(Vec3::new( - tx + (random::() - 0.5) * 16.0, - ty + (random::() - 0.5) * 16.0, - 0.0, - )), + Transform::from_translation(Vec3::new(position.x, position.y, 0.0)), GlobalTransform::default(), LockedAxes::ROTATION_LOCKED, RigidBody::Dynamic, diff --git a/src/inventory_item.rs b/src/inventory_item.rs index 2ceabe20..e61eb10b 100644 --- a/src/inventory_item.rs +++ b/src/inventory_item.rs @@ -46,8 +46,7 @@ pub fn spawn_inventory_item( spawn_dropped_item( &mut commands, &assets, - position.x, - position.y, + position, InventoryItem::Spell(spell), ); } @@ -55,8 +54,7 @@ pub fn spawn_inventory_item( spawn_dropped_item( &mut commands, &assets, - position.x, - position.y, + position, InventoryItem::Wand(wand_type), ); } @@ -64,8 +62,7 @@ pub fn spawn_inventory_item( spawn_dropped_item( &mut commands, &assets, - position.x, - position.y, + position, InventoryItem::Equipment(equipment_type), ); } diff --git a/src/level.rs b/src/level.rs index 2a62c21b..96c446d6 100644 --- a/src/level.rs +++ b/src/level.rs @@ -30,7 +30,9 @@ use crate::level::map::LevelTileMap; use crate::level::tile::*; use crate::player_state::PlayerState; use crate::random::random_select; +use crate::random::random_select_mut; use crate::spell::SpellType; +use crate::spell::SPELL_TYPES; use crate::states::GameState; use crate::wand::WandType; use bevy::asset::*; @@ -91,7 +93,7 @@ fn setup_level( level, ); - let entry_point = random_select(&mut chunk.entry_points); + let entry_point = random_select_mut(&mut chunk.entry_points); let player_x = TILE_SIZE * entry_point.x as f32 + TILE_HALF; let player_y = -TILE_SIZE * entry_point.y as f32 - TILE_HALF; @@ -208,9 +210,9 @@ fn spawn_level( spawn_entities(&mut commands, &assets, &chunk); - if 20 < empties.len() { + if 30 < empties.len() { for _ in 0..10 { - let (x, y) = random_select(&mut empties); + let (x, y) = random_select_mut(&mut empties); spawn_slime( &mut commands, &assets, @@ -223,7 +225,7 @@ fn spawn_level( } for _ in 0..10 { - let (x, y) = random_select(&mut empties); + let (x, y) = random_select_mut(&mut empties); spawn_eyeball( &mut commands, &assets, @@ -234,6 +236,20 @@ fn spawn_level( &life_bar_res, ); } + + let mut spells = Vec::from(SPELL_TYPES); + for _ in 0..3 { + let (x, y) = random_select_mut(&mut empties); + spawn_dropped_item( + &mut commands, + &assets, + Vec2::new( + TILE_SIZE * x as f32 + TILE_HALF, + TILE_SIZE * -y as f32 - TILE_HALF, + ), + InventoryItem::Spell(*random_select(&mut spells)), + ); + } } return chunk; @@ -404,8 +420,7 @@ fn spawn_entities(mut commands: &mut Commands, assets: &Res, chunk: spawn_dropped_item( &mut commands, &assets, - tx + TILE_HALF, - ty - TILE_HALF, + Vec2::new(tx + TILE_HALF, ty - TILE_HALF), InventoryItem::Spell(SpellType::MagicBolt), ); } @@ -413,8 +428,7 @@ fn spawn_entities(mut commands: &mut Commands, assets: &Res, chunk: spawn_dropped_item( &mut commands, &assets, - tx + TILE_HALF, - ty - TILE_HALF, + Vec2::new(tx + TILE_HALF, ty - TILE_HALF), InventoryItem::Wand(WandType::CypressWand), ); } diff --git a/src/random.rs b/src/random.rs index ff0e4186..2683a700 100644 --- a/src/random.rs +++ b/src/random.rs @@ -1,3 +1,8 @@ -pub fn random_select(xs: &mut Vec) -> T { +pub fn random_select_mut(xs: &mut Vec) -> T { xs.remove((rand::random::() % xs.len()) as usize) } + +pub fn random_select(xs: &Vec) -> &T { + xs.get((rand::random::() % xs.len()) as usize) + .unwrap() +} diff --git a/src/spell.rs b/src/spell.rs index ced65db2..5b12e447 100644 --- a/src/spell.rs +++ b/src/spell.rs @@ -10,3 +10,15 @@ pub enum SpellType { TripleCast, Homing, } + +pub const SPELL_TYPES: [SpellType; 9] = [ + SpellType::MagicBolt, + SpellType::PurpleBolt, + SpellType::SlimeCharge, + SpellType::Heal, + SpellType::BulletSpeedUp, + SpellType::BulletSpeedDoown, + SpellType::DualCast, + SpellType::TripleCast, + SpellType::Homing, +]; diff --git a/src/spell_props.rs b/src/spell_props.rs index e857e0ed..c3df9d55 100644 --- a/src/spell_props.rs +++ b/src/spell_props.rs @@ -164,10 +164,10 @@ const BULLET_SPEED_DOWN: SpellProps = SpellProps { const DUAL_CAST: SpellProps = SpellProps { name: Dict { - ja: "二重呪文", + ja: "並列詠唱", en: "Dual Cast", }, - description: Dict { ja: "ふたつの投射物呪文を同時に詠唱します。", + description: Dict { ja: "ふたつの投射物呪文を同時に詠唱します。詠唱遅延は大きいほうに揃えられます。", en: "Casts two projectile spells at the same time." }, mana_drain: 20, cast_delay: 0, @@ -177,7 +177,7 @@ const DUAL_CAST: SpellProps = SpellProps { const TRIPLE_CAST: SpellProps = SpellProps { name: Dict { - ja: "三重呪文", + ja: "三並列詠唱", en: "Triple Cast", }, description: Dict { ja: "みっつの投射物呪文を同時に詠唱します。", diff --git a/src/ui/inventory.rs b/src/ui/inventory.rs index 7b3a583a..9fe0eea3 100644 --- a/src/ui/inventory.rs +++ b/src/ui/inventory.rs @@ -209,8 +209,7 @@ fn interaction( spawn_dropped_item( &mut commands, &assets, - player_position.translation.x, - player_position.translation.y, + player_position.translation.truncate(), InventoryItem::Spell(spell), ); } diff --git a/src/ui/wand_editor.rs b/src/ui/wand_editor.rs index 87d2a712..53f6e274 100644 --- a/src/ui/wand_editor.rs +++ b/src/ui/wand_editor.rs @@ -173,8 +173,7 @@ fn drop_item( spawn_dropped_item( &mut commands, &assets, - dest.x, - dest.y, + dest, InventoryItem::Spell(spell), ); } @@ -182,8 +181,7 @@ fn drop_item( spawn_dropped_item( &mut commands, &assets, - dest.x, - dest.y, + dest, InventoryItem::Wand(wand.wand_type), ); actor.wands[index] = None; @@ -196,8 +194,7 @@ fn drop_item( spawn_dropped_item( &mut commands, &assets, - pointer_in_world.x, - pointer_in_world.y, + pointer_in_world, InventoryItem::Spell(spell), ); wand.slots[spell_index] = None;