Skip to content

Commit 7715ebf

Browse files
committed
double fix physics (should speedup), fix restart hint, fix dialogue padding, light UI, some levels
1 parent f0da38e commit 7715ebf

13 files changed

Lines changed: 295 additions & 201 deletions

File tree

assets/levels/lightborne.ldtk

Lines changed: 84 additions & 79 deletions
Large diffs are not rendered by default.

src/game/defs/merge_tile.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,30 @@ fn build_rects_by_row(width: i32, height: i32, tiles: &HashSet<GridCoords>) -> V
9292
rects
9393
}
9494

95-
fn transpose_coords_set(tiles: &HashSet<GridCoords>) -> HashSet<GridCoords> {
96-
tiles
97-
.iter()
98-
.map(|&GridCoords { x, y }| GridCoords { x: y, y: x })
99-
.collect()
100-
}
101-
102-
fn build_rects_by_column(width: i32, height: i32, tiles: &HashSet<GridCoords>) -> Vec<Rect> {
103-
let tset = transpose_coords_set(tiles);
104-
let mut rects_t = build_rects_by_row(height, width, &tset);
105-
106-
for r in &mut rects_t {
107-
let left = r.bottom;
108-
let right = r.top;
109-
let bottom = r.left;
110-
let top = r.right;
111-
r.left = left;
112-
r.right = right;
113-
r.bottom = bottom;
114-
r.top = top;
115-
}
116-
117-
rects_t
118-
}
95+
// fn transpose_coords_set(tiles: &HashSet<GridCoords>) -> HashSet<GridCoords> {
96+
// tiles
97+
// .iter()
98+
// .map(|&GridCoords { x, y }| GridCoords { x: y, y: x })
99+
// .collect()
100+
// }
101+
//
102+
// fn build_rects_by_column(width: i32, height: i32, tiles: &HashSet<GridCoords>) -> Vec<Rect> {
103+
// let tset = transpose_coords_set(tiles);
104+
// let mut rects_t = build_rects_by_row(height, width, &tset);
105+
//
106+
// for r in &mut rects_t {
107+
// let left = r.bottom;
108+
// let right = r.top;
109+
// let bottom = r.left;
110+
// let top = r.right;
111+
// r.left = left;
112+
// r.right = right;
113+
// r.bottom = bottom;
114+
// r.top = top;
115+
// }
116+
//
117+
// rects_t
118+
// }
119119

