Skip to content

Commit

Permalink
feat: movement
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Jul 19, 2024
1 parent bfcda8a commit efc8fcc
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
use bevy::prelude::*;
use bevy::{prelude::*, window::WindowResolution};
use kenney_jam::{
assets::SpriteAssets,
input::{Action, ActionState},
AppConfig, GamePlugin, GameState,
};

const GAME_RES: Vec2 = Vec2::new(256., 192.);
const SCALE: f32 = 3.;

fn main() {
App::new()
.insert_resource(AppConfig::default())
.insert_resource(AppConfig {
game_title: "Kenney Jam",
initial_window_res: (GAME_RES * SCALE).into(),
initial_game_res: GAME_RES,
})
.add_plugins(GamePlugin)
.add_systems(
OnEnter(GameState::Play),
Expand All @@ -34,7 +41,7 @@ struct Player;
fn init(mut cmd: Commands, sprite_assets: Res<SpriteAssets>) {
cmd.spawn((
SpriteBundle {
transform: Transform::from_scale(Vec3::splat(3.0)),
transform: Transform::from_scale(Vec3::splat(SCALE as f32)),
texture: sprite_assets.one_bit.clone(),
..default()
},
Expand All @@ -54,10 +61,12 @@ fn update_player(
let Ok(mut trans) = player.get_single_mut() else { return };
let Ok(input) = input.get_single() else { return };

let axis = input.clamped_axis_pair(&Action::Move);
// TODO: Proper movement
let dir = axis.unwrap_or_default().x();
trans.translation.x += dir * 1000. * time.delta_seconds();
let dir = axis.unwrap_or_default().y();
trans.translation.y += dir * 1000. * time.delta_seconds();
if input.just_pressed(&Action::Move) {
let Some(axis) = input.clamped_axis_pair(&Action::Move) else { return };
if axis.x().abs() > axis.y().abs() {
trans.translation.x += axis.x().signum() * SCALE * 16.;
} else {
trans.translation.y += axis.y().signum() * SCALE * 16.;
}
};
}

0 comments on commit efc8fcc

Please sign in to comment.