Skip to content

Commit

Permalink
Cannon juicing (#364)
Browse files Browse the repository at this point in the history
* Tweak cannon values and add big explosion effect to cannonball

* Add smoke for cannonball

* Add autoplay things to cannon

* Add option to set custom gravity for triggered effect

* Tweak cannon values

* Fix after rebase

* Fix typo and cargo fmt
  • Loading branch information
legendiguess committed Feb 5, 2022
1 parent 6a17d06 commit 55667c1
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 11 deletions.
40 changes: 34 additions & 6 deletions assets/items/cannon.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"y": -26
},
"effect_offset": {
"x": 36,
"y": 12
"x": 50,
"y": 28
},
"collider_size": {
"x": 64,
Expand All @@ -31,9 +31,10 @@
"ground",
"explosion"
],
"gravity": 0.5,
"velocity": {
"x": 10.0,
"y": -0.5
"x": 20.0,
"y": -2
},
"size": {
"x": 17,
Expand All @@ -43,10 +44,30 @@
"effects": [
{
"type": "circle_collider",
"radius": 64,
"radius": 80,
"is_explosion": true,
"particle_effect": "hit",
"sound_effect": "explode"
},
{
"type": "triggered_effect",
"size": {
"x": 176,
"y": 144
},
"timed_trigger": 0.7,
"sprite": {
"texture": "explosion_big",
"autoplay_id": "effect",
"animations": [
{
"id": "effect",
"row": 0,
"frames": 12,
"fps": 24
}
]
}
}
],
"sprite": {
Expand All @@ -61,7 +82,14 @@
"is_looping": true
}
]
}
},
"particles": [
{
"particle_effect": "cannon_cannonball_smoke",
"interval": 0.04,
"delay": 0.04
}
]
}
],
"sprite": {
Expand Down
4 changes: 4 additions & 0 deletions assets/particle_effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@
{
"id": "sniper_rifle_bullet_smoke",
"path": "particle_effects/sniper_rifle_bullet_smoke.json"
},
{
"id": "cannon_cannonball_smoke",
"path": "particle_effects/cannon_cannonball_smoke.json"
}
]
65 changes: 65 additions & 0 deletions assets/particle_effects/cannon_cannonball_smoke.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"local_coords": false,
"emission_shape": "Point",
"one_shot": true,
"lifetime": 1.0,
"lifetime_randomness": 0,
"explosiveness": 1,
"amount": 1,
"shape": {
"Circle": {
"subdivisions": 18
}
},
"emitting": false,
"initial_direction": {
"x": 0,
"y": -1
},
"initial_direction_spread": 6.2831855,
"initial_velocity": 0,
"initial_velocity_randomness": 0,
"linear_accel": 0,
"size": 6,
"size_randomness": 0.2,
"size_curve": {
"points": [
[
0,
2
],
[
1,
0
]
],
"interpolation": "Linear",
"resolution": 30
},
"blend_mode": "Alpha",
"colors_curve": {
"start": {
"r": 0.4,
"g": 0.4,
"b": 0.4,
"a": 1
},
"mid": {
"r": 0.8,
"g": 0.8,
"b": 0.8,
"a": 1
},
"end": {
"r": 1,
"g": 1,
"b": 1,
"a": 0
}
},
"gravity": {
"x": 0,
"y": 0
},
"post_processing": {}
}
13 changes: 9 additions & 4 deletions src/effects/active/triggered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use core::Result;

use crate::effects::active::spawn_active_effect;
use crate::particles::{ParticleEmitter, ParticleEmitterMetadata};
use crate::physics;
use crate::player::{Player, PlayerState};
use crate::{json, Drawable, PhysicsBodyParams};
use crate::{ActiveEffectMetadata, AnimatedSpriteMetadata, CollisionWorld, PhysicsBody, Transform};
Expand Down Expand Up @@ -106,6 +107,7 @@ pub fn spawn_triggered_effect(
offset,
size: meta.size,
can_rotate: meta.can_rotate,
gravity: meta.gravity,
..Default::default()
},
),
Expand Down Expand Up @@ -327,9 +329,8 @@ pub struct TriggeredEffectMetadata {
/// If this is `true` the triggered physics body will rotate while in the air.
#[serde(default)]
pub can_rotate: bool,
/// The angle of rotation with which the triggered physics body will spawn.
#[serde(default)]
pub spawn_angle: f32,
#[serde(default = "default_physics_gravity")]
pub gravity: f32,
}

impl Default for TriggeredEffectMetadata {
Expand All @@ -348,7 +349,11 @@ impl Default for TriggeredEffectMetadata {
is_kickable: false,
should_collide_with_platforms: false,
can_rotate: false,
spawn_angle: 0.0,
gravity: default_physics_gravity(),
}
}
}

fn default_physics_gravity() -> f32 {
physics::GRAVITY
}
6 changes: 5 additions & 1 deletion src/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct PhysicsBodyParams {
pub has_friction: bool,
pub can_rotate: bool,
pub bouncyness: f32,
pub gravity: f32,
}

impl Default for PhysicsBodyParams {
Expand All @@ -74,6 +75,7 @@ impl Default for PhysicsBodyParams {
has_friction: true,
can_rotate: true,
bouncyness: 0.0,
gravity: GRAVITY,
}
}
}
Expand All @@ -96,6 +98,7 @@ pub struct PhysicsBody {
pub can_rotate: bool,
pub bouncyness: f32,
pub is_deactivated: bool,
pub gravity: f32,
}

impl PhysicsBody {
Expand All @@ -119,6 +122,7 @@ impl PhysicsBody {
can_rotate: params.can_rotate,
bouncyness: params.bouncyness,
is_deactivated: false,
gravity: params.gravity,
}
}

Expand Down Expand Up @@ -155,7 +159,7 @@ pub fn fixed_update_physics_bodies(world: &mut World) {
}

if !body.is_on_ground && body.has_mass {
body.velocity.y += GRAVITY;
body.velocity.y += body.gravity;

if body.velocity.y > TERMINAL_VELOCITY {
body.velocity.y = TERMINAL_VELOCITY;
Expand Down

0 comments on commit 55667c1

Please sign in to comment.