120120
pub fn spawn_merged_tiles<Tile>(
121121
mut commands: Commands,
@@ -166,12 +166,12 @@ pub fn spawn_merged_tiles<Tile>(
166166

167167
for (compare_data, tile_coords) in level_tiles.iter() {
168168
let rects_h = build_rects_by_row(width, height, tile_coords);
169-
let rects_v = build_rects_by_column(width, height, tile_coords);
169+
// let rects_v = build_rects_by_column(width, height, tile_coords);
170170

171171
commands.entity(level_entity).with_children(|level| {
172172
for r in rects_h.iter() {
173173
let extent = Vec2::new(
174-
(r.right - r.left + 1) as f32 * grid - 0.1,
174+
(r.right - r.left + 1) as f32 * grid,
175175
(r.top - r.bottom + 1) as f32 * grid,
176176
)
177177
.abs();
@@ -184,20 +184,20 @@ pub fn spawn_merged_tiles<Tile>(
184184
Tile::bundle(&mut level.spawn_empty(), center, extent, compare_data);
185185
}
186186
//cover gaps because sadge
187-
for r in rects_v.iter() {
188-
let extent = Vec2::new(
189-
(r.right - r.left + 1) as f32 * grid,
190-
(r.top - r.bottom + 1) as f32 * grid - 0.1,
191-
)
192-
.abs();
193-
194-
let center = Vec2::new(
195-
(r.left + r.right + 1) as f32 * grid / 2.0,
196-
(r.bottom + r.top + 1) as f32 * grid / 2.0,
197-
);
198-
199-
Tile::bundle(&mut level.spawn_empty(), center, extent, compare_data);
200-
}
187+
// for r in rects_v.iter() {
188+
// let extent = Vec2::new(
189+
// (r.right - r.left + 1) as f32 * grid,
190+
// (r.top - r.bottom + 1) as f32 * grid - 0.1,
191+
// )
192+
// .abs();
193+
//
194+
// let center = Vec2::new(
195+
// (r.left + r.right + 1) as f32 * grid / 2.0,
196+
// (r.bottom + r.top + 1) as f32 * grid / 2.0,
197+
// );
198+
//
199+
// Tile::bundle(&mut level.spawn_empty(), center, extent, compare_data);
200+
// }
201201
});
202202
}
203203
});

src/game/defs/one_way_platform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl MergedTile for OneWayMarker {
5454
)]))
5555
.insert(Friction::new(0.))
5656
.insert(CollisionLayers::new(
57-
Layers::Terrain,
57+
Layers::Platform,
5858
[
5959
Layers::PlayerCollider,
6060
Layers::LightRay,

src/game/dialogue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub fn handle_start_dialogue(
122122
margin: UiRect::new(
123123
Val::Percent(20.),
124124
Val::Percent(20.),
125-
Val::Percent(6.),
125+
Val::Percent(7.),
126126
Val::Percent(5.),
127127
),
128128
..default()

src/game/light/segments.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub fn play_light_beam(
119119
Layers::LightSensor,
120120
Layers::Spike,
121121
Layers::BlueCrystal,
122+
Layers::Platform,
122123
],
123124
),
124125
// LightColor::Black => {
@@ -131,6 +132,7 @@ pub fn play_light_beam(
131132
Layers::LightSensor,
132133
Layers::WhiteRay,
133134
Layers::Spike,
135+
Layers::Platform,
134136
],
135137
),
136138
_ => CollisionLayers::new(
@@ -141,6 +143,7 @@ pub fn play_light_beam(
141143
Layers::WhiteRay,
142144
Layers::Spike,
143145
Layers::BlueCrystal,
146+
Layers::Platform,
144147
],
145148
),
146149
};

src/game/lyra/animation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn flip_player_direction(
127127
// return;
128128
// }
129129

130-
const PLAYER_FACING_EPSILON: f32 = 0.01;
130+
const PLAYER_FACING_EPSILON: f32 = 0.5;
131131
if lin_vel.0.x < -PLAYER_FACING_EPSILON {
132132
player_sprite.flip_x = true;
133133
} else if lin_vel.0.x > PLAYER_FACING_EPSILON {

src/game/lyra/beam.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ pub fn reset_light_inventory(
6868
inventory.current_color = old_color;
6969
}
7070
}
71+
// if select none, make sure to select some
72+
if old_color.is_none() && allowed_cols[LightColor::Green] {
73+
inventory.current_color = Some(LightColor::Green);
74+
}
7175
}
7276

7377
#[derive(Message)]

src/game/lyra/controller.rs

Lines changed: 87 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use avian2d::{math::*, prelude::*};
22
use bevy::{ecs::query::Has, prelude::*};
33

44
use crate::{
5-
game::{lyra::Lyra, LevelSystems},
5+
game::{
6+
lyra::{Lyra, LyraWallCaster},
7+
LevelSystems,
8+
},
69
shared::PlayState,
710
};
811

@@ -107,10 +110,10 @@ pub fn keyboard_input(
107110
if keyboard_input.just_released(KeyCode::Space) {
108111
movement_writer.write(MovementAction::JumpCut);
109112
}
110-
if keyboard_input.just_pressed(KeyCode::ShiftLeft) {
113+
if keyboard_input.just_pressed(KeyCode::ControlLeft) {
111114
movement_writer.write(MovementAction::Crouch);
112115
}
113-
if keyboard_input.just_released(KeyCode::ShiftLeft) {
116+
if keyboard_input.just_released(KeyCode::ControlLeft) {
114117
movement_writer.write(MovementAction::Stand);
115118
}
116119
}
@@ -130,78 +133,99 @@ pub fn update_grounded(
130133
}
131134

132135
pub fn movement(
133-
time: Res<Time>,
134136
mut movement_reader: MessageReader<MovementAction>,
135-
mut controllers: Query<(
136-
&mut MovementInfo,
137-
&mut LinearVelocity,
138-
&ShapeHits,
139-
Has<Grounded>,
140-
)>,
137+
lyra: Single<
138+
(
139+
&mut MovementInfo,
140+
&mut LinearVelocity,
141+
&ShapeHits,
142+
Has<Grounded>,
143+
),
144+
With<Lyra>,
145+
>,
146+
wall_casters: Query<(&ShapeHits, &LyraWallCaster), Without<Lyra>>,
141147
) {
142-
let delta = time.delta_secs() * 64.;
143-
for (mut movement_info, mut linear_velocity, shape_hits, is_grounded) in &mut controllers {
144-
if is_grounded {
145-
movement_info.coyote_time_ticks = COYOTE_TIME_TICKS;
146-
}
148+
let (mut movement_info, mut linear_velocity, shape_hits, is_grounded) = lyra.into_inner();
149+
if is_grounded {
150+
movement_info.coyote_time_ticks = COYOTE_TIME_TICKS;
151+
}
147152

148-
let mut moved = false;
149-
let mut crouch = false;
150-
for event in movement_reader.read() {
151-
match event {
152-
MovementAction::Move(direction) => {
153-
linear_velocity.x += *direction * PLAYER_MOVE_VEL * 64. * delta;
154-
moved = true;
155-
}
156-
MovementAction::Jump => {
157-
movement_info.should_jump_ticks = SHOULD_JUMP_TICKS;
158-
}
159-
MovementAction::JumpCut => {
160-
if linear_velocity.y > 0. {
161-
linear_velocity.y /= 3.;
162-
movement_info.jump_boost_ticks = 0;
163-
movement_info.should_jump_ticks = 0;
164-
}
153+
let mut moved = false;
154+
for event in movement_reader.read() {
155+
match event {
156+
MovementAction::Move(direction) => {
157+
linear_velocity.x += *direction * PLAYER_MOVE_VEL * 64.;
158+
moved = true;
159+
}
160+
MovementAction::Jump => {
161+
movement_info.should_jump_ticks = SHOULD_JUMP_TICKS;
162+
}
163+
MovementAction::JumpCut => {
164+
if linear_velocity.y > 0. {
165+
linear_velocity.y /= 3.;
166+
movement_info.jump_boost_ticks = 0;
167+
movement_info.should_jump_ticks = 0;
165168
}
166-
MovementAction::Crouch => crouch = true,
167-
MovementAction::Stand => crouch = false,
168169
}
170+
MovementAction::Crouch => movement_info.crouched = true,
171+
MovementAction::Stand => movement_info.crouched = false,
169172
}
173+
}
170174

171-
if movement_info.should_jump_ticks > 0 && movement_info.coyote_time_ticks > 0 {
172-
movement_info.jump_boost_ticks = JUMP_BOOST_TICKS;
173-
}
175+
if movement_info.should_jump_ticks > 0 && movement_info.coyote_time_ticks > 0 {
176+
movement_info.jump_boost_ticks = JUMP_BOOST_TICKS;
177+
}
174178

175-
let too_close = shape_hits.iter().any(|hit| hit.distance < 0.25);
176-
if movement_info.jump_boost_ticks > 0 {
177-
linear_velocity.y = PLAYER_JUMP_VEL * 64.;
178-
} else if too_close && linear_velocity.y < 0.5 {
179-
linear_velocity.y = 0.45;
180-
} else if is_grounded && linear_velocity.y < 0.5 {
181-
linear_velocity.y = 0.;
182-
} else {
183-
linear_velocity.y -= PLAYER_GRAVITY * 64. * delta;
184-
}
179+
let too_close = shape_hits.iter().any(|hit| hit.distance < 0.25);
180+
if movement_info.jump_boost_ticks > 0 {
181+
linear_velocity.y = PLAYER_JUMP_VEL * 64.;
182+
} else if too_close && linear_velocity.y < 0.5 {
183+
linear_velocity.y = 0.45;
184+
} else if is_grounded && linear_velocity.y < 0.5 {
185+
linear_velocity.y = 0.;
186+
} else {
187+
linear_velocity.y -= PLAYER_GRAVITY * 64.;
188+
}
185189

186-
linear_velocity.y = linear_velocity
187-
.y
188-
.clamp(-PLAYER_MAX_Y_VEL * 64., PLAYER_MAX_Y_VEL * 64.);
190+
linear_velocity.y = linear_velocity
191+
.y
192+
.clamp(-PLAYER_MAX_Y_VEL * 64., PLAYER_MAX_Y_VEL * 64.);
189193

190-
let crouch_modif = if crouch { 0.5 } else { 1.0 };
191-
linear_velocity.x = linear_velocity.x.clamp(
192-
-PLAYER_MAX_H_VEL * 64. * crouch_modif,
193-
PLAYER_MAX_H_VEL * 64. * crouch_modif,
194-
);
194+
if !moved {
195+
linear_velocity.x *= 0.6;
196+
if linear_velocity.x.abs() < 0.1 {
197+
linear_velocity.x = 0.;
198+
}
199+
}
195200

196-
if !moved {
197-
linear_velocity.x *= 0.6;
198-
if linear_velocity.x.abs() < 0.1 {
199-
linear_velocity.x = 0.;
201+
for (wall_hits, side) in wall_casters.iter() {
202+
let too_close = wall_hits.iter().any(|hit| hit.distance < 0.25);
203+
let any_hit = wall_hits.iter().next().is_some();
204+
match side {
205+
LyraWallCaster::Left => {
206+
if too_close && linear_velocity.x < 0.5 {
207+
linear_velocity.x = 0.45;
208+
} else if any_hit && linear_velocity.x < 0.5 {
209+
linear_velocity.x = 0.;
210+
}
211+
}
212+
LyraWallCaster::Right => {
213+
if too_close && linear_velocity.x > -0.5 {
214+
linear_velocity.x = -0.45;
215+
} else if any_hit && linear_velocity.x > -0.5 {
216+
linear_velocity.x = 0.;
217+
}
200218
}
201219
}
202-
203-
movement_info.should_jump_ticks -= 1;
204-
movement_info.jump_boost_ticks -= 1;
205-
movement_info.coyote_time_ticks -= 1;
206220
}
221+
222+
let crouch_modif = if movement_info.crouched { 0.5 } else { 1.0 };
223+
linear_velocity.x = linear_velocity.x.clamp(
224+
-PLAYER_MAX_H_VEL * 64. * crouch_modif,
225+
PLAYER_MAX_H_VEL * 64. * crouch_modif,
226+
);
227+
228+
movement_info.should_jump_ticks -= 1;
229+
movement_info.jump_boost_ticks -= 1;
230+
movement_info.coyote_time_ticks -= 1;
207231
}

0 commit comments

Comments
 (0)