Skip to content

Commit

Permalink
feat: Manage next levels and game finished
Browse files Browse the repository at this point in the history
- Manage exit sensors to trigger next levels or game completion.
- Add new states FinishLevel and NextLevel.
      - FinishLevel allows to despawn current level entities.
      - NextLevel spawn the next level entities.
- Add GameFinished state to manage game completion.
- Add a victory image when game is completed.
- Add a new draft new level 1.
- Change previous level to level 2.
  • Loading branch information
uggla committed Jul 3, 2024
1 parent 1f0e27b commit ce6eb1b
Show file tree
Hide file tree
Showing 24 changed files with 887 additions and 346 deletions.
Binary file added assets/cloud-1.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/forest-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
449 changes: 209 additions & 240 deletions assets/level01.tmx

Large diffs are not rendered by default.

260 changes: 260 additions & 0 deletions assets/level02.tmx

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions assets/locales/en-US/rock_run.ftl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
lang01 = English
lang02 = French
start_game = Start game
current_level = Level { $current_level }
hello-world = Hello world { $name }.
story01-01 = Hel-lo, my name is Rose.
story01-02 = It's get-ting late, I need to go home be-cause the night is the do-main of pre-da-tors.
story01-03 = Can you help me get home?
story02-01 = It's strange, I have the im-pres-sion that this di-no-saur was crushed by some-thing.
story02-02 = I have a bad feel-ing.
story03-01 = { $n1 } + { $n2 }=\("selection_items":["0","0"],"selected_item":0\)
1 change: 1 addition & 0 deletions assets/locales/fr-FR/rock_run.ftl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
lang01 = Anglais
lang02 = Francais
start_game = Commencer le jeu
current_level = Niveau { $current_level }
hello-world = Salut monde { $name }.
story01-01 = Sa-lut, je m'ap-pel-le Ro-se.
story01-02 = Il com-men-ce à ê-tre tard, il faut que je ren-tre car la nuit c'est le do-mai-ne des pré-da-teurs.
Expand Down
Binary file added assets/musics/theme-1.ogg
Binary file not shown.
Binary file added assets/musics/theme-7.ogg
Binary file not shown.
59 changes: 52 additions & 7 deletions assets/rockrun.tiled-session
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"height": 4300,
"width": 2
},
"activeFile": "level01.tmx",
"activeFile": "level02.tmx",
"expandedProjectPaths": [
"."
],
Expand All @@ -13,18 +13,28 @@
"scaleInDock": 1
},
"level01.tmx": {
"scale": 1,
"selectedLayer": 4,
"expandedObjectLayers": [
4,
6
],
"scale": 2,
"selectedLayer": 6,
"viewCenter": {
"x": 5487,
"y": 446.5
"x": 763.75,
"y": 603.25
}
},
"level01.tmx#backgrounds": {
"dynamicWrapping": true,
"scaleInDock": 1,
"scaleInEditor": 1
},
"level01.tmx#cloud-1": {
"scaleInDock": 0.25
},
"level01.tmx#forest-1": {
"scaleInDock": 0.33
},
"level01.tmx#grad-1": {
"scaleInDock": 1
},
Expand All @@ -41,9 +51,38 @@
"level01.tmx#sky-2": {
"scaleInDock": 1
},
"level01.tmx#sky-3": {
"scaleInDock": 0.25
},
"level01.tmx#tileset-1": {
"dynamicWrapping": false,
"scaleInDock": 0.125
"scaleInDock": 1
},
"level02.tmx": {
"expandedObjectLayers": [
8
],
"scale": 1.5,
"selectedLayer": 4,
"viewCenter": {
"x": 5285.666666666666,
"y": 293.66666666666663
}
},
"level02.tmx#grad-1": {
"scaleInDock": 1
},
"level02.tmx#rock-1": {
"scaleInDock": 1
},
"level02.tmx#sky-1": {
"scaleInDock": 1
},
"level02.tmx#sky-2": {
"scaleInDock": 1
},
"level02.tmx#tileset-1": {
"scaleInDock": 1
},
"menu.tmx": {
"scale": 0.5,
Expand All @@ -58,17 +97,23 @@
}
},
"last.imagePath": "/home/rribaud/workspace/rust/rock_run/assets",
"last.worldFilePath": "/home/rribaud/workspace/rust/rock_run/assets",
"loadedWorlds": [
"/home/rribaud/workspace/rust/rock_run/assets/level01.tmx"
],
"map.height": 45,
"map.lastUsedFormat": "tmx",
"map.tileHeight": 16,
"map.tileWidth": 16,
"map.width": 80,
"openFiles": [
"level01.tmx"
"level01.tmx",
"level02.tmx"
],
"project": "rockrun.tiled-project",
"recentFiles": [
"level01.tmx",
"level02.tmx",
"menu.tmx"
],
"tileset.embedInMap": true,
Expand Down
Binary file added assets/victory.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/bat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_rapier2d::{
use crate::{
collision::CollisionSet,
coregame::state::AppState,
events::{Hit, PositionSensorCollision, Restart},
events::{Hit, PositionSensorCollisionStart, Restart},
helpers::texture::cycle_texture,
player::Player,
};
Expand Down Expand Up @@ -53,6 +53,7 @@ pub struct BatPlugin;
impl Plugin for BatPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(AppState::StartMenu), despawn_bat)
.add_systems(OnEnter(AppState::FinishLevel), despawn_bat)
.add_systems(
Update,
(move_bat, spawn_bat, despawn_bat_on_restart)
Expand Down Expand Up @@ -84,7 +85,7 @@ fn spawn_bat(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
mut bat_sensor_collision: EventReader<PositionSensorCollision>,
mut bat_sensor_collision: EventReader<PositionSensorCollisionStart>,
) {
for collision_event in bat_sensor_collision.read() {
if !collision_event.sensor_name.contains("bat") {
Expand Down
5 changes: 5 additions & 0 deletions src/colliders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ pub struct GroundAndPlatformsPlugin;
impl Plugin for GroundAndPlatformsPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(AppState::GameCreate), setup_ground_platforms_spikes)
.add_systems(OnEnter(AppState::NextLevel), setup_ground_platforms_spikes)
.add_systems(
OnEnter(AppState::StartMenu),
despawn_ground_platforms_spikes,
)
.add_systems(
OnEnter(AppState::FinishLevel),
despawn_ground_platforms_spikes,
);
}
}
Expand Down
41 changes: 30 additions & 11 deletions src/collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use crate::{
enigma::{EnigmaKind, Enigmas},
events::{
Hit, LadderCollisionStart, LadderCollisionStop, MovingPlatformCollision,
PositionSensorCollision, StoryMessages, TriceratopsCollision,
PositionSensorCollisionStart, PositionSensorCollisionStop, StoryMessages,
TriceratopsCollision,
},
moving_platform::MovingPlatform,
player::{self, Player, PlayerState, PLAYER_HEIGHT},
Expand Down Expand Up @@ -47,7 +48,8 @@ impl Plugin for CollisionPlugin {
.add_systems(OnEnter(AppState::StartMenu), despawn_qm)
.add_event::<Hit>()
.add_event::<TriceratopsCollision>()
.add_event::<PositionSensorCollision>()
.add_event::<PositionSensorCollisionStart>()
.add_event::<PositionSensorCollisionStop>()
.add_event::<LadderCollisionStart>()
.add_event::<LadderCollisionStop>()
.add_event::<MovingPlatformCollision>();
Expand Down Expand Up @@ -374,21 +376,26 @@ fn bat_collision(
fn position_sensor_collision(
position_sensors: Query<(Entity, &ColliderName), With<PositionSensor>>,
collision_events: EventReader<CollisionEvent>,
event_to_send: EventWriter<PositionSensorCollision>,
mut event_start: EventWriter<PositionSensorCollisionStart>,
mut event_stop: EventWriter<PositionSensorCollisionStop>,
levels: Query<&Level, With<Level>>,
current_level: Res<CurrentLevel>,
) {
let mut collision_events = collision_events;
let mut event_to_send = event_to_send;
for collision_event in collision_events.read() {
let level = levels
.iter()
.find(|level| level.id == current_level.id)
.unwrap();

let mut level_bat_pos: HashMap<u8, HashMap<String, [Vec2; 2]>> = HashMap::new();
level_bat_pos.insert(
let mut level_sensor_pos: HashMap<u8, HashMap<String, [Vec2; 2]>> = HashMap::new();
level_sensor_pos.insert(
1,
HashMap::from([("exit01".to_string(), [Vec2::ZERO, Vec2::ZERO])]),
);

level_sensor_pos.insert(
2,
HashMap::from([
(
"bat01".to_string(),
Expand Down Expand Up @@ -418,6 +425,7 @@ fn position_sensor_collision(
level.map.tiled_to_bevy_coord(Vec2::new(5300.0, 600.0)),
],
),
("exit01".to_string(), [Vec2::ZERO, Vec2::ZERO]),
]),
);

Expand All @@ -433,9 +441,9 @@ fn position_sensor_collision(
collision_event, collider_name
);

if let Some(collider) = level_bat_pos.get(&current_level.id) {
if let Some(collider) = level_sensor_pos.get(&current_level.id) {
if let Some(pos) = collider.get(&collider_name.0) {
event_to_send.send(PositionSensorCollision {
event_start.send(PositionSensorCollisionStart {
sensor_name: collider_name.0.clone(),
spawn_pos: pos[0],
exit_pos: pos[1],
Expand All @@ -445,9 +453,20 @@ fn position_sensor_collision(
};
}
CollisionEvent::Stopped(e1, e2, _cf) => {
if position_sensors.contains(*e1) || position_sensors.contains(*e2) {
debug!("Received collision event: {:?}", collision_event);
}
// Warning, e1 and e2 can be swapped.
if let Some((_entity, collider_name)) = position_sensors
.iter()
.find(|(entity, _collider_name)| entity == e1 || entity == e2)
{
debug!(
"Received collision event: {:?}, collider name: {:?}",
collision_event, collider_name
);

event_stop.send(PositionSensorCollisionStop {
sensor_name: collider_name.0.clone(),
});
};
}
}
}
Expand Down
Loading

0 comments on commit ce6eb1b

Please sign in to comment.