Skip to content

Commit

Permalink
Fix various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 26, 2024
1 parent 779ed34 commit 51521e8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
24 changes: 12 additions & 12 deletions assets/config/actor.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
),
sprite_animation: SpriteAnimation(
frames: [
SpriteAnimationFrame(index: 0, beats: 1),
SpriteAnimationFrame(index: 1, beats: 1),
SpriteAnimationFrame(index: 0, beats: 16),
SpriteAnimationFrame(index: 1, beats: 16),
],
),

Expand Down Expand Up @@ -48,8 +48,8 @@
),
sprite_animation: SpriteAnimation(
frames: [
SpriteAnimationFrame(index: 0, beats: 1),
SpriteAnimationFrame(index: 1, beats: 1),
SpriteAnimationFrame(index: 0, beats: 16),
SpriteAnimationFrame(index: 1, beats: 16),
],
),

Expand All @@ -72,8 +72,8 @@
),
sprite_animation: SpriteAnimation(
frames: [
SpriteAnimationFrame(index: 0, beats: 1),
SpriteAnimationFrame(index: 1, beats: 1),
SpriteAnimationFrame(index: 0, beats: 16),
SpriteAnimationFrame(index: 1, beats: 16),
],
),

Expand All @@ -96,8 +96,8 @@
),
sprite_animation: SpriteAnimation(
frames: [
SpriteAnimationFrame(index: 0, beats: 1),
SpriteAnimationFrame(index: 1, beats: 1),
SpriteAnimationFrame(index: 0, beats: 16),
SpriteAnimationFrame(index: 1, beats: 16),
],
),

Expand All @@ -120,8 +120,8 @@
),
sprite_animation: SpriteAnimation(
frames: [
SpriteAnimationFrame(index: 0, beats: 1),
SpriteAnimationFrame(index: 1, beats: 1),
SpriteAnimationFrame(index: 0, beats: 16),
SpriteAnimationFrame(index: 1, beats: 16),
],
),

Expand All @@ -144,8 +144,8 @@
),
sprite_animation: SpriteAnimation(
frames: [
SpriteAnimationFrame(index: 0, beats: 1),
SpriteAnimationFrame(index: 1, beats: 1),
SpriteAnimationFrame(index: 0, beats: 16),
SpriteAnimationFrame(index: 1, beats: 16),
],
),

Expand Down
16 changes: 9 additions & 7 deletions src/game/actor/level/xp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::core::UpdateSet;
use crate::game::actor::faction::Faction;
use crate::game::actor::level::Level;
use crate::game::actor::level::LevelConfig;
use crate::game::actor::player::IsPlayer;
use crate::game::combat::death::OnDeath;
use crate::ui::prelude::*;
use crate::util::prelude::*;
Expand Down Expand Up @@ -47,15 +48,16 @@ impl Configure for OnXpReward {
}
}

fn receive_xp(trigger: Trigger<OnXpReward>, mut xp_query: Query<&mut Xp>) {
let entity = r!(trigger.get_entity());
let mut xp = r!(xp_query.get_mut(entity));
xp.gain(trigger.event().0);
// TODO: Not needed for this jam game, but it would be "more correct" to track
// the owner of the projectile that killed the actor with the `XpReward`,
// and only trigger `OnXpReward` for that entity.
fn receive_xp(trigger: Trigger<OnXpReward>, mut xp_query: Query<&mut Xp, With<IsPlayer>>) {
for mut xp in &mut xp_query {
xp.gain(trigger.event().0);
}
}

// TODO: Not needed for this jam game, but it would be "more correct" to track
// the owner of the projectile that killed the actor with the `XpReward`.
/// Experience rewarded to player entities on death.
/// Experience points rewarded to the killer on death.
#[derive(Component, Reflect, Serialize, Deserialize, Copy, Clone)]
#[reflect(Component)]
#[serde(transparent)]
Expand Down
4 changes: 2 additions & 2 deletions src/game/spotlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl Config for SpotlightConfig {
impl SpotlightConfig {
fn color(&self, t: f32) -> Color {
let n = self.color_loop.len();
let t = t * n as f32;
let lo = (t as usize).rem_euclid(n);
let t = (t * n as f32).rem_euclid(n as f32);
let lo = t as usize;
let hi = if lo + 1 < n { lo + 1 } else { 0 };
let t = t.fract().quadratic_in_out();

Expand Down
2 changes: 1 addition & 1 deletion src/game/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Configure for SpriteAnimation {
Update,
update_sprite_animation
.in_set(UpdateSet::Update)
.run_if(on_beat(4)),
.run_if(on_beat(1)),
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/game/wave.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::ecs::system::EntityCommand;
use bevy::prelude::*;
use bevy::utils::HashMap;
use pyri_state::prelude::*;
Expand Down Expand Up @@ -122,3 +123,9 @@ fn any_condition_met(conditions: &[SpawnCondition], current_level: &usize) -> bo
SpawnCondition::LessThan(value) => current_level < value,
})
}

pub fn wave(player: Entity) -> impl EntityCommand<World> {
move |mut entity: EntityWorldMut| {
entity.insert((Name::new("Wave"), Wave::default(), Selection(player)));
}
}
9 changes: 9 additions & 0 deletions src/screen/playing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use pyri_state::schedule::ResolveStateSet;
use crate::core::pause::Pause;
use crate::game::actor::player::player;
use crate::game::spotlight::spotlight_lamp_spawner;
use crate::game::wave::wave;
use crate::game::GameRoot;
use crate::screen::fade_in;
use crate::screen::playing::hud::playing_hud;
Expand All @@ -31,12 +32,20 @@ fn enter_playing(mut commands: Commands, game_root: Res<GameRoot>, ui_root: Res<
commands.spawn_with(fade_in);

// TODO: Character select screen.
// Spawn player.
let player = commands.spawn_with(player("pink")).id();

// Spawn enemies.
commands
.spawn_with(wave(player))
.set_parent(game_root.enemies);

// Spawn VFX.
commands
.spawn_with(spotlight_lamp_spawner)
.set_parent(game_root.vfx);

// Spawn UI.
commands
.spawn_with(playing_hud(player))
.set_parent(ui_root.body);
Expand Down

0 comments on commit 51521e8

Please sign in to comment.