Skip to content

Commit

Permalink
feat: add sprites 🎨
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Dec 10, 2023
1 parent 4064360 commit ca53563
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bevy = { version = "0.12", default-features = false, features = [
"bevy_text", "bevy_ui", "multi-threaded", "png", "hdr", "x11", "bevy_gizmos",
"tonemapping_luts", "default_font", "webgl2",
]}
bevy_asset_loader = { version = "0.18", features = [ "progress_tracking" ] } # Better asset loader
bevy_asset_loader = { version = "0.18", features = [ "progress_tracking", "2d" ] } # Better asset loader
bevy_embedded_assets = { version = "0.9" } # Embed assets in binary
bevy_kira_audio = { version = "0.18" } # Improved audio library
iyes_progress = { version = "0.10", features = [ "assets" ] } # Track loading and game state
Expand Down
Binary file added assets/sprites/explosion_kenney.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/patterns_kenney.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/river_stix.aseprite
Binary file not shown.
Binary file added assets/sprites/river_stix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/spirits_phlege.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/spirits_stix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/ui_kenney.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const START_SCORES: [u32; 22] = [
5000, 7000, 8500,
];

const END_SCORES: [u32; 5] = [0, 50, 400, 3000, 9000];
const END_SCORES: [u32; 5] = [0, 60, 350, 3000, 9000];

pub struct CharonPlugin;

