corrections
This commit is contained in:
+2
-2
@@ -1,10 +1,10 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{collision::Collider, player::Player};
|
||||
use crate::{camera::MainCamera, collision::Collider, player::Player};
|
||||
|
||||
fn constrain_player(
|
||||
mut player: Single<(&Collider, &mut Transform), With<Player>>,
|
||||
camera: Single<&Camera, With<Camera2d>>,
|
||||
camera: Single<&Camera, With<MainCamera>>,
|
||||
) {
|
||||
let viewport = camera
|
||||
.logical_viewport_size()
|
||||
|
||||
+8
-5
@@ -3,14 +3,17 @@ use bevy::prelude::*;
|
||||
use crate::player::Player;
|
||||
use crate::player::move_player;
|
||||
|
||||
fn spawn_camera(mut commands: Commands) {
|
||||
commands.spawn(Camera2d);
|
||||
#[derive(Component)]
|
||||
pub struct MainCamera;
|
||||
|
||||
fn spawn_main_camera(mut commands: Commands) {
|
||||
commands.spawn((Camera2d, MainCamera));
|
||||
}
|
||||
|
||||
// Follow the player with the camera
|
||||
fn follow_player(
|
||||
player: Single<&Transform, (With<Player>, Without<Camera2d>)>,
|
||||
mut camera: Single<&mut Transform, (With<Camera2d>, Without<Player>)>,
|
||||
player: Single<&Transform, (With<Player>, Without<MainCamera>)>,
|
||||
mut camera: Single<&mut Transform, (With<MainCamera>, Without<Player>)>,
|
||||
// time: Res<Time>,
|
||||
) {
|
||||
camera.translation.y = player.translation.y; // without delay
|
||||
@@ -22,7 +25,7 @@ pub struct CameraPlugin;
|
||||
|
||||
impl Plugin for CameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_camera)
|
||||
app.add_systems(Startup, spawn_main_camera)
|
||||
.add_systems(Update, follow_player.after(move_player));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -1,20 +1,23 @@
|
||||
use bevy::{prelude::*, window::PresentMode};
|
||||
|
||||
use crate::background::BackgroundPlugin;
|
||||
use crate::bounds::BoundsPlugin;
|
||||
use crate::camera::CameraPlugin;
|
||||
use crate::collision::CollisionPlugin;
|
||||
use crate::debug::DebugPlugin;
|
||||
use crate::obstacle::ObstaclePlugin;
|
||||
use crate::player::PlayerPlugin;
|
||||
use crate::score::ScorePlugin;
|
||||
use crate::world::WorldPlugin;
|
||||
|
||||
mod background;
|
||||
mod bounds;
|
||||
mod camera;
|
||||
mod collision;
|
||||
mod debug;
|
||||
mod obstacle;
|
||||
mod player;
|
||||
mod score;
|
||||
mod world;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
@@ -27,12 +30,13 @@ fn main() {
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_plugins(BackgroundPlugin) // Checkerboard background
|
||||
.add_plugins(PlayerPlugin) // Player
|
||||
.add_plugins(CameraPlugin) // Camera
|
||||
.add_plugins(CollisionPlugin) // Collisions
|
||||
.add_plugins(ObstaclePlugin) // Obstacles
|
||||
.add_plugins(BoundsPlugin) // Bound player
|
||||
.add_plugins(ScorePlugin) // Score
|
||||
.add_plugins(WorldPlugin) // Chunk logic
|
||||
.add_plugins(DebugPlugin) // Debug
|
||||
.run();
|
||||
}
|
||||
|
||||
+6
-1
@@ -1,6 +1,10 @@
|
||||
use crate::{collision::Collider, player::reset_player};
|
||||
use bevy::prelude::*;
|
||||
use rand::RngExt;
|
||||
use rand::SeedableRng;
|
||||
|
||||
//TODO: add chunk logic to obstacles
|
||||
// TODO: add seed logic to obstacles
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Obstacle;
|
||||
@@ -64,7 +68,8 @@ pub struct ObstaclePlugin;
|
||||
|
||||
impl Plugin for ObstaclePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_obstacles)
|
||||
app
|
||||
// .add_systems(Startup, spawn_obstacles)
|
||||
.init_resource::<RegenerateObstacles>()
|
||||
.add_systems(Update, regenerate_obstacles.after(reset_player));
|
||||
}
|
||||
|
||||
+2
-1
@@ -101,7 +101,8 @@ pub fn reset_player(
|
||||
|
||||
has_collided.0 = false;
|
||||
fall_started.0 = false;
|
||||
regenerate_obstacles.0 = true;
|
||||
// TODO: uncomment when obstacle chunk logic is implemented
|
||||
// regenerate_obstacles.0 = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user