Skip to content

Commit

Permalink
Unlimited spiders.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankopf committed Aug 8, 2023
1 parent 86f9052 commit e987538
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 63 deletions.
30 changes: 23 additions & 7 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ pub enum ActorType { // Entity? Character? Creature? Actor? Avatar? Unit? Agent?
ManCave,
Pig,
Rat,
Spider,
Bear,
Ant,
Locust,
Wasp,
Dingo,
Kangaroo,
IceFox
}
impl ActorType {
pub fn sprite_row_and_col(&self) -> (usize, usize) {
Expand All @@ -96,6 +104,14 @@ impl ActorType {
ActorType::ManCave => (60, 25),
ActorType::Pig => (64, 0),
ActorType::Rat => (64, 19),
ActorType::Spider => (64, 20),
ActorType::Bear => (64, 21),
ActorType::Ant => (64, 22),
ActorType::Locust => (64, 23),
ActorType::Wasp => (64, 24),
ActorType::Dingo => (64, 25),
ActorType::Kangaroo => (64, 26),
ActorType::IceFox => (64, 27),
}
}
pub fn sprite_index(&self) -> usize {
Expand Down Expand Up @@ -242,12 +258,12 @@ impl Default for Attributeset {
fn default() -> Self {
Attributeset {
health: 100,
strength: 10,
dexterity: 10,
constitution: 10,
intelligence: 10,
wisdom: 10,
charisma: 10,
strength: 1,
dexterity: 1,
constitution: 1,
intelligence: 1,
wisdom: 1,
charisma: 1,
}
}
}
Expand Down Expand Up @@ -513,7 +529,7 @@ impl InfoPanel for Brain {
}
}

#[derive(Component, PartialEq)]
#[derive(Component, PartialEq, Copy, Clone)]
pub enum PersonalityTrait {
// Traits for People
Adventurous, Ambitious, Analytical, Airheaded, Artistic, Brave, Calm, Charismatic, Confident, Cowardly,
Expand Down
45 changes: 12 additions & 33 deletions src/monstergenerator_system.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{prelude::*, components::{Attributeset, PersonalityTrait}};
use crate::{prelude::*, unitgenerator_system::spawn_unit_from_template, UnitTemplate};

// Make plugin
pub struct MonsterGeneratorPlugin;
Expand Down Expand Up @@ -45,38 +45,17 @@ pub fn monster_generator(
if !can_generate {
return;
}
let sprite = TextureAtlasSprite::new(ActorType::Rat.sprite_index());
commands
.spawn(SpriteSheetBundle {
sprite,
texture_atlas: sprite_sheet.0.clone(),
..default()
})
.insert(new_position)
.insert(SizeXYZ::cube(1.1))
.insert(new_position.to_transform_layer(1.0))
.insert(GeneratedBy { entity })
// .insert(MoveTowardsNearestAttackable)
.insert( PhysicalBody {
needs_food: None,//Some(NeedsFood { current: 25.1, max: 100.0, rate: 0.1 }),
needs_entertainment: None,//Some(NeedsEntertainment { current: 100.0, max: 100.0, rate: 0.1 }),
needs_sleep: None,//Some(NeedsSleep { current: 15.2, max: 100.0, rate: 0.1 }),
index: 0,
crisis: None,
danger: None,
injured: false,
afflictions: Vec::new(),
skillset: Skillset::default(),
attributes: Attributeset::default(),
} )
.insert( Brain {
motivation: None,
task: None,
order: None,
personality: vec![PersonalityTrait::Creature, PersonalityTrait::Vicious],
} )
.insert( HasName { name: "Rat".to_string() } )
;
match rand::thread_rng().gen_range(0..6) {
0 => {
let monster = spawn_unit_from_template(&mut commands, new_position, &sprite_sheet, &UnitTemplate::rat());
commands.entity(monster).insert(GeneratedBy { entity });
}
_ => {
let monster = spawn_unit_from_template(&mut commands, new_position, &sprite_sheet, &UnitTemplate::spider());
commands.entity(monster).insert(GeneratedBy { entity });
}
}

//*position = new_position;
}

Expand Down
102 changes: 79 additions & 23 deletions src/unitgenerator_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ pub fn spawn_unit_from_template(
template: &UnitTemplate,
) -> Entity {
let sprite = TextureAtlasSprite::new(template.actor_type.sprite_index());
commands
let entity = commands
.spawn(SpriteSheetBundle {
sprite,
texture_atlas: sprite_sheet.0.clone(),
..default()
})
.insert(position)
.insert(position.to_transform_layer(1.0))
.insert( GiveMeAName )
.insert( PhysicalBody {
needs_food: Some(template.food_need.into()),
needs_entertainment: Some(template.entertainment_need.into()),
needs_sleep: Some(template.sleep_need.into()),
needs_food: template.food_need.map(Into::into),
needs_entertainment: template.entertainment_need.map(Into::into),
needs_sleep: template.sleep_need.map(Into::into),
index: 0,
crisis: None,
danger: None,
Expand All @@ -37,18 +36,29 @@ pub fn spawn_unit_from_template(
skillset: template.skillset.clone(),
attributes: template.attributes.clone(),
} )
.insert( Brain { ..default() } )
.id()
.insert( Brain {
personality: template.personality.clone(),
..default()
} )
.id();
for builder in &template.component_builders {
builder(commands, entity);
};
entity
}

type ComponentBuilder = fn(&mut Commands, Entity);

pub struct UnitTemplate {
pub actor_type: ActorType,
pub food_need: NeedExample,
pub entertainment_need: NeedExample,
pub sleep_need: NeedExample,
pub afflictions: Vec<Affliction>,
pub food_need: Option<NeedExample>,
pub entertainment_need: Option<NeedExample>,
pub sleep_need: Option<NeedExample>,
pub personality: Vec<PersonalityTrait>,
pub skillset: Skillset,
pub attributes: Attributeset,
pub afflictions: Vec<Affliction>,
pub component_builders: Vec<ComponentBuilder>,
}
#[derive(Copy, Clone)]
pub struct NeedExample {
Expand Down Expand Up @@ -91,38 +101,84 @@ impl UnitTemplate {
let random_afflictions = Self::random_afflictions_humanoid();
Self {
actor_type,
food_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
entertainment_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
sleep_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
afflictions: random_afflictions.to_vec(),
food_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
entertainment_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
sleep_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
personality: vec![],
skillset: Self::random_skillset_humanoid(),
attributes: Self::random_attributeset_humanoid(),
afflictions: random_afflictions.to_vec(),
component_builders: vec![
|commands: &mut Commands, entity: Entity| { commands.entity(entity).insert(GiveMeAName); },
],
}
}
pub fn elf() -> Self {
let actor_type = ActorType::Elf;
let random_afflictions = Self::random_afflictions_humanoid();
Self {
actor_type,
food_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
entertainment_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
sleep_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
afflictions: random_afflictions.to_vec(),
food_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
entertainment_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
sleep_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
personality: vec![],
skillset: Self::random_skillset_humanoid(),
attributes: Self::random_attributeset_humanoid(),
afflictions: random_afflictions.to_vec(),
component_builders: vec![
|commands: &mut Commands, entity: Entity| { commands.entity(entity).insert(GiveMeAName); },
],
}
}
pub fn dwarf() -> Self {
let actor_type = ActorType::Dwarf;
let random_afflictions = Self::random_afflictions_humanoid();
Self {
actor_type,
food_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
entertainment_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
sleep_need: NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 },
afflictions: random_afflictions.to_vec(),
food_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
entertainment_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
sleep_need: Some(NeedExample { current: 90.0, max: 100.0, rate: 0.1, low: 10.0, normal: 25.0, high: 80.0, variance: 5.0 }),
personality: vec![],
skillset: Self::random_skillset_humanoid(),
attributes: Self::random_attributeset_humanoid(),
afflictions: random_afflictions.to_vec(),
component_builders: vec![
|commands: &mut Commands, entity: Entity| { commands.entity(entity).insert(GiveMeAName); },
],
}
}
pub fn rat() -> Self {
let actor_type = ActorType::Rat;
let random_afflictions = vec![];//Self::random_afflictions_animal();
Self {
actor_type,
food_need: None,
entertainment_need: None,
sleep_need: None,
personality: vec![PersonalityTrait::Creature, PersonalityTrait::Vicious],
afflictions: random_afflictions.to_vec(),
skillset: Skillset::default(),
attributes: Attributeset::default(),
component_builders: vec![
|commands: &mut Commands, entity: Entity| { commands.entity(entity).insert(HasName { name: "Rat".to_string() }); },
],
}
}
pub fn spider() -> Self {
let actor_type = ActorType::Spider;
let random_afflictions = vec![];//Self::random_afflictions_animal();
Self {
actor_type,
food_need: None,
entertainment_need: None,
sleep_need: None,
personality: vec![PersonalityTrait::Creature, PersonalityTrait::Vicious],
afflictions: random_afflictions.to_vec(),
skillset: Skillset::default(),
attributes: Attributeset::default(),
component_builders: vec![
|commands: &mut Commands, entity: Entity| { commands.entity(entity).insert(HasName { name: "Spider".to_string() }); },
],
}
}
pub fn random_afflictions_humanoid() -> Vec<Affliction> {
Expand Down

0 comments on commit e987538

Please sign in to comment.