Skip to content

Commit

Permalink
Final Cinematic
Browse files Browse the repository at this point in the history
Merge pull request #3 from Fabinistere/develop
  • Loading branch information
Wabtey authored Jun 11, 2023
2 parents 7e09606 + 57cb648 commit ed6e78e
Show file tree
Hide file tree
Showing 11 changed files with 559 additions and 287 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ or in the correct release note (if from other version):

## Rules

***But du jeu*** : Arriver à s’enfuir du Labo
***But du jeu**- : Arriver à s’enfuir du Labo

### Binding

Expand All @@ -24,6 +24,15 @@ or in the correct release note (if from other version):
- `Left Click` on the button *Hack* to hack doors
- `Z Q S D` or `W A S D` or `Up Left Down Right` to move

### Future... (lmao)

- [ ] TODO: LevelScene, CinematicScene
- [ ] TODO: MustHave - Reset the scene when touched (by an enemy)
- [ ] TODO: Background + MovingBubbles
- [x] Final Cinematic
- [x] Animations
- [x] Black Cat, EasterEgg

### Level Design

#### Tutorial
Expand Down
16 changes: 13 additions & 3 deletions src/characters/npcs/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

use crate::{
characters::movement::{Dazed, Speed},
characters::{effects::style::DazeAnimation, movement::{Dazed, Speed}},
characters::{npcs::NPC, player::Player},
constants::character::npc::movement::BLACK_CAT_STARTING_POSITION,
tablet::mind_control::MindControled,
Expand Down Expand Up @@ -239,17 +239,27 @@ pub fn daze_wait(
mut commands: Commands,

time: Res<Time>,
mut npc_query: Query<(Entity, &mut Dazed, &mut Velocity, &Name), (With<NPC>, Without<Player>)>,
mut npc_query: Query<(Entity, &mut Dazed, &mut Velocity, &Children, &Name), (With<NPC>, Without<Player>)>,
daze_effect_query: Query<Entity, With<DazeAnimation>>,
) {
for (npc, mut daze_timer, mut _rb_vel, name) in npc_query.iter_mut() {
for (npc, mut daze_timer, mut _rb_vel, children, name) in npc_query.iter_mut() {
daze_timer.timer.tick(time.delta());

// not required to control velocity because it is managed elsewhere

if daze_timer.timer.finished() {
info!("{:?}, {} can now aggro", npc, name);

// REFACTOR: Abstract Daze Cure by event (also in daze_cure_by_mind_control())
commands.entity(npc).remove::<Dazed>();
for child in children {
match daze_effect_query.get(*child) {
Err(_) => continue,
Ok(daze_effect) => {
commands.entity(daze_effect).despawn();
}
}
}
}
}
}
16 changes: 12 additions & 4 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub const RESOLUTION: f32 = 16. / 9.;

pub const TILE_SIZE: f32 = 1.;

pub const FRAME_TIME: f32 = 0.1;

pub mod character {

use super::TILE_SIZE;
Expand Down Expand Up @@ -49,23 +51,29 @@ pub mod locations {
pub const LEVEL_Z: f32 = 3.;
pub const LEVEL_POSITION: (f32, f32, f32) = (0., 0., LEVEL_Z);
pub const LEVEL_SCALE: (f32, f32, f32) = (-1., 1., 1.);

pub const FLOOR_Z: f32 = 1.;
pub const FLOOR_POSITION: (f32, f32, f32) = (0., 0., FLOOR_Z);

pub mod level_one {
use super::LEVEL_Z;

pub const IN_DOOR_POSITION: (f32, f32, f32) = (5., -36., LEVEL_Z);
pub const ALT_DOOR_POSITION: (f32, f32, f32) = (-2.5, 6., LEVEL_Z);
pub const OUT_DOOR_POSITION: (f32, f32, f32) = (5., 36., LEVEL_Z);

pub const BUTTON_POSITION: (f32, f32, f32) = (-24., 6., LEVEL_Z - 1.);
pub const BUTTON_HITBOX_X_OFFSET: (f32, f32, f32) = (3., 0., 0.);
pub const BUTTON_SENSOR_POSITION: (f32, f32, f32) = (-25.5, 6., LEVEL_Z);
}
}

pub mod cinematics {
pub const CLOUDS_LIMIT: f32 = -333.;
pub const CLOUDS_RESET: f32 = 334.;
pub const SECOND_CLOUDS_INIT: f32 = 1001.;
}

pub mod ui {
pub mod tablet {
use bevy::prelude::Color;
Expand Down
193 changes: 193 additions & 0 deletions src/locations/cinematics/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
//! This is a speedrun to have an cinematic in this game-mockup
//! Do not use it as example (not a good one at least)
use bevy::prelude::*;

use crate::{
characters::npcs::NPC,
constants::{FRAME_TIME, locations::LEVEL_SCALE, cinematics::*},
tablet::mind_control::MindControled,
spritesheet::AnimationTimer,
};

/* -------------------------------------------------------------------------- */
/* Final */
/* -------------------------------------------------------------------------- */

/// Marker for the final cat sprite anim
#[derive(Component)]
struct FinalFormCat;

/// Marker for the final cat sprite anim
#[derive(Component)]
pub struct Clouds;

#[derive(Component)]
pub struct PlayerHusk;

pub fn cinematic_camera(
mut camera_query: Query<&mut Transform, With<Camera>>,
) {
let mut camera_transform = camera_query.single_mut();

camera_transform.translation.x = 0.;
camera_transform.translation.y = 3.;

camera_transform.scale = Vec3::new(1.4, 1.4, 1.)
}

pub fn spawn_cinematic_final(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
mut clear_color: ResMut<ClearColor>,

blue_cat_controlled_query: Query<Entity, (Without<NPC>, With<MindControled>)>,
) {
info!("Spawn Cinematic");

clear_color.0 = Color::rgb(0.753, 0.126, 0.158);

commands.spawn((
SpriteBundle {
texture: asset_server.load("textures/cinematics/final/FullClouds.png"),
transform: Transform {
translation: Vec3::from((CLOUDS_RESET, 0., 1.)),
scale: Vec3::from(LEVEL_SCALE),
..default()
},
..default()
},
Name::new("Cinematics - Clouds"),
Clouds,
// -- Animation --
AnimationTimer(Timer::from_seconds(FRAME_TIME, TimerMode::Repeating)),
));

commands.spawn((
SpriteBundle {
texture: asset_server.load("textures/cinematics/final/FullClouds.png"),
transform: Transform {
translation: Vec3::from((SECOND_CLOUDS_INIT, 0., 1.)),
scale: Vec3::from(LEVEL_SCALE),
..default()
},
..default()
},
Name::new("Cinematics - Clouds"),
Clouds,
// -- Animation --
AnimationTimer(Timer::from_seconds(FRAME_TIME, TimerMode::Repeating)),
));

commands.spawn((
SpriteBundle {
texture: asset_server.load("textures/cinematics/final/evasion-mountain-lab.png"),
transform: Transform {
translation: Vec3::from((0., 0., 2.)),
scale: Vec3::from(LEVEL_SCALE),
..default()
},
..default()
},
Name::new("Cinematics - Mountain Lab"),
));

let cat_escape_image = if blue_cat_controlled_query.is_empty() {
info!("EasterEgg: Black Cat Escaped");
asset_server.load("textures/cinematics/final/black-cat-sheet.png")
} else {
info!("NormalEnd: Blue Cat Escaped");
asset_server.load("textures/cinematics/final/blue-cat-sheet.png")
};

let cat_escape_atlas = TextureAtlas::from_grid(
cat_escape_image,
Vec2::from((19., 17.)),
14,
1,
None,
None,
);
let cat_escape_atlas_handle = texture_atlases.add(cat_escape_atlas);

commands.spawn((
SpriteSheetBundle {
texture_atlas: cat_escape_atlas_handle.clone(),
transform: Transform {
translation: Vec3::from((12., -12., 9.)),
scale: Vec3::from(LEVEL_SCALE),
..default()
},
..default()
},
Name::new("Cinematics - Cat"),
PlayerHusk,
// -- Animation --
AnimationTimer(Timer::from_seconds(FRAME_TIME, TimerMode::Repeating)),
));

info!("Cinematic Spawned");
}

// TODO: spawn a Quit button after x seconds
// TODO: adpat the camera to be centered on the endcinematic

// LEVEL_SCALE

/// Infinitly loop the clouds
pub fn animate_clouds(
time: Res<Time>,
mut clouds_query: Query<
(
&mut AnimationTimer,
&mut Transform,
),
With<Clouds>,
>,
) {
for (mut timer, mut transform) in &mut clouds_query {
timer.tick(time.delta());

if timer.just_finished() {
transform.translation.x =
if transform.translation.x == CLOUDS_LIMIT {
CLOUDS_RESET
} else {
// IDEA: can be smoother if - 0.1 and faster timer
transform.translation.x - 1.
};
}
}
}

pub fn animate_free_cat(
texture_atlases: Res<Assets<TextureAtlas>>,

time: Res<Time>,
mut running_cat: Query<
(
&mut AnimationTimer,
&mut TextureAtlasSprite,
&Handle<TextureAtlas>,
),
With<PlayerHusk>,
>,
) {
for (mut timer, mut sprite, texture_atlas_handle) in &mut running_cat {
timer.tick(time.delta());

if timer.just_finished() {
let texture_atlas = texture_atlases.get(texture_atlas_handle).unwrap();

sprite.index = if sprite.index + 1 < texture_atlas.textures.len() {
sprite.index + 1
} else if sprite.index == texture_atlas.textures.len() - 1 {
texture_atlas.textures.len() - 2
} else {
warn!("Overflow CatAnim FinalCinematic");
texture_atlas.textures.len() - 2
};
}
}
}
4 changes: 2 additions & 2 deletions src/locations/level_one/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::constants::locations::{
/// Link Doors and Button:
/// Button { pub linked_doors: Vec<Entity> }
#[derive(Component)]
pub struct Button;
pub struct PushButton;

#[derive(Component)]
pub struct ButtonSensor;
Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn set_up_button(
..default()
},
Name::new("OneWay Button"),
Button,
PushButton,
RigidBody::Dynamic,
LockedAxes::ROTATION_LOCKED,
))
Expand Down
Loading

0 comments on commit ed6e78e

Please sign in to comment.