Skip to content

Commit

Permalink
feat: port machine gun (#954)
Browse files Browse the repository at this point in the history
This PR closes #573.

I added `bullet_spread` system to the machine gun because I think it
balances the game and looks good, and added `empty_cooldown` because it
would be really boring if `gun_empty.ogg` kept playing at the same
frequency as the normal cooldown, so in this gun we have the shooting
cooldown and the empty sound cooldown. I also made a very slight change
in the main system for using items because it had to be able to shoot
constantly, so now you can keep shoot input pressed with any weapon.

Something I think is important to mention is that the shooting animation
is synchronized to the rate of fire, so if you change the rate of fire
the animation will also change. It could be easily changed with a new
variable in the .yaml so let me know whether you think it should be
faster or slower.

The machine gun has two states (idle and shooting) and its only function
is to reset and start animations.
  • Loading branch information
DRuppFv authored Apr 4, 2024
1 parent 0ba5b5a commit 8fb37e1
Show file tree
Hide file tree
Showing 20 changed files with 369 additions and 12 deletions.
11 changes: 11 additions & 0 deletions assets/elements/item/machine_gun/bullet/machine_gun.bullet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
lifetime: 0.65
speed: 650
body_diameter: 15
atlas: ./machine_gun_bullet.atlas.yaml

explosion_fps: 12
explosion_frames: 3
explosion_volume: 0.025
explosion_lifetime: 0.4
explosion_sound: ../explosion/bullet_hit_dull.ogg
explosion_atlas: ../explosion/explosion.atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./machine_gun_bullet.png
tile_size: [30, 4]
rows: 1
columns: 1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./explosion.png
tile_size: [11, 11]
rows: 1
columns: 4
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/machine_gun/machine_gun.atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
image: ./machine_gun.png
tile_size: [80, 24]
rows: 2
columns: 2
3 changes: 2 additions & 1 deletion assets/elements/item/machine_gun/machine_gun.element.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
name: Machine Gun
name: MachineGun
category: Weapons
data: machine_gun.yaml
Binary file added assets/elements/item/machine_gun/machine_gun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions assets/elements/item/machine_gun/machine_gun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
atlas: ./machine_gun.atlas.yaml

max_ammo: 25
cooldown: 125ms
empty_cooldown: 600ms
bullet_meta: ./bullet/machine_gun.bullet.yaml
bullet_spread: 0.1

shoot_sound_volume: 0.1
shoot_sound: ./shoot/shoot.ogg
empty_shoot_sound_volume: 0.1
empty_shoot_sound: ./shoot/gun_empty.ogg

bounciness: 0.3
can_rotate: true
body_size: [32, 8]
fin_anim: grab_2
angular_velocity: 0.1
throw_velocity: 360
grab_offset: [13, -3]
kickback: 75
Binary file not shown.
Binary file added assets/elements/item/machine_gun/shoot/shoot.ogg
Binary file not shown.
1 change: 1 addition & 0 deletions assets/game.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ core:
- /elements/item/jellyfish/jellyfish.element.yaml
- /elements/item/kick_bomb/kick_bomb.element.yaml
- /elements/item/mine/mine.element.yaml
- /elements/item/machine_gun/machine_gun.element.yaml
- /elements/item/musket/musket.element.yaml
- /elements/item/buss/buss.element.yaml
- /elements/item/periscope/periscope.element.yaml
Expand Down
2 changes: 1 addition & 1 deletion assets/map/levels/level_7.map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ layers:
- pos:
- 216.0
- 310.5
element: /elements/item/musket/musket.element.yaml
element: /elements/item/machine_gun/machine_gun.element.yaml
- pos:
- 248.0
- 438.5
Expand Down
8 changes: 5 additions & 3 deletions src/core/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod flappy_jellyfish;
pub mod grenade;
pub mod jellyfish;
pub mod kick_bomb;
pub mod machine_gun;
pub mod mine;
pub mod musket;
pub mod periscope;
Expand All @@ -31,9 +32,9 @@ pub mod urchin;
pub mod prelude {
pub use super::{
buss::*, crab::*, crate_item::*, decoration::*, fish_school::*, grenade::*, jellyfish::*,
kick_bomb::*, mine::*, musket::*, periscope::*, player_spawner::*, slippery::*,
slippery_seaweed::*, snail::*, spike::*, sproinger::*, stomp_boots::*, sword::*, urchin::*,
*,
kick_bomb::*, machine_gun::*, mine::*, musket::*, periscope::*, player_spawner::*,
slippery::*, slippery_seaweed::*, snail::*, spike::*, sproinger::*, stomp_boots::*,
sword::*, urchin::*, *,
};
}

Expand Down Expand Up @@ -316,6 +317,7 @@ install_plugins!(
jellyfish,
kick_bomb,
mine,
machine_gun,
musket,
buss,
player_spawner,
Expand Down
5 changes: 3 additions & 2 deletions src/core/elements/buss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ fn update(
// If the item is being used
let item_used = items_used.remove(entity).is_some();
if item_used && buss.cooldown.finished() {
// Reset fire cooldown
buss.cooldown = Timer::new(*cooldown, TimerMode::Once);
// Empty
if buss.ammo.eq(&0) {
audio_center.play_sound(*empty_shoot_sound, *empty_shoot_sound_volume);
continue;
}

// Reset fire cooldown and subtract ammo
buss.cooldown = Timer::new(*cooldown, TimerMode::Once);
// Subtract ammo
buss.ammo = buss.ammo.saturating_sub(1).clamp(0, buss.ammo);
audio_center.play_sound(*shoot_sound, *shoot_sound_volume);

Expand Down
Loading

0 comments on commit 8fb37e1

Please sign in to comment.