respawning and such, balls
This commit is contained in:
parent
fb1b776e78
commit
88da62242e
5 changed files with 60 additions and 25 deletions
|
@ -6,12 +6,21 @@ header
|
||||||
.G = grasblock_lower.png
|
.G = grasblock_lower.png
|
||||||
._ = _grasblock_upper.png
|
._ = _grasblock_upper.png
|
||||||
., = _erdblock_upper.png
|
., = _erdblock_upper.png
|
||||||
body
|
.a = _tree1_greenish.png
|
||||||
|
.O = ~Blockgrau.png
|
||||||
|
links
|
||||||
|
|
||||||
T P
|
blocks
|
||||||
TT ,,,_______,,,______,___
|
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
|
||||||
TTTTTTTTEEEGGGGGGGEEEGGGGGGEGGGE
|
T T
|
||||||
TTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE
|
T T
|
||||||
TTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE
|
T O T
|
||||||
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
|
T O T
|
||||||
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
|
T O T
|
||||||
|
T P _______ _ T
|
||||||
|
TT ,,,_______,,,_a____,___ __GGGGGGG_______TTTTTTTTTTTT T
|
||||||
|
TTTTTTTTEEEGGGGGGGEEEGGGGGGEGGGE GGEEEEEEEGGEEEEETTTTTTTTTTTTTTTTTTT
|
||||||
|
TTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEEEEEETTTTTTTTTTTTTTTEEET
|
||||||
|
TTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEEEEEEEETTTTTTEEEEEEEEEET
|
||||||
|
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
|
||||||
|
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{hash::Hash, time::Duration};
|
use std::{any::Any, hash::Hash, time::Duration};
|
||||||
|
|
||||||
use animation::{run_animations, AnimBundle, Animation};
|
use animation::{run_animations, AnimBundle, Animation};
|
||||||
use bevy::{ecs::system::SystemId, prelude::*, sprite::MaterialMesh2dBundle, utils::HashMap};
|
use bevy::{ecs::system::SystemId, prelude::*, sprite::MaterialMesh2dBundle, utils::HashMap};
|
||||||
|
@ -7,7 +7,7 @@ use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
use crate::{AppState, METER};
|
use crate::{AppState, METER};
|
||||||
|
|
||||||
use super::{scene::PlayerCoords, set::IngameSet};
|
use super::{scene::PlayerCoords, set::IngameSet, PLAYER_DEPTH};
|
||||||
|
|
||||||
mod animation;
|
mod animation;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ fn move_player(
|
||||||
kb_input: Res<ButtonInput<KeyCode>>,
|
kb_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<(
|
mut query: Query<(
|
||||||
&mut Velocity,
|
&mut Velocity,
|
||||||
&Transform,
|
&mut Transform,
|
||||||
&mut Player,
|
&mut Player,
|
||||||
&mut KinematicCharacterController,
|
&mut KinematicCharacterController,
|
||||||
&mut Sprite,
|
&mut Sprite,
|
||||||
|
@ -70,7 +70,7 @@ fn move_player(
|
||||||
player_coords: Res<PlayerCoords>,
|
player_coords: Res<PlayerCoords>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
let (mut vel, p_transform, mut player, mut controller, mut sprite, mut anim_state) =
|
let (mut vel, mut p_transform, mut player, mut controller, mut sprite, mut anim_state) =
|
||||||
query.single_mut();
|
query.single_mut();
|
||||||
let (mut cam_transform) = camera_query.single_mut();
|
let (mut cam_transform) = camera_query.single_mut();
|
||||||
let (output) = phys.get_single();
|
let (output) = phys.get_single();
|
||||||
|
@ -88,7 +88,7 @@ fn move_player(
|
||||||
moved = true;
|
moved = true;
|
||||||
move_x += 1;
|
move_x += 1;
|
||||||
}
|
}
|
||||||
if kb_input.pressed(KeyCode::Space) && grounded {
|
if kb_input.pressed(KeyCode::Space) && vel.linvel.y < 0.1 && grounded {
|
||||||
moved = true;
|
moved = true;
|
||||||
move_y += 1;
|
move_y += 1;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ fn move_player(
|
||||||
cam_transform.translation -= ((orig - p_transform.translation.xy().extend(0.0)) / 30.0);
|
cam_transform.translation -= ((orig - p_transform.translation.xy().extend(0.0)) / 30.0);
|
||||||
|
|
||||||
controller.translation = Some(Vec2::new(move_x as f32 * 6., 0. - 0.01));
|
controller.translation = Some(Vec2::new(move_x as f32 * 6., 0. - 0.01));
|
||||||
vel.linvel += Vec2::new(0., move_y as f32 * 3. * METER);
|
vel.linvel += Vec2::new(0., move_y as f32 * 6. * METER);
|
||||||
|
|
||||||
if moved && move_x != 0 && grounded {
|
if moved && move_x != 0 && grounded {
|
||||||
*anim_state = PlayerAnimations::Walk;
|
*anim_state = PlayerAnimations::Walk;
|
||||||
|
@ -105,6 +105,11 @@ fn move_player(
|
||||||
} else if !moved {
|
} else if !moved {
|
||||||
*anim_state = PlayerAnimations::Idle;
|
*anim_state = PlayerAnimations::Idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p_transform.translation.y < -10. * player_coords.block_size {
|
||||||
|
p_transform.translation =
|
||||||
|
Vec2::new(player_coords.x, player_coords.y).extend(PLAYER_DEPTH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,11 +165,16 @@ fn add_player(
|
||||||
player_coords.get_collider(),
|
player_coords.get_collider(),
|
||||||
LockedAxes::ROTATION_LOCKED,
|
LockedAxes::ROTATION_LOCKED,
|
||||||
Velocity::default(),
|
Velocity::default(),
|
||||||
|
AdditionalMassProperties::MassProperties(MassProperties {
|
||||||
|
local_center_of_mass: Vec2 { x: 0.5, y: 0.5 },
|
||||||
|
mass: 10000.0,
|
||||||
|
principal_inertia: 1.,
|
||||||
|
}),
|
||||||
))
|
))
|
||||||
.insert(KinematicCharacterController {
|
.insert(KinematicCharacterController {
|
||||||
//translation: todo!(),
|
//translation: todo!(),
|
||||||
//custom_shape: todo!(),
|
//custom_shape: todo!(),
|
||||||
//custom_mass: todo!(),
|
custom_mass: Some(10000.0),
|
||||||
//up: todo!(),
|
//up: todo!(),
|
||||||
offset: CharacterLength::Absolute(0.01),
|
offset: CharacterLength::Absolute(0.01),
|
||||||
slide: true,
|
slide: true,
|
||||||
|
@ -175,7 +185,7 @@ fn add_player(
|
||||||
//}),
|
//}),
|
||||||
//max_slope_climb_angle: todo!(),
|
//max_slope_climb_angle: todo!(),
|
||||||
//min_slope_slide_angle: todo!(),
|
//min_slope_slide_angle: todo!(),
|
||||||
//apply_impulse_to_dynamic_bodies: todo!(),
|
apply_impulse_to_dynamic_bodies: true,
|
||||||
snap_to_ground: Some(CharacterLength::Absolute(0.5)),
|
snap_to_ground: Some(CharacterLength::Absolute(0.5)),
|
||||||
//filter_flags: todo!(),
|
//filter_flags: todo!(),
|
||||||
//filter_groups: todo!(),
|
//filter_groups: todo!(),
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub fn run_animations<Tag: Hash + Eq + Component>(
|
||||||
anim.frame_timer.tick(time.delta());
|
anim.frame_timer.tick(time.delta());
|
||||||
|
|
||||||
if anim.frame_timer.just_finished() {
|
if anim.frame_timer.just_finished() {
|
||||||
dbg!(atlas.index);
|
// dbg!(atlas.index);
|
||||||
if atlas.index >= anim.max_index {
|
if atlas.index >= anim.max_index {
|
||||||
atlas.index = 0;
|
atlas.index = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl PlayerCoords {
|
||||||
pub fn get_collider(&self) -> Collider {
|
pub fn get_collider(&self) -> Collider {
|
||||||
let size = 0.5;
|
let size = 0.5;
|
||||||
|
|
||||||
Collider::round_cuboid(size, size, 1.5)
|
Collider::round_cuboid(size, size, 2.0)
|
||||||
// Collider::cuboid(size, size)
|
// Collider::cuboid(size, size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,9 @@ pub(super) fn import_text_world(
|
||||||
mut player_spawn_oneshot: Res<PlayerSpawnOneshot>,
|
mut player_spawn_oneshot: Res<PlayerSpawnOneshot>,
|
||||||
) {
|
) {
|
||||||
let world_string = fs::read_to_string("assets/world.txt").expect("need a world to load");
|
let world_string = fs::read_to_string("assets/world.txt").expect("need a world to load");
|
||||||
let [info_string, world_string] =
|
let [info_string, links_string, world_string] =
|
||||||
&readf("header\n{}\nbody\n{}", &world_string).expect("world does not have sections")[..]
|
&readf("header\n{}\nlinks\n{}\nblocks\n{}", &world_string)
|
||||||
|
.expect("world does not have sections")[..]
|
||||||
else {
|
else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
@ -109,6 +110,12 @@ pub(super) fn import_text_world(
|
||||||
(possible_block.1.to_owned(), true)
|
(possible_block.1.to_owned(), true)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let (tex, fixed) = if let Some(s) = tex.strip_prefix("~") {
|
||||||
|
(s.to_owned(), false)
|
||||||
|
} else {
|
||||||
|
(tex, true)
|
||||||
|
};
|
||||||
|
|
||||||
let x = i as f32 * wi.block_size;
|
let x = i as f32 * wi.block_size;
|
||||||
let y = current_y as f32 * wi.block_size;
|
let y = current_y as f32 * wi.block_size;
|
||||||
if tex == "[player]" {
|
if tex == "[player]" {
|
||||||
|
@ -126,7 +133,7 @@ pub(super) fn import_text_world(
|
||||||
&assets,
|
&assets,
|
||||||
tex,
|
tex,
|
||||||
(x, y, len, wi.block_size),
|
(x, y, len, wi.block_size),
|
||||||
collider,
|
(collider, fixed),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
println!("spawned {possible_block:?} at {x}, {y}");
|
println!("spawned {possible_block:?} at {x}, {y}");
|
||||||
|
@ -147,7 +154,7 @@ fn spawn_block(
|
||||||
assets: &Res<AssetServer>,
|
assets: &Res<AssetServer>,
|
||||||
tex: String,
|
tex: String,
|
||||||
(x, y, len, block_size): (f32, f32, usize, f32),
|
(x, y, len, block_size): (f32, f32, usize, f32),
|
||||||
collider: bool,
|
(collider, fixed): (bool, bool),
|
||||||
) {
|
) {
|
||||||
let mut command = commands.spawn((
|
let mut command = commands.spawn((
|
||||||
Block,
|
Block,
|
||||||
|
@ -162,8 +169,17 @@ fn spawn_block(
|
||||||
));
|
));
|
||||||
if collider {
|
if collider {
|
||||||
command.insert((
|
command.insert((
|
||||||
RigidBody::Fixed,
|
if fixed {
|
||||||
Collider::cuboid(block_size / 2.0 * len as f32, block_size / 2.0),
|
RigidBody::Fixed
|
||||||
|
} else {
|
||||||
|
RigidBody::Dynamic
|
||||||
|
},
|
||||||
|
if fixed {
|
||||||
|
Collider::cuboid(block_size / 2.0 * len as f32, block_size / 2.0)
|
||||||
|
} else {
|
||||||
|
Collider::ball(block_size as f32 / 2.)
|
||||||
|
},
|
||||||
|
AdditionalMassProperties::Mass(1.0),
|
||||||
Velocity::default(),
|
Velocity::default(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use game::game_plugin;
|
||||||
|
|
||||||
mod game;
|
mod game;
|
||||||
|
|
||||||
const METER: f32 = 60.;
|
const METER: f32 = 100.;
|
||||||
|
|
||||||
#[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)]
|
#[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)]
|
||||||
enum AppState {
|
enum AppState {
|
||||||
|
|
Loading…
Add table
Reference in a new issue