Skip to content

Commit

Permalink
feat: multiple improvemens and fixes 🍊
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Dec 10, 2023
1 parent aebe0e3 commit f3265b9
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 92 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ a game for the bevy jam 4
- [x] lose timer and visual feedback

- [ ] important tweaks (dom mañ)
- [ ] add sprites
- [x] add sprites
- [x] zoom out screen
- [x] limited path tiles
- [ ] end screen (win/lose)
Expand All @@ -33,7 +33,7 @@ a game for the bevy jam 4
- [ ] other river types
- [ ] other spirit behaviour
- [ ] bridges
- [ ] overlay ui (bridge selection, n paths...)
- [x] overlay ui
- [ ] better path drawing

- [ ] presentation (dom tar)
Expand All @@ -44,7 +44,7 @@ a game for the bevy jam 4
- [ ] would be nice (???)
- [ ] alternate paths
- [ ] improve lose timer
- [ ] animations
- [x] animations
- [ ] spirit dialogues
- [ ] sound and music
- [ ] tweening and animation
Expand Down
Binary file added assets/sprites/coin.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.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const START_SCORES: [u32; 20] = [
5000,
];

const END_SCORES: [u32; 4] = [0, 60, 350, 3000];
const END_SCORES: [u32; 6] = [0, 60, 120, 350, 1000, 3000];

pub struct CharonPlugin;

Expand Down Expand Up @@ -127,7 +127,7 @@ fn spawn_start_end(
};

