Skip to content

Commit

Permalink
Merge pull request #53 from thetawavegame/bullet-projectile
Browse files Browse the repository at this point in the history
Finish implementing bullet projectile
  • Loading branch information
cdsupina authored May 8, 2023
2 parents 2e72587 + 73bbf67 commit be0f7ee
Show file tree
Hide file tree
Showing 13 changed files with 522 additions and 134 deletions.
2 changes: 1 addition & 1 deletion assets/data/characters.ron
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
collider_dimensions: (4.0 , 5.5),
collider_density: 1.5,
character_type: Juggernaut,
projectile_type: Blast(Ally),
projectile_type: Bullet(Ally),
projectile_despawn_time: 0.7,
projectile_velocity: (0.0, 400.0),
projectile_offset_position: (0.0, 45.0),
Expand Down
46 changes: 45 additions & 1 deletion assets/data/formation_pools.ron
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@
),
],
"medium": [
(
formation_spawnables: [
(
spawnable_type: Mob(Enemy(Shelly)),
position: (-150.0, 500.0),
),
(
spawnable_type: Mob(Enemy(Shelly)),
position: (0.0, 500.0),
),
(
spawnable_type: Mob(Enemy(Shelly)),
position: (150.0, 500.0),
),
],
weight: 1.0,
period: 13.0,
),
(
formation_spawnables: [
(
Expand All @@ -117,7 +135,7 @@
),
],
weight: 1.0,
period: 13.0,
period: 12.0,
),
(
formation_spawnables: [
Expand Down Expand Up @@ -325,6 +343,32 @@
),
],
"hard": [
(
formation_spawnables: [
(
spawnable_type: Mob(Enemy(Shelly)),
position: (-250.0, 500.0),
),
(
spawnable_type: Mob(Enemy(Shelly)),
position: (-150.0, 500.0),
),
(
spawnable_type: Mob(Enemy(Shelly)),
position: (0.0, 500.0),
),
(
spawnable_type: Mob(Enemy(Shelly)),
position: (150.0, 500.0),
),
(
spawnable_type: Mob(Enemy(Shelly)),
position: (250.0, 500.0),
),
],
weight: 1.0,
period: 13.0,
),
(
formation_spawnables: [
(
Expand Down
22 changes: 4 additions & 18 deletions assets/data/levels.ron
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,13 @@
)),
timeline: (
phases: [
/*
(
phase_type: Boss(
mob_type: Enemy(Repeater),
position: (0.0, 550.0),
initial_delay: 5.0,
is_defeated: false,
phase_type: FormationSpawn(
time: 400000.0,
formation_pool: "medium",
initial_delay: 1.0,
),
bg_music_transition: Some((
loop_from: 9.615,
bg_music: Boss,
)),
),
*/
(
phase_type: Break( time: 5.0),
bg_music_transition: Some((
loop_from: 0.0,
bg_music: Game,
)),
)
],
),
),
Expand Down
50 changes: 49 additions & 1 deletion assets/data/mobs.ron
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
deceleration: (2.0, 1.0),
speed: (0.0, 100.0),
collision_damage: 12.0,
defense_damage: 10.0,
defense_damage: 8.0,
colliders: [
(
dimensions: (6.5, 6.5),
Expand Down Expand Up @@ -448,6 +448,54 @@
]
}
),
Enemy(Shelly): (
mob_type: Enemy(Shelly),
spawnable_behaviors: [MoveDown, BrakeHorizontal],
mob_behaviors: [
ReceiveDamageOnImpact,
DealDamageToPlayerOnImpact,
DieAtZeroHealth,
PeriodicFire("bullet"),
],
acceleration: (0.0, 2.0),
deceleration: (2.0, 1.0),
speed: (0.0, 75.0),
attack_damage: 10.0,
collision_damage: 8.0,
defense_damage: 8.0,
colliders: [
(
dimensions: (7.0, 7.5),
position: (0.0, 0.0),
rotation: 0.0,
)
],
z_level: 5.0,
consumable_drops: Standard,
health: (
max_health: 25.0,
health: 25.0,
armor: 0,
),
animation: (
direction: PingPong(Forward),
frame_duration: 0.25,
),
projectile_spawners: {
"bullet": [
(
projectile_type: Bullet(Enemy),
period: 3.0,
position: Local((0.0, -40.0)),
despawn_time: 2.5,
initial_motion: (
random_angvel: None,
linvel: Some((0.0, -400.0)),
),
)
],
}
),
Ally(Hauler3): (
mob_type: Ally(Hauler3),
spawnable_behaviors: [MoveDown, BrakeHorizontal],
Expand Down
6 changes: 3 additions & 3 deletions assets/data/projectiles.ron
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
Bullet(Enemy): (
projectile_type: Bullet(Enemy),
spawnable_behaviors: [],
projectile_behaviors: [DealDamageOnContact, ReceiveDamageOnContact, DieAtZeroHealth],
projectile_behaviors: [DealDamageOnContact, ExplodeOnContact],
collider_dimensions: (1.5, 1.5),
z_level: 20.0,
animation: (
Expand All @@ -69,7 +69,7 @@
Bullet(Neutral): (
projectile_type: Bullet(Neutral),
spawnable_behaviors: [],
projectile_behaviors: [DealDamageOnContact],
projectile_behaviors: [DealDamageOnContact, ExplodeOnContact],
collider_dimensions: (1.5, 1.5),
z_level: 20.0,
animation: (
Expand All @@ -86,7 +86,7 @@
Bullet(Ally): (
projectile_type: Bullet(Ally),
spawnable_behaviors: [],
projectile_behaviors: [DealDamageOnContact],
projectile_behaviors: [DealDamageOnContact, ExplodeOnContact],
collider_dimensions: (1.5, 1.5),
z_level: 19.0,
animation: (
Expand Down
7 changes: 7 additions & 0 deletions assets/mob_assets.assets.ron
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
columns: 3,
rows: 1,
),
"shelly": TextureAtlas (
path: "texture/shelly_spritesheet.png",
tile_size_x: 24.,
tile_size_y: 25.,
columns: 3,
rows: 1,
),
"hauler.front": TextureAtlas (
path: "texture/hauler_front.png",
tile_size_x: 18.,
Expand Down
Binary file added assets/texture/shelly_spritesheet.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 src/assets/mob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::spawnable::{EnemyMobType, MobSegmentType, MobType};

#[derive(AssetCollection, Resource)]
pub struct MobAssets {
#[asset(key = "shelly")]
pub shelly: Handle<TextureAtlas>,
#[asset(key = "drone")]
pub drone: Handle<TextureAtlas>,
#[asset(key = "drone.thruster")]
Expand Down Expand Up @@ -74,6 +76,7 @@ impl MobAssets {
self.crustling_head.clone()
}
EnemyMobType::Repeater => self.repeater_head.clone(),
EnemyMobType::Shelly => self.shelly.clone(),
},
MobType::Ally(ally_type) => match ally_type {
crate::spawnable::AllyMobType::Hauler2 => self.hauler_front.clone(),
Expand Down Expand Up @@ -136,6 +139,7 @@ impl MobAssets {
EnemyMobType::Missile => Some(self.missile_thruster.clone()),
EnemyMobType::CrustlingRight | EnemyMobType::CrustlingLeft => None,
EnemyMobType::Repeater => None,
EnemyMobType::Shelly => None,
},
MobType::Ally(ally_type) => match ally_type {
crate::spawnable::AllyMobType::Hauler2 => Some(self.hauler_thruster.clone()),
Expand Down
125 changes: 123 additions & 2 deletions src/collision/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,29 @@ pub fn contact_collision_system(
}

// check if mob collided with projectile
for (projectile_entity, _projectile_component) in projectile_query.iter() {
for (projectile_entity, projectile_component) in projectile_query.iter() {
// check if secondary entity is a projectile
if colliding_entities.secondary == projectile_entity {
audio_channel.play(audio_assets.bullet_bounce.clone());

collision_event_writer.send(
SortedCollisionEvent::MobToProjectileContact {
mob_entity: colliding_entities.primary,
projectile_entity: colliding_entities.secondary,
projectile_faction: match &projectile_component.projectile_type
{
ProjectileType::Blast(faction) => faction.clone(),
ProjectileType::Bullet(faction) => faction.clone(),
},
mob_faction: match mob_component_1.mob_type {
MobType::Enemy(_) => Faction::Enemy,
MobType::Ally(_) => Faction::Ally,
MobType::Neutral(_) => Faction::Neutral,
},
projectile_damage: projectile_component.damage,
},
);
continue 'collision_events;
}
}
}
Expand Down Expand Up @@ -369,7 +388,35 @@ pub fn contact_collision_system(
}
}

// check if mob collided with barrier
// check if mob segment collided with projectile
for (projectile_entity, projectile_component) in projectile_query.iter() {
// check if secondary entity is a projectile
if colliding_entities.secondary == projectile_entity {
audio_channel.play(audio_assets.bullet_bounce.clone());

collision_event_writer.send(
SortedCollisionEvent::MobSegmentToProjectileContact {
mob_segment_entity: colliding_entities.primary,
projectile_entity: colliding_entities.secondary,
projectile_faction: match &projectile_component.projectile_type
{
ProjectileType::Blast(faction) => faction.clone(),
ProjectileType::Bullet(faction) => faction.clone(),
},
mob_segment_faction: match mob_segment_component_1
.mob_segment_type
{
MobSegmentType::Enemy(_) => Faction::Enemy,
MobSegmentType::Neutral(_) => Faction::Neutral,
},
projectile_damage: projectile_component.damage,
},
);
continue 'collision_events;
}
}

// check if mob segment collided with barrier
for barrier_entity in barrier_query.iter() {
// check if secondary entity is a barrier
if colliding_entities.secondary == barrier_entity {
Expand All @@ -380,6 +427,80 @@ pub fn contact_collision_system(
}
}
}

// check if projectile was in collision
for (projectile_entity_1, projectile_component_1) in projectile_query.iter() {
// first entity is the projectile, the second entity is the other colliding entity
let colliding_entities: Option<CollidingEntityPair> =
if projectile_entity_1 == *collider1_entity {
Some(CollidingEntityPair {
primary: *collider1_entity,
secondary: *collider2_entity,
})
} else if projectile_entity_1 == *collider2_entity {
Some(CollidingEntityPair {
primary: *collider2_entity,
secondary: *collider1_entity,
})
} else {
None
};

if let Some(colliding_entities) = colliding_entities {
// check if the projectile collided with another projectile
for (projectile_entity_2, projectile_component_2) in projectile_query.iter() {
// check if secondary entity is a projectile
if colliding_entities.secondary == projectile_entity_2 {
//audio_channel.play(audio_assets.bullet_bounce.clone());
if matches!(
projectile_component_1.projectile_type,
ProjectileType::Bullet(_)
) && matches!(
projectile_component_2.projectile_type,
ProjectileType::Bullet(_)
) {
collision_event_writer.send(
SortedCollisionEvent::ProjectileToProjectileContact {
projectile_entity_1,
projectile_faction_1: match &projectile_component_1
.projectile_type
{
ProjectileType::Blast(faction) => faction.clone(),
ProjectileType::Bullet(faction) => faction.clone(),
},
projectile_entity_2,
projectile_faction_2: match &projectile_component_1
.projectile_type
{
ProjectileType::Blast(faction) => faction.clone(),
ProjectileType::Bullet(faction) => faction.clone(),
},
},
);
collision_event_writer.send(
SortedCollisionEvent::ProjectileToProjectileContact {
projectile_entity_1: projectile_entity_2,
projectile_faction_1: match &projectile_component_2
.projectile_type
{
ProjectileType::Blast(faction) => faction.clone(),
ProjectileType::Bullet(faction) => faction.clone(),
},
projectile_entity_2: projectile_entity_1,
projectile_faction_2: match &projectile_component_1
.projectile_type
{
ProjectileType::Blast(faction) => faction.clone(),
ProjectileType::Bullet(faction) => faction.clone(),
},
},
);
continue 'collision_events;
}
}
}
}
}
}
}
}
Loading

0 comments on commit be0f7ee

Please sign in to comment.