Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Add high-res spritesheets #69

Merged
merged 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added game/assets/sprites/airplanes.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 game/assets/sprites/airports.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 game/assets/sprites/decorations.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 game/assets/sprites/landscape.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 removed game/assets/sprites/spritesheet.png
Binary file not shown.
20 changes: 14 additions & 6 deletions game/src/systems/setup_airport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ pub fn setup_airport(
asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
) {
let texture_handle = asset_server.load("sprites/spritesheet.png");
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(32.0, 32.0), 8, 5);
let texture_handle = asset_server.load("sprites/airports.png");
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(128.0, 128.0), 8, 2);
let texture_atlas_handle = texture_atlases.add(texture_atlas);

for airport in map.airports() {
let airport_vec3 = airport.node().as_vec3(RenderLayer::Airport.z());
let runway_vec3 = airport_vec3 + airport.runway().to_vec3() * Vec3::splat(TILE_SIZE as f32);

let color_offset = match airport.tag() {
Tag::Blue => 24,
Tag::Red => 32,
Tag::Blue => 0,
Tag::Red => 8,
};

let airport_offset = match airport.runway() {
Expand All @@ -39,7 +39,11 @@ pub fn setup_airport(
translation: airport_vec3,
..Default::default()
},
sprite: TextureAtlasSprite::new(color_offset + airport_offset),
sprite: TextureAtlasSprite {
index: color_offset + airport_offset,
custom_size: Some(Vec2::new(32.0, 32.0)),
..Default::default()
},
..Default::default()
});

Expand All @@ -49,7 +53,11 @@ pub fn setup_airport(
translation: runway_vec3,
..Default::default()
},
sprite: TextureAtlasSprite::new(color_offset + runway_offset),
sprite: TextureAtlasSprite {
index: color_offset + runway_offset,
custom_size: Some(Vec2::new(32.0, 32.0)),
..Default::default()
},
..Default::default()
});
}
Expand Down
35 changes: 19 additions & 16 deletions game/src/systems/setup_landscape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ pub fn setup_landscape(
) {
let mut rng = thread_rng();

let texture_handle = asset_server.load("sprites/spritesheet.png");
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(32.0, 32.0), 8, 5);
let texture_atlas_handle = texture_atlases.add(texture_atlas);
let landscape_handle = asset_server.load("sprites/landscape.png");
let landscape_atlas = TextureAtlas::from_grid(landscape_handle, Vec2::new(32.0, 32.0), 1, 1);
let landscape_atlas_handle = texture_atlases.add(landscape_atlas);

let decorations_handle = asset_server.load("sprites/decorations.png");
let decorations_atlas =
TextureAtlas::from_grid(decorations_handle, Vec2::new(128.0, 128.0), 4, 2);
let decorations_atlas_handle = texture_atlases.add(decorations_atlas);

let horizontal_tiles = (SCREEN_WIDTH as i32 / TILE_SIZE + 1) as i32;
let vertical_tiles = (SCREEN_HEIGHT as i32 / TILE_SIZE + 1) as i32;
Expand All @@ -24,7 +29,7 @@ pub fn setup_landscape(
let y = (y * TILE_SIZE) as f32;

commands.spawn_bundle(SpriteSheetBundle {
texture_atlas: texture_atlas_handle.clone(),
texture_atlas: landscape_atlas_handle.clone(),
transform: Transform {
translation: Vec3::new(x, y, RenderLayer::Landscape.z()),
..Default::default()
Expand All @@ -34,24 +39,22 @@ pub fn setup_landscape(
});

// 25% chance of a decoration
let sprite = match rng.gen_range(0..28) {
0 => 1, // #
1 => 2, // //
2 => 3, // {
3 => 4, // ;
4 => 5, // )
5 => 6, // &
6 => 7, // }
_ => continue,
};
let sprite = rng.gen_range(0..32);
if sprite >= 8 {
continue;
}

commands.spawn_bundle(SpriteSheetBundle {
texture_atlas: texture_atlas_handle.clone(),
texture_atlas: decorations_atlas_handle.clone(),
transform: Transform {
translation: Vec3::new(x - 16.0, y - 16.0, RenderLayer::Decoration.z()),
..Default::default()
},
sprite: TextureAtlasSprite::new(sprite),
sprite: TextureAtlasSprite {
index: sprite,
custom_size: Some(Vec2::new(32.0, 32.0)),
..Default::default()
},
..Default::default()
});
}
Expand Down
14 changes: 9 additions & 5 deletions game/src/systems/spawn_airplane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub fn spawn_airplane(
) {
let mut rng = thread_rng();

let texture_handle = asset_server.load("sprites/spritesheet.png");
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(32.0, 32.0), 8, 5);
let texture_handle = asset_server.load("sprites/airplanes.png");
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(128.0, 128.0), 2, 1);
let texture_atlas_handle = texture_atlases.add(texture_atlas);

if timer.0.tick(time.delta()).just_finished() {
Expand All @@ -49,8 +49,8 @@ pub fn spawn_airplane(
};

let color_offset = match tag {
Tag::Blue => 10,
Tag::Red => 18,
Tag::Blue => 0,
Tag::Red => 1,
};

commands
Expand All @@ -65,7 +65,11 @@ pub fn spawn_airplane(
rotation: Quat::from_rotation_z(direction.to_degree().to_radians()),
..Default::default()
},
sprite: TextureAtlasSprite::new(color_offset),
sprite: TextureAtlasSprite {
index: color_offset,
custom_size: Some(Vec2::new(32.0, 32.0)),
..Default::default()
},
..Default::default()
})
.insert(Airplane)
Expand Down