Skip to content

Commit

Permalink
update kickball
Browse files Browse the repository at this point in the history
  • Loading branch information
DRuppFv committed Apr 24, 2024
1 parent b9a8041 commit 5e5c1af
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 40 deletions.
4 changes: 4 additions & 0 deletions assets/elements/item/cannonball/cannonball.atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./cannonball.png
tile_size: [17, 17]
rows: 1
columns: 1
3 changes: 3 additions & 0 deletions assets/elements/item/cannonball/cannonball.element.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: Cannonball
category: Weapons
data: kick_bomb.yaml
Binary file added assets/elements/item/cannonball/cannonball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/elements/item/cannonball/cannonball_or.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/elements/item/cannonball/explosion.atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./explosion.png
tile_size: [144, 112]
rows: 1
columns: 11
Binary file added assets/elements/item/cannonball/explosion.ogg
Binary file not shown.
Binary file added assets/elements/item/cannonball/explosion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/elements/item/cannonball/fuse.ogg
Binary file not shown.
32 changes: 32 additions & 0 deletions assets/elements/item/cannonball/kick_bomb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
fuse_time: 4s
kick_velocity: [0.0, 0.0]
kickable: false
throw_velocity: 800
damage_region_size: [60, 60]
damage_region_lifetime: 0.5

atlas: ./cannonball.atlas.yaml

explosion_atlas: ./explosion.atlas.yaml
explosion_lifetime: 1.0
explosion_frames: 12
explosion_fps: 8
explosion_sound: ./explosion.ogg
explosion_volume: 0.1
explode_on_contact: true

lit_frames_start: 0
lit_frames_end: 1
lit_fps: 1.0

fuse_sound: ./fuse.ogg
fuse_sound_volume: 0.1

body_diameter: 16
grab_offset: [5, -2]
fin_anim: grab_2
can_rotate: true
bounciness: 0.4
angular_velocity: 0.1
# arm_delay: 0.02
arm_delay: 1000ms
6 changes: 6 additions & 0 deletions assets/elements/item/kick_bomb/kick_bomb.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fuse_time: 4s
kick_velocity: [600.0, 120.0]
kickable: true
throw_velocity: 600
damage_region_size: [60, 60]
damage_region_lifetime: 0.6
Expand All @@ -12,6 +13,11 @@ explosion_frames: 12
explosion_fps: 8
explosion_sound: ./explosion.ogg
explosion_volume: 0.1
explode_on_contact: false

lit_frames_start: 3
lit_frames_end: 5
lit_fps: 8.0

