diff --git a/assets/bgp_catdev/Player and UI/Basic_HeartsAndCoins.png b/assets/bgp_catdev/player_and_ui/Basic_HeartsAndCoins.png similarity index 100% rename from assets/bgp_catdev/Player and UI/Basic_HeartsAndCoins.png rename to assets/bgp_catdev/player_and_ui/Basic_HeartsAndCoins.png diff --git a/assets/bgp_catdev/Player and UI/Basic_HeartsAndCoinsWhiteVer.png b/assets/bgp_catdev/player_and_ui/Basic_HeartsAndCoinsWhiteVer.png similarity index 100% rename from assets/bgp_catdev/Player and UI/Basic_HeartsAndCoinsWhiteVer.png rename to assets/bgp_catdev/player_and_ui/Basic_HeartsAndCoinsWhiteVer.png diff --git a/assets/bgp_catdev/Player and UI/Basic_Player.png b/assets/bgp_catdev/player_and_ui/Basic_Player.png similarity index 100% rename from assets/bgp_catdev/Player and UI/Basic_Player.png rename to assets/bgp_catdev/player_and_ui/Basic_Player.png diff --git a/src/character.rs b/src/character.rs index 4721eee..12aee25 100644 --- a/src/character.rs +++ b/src/character.rs @@ -1,9 +1,9 @@ use bevy::{ app::{Plugin, Startup, Update}, - asset::AssetServer, - math::{Rect, Vec2}, - prelude::{default, Commands, Component, Query, Res, With}, - sprite::{Sprite, SpriteBundle}, + asset::{AssetServer, Assets, Handle}, + math::{Rect, UVec2, Vec2}, + prelude::{default, Commands, Component, Image, Query, Res, ResMut, Resource, With}, + sprite::{Sprite, SpriteBundle, TextureAtlas, TextureAtlasLayout}, time::Time, transform::components::Transform, }; @@ -11,7 +11,7 @@ use bevy_rapier2d::prelude::*; use crate::{ control::{CharacterControlOffset, MapControlOffset}, - GameWorld, BLOCK_SIZE, CHARACTER_MOVEMENT_SPEED, PIXEL_PERFECT_LAYERS, + GameWorld, BLOCK_SIZE, CHARACTER_MOVEMENT_SPEED, CHARACTER_SIZE, PIXEL_PERFECT_LAYERS, WORLD_BOTTOM_OFFSET_IN_PIXELS, WORLD_CENTER_COL, }; @@ -29,13 +29,21 @@ impl Plugin for CharacterPlugin { } } -fn startup(mut commands: Commands, asset_server: Res, game_world: Res) { +fn startup( + mut commands: Commands, + asset_server: Res, + game_world: Res, + mut texture_atlases: ResMut>, +) { + let atlas_layout = TextureAtlasLayout::from_grid(UVec2::new(16, 16), 8, 5, None, None); + let atlas_layout_handle = texture_atlases.add(atlas_layout); + let texture = asset_server.load("bgp_catdev/player_and_ui/Basic_Player.png"); commands.spawn(( Character { movement_speed: CHARACTER_MOVEMENT_SPEED as f32, }, SpriteBundle { - texture: asset_server.load("character/idle/i2.png"), + texture, transform: Transform::from_xyz( (BLOCK_SIZE as f32) * 0.5, (((game_world.get_height_in_blocks(WORLD_CENTER_COL) as usize + 10) * BLOCK_SIZE) @@ -45,28 +53,34 @@ fn startup(mut commands: Commands, asset_server: Res, game_world: R ), sprite: Sprite { //anchor: bevy::sprite::Anchor::BottomCenter, - custom_size: Option::Some(Vec2::new(14.0, 30.0)), - rect: Some(Rect { - max: Vec2::new(520.0, 540.0), - min: Vec2::new(320.0, 110.0), - }), + custom_size: Option::Some(Vec2::new(CHARACTER_SIZE as f32, CHARACTER_SIZE as f32)), ..default() }, + ..default() }, + TextureAtlas { + layout: atlas_layout_handle, + index: 0, + ..Default::default() + }, RigidBody::KinematicPositionBased, - Collider::capsule_y(11.5, 7.), + Collider::capsule_y((CHARACTER_SIZE / 16) as f32, (CHARACTER_SIZE / 2) as f32), KinematicCharacterController { - custom_shape: Option::Some((Collider::cuboid(7., 15.), Vec2::new(0., 5.), 0.)), + custom_shape: Option::Some(( + Collider::cuboid((CHARACTER_SIZE / 2) as f32, (CHARACTER_SIZE / 2) as f32), + Vec2::new(0., 5.), + 0., + )), offset: CharacterLength::Absolute(0.1), autostep: Option::Some(CharacterAutostep { - max_height: CharacterLength::Relative(0.5), + max_height: CharacterLength::Relative(0.4), min_width: CharacterLength::Relative(0.1), ..default() }), slide: true, snap_to_ground: Option::Some(CharacterLength::Absolute(0.1)), - normal_nudge_factor: 1., + normal_nudge_factor: 0.1, ..default() }, //LockedAxes::ROTATION_LOCKED, diff --git a/src/main.rs b/src/main.rs index 066a2d6..08e4d12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,8 @@ pub const CHUNKS_TO_LOAD: usize = CHUNKS_IN_CANVAS + CHUNKS_LOAD_THRESHOLD; pub const MAP_MOVEMENT_SPEED_IN_BLOCKS: usize = 4; //camera speed in blocks/second pub const MAP_MOVEMENT_SPEED: usize = BLOCK_SIZE * MAP_MOVEMENT_SPEED_IN_BLOCKS; //camera speed in pixels/second + +pub const CHARACTER_SIZE: usize = BLOCK_SIZE * 4; pub const CHARACTER_MOVEMENT_SPEED: usize = MAP_MOVEMENT_SPEED_IN_BLOCKS * 2; //camera speed in blocks/second pub const DAY_DURATION_IN_SECONDS: usize = 4 * 60;