respawning and such, balls

This commit is contained in:
TudbuT 2024-11-23 22:55:19 +01:00
parent fb1b776e78
commit 88da62242e
5 changed files with 60 additions and 25 deletions

View file

@ -6,12 +6,21 @@ header
.G = grasblock_lower.png
._ = _grasblock_upper.png
., = _erdblock_upper.png
body
.a = _tree1_greenish.png
.O = ~Blockgrau.png
links
T P
TT ,,,_______,,,______,___
TTTTTTTTEEEGGGGGGGEEEGGGGGGEGGGE
TTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE
TTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
blocks
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
T T
T T
T O T
T O T
T O T
T P _______ _ T
TT ,,,_______,,,_a____,___ __GGGGGGG_______TTTTTTTTTTTT T
TTTTTTTTEEEGGGGGGGEEEGGGGGGEGGGE GGEEEEEEEGGEEEEETTTTTTTTTTTTTTTTTTT
TTTTTTTTTEEEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEEEEEETTTTTTTTTTTTTTTEEET
TTTTTTEEEEEEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEEEEEEEETTTTTTEEEEEEEEEET
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

View file

@ -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 bevy::{ecs::system::SystemId, prelude::*, sprite::MaterialMesh2dBundle, utils::HashMap};
@ -7,7 +7,7 @@ use bevy_rapier2d::prelude::*;
use crate::{AppState, METER};
use super::{scene::PlayerCoords, set::IngameSet};
use super::{scene::PlayerCoords, set::IngameSet, PLAYER_DEPTH};
mod animation;
@ -59,7 +59,7 @@ fn move_player(
kb_input: Res<ButtonInput<KeyCode>>,
mut query: Query<(
&mut Velocity,
&Transform,
&mut Transform,
&mut Player,
&mut KinematicCharacterController,
&mut Sprite,
@ -70,7 +70,7 @@ fn move_player(
player_coords: Res<PlayerCoords>,
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();
let (mut cam_transform) = camera_query.single_mut();
let (output) = phys.get_single();
@ -88,7 +88,7 @@ fn move_player(
moved = true;
move_x += 1;
}
if kb_input.pressed(KeyCode::Space) && grounded {
if kb_input.pressed(KeyCode::Space) && vel.linvel.y < 0.1 && grounded {
moved = true;
move_y += 1;
}
@ -97,7 +97,7 @@ fn move_player(
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));
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 {
*anim_state = PlayerAnimations::Walk;
@ -105,6 +105,11 @@ fn move_player(
} else if !moved {
*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(),
LockedAxes::ROTATION_LOCKED,
Velocity::default(),
AdditionalMassProperties::MassProperties(MassProperties {
local_center_of_mass: Vec2 { x: 0.5, y: 0.5 },
mass: 10000.0,
principal_inertia: 1.,
}),
))
.insert(KinematicCharacterController {
//translation: todo!(),
//custom_shape: todo!(),
//custom_mass: todo!(),
custom_mass: Some(10000.0),
//up: todo!(),
offset: CharacterLength::Absolute(0.01),
slide: true,
@ -175,7 +185,7 @@ fn add_player(
//}),
//max_slope_climb_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)),
//filter_flags: todo!(),
//filter_groups: todo!(),

View file

@ -29,7 +29,7 @@ pub fn run_animations<Tag: Hash + Eq + Component>(
anim.frame_timer.tick(time.delta());
if anim.frame_timer.just_finished() {
dbg!(atlas.index);
// dbg!(atlas.index);
if atlas.index >= anim.max_index {
atlas.index = 0;
} else {

View file

@ -28,7 +28,7 @@ impl PlayerCoords {
pub fn get_collider(&self) -> Collider {
let size = 0.5;
Collider::round_cuboid(size, size, 1.5)
Collider::round_cuboid(size, size, 2.0)
// Collider::cuboid(size, size)
}
}
@ -68,8 +68,9 @@ pub(super) fn import_text_world(
mut player_spawn_oneshot: Res<PlayerSpawnOneshot>,
) {
let world_string = fs::read_to_string("assets/world.txt").expect("need a world to load");
let [info_string, world_string] =
&readf("header\n{}\nbody\n{}", &world_string).expect("world does not have sections")[..]
let [info_string, links_string, world_string] =
&readf("header\n{}\nlinks\n{}\nblocks\n{}", &world_string)
.expect("world does not have sections")[..]
else {
unreachable!()
};
@ -109,6 +110,12 @@ pub(super) fn import_text_world(
(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 y = current_y as f32 * wi.block_size;
if tex == "[player]" {
@ -126,7 +133,7 @@ pub(super) fn import_text_world(
&assets,
tex,
(x, y, len, wi.block_size),
collider,
(collider, fixed),
);
}
println!("spawned {possible_block:?} at {x}, {y}");
@ -147,7 +154,7 @@ fn spawn_block(
assets: &Res<AssetServer>,
tex: String,
(x, y, len, block_size): (f32, f32, usize, f32),
collider: bool,
(collider, fixed): (bool, bool),
) {
let mut command = commands.spawn((
Block,
@ -162,8 +169,17 @@ fn spawn_block(
));
if collider {
command.insert((
RigidBody::Fixed,
Collider::cuboid(block_size / 2.0 * len as f32, block_size / 2.0),
if fixed {
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(),
));
}

View file

@ -5,7 +5,7 @@ use game::game_plugin;
mod game;
const METER: f32 = 60.;
const METER: f32 = 100.;
#[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)]
enum AppState {