Skip to content

Commit

Permalink
Start preparing for logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinmorrow committed Jul 19, 2023
1 parent a043ab4 commit c9d6e48
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;

use block::BlockBundle;

mod block;
pub mod block;

pub struct Level {
pub id: u32,
Expand Down
5 changes: 5 additions & 0 deletions src/level/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ use bevy_xpbd_2d::prelude::*;
pub const SIZE: f32 = 64.0;
pub const SIZE_VEC2: Vec2 = Vec2::new(SIZE, SIZE);

#[derive(Component, Clone, Default)]
pub struct Block;

#[derive(Bundle, Clone)]
pub struct BlockBundle {
sprite_bundle: SpriteBundle,
rigid_body: RigidBody,
collider: Collider,
friction: Friction,
block: Block,
}

impl core::fmt::Debug for BlockBundle {
Expand Down Expand Up @@ -45,6 +49,7 @@ impl BlockBundle {
rigid_body: RigidBody::Static,
collider: Collider::cuboid(SIZE, SIZE),
friction: Friction::new(1.0),
block: Block,
}
}
}
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn start_app() {
))
.insert_resource(level::Level::new(0))
.insert_resource(Gravity(Vec2::new(0.0, -9.81 * 100.0)))
.insert_resource(player::CanJump(true))
.add_systems(
Startup,
(camera::spawn_camera, player::spawn, level::spawn_blocks),
Expand All @@ -27,6 +28,7 @@ pub fn start_app() {
(
camera::keep_player_in_view.after(player::r#move),
player::r#move,
player::can_jump.before(player::r#move),
bevy::window::close_on_esc,
),
)
Expand All @@ -41,7 +43,7 @@ fn setup_default_plugins() -> PluginGroupBuilder {
})
.set(WindowPlugin {
primary_window: Some(Window {
mode: WindowMode::BorderlessFullscreen,
mode: WindowMode::Windowed,
title: "Pollywog".to_string(),
..default()
}),
Expand Down
21 changes: 20 additions & 1 deletion src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ pub enum Action {
Grapple,
}

#[derive(Resource, Default)]
pub struct CanJump(pub bool);

pub fn spawn(
mut commands: Commands,
asset_server: Res<AssetServer>,
Expand All @@ -91,6 +94,7 @@ pub fn spawn(
// FIXME: make a better movement system, this is just a placeholder
pub fn r#move(
action_state_query: Query<&ActionState<Action>, With<Player>>,
can_jump: Res<CanJump>,
mut player_query: Query<&mut LinearVelocity, With<Player>>,
) {
let action_state = action_state_query.single();
Expand All @@ -106,12 +110,27 @@ pub fn r#move(
match action {
Action::Left => player.x = -300.0,
Action::Right => player.x = 300.0,
Action::Jump => player.y = 300.0,
Action::Jump => {
if can_jump.0 {
player.y = 300.0
}
}
Action::Grapple => { /* Do nothing, this is handled elsewhere. */ }
}
}
}

pub fn can_jump(
mut collisions: EventReader<Collision>,
mut can_jump: ResMut<CanJump>,
player_query: Query<Entity, With<Player>>,
blocks_query: Query<Entity, With<crate::level::block::Block>>,
) {
for collision in collisions.iter() {

}
}

/// Add a force to the player in the given direction (to be used for grappling).
fn add_grapple_force(
mut player_query: Query<(&mut ExternalForce, &mut GravityScale), With<Player>>,
Expand Down

0 comments on commit c9d6e48

Please sign in to comment.