Expand Down Expand Up @@ -129,7 +129,7 @@ fn spawn_start_end(
level_size.0.x += 2;
level_size.0.y += 2;
if let Ok(mut cam) = cam.get_single_mut() {
cam.target_zoom += 0.13;
cam.target_zoom += 0.3;
}
}
let (offset, size) = play_to_real_size(&level_size);
Expand Down Expand Up @@ -171,7 +171,7 @@ fn spawn_start_end(

fn zoom_camera(mut cam: Query<(&mut OrthographicProjection, &GameCam)>) {
if let Ok((mut proj, cam)) = cam.get_single_mut() {
proj.scale = lerp(proj.scale, 0.7 + cam.target_zoom, 0.01);
proj.scale = lerp(proj.scale, 0.9 + cam.target_zoom, 0.01);
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl Plugin for LoadPlugin {
fn build(&self, app: &mut App) {
app.add_loading_state(LoadingState::new(GameState::Loading))
.init_collection::<GameAssets>()
.add_collection_to_loading_state::<_, SpiritAssets>(GameState::Loading)
.add_collection_to_loading_state::<_, TilemapAssets>(GameState::Loading)
.add_plugins((ProgressPlugin::new(GameState::Loading)
.continue_to(GameState::Menu)
Expand Down Expand Up @@ -52,10 +53,21 @@ pub struct GameAssets {
pub font: Handle<Font>,
}

#[derive(AssetCollection, Resource)]
pub struct SpiritAssets {
#[asset(texture_atlas(tile_size_x = 72., tile_size_y = 72., columns = 6, rows = 1))]
#[asset(path = "sprites/spirits_stix.png")]
pub stix: Handle<TextureAtlas>,

#[asset(texture_atlas(tile_size_x = 72., tile_size_y = 72., columns = 4, rows = 1))]
#[asset(path = "sprites/spirits_phlege.png")]
pub phlege: Handle<TextureAtlas>,
}

#[derive(AssetCollection, Resource)]
pub struct TilemapAssets {
#[asset(path = "sprites/tiles.png")]
pub tiles: Handle<Image>,
#[asset(path = "sprites/river_stix.png")]
pub stix: Handle<Image>,
}

// ··········
Expand Down
16 changes: 8 additions & 8 deletions src/spirits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand::Rng;

use crate::{
game::GameScore,
load::GameAssets,
load::{GameAssets, SpiritAssets},
tilemap::{get_neighbours, pos_to_tile, tile_to_pos, EndTile, PathTile, StartTile},
GameState,
};
Expand Down Expand Up @@ -82,7 +82,7 @@ pub struct LoseText;
fn spawn_spirit(
mut cmd: Commands,
time: Res<Time>,
assets: Res<GameAssets>,
spirit_assets: Res<SpiritAssets>,
mut start: Query<(&TilePos, &mut StartTile, &mut PathTile)>,
tilemap: Query<(&TilemapGridSize, &TilemapType, &Transform)>,
) {
Expand All @@ -107,15 +107,15 @@ fn spawn_spirit(

// Spawn the entity at the start of the path
cmd.spawn((
SpriteBundle {
texture: assets.bevy_icon.clone(),
transform: Transform::from_translation(pos.extend(1.))
.with_scale(Vec3::splat(0.15)),
SpriteSheetBundle {
sprite: TextureAtlasSprite::new(0),
texture_atlas: spirit_assets.stix.clone(),
transform: Transform::from_translation(pos.extend(1.)),
..default()
},
Spirit::new(*start_pos, pos),
));
start_tile.lose_counter = (start_tile.lose_counter - 1.5).max(0.);
start_tile.lose_counter = (start_tile.lose_counter - 2.).max(0.);

// Reduce timer 0.01 seconds until it is 0.5
let duration = start_tile.spawn_timer.duration().as_millis();
Expand Down Expand Up @@ -152,7 +152,7 @@ fn check_lose_count(
TextStyle {
font: assets.font.clone(),
font_size: 48.,
color: Color::rgb(0.0, 0.2, 0.4),
color: Color::rgb(0.9, 1.0, 0.6),
},
),
transform: Transform::from_translation(pos.extend(10.)),
Expand Down
25 changes: 14 additions & 11 deletions src/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
};

pub const MAP_SIZE: TilemapSize = TilemapSize { x: 20, y: 15 };
const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 64., y: 64. };
const GRID_SIZE: TilemapGridSize = TilemapGridSize { x: 72., y: 72. };
const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 128., y: 128. };
const GRID_SIZE: TilemapGridSize = TilemapGridSize { x: 127.8, y: 127.8 };

// ······
// Plugin
Expand Down Expand Up @@ -147,7 +147,7 @@ fn init_tilemap(mut cmd: Commands, tile_assets: Res<TilemapAssets>) {
grid_size: GRID_SIZE,
map_type,
storage,
texture: TilemapTexture::Single(tile_assets.tiles.clone()),
texture: TilemapTexture::Single(tile_assets.stix.clone()),
transform: get_tilemap_center_transform(&MAP_SIZE, &GRID_SIZE, &map_type, 0.0),
..default()
});
Expand Down Expand Up @@ -282,20 +282,23 @@ fn highlight_tile(

for (mut tex, mut color, mut flip, pos, selected, path, start, end) in tiles.iter_mut() {
*color = TileColor::default();

if selected.is_some() {
*color = TileColor(Color::rgb(0.5, 0.5, 1.0));
}

if !tile_in_level(pos, &level_size) {
*color = TileColor(Color::rgb(0., 0., 0.1));
} else if selected.is_some() {
*tex = TileTextureIndex(3);
} else if start.is_some() {
*tex = TileTextureIndex(2);
*tex = TileTextureIndex(11);
} else if end.is_some() {
*tex = TileTextureIndex(1);
*tex = TileTextureIndex(10);
} else if path.is_some() {
*tex = match path.unwrap().shape {
PathShape::None => TileTextureIndex(3),
PathShape::End => TileTextureIndex(4),
PathShape::Straight => TileTextureIndex(5),
PathShape::Turn => TileTextureIndex(6),
PathShape::None => TileTextureIndex(0),
PathShape::End => TileTextureIndex(3),
PathShape::Straight => TileTextureIndex(1),
PathShape::Turn => TileTextureIndex(5),
PathShape::Junction => TileTextureIndex(7),
PathShape::Crossing => TileTextureIndex(8),
};
Expand Down

0 comments on commit ca53563

Please sign in to comment.