// Grow level size every 2 starts (only if we are not at the max size)
if is_start && (*start_spawned + 2) % 3 == 0 && level_size.0.x < MAP_SIZE.x {
if is_start && (*start_spawned + 3) % 4 == 0 && level_size.0.x < MAP_SIZE.x {
level_size.0.x += 2;
level_size.0.y += 2;
if let Ok(mut cam) = cam.get_single_mut() {
Expand Down
108 changes: 76 additions & 32 deletions src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,85 @@ fn init_hud(mut cmd: Commands, assets: Res<GameAssets>, mut node: Query<Entity,
if let Ok(node) = node.get_single_mut() {
if let Some(mut node) = cmd.get_entity(node) {
node.with_children(|parent| {
parent.spawn((
TextBundle::from_section(
"<> 0",
TextStyle {
font: assets.font.clone(),
font_size: 24.0,
color: Color::WHITE,
parent
.spawn(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
left: Val::Px(5.0),
top: Val::Px(5.0),
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
column_gap: Val::Px(4.),
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
right: Val::Px(5.0),
top: Val::Px(5.0),
..default()
}),
ScoreText,
));
})
.with_children(|tiles| {
tiles.spawn(ImageBundle {
image: UiImage {
texture: assets.river_icon.clone(),
..default()
},
style: Style {
width: Val::Px(24.),
..default()
},
..default()
});

parent.spawn((
TextBundle::from_section(
"[] 0",
TextStyle {
font: assets.font.clone(),
font_size: 24.0,
color: Color::WHITE,
tiles.spawn((
TextBundle::from_section(
"0",
TextStyle {
font: assets.font.clone(),
font_size: 24.0,
color: Color::WHITE,
},
),
TilesText,
));
});

parent
.spawn(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
right: Val::Px(5.0),
top: Val::Px(5.0),
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
column_gap: Val::Px(4.),
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
left: Val::Px(5.0),
top: Val::Px(5.0),
..default()
}),
TilesText,
));
})
.with_children(|score| {
score.spawn((
TextBundle::from_section(
"0",
TextStyle {
font: assets.font.clone(),
font_size: 24.0,
color: Color::WHITE,
},
),
ScoreText,
));

score.spawn(ImageBundle {
image: UiImage {
texture: assets.coin_icon.clone(),
..default()
},
style: Style {
width: Val::Px(24.),
..default()
},
..default()
});
});
});
}
}
Expand All @@ -82,10 +126,10 @@ fn update_hud(
mut tiles_text: Query<&mut Text, (With<TilesText>, Without<ScoreText>)>,
) {
for mut text in score_text.iter_mut() {
text.sections[0].value = format!("<> {}", score.score);
text.sections[0].value = format!("{}", score.score);
}
for mut text in tiles_text.iter_mut() {
text.sections[0].value = format!("[] {}", tiles.0);
text.sections[0].value = format!("{}", tiles.0);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ pub struct GameAssets {
#[asset(path = "icons/bevy.png")]
pub bevy_icon: Handle<Image>,

#[asset(path = "sprites/coin.png")]
pub coin_icon: Handle<Image>,

#[asset(path = "sprites/river.png")]
pub river_icon: Handle<Image>,

#[asset(path = "fonts/sans.ttf")]
pub font: Handle<Font>,
}
Expand Down
122 changes: 69 additions & 53 deletions src/spirits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl Plugin for SpiritPlugin {
next_tile_spirit,
spirit_collision,
move_spirit,
animate_spirit,
integrate,
)
.run_if(in_state(GameState::Play)),
Expand All @@ -59,7 +60,7 @@ pub struct EndTimer(Timer);

impl Default for EndTimer {
fn default() -> Self {
Self(Timer::from_seconds(0.3, TimerMode::Repeating))
Self(Timer::from_seconds(0.25, TimerMode::Repeating))
}
}

Expand All @@ -76,6 +77,7 @@ pub struct Spirit {
next_pos: Vec2,
selected_end: Option<TilePos>,
vel: Vec2,
animate_timer: Timer,
}

impl Spirit {
Expand All @@ -88,6 +90,7 @@ impl Spirit {
next_pos: curr_pos,
selected_end: None,
vel: Vec2::ZERO,
animate_timer: Timer::from_seconds(0.5, TimerMode::Repeating),
}
}
}
Expand Down Expand Up @@ -133,7 +136,7 @@ fn spawn_spirit(
// Spawn the entity at the start of the path
cmd.spawn((
SpriteSheetBundle {
sprite: TextureAtlasSprite::new(0),
sprite: TextureAtlasSprite::new((rand::random::<usize>() % 3) * 2),
texture_atlas: spirit_assets.stix.clone(),
transform: Transform::from_translation(pos.extend(5.)),
..default()
Expand Down Expand Up @@ -163,49 +166,47 @@ fn check_lose_count(
tilemap: Query<(&TilemapLayer, &TilemapGridSize, &TilemapType, &Transform)>,
) {
for (pos, mut start) in start.iter_mut() {
if start.lose_counter > 1. {
let lose_text = start.lose_text;

if lose_text.is_none() {
for (layer, grid_size, map_type, trans) in tilemap.iter() {
match layer {
TilemapLayer::RiverStix => {}
_ => continue,
}
let lose_text = start.lose_text;

let pos = tile_to_pos(pos, grid_size, map_type, trans);
start.lose_text = Some(
cmd.spawn((
Text2dBundle {
text: Text::from_section(
"",
TextStyle {
font: assets.font.clone(),
font_size: 48.,
color: Color::rgb(0.9, 1.0, 0.6),
},
),
transform: Transform::from_translation(pos.extend(10.)),
..default()
},
LoseText,
))
.id(),
);
if lose_text.is_none() {
for (layer, grid_size, map_type, trans) in tilemap.iter() {
match layer {
TilemapLayer::RiverStix => {}
_ => continue,
}
continue;
};

if let Ok(mut text) = text.get_mut(lose_text.unwrap()) {
let remainder = (LOSE_COUNT - start.lose_counter) / 2. + 1.;
text.sections[0].value = if remainder <= 2. {
"!!!".to_string()
} else if remainder > 15. {
"".to_string()
} else {
remainder.round().to_string()
};
let pos = tile_to_pos(pos, grid_size, map_type, trans);
start.lose_text = Some(
cmd.spawn((
Text2dBundle {
text: Text::from_section(
"",
TextStyle {
font: assets.font.clone(),
font_size: 48.,
color: Color::rgb(0.9, 0.4, 0.6),
},
),
transform: Transform::from_translation(pos.extend(10.)),
..default()
},
LoseText,
))
.id(),
);
}
continue;
};

if let Ok(mut text) = text.get_mut(lose_text.unwrap()) {
let remainder = (LOSE_COUNT - start.lose_counter) / 2. - 3.;
text.sections[0].value = if remainder <= 0. {
"!!!".to_string()
} else if remainder > 10. {
"".to_string()
} else {
remainder.round().to_string()
};
}
if start.lose_counter >= LOSE_COUNT {
state.set(GameState::End);
Expand Down Expand Up @@ -249,17 +250,7 @@ fn next_tile_spirit(
}

// TODO: Move this so it updates for other spirits
// Update counts
if let Some(entity) = storage.get(&tile_pos) {
if let Ok((_, mut path)) = paths.get_mut(entity) {
path.count += 1;
}
}
if let Some(entity) = storage.get(&spirit.curr_tile) {
if let Ok((_, mut path)) = paths.get_mut(entity) {
path.count = path.count.saturating_sub(1);
}
}

spirit.curr_tile = tile_pos;

// If it arrived at the next tile (or if there is no next tile)
Expand Down Expand Up @@ -385,6 +376,18 @@ fn next_tile_spirit(
spirit.next_pos =
tile_to_pos(&spirit.next_tile.unwrap(), grid_size, map_type, map_trans);
spirit.selected_end = next.unwrap().2;

// Update counts
if let Some(entity) = storage.get(&spirit.next_tile.unwrap()) {
if let Ok((_, mut path)) = paths.get_mut(entity) {
path.count += 1;
}
}
if let Some(entity) = storage.get(&spirit.prev_tile.unwrap()) {
if let Ok((_, mut path)) = paths.get_mut(entity) {
path.count = path.count.saturating_sub(1);
}
}
}
}
}
Expand All @@ -406,7 +409,7 @@ fn clear_end_count(
for (entity, spirit) in spirits.iter() {
if spirit.curr_tile == *end_pos {
cmd.get_entity(entity).unwrap().despawn_recursive();
end.count -= 1;
end.count = end.count.saturating_sub(1);
score.score += 1;
break;
}
Expand Down Expand Up @@ -451,3 +454,16 @@ fn integrate(mut spirits: Query<(&Spirit, &mut Transform)>, time: Res<Time>) {
trans.translation += (spirit.vel + cross * offset).extend(0.) * time.delta_seconds();
}
}

fn animate_spirit(time: Res<Time>, mut spirits: Query<(&mut Spirit, &mut TextureAtlasSprite)>) {
for (mut spirit, mut tex) in spirits.iter_mut() {
if !spirit.animate_timer.tick(time.delta()).just_finished() {
continue;
}
tex.index = if tex.index % 2 == 0 {
tex.index + 1
} else {
tex.index - 1
};
}
}
4 changes: 2 additions & 2 deletions src/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct TilePlugin;

impl Plugin for TilePlugin {
fn build(&self, app: &mut App) {
app.insert_resource(TilesAvailable(11))
app.insert_resource(TilesAvailable(6))
.insert_resource(SelectedPos(None))
.add_plugins(TilemapPlugin)
.add_systems(OnEnter(GameState::Play), init_tilemap.run_if(run_once()))
Expand Down Expand Up @@ -299,7 +299,7 @@ fn highlight_tile(
}

if !tile_in_level(pos, &level_size) {
*color = TileColor(Color::rgb(0., 0., 0.1));
*color = TileColor(Color::rgb(0.2, 0.1, 0.35));
continue;
}

Expand Down

0 comments on commit f3265b9

Please sign in to comment.