Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
stillonearth committed Jun 27, 2024
1 parent c56e4e9 commit 052a97e
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 85 deletions.
38 changes: 28 additions & 10 deletions src/cutscene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ fn setup_cutscene(
left: Val::Px(20.0),
..default()
},
z_index: ZIndex::Global(100),
background_color: Color::WHITE.into(),
..default()
},
UiImage::new(avatar_assets.alextime.clone()),
Name::new("avatar alextime"),
CutsceneAvatarAlextime,
// ZIndex::Local(100),
));

parent.spawn((
Expand All @@ -104,6 +106,7 @@ fn setup_cutscene(
..default()
},
background_color: Color::WHITE.into(),
z_index: ZIndex::Global(100),
..default()
},
UiImage::new(avatar_assets.gennadiy.clone()),
Expand All @@ -119,6 +122,7 @@ fn setup_cutscene(
margin: UiRect::bottom(Val::Percent(10.)),
..default()
},
z_index: ZIndex::Global(101),
..default()
},
Name::new("dialog text"),
Expand Down Expand Up @@ -160,7 +164,7 @@ fn setup_cutscene(
.with_children(|parent| {
parent.spawn((
TextBundle::from_section(
" PRISON CPS 17\n <<MICHOACAN>>\nMEXICO, BUENAVISTA",
" PRISON CPS 17\nMEXICO, BUENAVISTA",
TextStyle {
font: font_assets.pixeloid_mono.clone(),
font_size: 40.0,
Expand Down Expand Up @@ -261,14 +265,28 @@ fn handle_cutscene_text(

fn get_cutscene_dialog_text() -> Vec<(usize, String)> {
vec![
(0, "LEGEND OF MIERDA".to_string()),
(1, "VERSION 24-4-4".to_string()),
// (0, "Privet gennadiy!.".to_string()),
// (0, "Shapka the snachala.".to_string()),
// (0, "Ya Alexey Viktorovich Makeev".to_string()),
// (0, "AlexTime".to_string()),
// (0, "Date of birth 08/22/1974".to_string()),
// (0, "Citizen of Russia".to_string()),
// (0, "CPS 17 Michoacan".to_string()),
(
1,
"Your Highness, they've charged you with smuggling red caviar into the mess hall."
.to_string(),
),
(
0,
"Ah, Gena, they simply cannot resist my gourmet diplomacy".to_string(),
),
(
1,
"Diplomacy, sire? It's more like high-seas gastronomy.".to_string(),
),
(
0,
"Fear not, Gena. If they lock me up, I'll become the Cell Block Caviar Tsar!"
.to_string(),
),
(
1,
"Your platform: From the Elecrostahl to the cell, promising red caviar for all!"
.to_string(),
),
]
}
22 changes: 13 additions & 9 deletions src/entities/weapons/machete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ use std::time::Duration;
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
use bevy_particle_systems::Lerpable;

use crate::GameState;
use crate::{controls::ControlEvent, entities::player::Player};

use crate::{
controls::ControlEvent,
entities::{
player::Player,
},
};
use crate::{GameState};
// note to self: attack happens every 1.3 seconds but there is delay
// for attack 0.3 secodns so i hinda hack this around

// ----------
// Components
Expand Down Expand Up @@ -96,8 +93,12 @@ fn animate_machete_indicator(
mut materials: ResMut<Assets<ColorMaterial>>,
) {
for (_, mut material, timer) in q_machete.iter_mut() {
let current_value = timer.0.percent_left().max(0.2);
let percentage = timer.0.percent_left().max(0.2).lerp(0.8, current_value);
let elapsed = timer.0.elapsed_secs();
let mut percentage = (1.0 - elapsed) / (1.0 - 0.3);
if elapsed < 0.3 {
percentage = 0.0;
}

*material = materials.add(ColorMaterial::from(Color::PURPLE.with_a(percentage)));
}
}
Expand All @@ -106,6 +107,9 @@ fn animate_machete_indicator(
// Plugin
// ------

// I--------I--------I
// x x

pub struct MachetePlugin;

impl Plugin for MachetePlugin {
Expand Down
50 changes: 42 additions & 8 deletions src/gameover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ use crate::{ui::UIGameOver, AudioAssets, ButtonColors, ChangeState, FontAssets,
#[derive(Event, Clone)]
pub struct GameOverEvent;

#[derive(Event, Clone)]
pub struct GameWinEvent;

#[derive(Component)]
struct UIGameOverButton;

#[derive(Component)]
struct UIGameOverText;

pub fn event_game_over(
mut ev_game_over: EventReader<GameOverEvent>,
mut q_ui_game_over: Query<(&mut Visibility, &UIGameOver)>,
mut next_state: ResMut<NextState<GameState>>,
audio: Res<Audio>,
audio_assets: Res<AudioAssets>,
mut text_query: Query<(&mut Text, &UIGameOverText)>,
) {
for _ in ev_game_over.read() {
for (mut visibility, _) in q_ui_game_over.iter_mut() {
Expand All @@ -23,6 +30,30 @@ pub fn event_game_over(

audio.play(audio_assets.gameover.clone()).with_volume(0.5);
next_state.set(GameState::GameOver);
for (mut text_component, _) in text_query.iter_mut() {
text_component.sections[0].value = " JUEGO\nTERMINADO".to_string();
}
}
}

pub fn event_game_won(
mut ev_game_over: EventReader<GameOverEvent>,
mut q_ui_game_over: Query<(&mut Visibility, &UIGameOver)>,
mut next_state: ResMut<NextState<GameState>>,
audio: Res<Audio>,
audio_assets: Res<AudioAssets>,
mut text_query: Query<(&mut Text, &UIGameOverText)>,
) {
for _ in ev_game_over.read() {
for (mut visibility, _) in q_ui_game_over.iter_mut() {
*visibility = Visibility::Visible;
}

// audio.play(audio_assets.gameover.clone()).with_volume(0.5);
next_state.set(GameState::GameOver);
for (mut text_component, _) in text_query.iter_mut() {
text_component.sections[0].value = " JUEGO\nGANADO".to_string();
}
}
}

Expand Down Expand Up @@ -53,13 +84,16 @@ pub(crate) fn draw_ui(mut commands: Commands, font_assets: Res<FontAssets>) {
Name::new("ui game over"),
))
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
" JUEGO\nTERMINADO",
TextStyle {
font: font_assets.pixeloid_mono.clone(),
font_size: 100.0,
color: Color::WHITE,
},
parent.spawn((
TextBundle::from_section(
" JUEGO\nTERMINADO",
TextStyle {
font: font_assets.pixeloid_mono.clone(),
font_size: 100.0,
color: Color::WHITE,
},
),
UIGameOverText,
));

parent
Expand Down Expand Up @@ -134,7 +168,7 @@ impl Plugin for GameOverPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(event_game_over,).run_if(in_state(GameState::GamePlay)),
(event_game_over, event_game_won).run_if(in_state(GameState::GamePlay)),
)
.add_systems(
Update,
Expand Down
96 changes: 53 additions & 43 deletions src/gameplay/waves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use std::time::Duration;
use bevy::prelude::*;
use rand::Rng;

use crate::entities::characters::enemy::{EnemyType, SpawnEnemyEvent};
use crate::entities::characters::enemy::{Enemy, EnemyType, SpawnEnemyEvent};
use crate::entities::items::item::ItemType;
use crate::gameover::{GameOverEvent, GameWinEvent};
use crate::ldtk::LevelChangeEvent;
use crate::GameState;
use crate::{entities::items::item::SpawnItemEvent, ui::*};

#[derive(Clone)]
Expand Down Expand Up @@ -166,6 +168,25 @@ pub fn event_on_level_change(
}
}

pub fn check_game_won_or_lost(
mut next_state: ResMut<NextState<GameState>>,
gameplay_state: Res<GameplayState>,
query: Query<&Enemy>,
mut ev_game_won: EventWriter<GameWinEvent>,
) {
// check if current wave is last
if let Some(current_wave) = gameplay_state.current_wave() {
if gameplay_state.wave_number.unwrap()
== (gameplay_state.current_level_waves().unwrap().len() - 1)
{
// check if all enemies are dead
if query.iter().count() == 0 {
ev_game_won.send(GameWinEvent);
}
}
}
}

pub fn event_wave(
mut er_on_wave_change: EventReader<WaveEvent>,

Expand Down Expand Up @@ -241,48 +262,37 @@ pub fn ui_wave_info_text(
pub fn get_level_1_waves() -> Vec<Wave> {
vec![
Wave {
events: vec![WaveEntry::Mierda { count: 800 }],
// events: vec![WaveEntry::Boss { count: 1 }],
event_duration: Duration::from_secs(30),
wave_duration: Duration::from_secs(30),
events: vec![WaveEntry::Mierda { count: 100 }],
event_duration: Duration::from_secs(10),
wave_duration: Duration::from_secs(10),
},
Wave {
events: vec![
WaveEntry::Mierda { count: 100 },
WaveEntry::Pizza { count: 5 },
WaveEntry::Mierda { count: 100 },
WaveEntry::Biboran { count: 5 },
WaveEntry::Mierda { count: 100 },
],
event_duration: Duration::from_secs(10),
wave_duration: Duration::from_secs(40),
},
Wave {
events: vec![
WaveEntry::Pendejo { count: 100 },
WaveEntry::Pizza { count: 3 },
WaveEntry::Pendejo { count: 100 },
WaveEntry::Pizza { count: 3 },
WaveEntry::Pendejo { count: 100 },
WaveEntry::Pizza { count: 3 },
],
event_duration: Duration::from_secs(5),
wave_duration: Duration::from_secs(60),
},
Wave {
events: vec![WaveEntry::Boss { count: 1 }],
event_duration: Duration::from_secs(5),
wave_duration: Duration::from_secs(120),
},
// Wave {
// events: vec![
// WaveEntry::Mierda { count: 200 },
// WaveEntry::Pizza { count: 5 },
// WaveEntry::Mierda { count: 300 },
// WaveEntry::Biboran { count: 5 },
// WaveEntry::Mierda { count: 400 },
// ],
// event_duration: Duration::from_secs(10),
// wave_duration: Duration::from_secs(60),
// },
// Wave {
// events: vec![
// WaveEntry::Pendejo { count: 200 },
// WaveEntry::Pizza { count: 3 },
// WaveEntry::Pendejo { count: 200 },
// WaveEntry::Pizza { count: 3 },
// WaveEntry::Pendejo { count: 200 },
// WaveEntry::Pizza { count: 3 },
// WaveEntry::Pendejo { count: 200 },
// WaveEntry::Pizza { count: 3 },
// WaveEntry::Pendejo { count: 200 },
// WaveEntry::Pizza { count: 3 },
// WaveEntry::Pendejo { count: 200 },
// WaveEntry::Pizza { count: 3 },
// WaveEntry::Pendejo { count: 200 },
// WaveEntry::Pizza { count: 3 },
// WaveEntry::Pendejo { count: 200 },
// WaveEntry::Pizza { count: 3 },
// ],
// event_duration: Duration::from_secs(5),
// wave_duration: Duration::from_secs(120),
// },
// Wave {
// events: vec![WaveEntry::Boss { count: 1 }],
// event_duration: Duration::from_secs(5),
// wave_duration: Duration::from_secs(120),
// },
]
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn main() {
.set(WindowPlugin {
primary_window: Some(Window {
title: "Legend of Mierda".into(),
resolution: (900., 900.).into(),
resolution: (700., 700.).into(),
present_mode: PresentMode::AutoVsync,
fit_canvas_to_parent: true,
prevent_default_event_handling: false,
Expand Down
Loading

0 comments on commit 052a97e

Please sign in to comment.