Compare commits
No commits in common. "d9232fd5f013383bbe3e8dc7773e4a111d0fb657" and "683bfa2c999ff1315b556b84524a82d9cde0fbdf" have entirely different histories.
d9232fd5f0
...
683bfa2c99
10 changed files with 183 additions and 377 deletions
11
README.md
11
README.md
|
@ -1,21 +1,18 @@
|
||||||
# Bevyjam
|
# Bevyjam
|
||||||
|
|
||||||
## Controls
|
|
||||||
|
|
||||||
* **Move**: arrows
|
|
||||||
* **Switch character**: Tab
|
|
||||||
* **Level up**: Enter (when character is white)
|
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
* name
|
* name
|
||||||
|
* scene management
|
||||||
* stream audio (with HexoSynthDSP)
|
* stream audio (with HexoSynthDSP)
|
||||||
|
* character fusion
|
||||||
* color filters
|
* color filters
|
||||||
* level design
|
* level design
|
||||||
|
* win
|
||||||
|
* menu GUI
|
||||||
* (?) can jump only from a surface (no mid-air jump)
|
* (?) can jump only from a surface (no mid-air jump)
|
||||||
* (?) multiplayer
|
* (?) multiplayer
|
||||||
* make WASM build work again (replace hanabi)
|
* make WASM build work again (replace hanabi)
|
||||||
* level reset
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
|
|
BIN
assets/Cantarell-VF.otf
Normal file
BIN
assets/Cantarell-VF.otf
Normal file
Binary file not shown.
Binary file not shown.
317
src/game.rs
317
src/game.rs
|
@ -1,21 +1,17 @@
|
||||||
#![allow(clippy::precedence)]
|
#![allow(clippy::precedence)]
|
||||||
#![allow(clippy::too_many_arguments)]
|
|
||||||
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
input::{keyboard::KeyCode, Input},
|
input::{keyboard::KeyCode, Input},
|
||||||
prelude::{shape::Quad, *},
|
prelude::{shape::Quad, *},
|
||||||
sprite::Mesh2dHandle,
|
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
|
||||||
};
|
};
|
||||||
use bevy_fundsp::prelude::*;
|
use bevy_fundsp::prelude::*;
|
||||||
use bevy_hanabi::*;
|
use bevy_hanabi::*;
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
|
||||||
pub struct LevelId(pub u32);
|
|
||||||
|
|
||||||
pub struct GamePlugin;
|
pub struct GamePlugin;
|
||||||
|
|
||||||
impl Plugin for GamePlugin {
|
impl Plugin for GamePlugin {
|
||||||
|
@ -24,29 +20,24 @@ impl Plugin for GamePlugin {
|
||||||
.init_resource::<CharacterMeshes>()
|
.init_resource::<CharacterMeshes>()
|
||||||
.insert_resource(CurrentLevel(None))
|
.insert_resource(CurrentLevel(None))
|
||||||
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(setup))
|
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(setup))
|
||||||
.add_system_set(SystemSet::on_enter(AppState::Win).with_system(win_setup))
|
|
||||||
.add_system_set(
|
|
||||||
SystemSet::on_exit(AppState::Win).with_system(crate::levels::despawn_level),
|
|
||||||
)
|
|
||||||
.add_system_set(
|
.add_system_set(
|
||||||
SystemSet::on_update(AppState::Game)
|
SystemSet::on_update(AppState::Game)
|
||||||
.with_system(crate::levels::post_setup_level)
|
.with_system(post_setup_level)
|
||||||
.with_system(keyboard_input_system),
|
.with_system(keyboard_input_system),
|
||||||
)
|
)
|
||||||
.add_system_set(SystemSet::on_update(AppState::Win).with_system(keyboard_input_system))
|
|
||||||
.add_system_to_stage(CoreStage::PostUpdate, collision_event_system);
|
.add_system_to_stage(CoreStage::PostUpdate, collision_event_system);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
|
|
||||||
pub struct LevelStartupEvent(pub Entity);
|
struct LevelStartupEvent(Entity);
|
||||||
|
|
||||||
// Resources
|
// Resources
|
||||||
|
|
||||||
pub struct CurrentLevel(pub Option<LevelId>);
|
struct CurrentLevel(Option<Entity>);
|
||||||
|
|
||||||
pub struct CharacterMeshes {
|
struct CharacterMeshes {
|
||||||
square: Mesh2dHandle,
|
square: Mesh2dHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,20 +57,17 @@ impl FromWorld for CharacterMeshes {
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Clone, Component, Copy, Eq, Hash, PartialEq)]
|
||||||
pub struct Level;
|
struct LevelId(u32);
|
||||||
|
|
||||||
#[derive(Clone, Component, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Component, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct CharacterId(pub u32);
|
struct CharacterId(u32);
|
||||||
|
|
||||||
#[derive(Clone, Component, Copy, Eq, Hash, PartialEq)]
|
#[derive(Clone, Component, Copy, Eq, Hash, PartialEq)]
|
||||||
pub struct SelectedCharacterId(pub Option<CharacterId>);
|
struct SelectedCharacterId(Option<CharacterId>);
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct CharacterIdList(pub BTreeSet<CharacterId>);
|
struct CharacterIdList(BTreeSet<CharacterId>);
|
||||||
|
|
||||||
#[derive(Clone, Component, PartialEq)]
|
|
||||||
pub struct CharacterColor(pub Color);
|
|
||||||
|
|
||||||
// Systems
|
// Systems
|
||||||
|
|
||||||
|
@ -88,16 +76,69 @@ fn setup(
|
||||||
mut current_level: ResMut<CurrentLevel>,
|
mut current_level: ResMut<CurrentLevel>,
|
||||||
mut level_startup_event: EventWriter<LevelStartupEvent>,
|
mut level_startup_event: EventWriter<LevelStartupEvent>,
|
||||||
) {
|
) {
|
||||||
let level_id = LevelId(current_level.0.map_or(0, |level_id| level_id.0 + 1));
|
let level_entity = commands
|
||||||
crate::levels::setup_level(
|
.spawn()
|
||||||
&mut commands,
|
.insert(LevelId(0))
|
||||||
&mut current_level,
|
.insert(SelectedCharacterId(None))
|
||||||
&mut level_startup_event,
|
.insert(CharacterIdList(BTreeSet::new()))
|
||||||
level_id,
|
.id();
|
||||||
);
|
current_level.0 = Some(level_entity);
|
||||||
|
|
||||||
|
commands
|
||||||
|
.spawn_bundle(TransformBundle::from(Transform::from_xyz(0.0, -256.0, 0.0)))
|
||||||
|
.insert(Collider::cuboid(400., 10.));
|
||||||
|
|
||||||
|
level_startup_event.send(LevelStartupEvent(level_entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_character(
|
// This is a bad design, but it's the only way I found
|
||||||
|
fn post_setup_level(
|
||||||
|
mut commands: Commands,
|
||||||
|
character_meshes: Res<CharacterMeshes>,
|
||||||
|
mut effects: ResMut<Assets<EffectAsset>>,
|
||||||
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
||||||
|
mut level_startup_event: EventReader<LevelStartupEvent>,
|
||||||
|
) {
|
||||||
|
for LevelStartupEvent(level_entity) in level_startup_event.iter() {
|
||||||
|
if let Ok((mut selected_character_id, mut character_id_list)) =
|
||||||
|
level_query.get_mut(*level_entity)
|
||||||
|
{
|
||||||
|
spawn_character(
|
||||||
|
&mut commands,
|
||||||
|
&character_meshes,
|
||||||
|
&mut effects,
|
||||||
|
&mut materials,
|
||||||
|
&mut selected_character_id,
|
||||||
|
&mut character_id_list,
|
||||||
|
Transform::from_xyz(-128., -64., 0.),
|
||||||
|
Color::RED,
|
||||||
|
);
|
||||||
|
spawn_character(
|
||||||
|
&mut commands,
|
||||||
|
&character_meshes,
|
||||||
|
&mut effects,
|
||||||
|
&mut materials,
|
||||||
|
&mut selected_character_id,
|
||||||
|
&mut character_id_list,
|
||||||
|
Transform::from_xyz(0., -64., 0.),
|
||||||
|
Color::GREEN,
|
||||||
|
);
|
||||||
|
spawn_character(
|
||||||
|
&mut commands,
|
||||||
|
&character_meshes,
|
||||||
|
&mut effects,
|
||||||
|
&mut materials,
|
||||||
|
&mut selected_character_id,
|
||||||
|
&mut character_id_list,
|
||||||
|
Transform::from_xyz(128., -64., 0.),
|
||||||
|
Color::BLUE,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_character(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
character_meshes: &Res<CharacterMeshes>,
|
character_meshes: &Res<CharacterMeshes>,
|
||||||
effects: &mut ResMut<Assets<EffectAsset>>,
|
effects: &mut ResMut<Assets<EffectAsset>>,
|
||||||
|
@ -133,22 +174,20 @@ pub fn spawn_character(
|
||||||
.clamp(Vec4::new(0., 0., 0., 0.), Vec4::new(1., 1., 1., 0.)),
|
.clamp(Vec4::new(0., 0., 0., 0.), Vec4::new(1., 1., 1., 0.)),
|
||||||
);
|
);
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(ColorMesh2dBundle {
|
.spawn_bundle(MaterialMesh2dBundle {
|
||||||
mesh: character_meshes.square.clone(),
|
mesh: character_meshes.square.clone(),
|
||||||
material: materials.add(ColorMaterial::from(color)),
|
material: materials.add(ColorMaterial::from(color)),
|
||||||
transform,
|
transform,
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.insert(Level)
|
|
||||||
.insert(character_id)
|
.insert(character_id)
|
||||||
.insert(CharacterColor(color))
|
|
||||||
.insert(RigidBody::Dynamic)
|
.insert(RigidBody::Dynamic)
|
||||||
.insert(Collider::cuboid(32., 32.))
|
.insert(Collider::cuboid(32., 32.))
|
||||||
.insert(ExternalForce::default())
|
.insert(ExternalForce::default())
|
||||||
.insert(Velocity::default())
|
.insert(Velocity::default())
|
||||||
.insert(GravityScale(10.0))
|
.insert(GravityScale(10.0))
|
||||||
.insert(LockedAxes::ROTATION_LOCKED)
|
.insert(LockedAxes::ROTATION_LOCKED)
|
||||||
.insert(Friction::new(0.8))
|
.insert(Friction::new(1.0))
|
||||||
.insert(Damping {
|
.insert(Damping {
|
||||||
linear_damping: 0.5,
|
linear_damping: 0.5,
|
||||||
angular_damping: 0.5,
|
angular_damping: 0.5,
|
||||||
|
@ -192,50 +231,31 @@ pub fn spawn_character(
|
||||||
|
|
||||||
fn collision_event_system(
|
fn collision_event_system(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
character_meshes: Res<CharacterMeshes>,
|
//materials: ResMut<Assets<ColorMaterial>>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
current_level: Res<CurrentLevel>,
|
||||||
mut effects: ResMut<Assets<EffectAsset>>,
|
|
||||||
mut collision_events: EventReader<CollisionEvent>,
|
mut collision_events: EventReader<CollisionEvent>,
|
||||||
character_query: Query<(&CharacterId, &CharacterColor, &Transform)>,
|
//character_query: Query<(&CharacterId, &Handle<ColorMaterial>)>,
|
||||||
|
character_query: Query<&CharacterId>,
|
||||||
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
||||||
mut app_state: ResMut<State<AppState>>,
|
|
||||||
) {
|
) {
|
||||||
for collision_event in collision_events.iter() {
|
if let Some(level_entity) = current_level.0 {
|
||||||
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
|
for collision_event in collision_events.iter() {
|
||||||
if flags.is_empty() {
|
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
|
||||||
if let (Ok((c1_id, c1_color, c1_transform)), Ok((c2_id, c2_color, _c2_transform))) =
|
if flags.is_empty() {
|
||||||
(character_query.get(*e1), character_query.get(*e2))
|
//if let (Ok((c1_id, c1_material)), Ok((c2_id, c2_material))) =
|
||||||
{
|
if let (Ok(c1_id), Ok(c2_id)) =
|
||||||
let (mut selected_character_id, mut character_id_list) =
|
(character_query.get(*e1), character_query.get(*e2))
|
||||||
level_query.single_mut();
|
|
||||||
character_id_list.0.remove(c1_id);
|
|
||||||
character_id_list.0.remove(c2_id);
|
|
||||||
selected_character_id.0 = None;
|
|
||||||
|
|
||||||
// TODO completely remove particles
|
|
||||||
commands.entity(*e1).despawn_recursive();
|
|
||||||
commands.entity(*e2).despawn_recursive();
|
|
||||||
|
|
||||||
let new_color = (Vec4::from(c1_color.0) + Vec4::from(c2_color.0))
|
|
||||||
.clamp(Vec4::ZERO, Vec4::ONE);
|
|
||||||
|
|
||||||
// If color approximately white
|
|
||||||
if app_state.current() == &AppState::Game
|
|
||||||
&& 4. - new_color.length_squared() < 0.1
|
|
||||||
{
|
{
|
||||||
app_state.replace(AppState::Win).ok();
|
//c1_material.color = (Vec4::from(c1_material.color) + Vec4::from(c2_material.color)).into();
|
||||||
}
|
|
||||||
|
|
||||||
spawn_character(
|
let (mut selected_character_id, mut character_id_list) =
|
||||||
&mut commands,
|
level_query.get_mut(level_entity).unwrap();
|
||||||
&character_meshes,
|
character_id_list.0.remove(c2_id);
|
||||||
&mut effects,
|
if selected_character_id.0 == Some(*c2_id) {
|
||||||
&mut materials,
|
selected_character_id.0 = Some(*c1_id);
|
||||||
&mut selected_character_id,
|
}
|
||||||
&mut character_id_list,
|
commands.entity(*e2).despawn_recursive();
|
||||||
*c1_transform,
|
}
|
||||||
new_color.into(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,9 +264,10 @@ fn collision_event_system(
|
||||||
|
|
||||||
fn keyboard_input_system(
|
fn keyboard_input_system(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<Input<KeyCode>>,
|
||||||
|
current_level: Res<CurrentLevel>,
|
||||||
mut characters: Query<(
|
mut characters: Query<(
|
||||||
&CharacterId,
|
&CharacterId,
|
||||||
&mut Velocity,
|
&mut Velocity,
|
||||||
&mut ExternalImpulse,
|
&mut ExternalImpulse,
|
||||||
&mut ExternalForce,
|
&mut ExternalForce,
|
||||||
&Children,
|
&Children,
|
||||||
|
@ -255,92 +276,100 @@ fn keyboard_input_system(
|
||||||
mut effect: Query<&mut ParticleEffect>,
|
mut effect: Query<&mut ParticleEffect>,
|
||||||
dsp_assets: Res<DspAssets>,
|
dsp_assets: Res<DspAssets>,
|
||||||
audio: Res<Audio>,
|
audio: Res<Audio>,
|
||||||
mut app_state: ResMut<State<AppState>>,
|
|
||||||
) {
|
) {
|
||||||
if let Ok((mut selected_character_id, character_id_list)) = level_query.get_single_mut() {
|
if let Some(level_entity) = current_level.0 {
|
||||||
if keyboard_input.just_pressed(KeyCode::Tab) {
|
if let Ok((mut selected_character_id, character_id_list)) =
|
||||||
audio.play(dsp_assets.graph(&sine_wave));
|
level_query.get_mut(level_entity)
|
||||||
|
{
|
||||||
|
if keyboard_input.just_pressed(KeyCode::Tab) {
|
||||||
|
audio.play(dsp_assets.graph(&sine_wave));
|
||||||
|
|
||||||
let selected = if let Some(selected_character_id) = &mut selected_character_id.0 {
|
let selected = if let Some(selected_character_id) = &mut selected_character_id.0 {
|
||||||
if let Some((_character_id, _velocity, _impulse, _force, children)) = characters
|
if let Some((
|
||||||
.iter_mut()
|
_character_id,
|
||||||
.find(|(character_id, _velocity, _impulse, _force, _children)| {
|
_velocity,
|
||||||
*character_id == selected_character_id
|
_impulse,
|
||||||
}) {
|
_force,
|
||||||
|
children
|
||||||
|
|
||||||
|
)) = characters.iter_mut().find(|(
|
||||||
|
character_id,
|
||||||
|
_velocity,
|
||||||
|
_impulse,
|
||||||
|
_force,
|
||||||
|
_children
|
||||||
|
|
||||||
|
)| { *character_id == selected_character_id }) {
|
||||||
|
effect
|
||||||
|
.get_mut(children[0])
|
||||||
|
.unwrap()
|
||||||
|
.maybe_spawner()
|
||||||
|
.unwrap()
|
||||||
|
.set_active(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
*selected_character_id = *character_id_list
|
||||||
|
.0
|
||||||
|
.range(*selected_character_id..)
|
||||||
|
.nth(1)
|
||||||
|
.unwrap_or_else(|| character_id_list.0.iter().next().unwrap());
|
||||||
|
*selected_character_id
|
||||||
|
} else {
|
||||||
|
selected_character_id.0 = Some(CharacterId(0));
|
||||||
|
CharacterId(0)
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some((
|
||||||
|
_character_id,
|
||||||
|
_velocity,
|
||||||
|
_impulse,
|
||||||
|
_force,
|
||||||
|
children
|
||||||
|
)) = characters.iter_mut().find(|(
|
||||||
|
character_id,
|
||||||
|
_velocity,
|
||||||
|
_impulse,
|
||||||
|
_force,
|
||||||
|
_children
|
||||||
|
)| **character_id == selected)
|
||||||
|
{
|
||||||
effect
|
effect
|
||||||
.get_mut(children[0])
|
.get_mut(children[0])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.maybe_spawner()
|
.maybe_spawner()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_active(false);
|
.set_active(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
*selected_character_id = *character_id_list
|
|
||||||
.0
|
|
||||||
.range(*selected_character_id..)
|
|
||||||
.nth(1)
|
|
||||||
.unwrap_or_else(|| character_id_list.0.iter().next().unwrap());
|
|
||||||
*selected_character_id
|
|
||||||
} else {
|
|
||||||
selected_character_id.0 = Some(CharacterId(0));
|
|
||||||
CharacterId(0)
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some((_character_id, _velocity, _impulse, _force, children)) = characters
|
|
||||||
.iter_mut()
|
|
||||||
.find(|(character_id, _velocity, _impulse, _force, _children)| {
|
|
||||||
**character_id == selected
|
|
||||||
}) {
|
|
||||||
effect
|
|
||||||
.get_mut(children[0])
|
|
||||||
.unwrap()
|
|
||||||
.maybe_spawner()
|
|
||||||
.unwrap()
|
|
||||||
.set_active(true);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let right_pressed: bool =
|
let right_pressed: bool = keyboard_input.pressed(KeyCode::Right) || keyboard_input.pressed(KeyCode::D);
|
||||||
keyboard_input.pressed(KeyCode::Right) || keyboard_input.pressed(KeyCode::D);
|
let left_pressed: bool = keyboard_input.pressed(KeyCode::Left) || keyboard_input.pressed(KeyCode::A);
|
||||||
let left_pressed: bool =
|
|
||||||
keyboard_input.pressed(KeyCode::Left) || keyboard_input.pressed(KeyCode::A);
|
|
||||||
|
|
||||||
if let Some(selected_character_id) = &selected_character_id.0 {
|
if let Some(selected_character_id) = &selected_character_id.0 {
|
||||||
if let Some((_character_id, mut velocity, _impulse, _force, _children)) = characters
|
if let Some((
|
||||||
.iter_mut()
|
_character_id,
|
||||||
.find(|(character_id, _velocity, _impulse, _force, _children)| {
|
mut velocity,
|
||||||
*character_id == selected_character_id
|
mut impulse,
|
||||||
}) {
|
mut force,
|
||||||
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
|
_children
|
||||||
|
|
||||||
if keyboard_input.just_pressed(KeyCode::Space) {
|
)) = characters.iter_mut().find(|(
|
||||||
velocity.linvel.y = 500.;
|
character_id,
|
||||||
|
_velocity,
|
||||||
|
_impulse,
|
||||||
|
_force,
|
||||||
|
_children
|
||||||
|
|
||||||
|
)| { *character_id == selected_character_id }) {
|
||||||
|
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
|
||||||
|
|
||||||
|
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||||
|
velocity.linvel.y = 500.;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if app_state.current() == &AppState::Win && keyboard_input.just_pressed(KeyCode::Return) {
|
|
||||||
app_state.replace(AppState::Game).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn win_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
||||||
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
|
||||||
commands
|
|
||||||
.spawn_bundle(Text2dBundle {
|
|
||||||
text: Text::from_section(
|
|
||||||
"Press ENTER to level up",
|
|
||||||
TextStyle {
|
|
||||||
font,
|
|
||||||
font_size: 32.0,
|
|
||||||
color: Color::WHITE,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.with_alignment(TextAlignment::CENTER),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.insert(Level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sounds
|
// Sounds
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
#![allow(clippy::too_many_arguments)]
|
|
||||||
|
|
||||||
mod game_over;
|
|
||||||
mod level0;
|
|
||||||
mod level1;
|
|
||||||
|
|
||||||
use crate::game::*;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
|
||||||
use bevy_hanabi::*;
|
|
||||||
use std::collections::BTreeSet;
|
|
||||||
|
|
||||||
pub fn setup_level(
|
|
||||||
commands: &mut Commands,
|
|
||||||
current_level: &mut ResMut<CurrentLevel>,
|
|
||||||
level_startup_event: &mut EventWriter<LevelStartupEvent>,
|
|
||||||
level_id: LevelId,
|
|
||||||
) {
|
|
||||||
let level_entity = commands
|
|
||||||
.spawn()
|
|
||||||
.insert(Level)
|
|
||||||
.insert(SelectedCharacterId(None))
|
|
||||||
.insert(CharacterIdList(BTreeSet::new()))
|
|
||||||
.id();
|
|
||||||
current_level.0 = Some(level_id);
|
|
||||||
|
|
||||||
level_startup_event.send(LevelStartupEvent(level_entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn despawn_level(mut commands: Commands, level_query: Query<Entity, With<Level>>) {
|
|
||||||
for entity in level_query.iter() {
|
|
||||||
commands.entity(entity).despawn_recursive();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a bad design, to be refactored some days
|
|
||||||
pub fn post_setup_level(
|
|
||||||
mut commands: Commands,
|
|
||||||
character_meshes: Res<CharacterMeshes>,
|
|
||||||
mut effects: ResMut<Assets<EffectAsset>>,
|
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
||||||
current_level: Res<CurrentLevel>,
|
|
||||||
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
|
||||||
mut level_startup_event: EventReader<LevelStartupEvent>,
|
|
||||||
asset_server: Res<AssetServer>,
|
|
||||||
) {
|
|
||||||
for LevelStartupEvent(level_entity) in level_startup_event.iter() {
|
|
||||||
if let Ok((mut selected_character_id, mut character_id_list)) =
|
|
||||||
level_query.get_mut(*level_entity)
|
|
||||||
{
|
|
||||||
if let Some(level_id) = current_level.0 {
|
|
||||||
match level_id.0 {
|
|
||||||
0 => level0::setup(
|
|
||||||
&mut commands,
|
|
||||||
&character_meshes,
|
|
||||||
&mut effects,
|
|
||||||
&mut materials,
|
|
||||||
&mut selected_character_id,
|
|
||||||
&mut character_id_list,
|
|
||||||
),
|
|
||||||
1 => level1::setup(
|
|
||||||
&mut commands,
|
|
||||||
&character_meshes,
|
|
||||||
&mut effects,
|
|
||||||
&mut materials,
|
|
||||||
&mut selected_character_id,
|
|
||||||
&mut character_id_list,
|
|
||||||
),
|
|
||||||
_ => game_over::setup(&mut commands, &asset_server),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
use crate::game::*;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
pub fn setup(commands: &mut Commands, asset_server: &Res<AssetServer>) {
|
|
||||||
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
|
||||||
commands
|
|
||||||
.spawn_bundle(Text2dBundle {
|
|
||||||
text: Text::from_section(
|
|
||||||
"GAME OVER",
|
|
||||||
TextStyle {
|
|
||||||
font: font.clone(),
|
|
||||||
font_size: 48.0,
|
|
||||||
color: Color::WHITE,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.with_alignment(TextAlignment::CENTER),
|
|
||||||
transform: Transform::from_xyz(0., 128.0, 0.),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.insert(Level);
|
|
||||||
commands
|
|
||||||
.spawn_bundle(Text2dBundle {
|
|
||||||
text: Text::from_section(
|
|
||||||
"There is no more light to combine.",
|
|
||||||
TextStyle {
|
|
||||||
font,
|
|
||||||
font_size: 32.0,
|
|
||||||
color: Color::WHITE,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.with_alignment(TextAlignment::CENTER),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.insert(Level);
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
use crate::game::*;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
|
||||||
use bevy_hanabi::*;
|
|
||||||
use bevy_rapier2d::prelude::*;
|
|
||||||
|
|
||||||
pub fn setup(
|
|
||||||
commands: &mut Commands,
|
|
||||||
character_meshes: &Res<CharacterMeshes>,
|
|
||||||
effects: &mut ResMut<Assets<EffectAsset>>,
|
|
||||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
|
||||||
selected_character_id: &mut Mut<SelectedCharacterId>,
|
|
||||||
character_id_list: &mut Mut<CharacterIdList>,
|
|
||||||
) {
|
|
||||||
commands
|
|
||||||
.spawn_bundle(TransformBundle::from(Transform::from_xyz(0.0, -256.0, 0.0)))
|
|
||||||
.insert(Collider::cuboid(400., 10.))
|
|
||||||
.insert(Level);
|
|
||||||
|
|
||||||
spawn_character(
|
|
||||||
commands,
|
|
||||||
character_meshes,
|
|
||||||
effects,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
Transform::from_xyz(-128., -64., 0.),
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
spawn_character(
|
|
||||||
commands,
|
|
||||||
character_meshes,
|
|
||||||
effects,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
Transform::from_xyz(0., -64., 0.),
|
|
||||||
Color::GREEN,
|
|
||||||
);
|
|
||||||
spawn_character(
|
|
||||||
commands,
|
|
||||||
character_meshes,
|
|
||||||
effects,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
Transform::from_xyz(128., -64., 0.),
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
use crate::game::*;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
|
||||||
use bevy_hanabi::*;
|
|
||||||
use bevy_rapier2d::prelude::*;
|
|
||||||
|
|
||||||
pub fn setup(
|
|
||||||
commands: &mut Commands,
|
|
||||||
character_meshes: &Res<CharacterMeshes>,
|
|
||||||
effects: &mut ResMut<Assets<EffectAsset>>,
|
|
||||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
|
||||||
selected_character_id: &mut Mut<SelectedCharacterId>,
|
|
||||||
character_id_list: &mut Mut<CharacterIdList>,
|
|
||||||
) {
|
|
||||||
commands
|
|
||||||
.spawn_bundle(TransformBundle::from(Transform::from_xyz(0.0, -256.0, 0.0)))
|
|
||||||
.insert(Collider::cuboid(400., 10.))
|
|
||||||
.insert(Level);
|
|
||||||
commands
|
|
||||||
.spawn_bundle(TransformBundle::from(Transform::from_xyz(
|
|
||||||
256.0, -128.0, 0.0,
|
|
||||||
)))
|
|
||||||
.insert(Collider::cuboid(200., 10.))
|
|
||||||
.insert(Level);
|
|
||||||
|
|
||||||
spawn_character(
|
|
||||||
commands,
|
|
||||||
character_meshes,
|
|
||||||
effects,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
Transform::from_xyz(128., 64., 0.),
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
|
||||||
spawn_character(
|
|
||||||
commands,
|
|
||||||
character_meshes,
|
|
||||||
effects,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
Transform::from_xyz(-128., -128., 0.),
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
spawn_character(
|
|
||||||
commands,
|
|
||||||
character_meshes,
|
|
||||||
effects,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
Transform::from_xyz(0., -128., 0.),
|
|
||||||
Color::GREEN,
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
mod game;
|
mod game;
|
||||||
mod levels;
|
|
||||||
mod menu;
|
mod menu;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
@ -15,7 +14,6 @@ use bevy_rapier2d::prelude::*;
|
||||||
enum AppState {
|
enum AppState {
|
||||||
Menu,
|
Menu,
|
||||||
Game,
|
Game,
|
||||||
Win,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -33,7 +31,6 @@ fn main() {
|
||||||
.add_plugin(RapierDebugRenderPlugin::default())
|
.add_plugin(RapierDebugRenderPlugin::default())
|
||||||
.add_plugin(menu::MenuPlugin)
|
.add_plugin(menu::MenuPlugin)
|
||||||
.add_plugin(game::GamePlugin)
|
.add_plugin(game::GamePlugin)
|
||||||
.add_plugin(bevy_inspector_egui::WorldInspectorPlugin::new())
|
|
||||||
.add_startup_system(setup)
|
.add_startup_system(setup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
@ -43,8 +40,7 @@ fn setup(
|
||||||
mut dsp_manager: ResMut<DspManager>,
|
mut dsp_manager: ResMut<DspManager>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
) {
|
) {
|
||||||
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
|
let _font: Handle<Font> = asset_server.load("Cantarell-VF.otf");
|
||||||
commands.insert_resource(font);
|
|
||||||
|
|
||||||
commands.spawn_bundle(Camera2dBundle {
|
commands.spawn_bundle(Camera2dBundle {
|
||||||
camera_2d: Camera2d {
|
camera_2d: Camera2d {
|
||||||
|
|
10
src/menu.rs
10
src/menu.rs
|
@ -8,7 +8,7 @@ use bevy::{
|
||||||
pub struct MenuPlugin;
|
pub struct MenuPlugin;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Menu;
|
struct Menu();
|
||||||
|
|
||||||
impl Plugin for MenuPlugin {
|
impl Plugin for MenuPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
|
@ -19,7 +19,7 @@ impl Plugin for MenuPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
let font = asset_server.get_handle("Cantarell-VF.otf");
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(Text2dBundle {
|
.spawn_bundle(Text2dBundle {
|
||||||
text: Text::from_section(
|
text: Text::from_section(
|
||||||
|
@ -31,10 +31,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.with_alignment(TextAlignment::CENTER),
|
.with_alignment(TextAlignment::CENTER),
|
||||||
transform: Transform::from_xyz(0., 128.0, 0.),
|
transform: Transform::from_xyz(0., -128.0, 0.),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.insert(Menu);
|
.insert(Menu());
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(Text2dBundle {
|
.spawn_bundle(Text2dBundle {
|
||||||
text: Text::from_section(
|
text: Text::from_section(
|
||||||
|
@ -48,7 +48,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
.with_alignment(TextAlignment::CENTER),
|
.with_alignment(TextAlignment::CENTER),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.insert(Menu);
|
.insert(Menu());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn despawn(mut commands: Commands, menu_query: Query<Entity, With<Menu>>) {
|
fn despawn(mut commands: Commands, menu_query: Query<Entity, With<Menu>>) {
|
||||||
|
|
Loading…
Reference in a new issue