Skip to main content

Size

Struct Size 

Source
pub struct Size {
    pub width: u32,
    pub height: u32,
}
Expand description

Size component defining how much space an entity occupies.

This component describes the entity’s spatial footprint, which can affect collision detection, movement constraints, and rendering.

Fields§

§width: u32

Width in grid units

§height: u32

Height in grid units

Implementations§

Source§

impl Size

Source

pub fn new(width: u32, height: u32) -> Self

Creates a new size component.

Source

pub fn single() -> Self

Creates a square size (1x1).

Examples found in repository?
examples/tactical_rpg.rs (line 284)
255  pub fn new() -> Self {
256  let mut world = World::new();
257  let player_team = Team::new(0);
258  let enemy_team = Team::hostile(1);
259  
260  // Spawn player units
261  let player_warrior = world.spawn((
262    Position::new(HexCoord::<Axial, Pointy>::new(-2, 1)),
263    Health::new(120),
264    Stats::new(18, 12, 10, 1),
265    player_team,
266    Movable::new(3),
267    Experience::new(1),
268    Initiative::new(15),
269    Equipment {
270      weapon: Some(Weapon {
271        name: "Iron Sword".to_string(),
272        attack_bonus: 5,
273        range: 1,
274        damage_type: DamageType::Physical,
275      }),
276      armor: Some(Armor {
277        name: "Chain Mail".to_string(),
278        defense_bonus: 3,
279        resistances: vec![DamageType::Physical],
280      }),
281      accessories: Vec::new(),
282      inventory_slots: 10,
283    },
284    Size::single(),
285  ));
286  
287  let player_mage = world.spawn((
288    Position::new(HexCoord::<Axial, Pointy>::new(-1, 0)),
289    Health::new(80),
290    Stats::new(12, 8, 14, 1),
291    player_team,
292    Movable::new(2),
293    Experience::new(1),
294    Initiative::new(12),
295    Equipment {
296      weapon: Some(Weapon {
297        name: "Fire Staff".to_string(),
298        attack_bonus: 2,
299        range: 3,
300        damage_type: DamageType::Fire,
301      }),
302      armor: None,
303      accessories: vec![Accessory {
304        name: "Mana Crystal".to_string(),
305        effect: AccessoryEffect::StatBonus(StatType::Speed, 2),
306      }],
307      inventory_slots: 8,
308    },
309    {
310      let mut abilities = Abilities::new(50);
311      abilities.add_ability(Ability {
312        name: "Fireball".to_string(),
313        mana_cost: 10,
314        range: 4,
315        area_of_effect: 1,
316        damage: 25,
317        damage_type: DamageType::Fire,
318        cooldown: 2,
319        current_cooldown: 0,
320      });
321      abilities.add_ability(Ability {
322        name: "Heal".to_string(),
323        mana_cost: 8,
324        range: 2,
325        area_of_effect: 0,
326        damage: 0, // Actually healing
327        damage_type: DamageType::Healing,
328        cooldown: 1,
329        current_cooldown: 0,
330      });
331      abilities
332    },
333    Size::single(),
334  ));
335  
336  // Spawn enemy units
337  let enemy_goblin = world.spawn((
338    Position::new(HexCoord::<Axial, Pointy>::new(2, -1)),
339    Health::new(60),
340    Stats::new(12, 6, 12, 1),
341    enemy_team,
342    Movable::new(4),
343    AI::new(1.0),
344    Initiative::new(14),
345    Equipment {
346      weapon: Some(Weapon {
347        name: "Rusty Dagger".to_string(),
348        attack_bonus: 2,
349        range: 1,
350        damage_type: DamageType::Physical,
351      }),
352      armor: None,
353      accessories: Vec::new(),
354      inventory_slots: 5,
355    },
356    Size::single(),
357  ));
358  
359  let enemy_orc = world.spawn((
360    Position::new(HexCoord::<Axial, Pointy>::new(3, -2)),
361    Health::new(100),
362    Stats::new(16, 10, 8, 1),
363    enemy_team,
364    Movable::new(2),
365    AI::new(1.5),
366    Initiative::new(10),
367    Equipment {
368      weapon: Some(Weapon {
369        name: "War Axe".to_string(),
370        attack_bonus: 6,
371        range: 1,
372        damage_type: DamageType::Physical,
373      }),
374      armor: Some(Armor {
375        name: "Hide Armor".to_string(),
376        defense_bonus: 2,
377        resistances: Vec::new(),
378      }),
379      accessories: Vec::new(),
380      inventory_slots: 6,
381    },
382    Size::single(),
383  ));
384  
385  let mut turn_queue = VecDeque::new();
386  turn_queue.extend([player_warrior, player_mage, enemy_goblin, enemy_orc]);
387  
388  Self {
389    world,
390    turn_queue,
391    current_turn: None,
392    turn_number: 1,
393    player_team,
394    enemy_team,
395    game_phase: GamePhase::Planning,
396  }
397  }
Source

pub fn square(size: u32) -> Self

Creates a square size with the specified dimension.

Source

pub fn area(&self) -> u32

Calculates the total area occupied.

Trait Implementations§

Source§

impl Clone for Size

Source§

fn clone(&self) -> Size

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Size

Source§

impl Debug for Size

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Size

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Size

Source§

impl Hash for Size

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Size

Source§

fn eq(&self, other: &Size) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Size

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Size

Auto Trait Implementations§

§

impl Freeze for Size

§

impl RefUnwindSafe for Size

§

impl Send for Size

§

impl Sync for Size

§

impl Unpin for Size

§

impl UnsafeUnpin for Size

§

impl UnwindSafe for Size

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneDyn for T
where T: Clone,

Source§

fn __clone_dyn(&self, _: DontCallMe) -> *mut ()

Source§

impl<T> CloneDyn for T
where T: Clone,

Source§

fn __clone_dyn(&self, _: DontCallMe) -> *mut ()

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> Event for T
where T: Any + Send + Sync + Debug + Clone,

Source§

impl<T, All> From1<(T,)> for All
where All: From1<T>,

Source§

fn from1(arg: (T,)) -> All

Constructor with a single arguments.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<All, F> Into1<F> for All
where F: From1<All>,

Source§

fn to(self) -> F

Converts this type into the (usually inferred) input type.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToRef<T> for T
where T: ?Sized,

Source§

fn to_ref(&self) -> &T

Converts the implementing type to an immutable reference. Read more
Source§

impl<T> ToValue<T> for T

Source§

fn to_value(self) -> T

Obtains the value from the implementing type. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.