Skip to content

Commit

Permalink
backup: experimentation in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
uggla committed May 5, 2024
1 parent 1160a7d commit b418fe7
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 128 deletions.
276 changes: 183 additions & 93 deletions assets/level01.tmx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/rockrun.tiled-session
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"scale": 0.7310546874999999,
"selectedLayer": 0,
"viewCenter": {
"x": 592.9788939353462,
"y": 359.07026449372165
"x": 1467.742452578146,
"y": 352.23083088431736
}
},
"level01.tmx#backgrounds": {
Expand Down
12 changes: 8 additions & 4 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,21 @@ fn camera_follows_player(
mut camera_query: Query<&mut Transform, (With<Camera2d>, Without<Player>)>,
current_level: Res<CurrentLevel>,
levels: Query<&Level, With<Level>>,
mut ground_h_axis: Local<f32>,
) {
let mut camera = camera_query.single_mut();
let player = player_query.single();

*ground_h_axis += 1.0;

dbg!(&ground_h_axis);
for level in levels.iter() {
if level.id == current_level.id {
dbg!(&player.translation);
camera.translation = dbg!(level
let new_camera_pos = Vec2::new(player.translation.x, player.translation.y + 232.0);
camera.translation = level
.map
.move_camera(camera.translation.xy(), player.translation.xy())
.extend(0.0));
.move_camera(camera.translation.xy(), new_camera_pos)
.extend(0.0);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn setup_background(mut commands: Commands, asset_server: Res<AssetServer>) {
Level {
id: 1,
handle: map_handle.clone(),
map: Map::new("SO", WINDOW_WIDTH as usize, WINDOW_HEIGHT as usize),
map: Map::new("SOO\nXXO", WINDOW_WIDTH as usize, WINDOW_HEIGHT as usize),
},
));
}
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ struct Platform;
fn setup_physics(mut commands: Commands) {
/* Create the ground. */
let points = vec![
Vec2::new(-1280.0, -8.0 - 224.0),
Vec2::new(48.0, -8.0 - 224.0),
Vec2::new(48.0 + 14.0 * 16.0, -8.0 - (224.0 - 7.0 * 16.0)),
Vec2::new(272.0 + 3.0 * 16.0, -8.0 - (224.0 - 7.0 * 16.0)),
Vec2::new(320.0 + 7.0 * 16.0, -8.0 - (224.0)),
Vec2::new(1280.0, -8.0 - 224.0),
Vec2::new(-1280.0 * 2.0 * 3.0, 128.0),
// Vec2::new(48.0, -8.0 - 224.0),
// Vec2::new(48.0 + 14.0 * 16.0, -8.0 - (224.0 - 7.0 * 16.0)),
// Vec2::new(272.0 + 3.0 * 16.0, -8.0 - (224.0 - 7.0 * 16.0)),
// Vec2::new(320.0 + 7.0 * 16.0, -8.0 - (224.0)),
Vec2::new(1280.0 / 2.0 * 2.0 + 30.0, 128.0),
];

commands
Expand Down
2 changes: 1 addition & 1 deletion src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const PLAYER_WIDTH: f32 = 100.0;
pub const PLAYER_HEIGHT: f32 = 75.0;
const PLAYER_HITBOX: (Vec2, Vec2, f32) = (Vec2::new(-4.0, -9.0), Vec2::new(-4.0, 8.0), 22.0);
const PLAYER_HITBOX_TRANSLATION: Vec2 = Vec2::new(8.0, 0.0);
const LEVEL01_START: Vec3 = Vec3::new(-WINDOW_WIDTH / 2.0, 200.0, 20.0);
const LEVEL01_START: Vec3 = Vec3::new(-WINDOW_WIDTH / 2.0, 400.0, 20.0);

#[derive(Component)]
pub struct Player;
Expand Down
28 changes: 7 additions & 21 deletions src/screen_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,12 @@ impl Map {
&& self.check_points(
&camera_points,
Direction::get_points(Direction::Right),
old_pos,)
)
// move to left
|| direction.x < 0.0
&& self.check_points(
&camera_points,
Direction::get_points(Direction::Left),
old_pos,
)
{
camera_pos.x = new_pos.x;
Expand All @@ -189,19 +188,20 @@ impl Map {
}

let camera_points = self.get_camera_points_coords(Vec2::new(camera_pos.x, new_pos.y));
if direction.y == 0.0 {
// Do nothing because we're not moving vertically
} else if
// move up
if direction.y > 0.0
direction.y > 0.0
&& self.check_points(
&camera_points,
Direction::get_points(Direction::Up),
old_pos,
)
// move down
|| direction.y < 0.0
&& self.check_points(
&camera_points,
Direction::get_points(Direction::Down),
old_pos,
)
{
camera_pos.y = new_pos.y;
Expand All @@ -216,25 +216,11 @@ impl Map {
camera_pos
}

fn check_points(
&self,
camera_points: &[Vec2],
(p1, p2): (usize, usize),
old_pos: Vec2,
) -> bool {
fn check_points(&self, camera_points: &[Vec2], (p1, p2): (usize, usize)) -> bool {
self.get_screen(camera_points[p1]).is_some()
&& self.get_screen(camera_points[p2]).is_some()
&& self.get_screen(camera_points[p1]).unwrap().allowed_screen
&& self.get_screen(camera_points[p2]).unwrap().allowed_screen
&& self.get_screen(old_pos).is_some()
&& !self
.get_screen(old_pos)
.unwrap()
.contains(&camera_points[p1])
&& !self
.get_screen(old_pos)
.unwrap()
.contains(&camera_points[p2])
}

pub fn get_start_screen(&self) -> &Screen {
Expand Down Expand Up @@ -505,7 +491,7 @@ mod tests {
// Camera should be clipped to the screen center
assert_eq!(
map.move_camera(Vec2::new(1380.0, 0.0), Vec2::new(1300.0, -120.0)),
Vec2::new(1280.0, 0.0)
Vec2::new(1300.0, 0.0)
);
}

Expand Down

0 comments on commit b418fe7

Please sign in to comment.