Skip to content

Commit

Permalink
Add effect images and target height indicator asset
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Dec 10, 2023
1 parent a5e1f64 commit 74cffa5
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 17 deletions.
Binary file added assets/effects/glue/i.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/effects/glue/j.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/effects/glue/l.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/effects/glue/o.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/effects/glue/s.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/effects/glue/t.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/effects/glue/z.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/effects/magnet/L.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/effects/magnet/i.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/effects/magnet/j.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/effects/magnet/o.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/effects/magnet/s.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/effects/magnet/t.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/effects/magnet/z.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/target_height_indicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ impl Block {
.id();

if let Some(effect) = effect_type {
effect.enable(&mut commands, assets, entity);
effect.enable(&mut commands, assets, entity, block_type);
}
entity
}
Expand Down
26 changes: 25 additions & 1 deletion src/effect/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::mem;
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

use crate::block::{CaughtBlock, FallingBlockCollision};
use crate::block::{Block, CaughtBlock, FallingBlockCollision};
use crate::effect::glue_texture;

pub struct GluePlugin;

Expand Down Expand Up @@ -35,8 +36,11 @@ impl Default for GlueEffectPhase {
pub struct GlueJoint;

pub fn collect_glue_list_system(
mut commands: Commands,
mut event_reader: EventReader<FallingBlockCollision>,
mut query: Query<(Entity, &mut GlueEffect)>,
hit_query: Query<(Entity, &Block)>,
assets: Res<AssetServer>,
) {
for event in event_reader.read() {
let FallingBlockCollision { falling, hit } = event;
Expand All @@ -45,6 +49,26 @@ pub fn collect_glue_list_system(
if let GlueEffectPhase::Gluing { targets } = &mut glue_effect.0 {
if !targets.contains(hit) {
targets.push(*hit);

if let Ok((hit, block)) = hit_query.get(*hit) {
commands.entity(hit).with_children(|parent| {
parent.spawn(
(SpriteBundle {
transform: Transform::from_xyz(0.0, 0.0, 1.0),
texture: assets.load(glue_texture(block.block_type)),
sprite: Sprite {
custom_size: Some(Vec2::new(
block.block_type.width(),
block.block_type.height(),
)),
color: Color::rgba(1.0, 1.0, 1.0, 0.5),
..Default::default()
},
..Default::default()
}),
);
});
}
}
}
}
Expand Down
32 changes: 24 additions & 8 deletions src/effect/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use bevy::prelude::*;

use crate::block::BlockType;
use crate::effect::glue::GlueEffect;
use crate::effect::platform::PlatformEffect;
use bevy::prelude::*;

pub mod glue;
pub mod magnetic;
Expand Down Expand Up @@ -30,12 +32,18 @@ pub const ALL_EFFECTS: [EffectType; 3] =

pub const DEFAULT_EFFECTS: [EffectType; 2] = [EffectType::Glue, EffectType::Magnetic];

pub fn glue_texture(block_type: BlockType) -> String {
format!("effects/glue/{}.png", block_type.letter().to_lowercase())
}

impl EffectType {
pub fn texture(&self) -> &'static str {
pub fn texture(&self, block_type: BlockType) -> String {
match self {
EffectType::Glue => "glue.png",
EffectType::Platform => "fixed.png",
EffectType::Magnetic => "magnet.png",
EffectType::Glue => glue_texture(block_type),
EffectType::Platform => "fixed.png".to_string(),
EffectType::Magnetic => {
format!("effects/magnet/{}.png", block_type.letter().to_lowercase())
}
}
}

Expand All @@ -55,14 +63,22 @@ impl EffectType {
}
}

pub fn enable(&self, commands: &mut Commands, assets: &AssetServer, entity: Entity) {
pub fn enable(
&self,
commands: &mut Commands,
assets: &AssetServer,
entity: Entity,
block_type: BlockType,
) {
self.insert_effect(commands, entity);
let texture = self.texture();
let texture = self.texture(block_type);
commands.entity(entity).with_children(|parent| {
parent.spawn(SpriteBundle {
transform: Transform::from_xyz(0.0, 0.0, 1.0),
texture: assets.load(texture),
sprite: Sprite {
custom_size: Some(Vec2::new(1.0, 1.0)),
custom_size: Some(Vec2::new(block_type.width(), block_type.height())),
color: Color::rgba(1.0, 1.0, 1.0, 0.75),
..Default::default()
},
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub const DEFAULT_LEVEL: Level = Level {
..default_level_base()
}],
enabled_effects: &DEFAULT_EFFECTS,
effect_likelihood: 0.05,
effect_likelihood: 0.5,
intro_text: "Welcome to the game!",
rain: None,
friction: 0.5,
Expand Down
14 changes: 8 additions & 6 deletions src/target_height_indicator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::ASSET_SCALE;
use bevy::prelude::*;

use crate::level::{Level, LevelGoal, LevelLifecycle};
Expand All @@ -21,6 +22,7 @@ pub fn setup_target_height_indicator(
mut commands: Commands,
mut level: Res<Level>,
old_indicator: Query<Entity, With<TargetHeightIndicator>>,
assets: Res<AssetServer>,
) {
println!("Setting up target height indicator");
for entity in old_indicator.iter() {
Expand All @@ -32,12 +34,12 @@ pub fn setup_target_height_indicator(
TargetHeightIndicator,
LevelLifecycle,
SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::new(1000.0, 0.1)),
color: Color::rgb(1.0, 0.0, 0.0),
..Default::default()
},
transform: Transform::from_xyz(0.0, height, 0.0),
transform: Transform::from_xyz(0.0, height, 5.0).with_scale(Vec3::new(
ASSET_SCALE,
ASSET_SCALE * 0.5,
1.0,
)),
texture: assets.load("target_height_indicator.png"),
..Default::default()
},
));
Expand Down

0 comments on commit 74cffa5

Please sign in to comment.