diff --git a/README.md b/README.md index ea72b51..b291898 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ A rogue-like game built in bevy and rust. ### Screenshots: ![island](images/island.png) ![zoom-island](images/zoom-island.png) +![spider-spawner](images/spider-spawn.png) ### Credits: - `Toen's Medieval Strategy Sprite Pack` - Created by Andre Mari Coppola (http://toen.itch.io/toens-medieval-strategy) diff --git a/assets/textures/cave_sprite.aseprite b/assets/textures/cave_sprite.aseprite new file mode 100644 index 0000000..eaabe55 Binary files /dev/null and b/assets/textures/cave_sprite.aseprite differ diff --git a/assets/textures/cave_sprite.png b/assets/textures/cave_sprite.png new file mode 100644 index 0000000..09a1513 Binary files /dev/null and b/assets/textures/cave_sprite.png differ diff --git a/assets/textures/spider_sprite.png b/assets/textures/spider_sprite.png index 5ef1d1d..d39eaa8 100644 Binary files a/assets/textures/spider_sprite.png and b/assets/textures/spider_sprite.png differ diff --git a/assets/textures/spider_sprite.png~ b/assets/textures/spider_sprite.png~ new file mode 100644 index 0000000..d7101dc Binary files /dev/null and b/assets/textures/spider_sprite.png~ differ diff --git a/images/spider-spawn.png b/images/spider-spawn.png new file mode 100644 index 0000000..b42160d Binary files /dev/null and b/images/spider-spawn.png differ diff --git a/src/game/gameplay/enemy/mod.rs b/src/game/gameplay/enemy/mod.rs new file mode 100644 index 0000000..0094ae4 --- /dev/null +++ b/src/game/gameplay/enemy/mod.rs @@ -0,0 +1,24 @@ +use bevy::prelude::*; + +pub mod spawner; + +#[derive(Default)] +pub struct Enemy { +} + +pub fn spawn_map_enemy( + commands: &mut Commands, + asset_server: &Res, + materials: &mut ResMut>, + position: Vec2, +) { + let texture_handle: Handle = asset_server.load("textures/spider_sprite.png"); + let enemy_sprite_material = materials.add(texture_handle.into()); + commands + .spawn_bundle(SpriteBundle { + material: enemy_sprite_material, + transform: Transform::from_xyz(position.x, position.y, 12.0), + ..Default::default() + }) + .insert(Enemy::default()); +} \ No newline at end of file diff --git a/src/game/gameplay/enemy/spawner.rs b/src/game/gameplay/enemy/spawner.rs new file mode 100644 index 0000000..14f1c34 --- /dev/null +++ b/src/game/gameplay/enemy/spawner.rs @@ -0,0 +1,66 @@ +use bevy::prelude::*; +use rand::{Rng, prelude::ThreadRng, thread_rng}; + +use super::spawn_map_enemy; + +#[derive(Default)] +pub struct Spawner { + wait_time: f64, // How long until a enemy spawns + last_time: f64, // The time since the last spawn + limit: u32, // The maximum enemy's that can spawn from this spawner. + current: u32, // The current count of spawned enemies. + range: f32, // How far away from the spawner an enemy can spawn. +} + +pub fn spawn( + commands: &mut Commands, + asset_server: &Res, + materials: &mut ResMut>, + position: Vec2, +) { + let texture_handle: Handle = asset_server.load("textures/cave_sprite.png"); + let cave_sprite_material = materials.add(texture_handle.into()); + commands + .spawn_bundle(SpriteBundle { + material: cave_sprite_material, + transform: Transform::from_xyz(position.x, position.y, 10.0), + ..Default::default() + }) + .insert(Spawner { + wait_time: 10.0, + last_time: 0.0, + limit: 3, + current: 0, + range: 2.0 + }); +} + +pub fn tick( + mut commands: Commands, + asset_server: Res, + mut materials: ResMut>, + mut spawner_query: Query<(&Transform, &mut Spawner)>, + time: Res