fuse_sound_volume: 0.1
fuse_sound: ./fuse.ogg
Expand Down
112 changes: 72 additions & 40 deletions src/core/elements/kick_bomb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ pub struct KickBombMeta {
pub damage_region_size: Vec2,
pub damage_region_lifetime: f32,
pub kick_velocity: Vec2,
pub kickable: bool,
pub throw_velocity: f32,
pub explosion_lifetime: f32,
pub explosion_frames: u32,
pub explosion_fps: f32,
pub explosion_sound: Handle<AudioSource>,
pub explosion_volume: f64,
pub lit_frames_start: u32,
pub lit_frames_end: u32,
pub lit_fps: f32,
pub fuse_sound: Handle<AudioSource>,
pub fuse_sound_volume: f64,
/// The time in seconds before a grenade explodes
Expand All @@ -27,6 +31,7 @@ pub struct KickBombMeta {
pub bounciness: f32,
pub angular_velocity: f32,
pub arm_delay: Duration,
pub explode_on_contact: bool,
}

pub fn game_plugin(_game: &mut Game) {
Expand Down Expand Up @@ -212,15 +217,21 @@ fn update_idle_kick_bombs(
fuse_sound_volume,
arm_delay,
fuse_time,
lit_frames_start,
lit_frames_end,
lit_fps,
..
} = *kick_bomb_meta;

if items_used.remove(entity).is_some() {
audio_center.play_sound(fuse_sound, fuse_sound_volume);
let animated_sprite = animated_sprites.get_mut(entity).unwrap();
animated_sprite.frames = [3, 4, 5].into_iter().collect();
animated_sprite.frames = ( lit_frames_start..lit_frames_end ).into_iter().collect();

Check failure on line 229 in src/core/elements/kick_bomb.rs

View workflow job for this annotation

GitHub Actions / 🔧 Clippy correctness checks (wasm32-unknown-unknown, web-target)

useless conversion to the same type: `std::ops::Range<u32>`

Check failure on line 229 in src/core/elements/kick_bomb.rs

View workflow job for this annotation

GitHub Actions / 🔧 Clippy correctness checks (x86_64-unknown-linux-gnu, target)

useless conversion to the same type: `std::ops::Range<u32>`

Check failure on line 229 in src/core/elements/kick_bomb.rs

View workflow job for this annotation

GitHub Actions / 🔧 Clippy correctness checks (wasm32-unknown-unknown, web-target)

useless conversion to the same type: `std::ops::Range<u32>`

Check failure on line 229 in src/core/elements/kick_bomb.rs

View workflow job for this annotation

GitHub Actions / 🔧 Clippy correctness checks (x86_64-unknown-linux-gnu, target)

useless conversion to the same type: `std::ops::Range<u32>`
// animated_sprite.frames = [lit_frames_start..lit_frames_end];
// animated_sprite.frames = lit_frames.into_iter().collect();
// animated_sprite.frames = lit_frames.clone();
animated_sprite.repeat = true;
animated_sprite.fps = 8.0;
animated_sprite.fps = lit_fps;
commands.add(
move |mut idle: CompMut<IdleKickBomb>, mut lit: CompMut<LitKickBomb>| {
idle.remove(entity);
Expand Down Expand Up @@ -265,7 +276,9 @@ fn update_lit_kick_bombs(
let KickBombMeta {
explosion_sound,
explosion_volume,
explode_on_contact,
kick_velocity,
kickable,
damage_region_lifetime,
damage_region_size,
explosion_lifetime,
Expand All @@ -283,55 +296,74 @@ fn update_lit_kick_bombs(
break 'should_explode true;
}

// If the item is being held
if player_inventories.find_item(entity).is_some() {
kick_bomb.kicking = false;
break 'should_explode false;
}
if explode_on_contact {
let players = entities
.iter_with(&player_indexes)
.map(|x| x.0)
.collect::<Vec<_>>();

// If the item is colliding with a non-invincible player
if let Some(player_entity) = collision_world
.actor_collisions_filtered(entity, |e| !invincibles.contains(e))
.into_iter()
.find(|&x| player_indexes.contains(x))
{
if !std::mem::replace(&mut kick_bomb.kicking, true) {
kick_bomb.kicks += 1;
}
let colliding_with_players = collision_world
.actor_collisions_filtered(entity, |e| {
players.contains(&e) && invincibles.get(e).is_none()
})
.into_iter()
.collect::<Vec<_>>();

// Explode on the 3rd kick.
// Dropping the bomb is detected as a kick so we explode when
// the counter reaches 4.
if kick_bomb.kicks > 3 {
if !colliding_with_players.is_empty() && kick_bomb.arm_delay.finished() {
break 'should_explode true;
}
}

let body = bodies.get_mut(entity).unwrap();
let translation = transforms.get_mut(entity).unwrap().translation;
// If the item is being held
if player_inventories.find_item(entity).is_some() {
kick_bomb.kicking = false;
break 'should_explode false;
}

let player_sprite = sprites.get_mut(player_entity).unwrap();
let player_translation = transforms.get(player_entity).unwrap().translation;
if kickable {
// If the item is colliding with a non-invincible player
if let Some(player_entity) = collision_world
.actor_collisions_filtered(entity, |e| !invincibles.contains(e))
.into_iter()
.find(|&x| player_indexes.contains(x))
{
if !std::mem::replace(&mut kick_bomb.kicking, true) {
kick_bomb.kicks += 1;
}

let player_standing_left = player_translation.x <= translation.x;
// Explode on the 3rd kick.
// Dropping the bomb is detected as a kick so we explode when
// the counter reaches 4.
if kick_bomb.kicks > 3 {
break 'should_explode true;
}

if body.velocity.x == 0.0 {
body.velocity = kick_velocity;
if player_sprite.flip_x {
body.velocity.x *= -1.0;
let body = bodies.get_mut(entity).unwrap();
let translation = transforms.get_mut(entity).unwrap().translation;

let player_sprite = sprites.get_mut(player_entity).unwrap();
let player_translation = transforms.get(player_entity).unwrap().translation;

let player_standing_left = player_translation.x <= translation.x;

if body.velocity.x == 0.0 {
body.velocity = kick_velocity;
if player_sprite.flip_x {
body.velocity.x *= -1.0;
}
} else if player_standing_left && !player_sprite.flip_x {
body.velocity.x = kick_velocity.x;
body.velocity.y = kick_velocity.y;
} else if !player_standing_left && player_sprite.flip_x {
body.velocity.x = -kick_velocity.x;
body.velocity.y = kick_velocity.y;
} else if kick_bomb.arm_delay.finished() {
break 'should_explode true;
}
} else if player_standing_left && !player_sprite.flip_x {
body.velocity.x = kick_velocity.x;
body.velocity.y = kick_velocity.y;
} else if !player_standing_left && player_sprite.flip_x {
body.velocity.x = -kick_velocity.x;
body.velocity.y = kick_velocity.y;
} else if kick_bomb.arm_delay.finished() {
break 'should_explode true;
} else {
kick_bomb.kicking = false;
}
} else {
kick_bomb.kicking = false;
}

false
};

Expand Down

0 comments on commit 5e5c1af

Please sign in to comment.