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: u32Width in grid units
height: u32Height in grid units
Implementations§
Source§impl Size
impl Size
Sourcepub fn single() -> Self
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 }Trait Implementations§
impl Copy for Size
Source§impl<'de> Deserialize<'de> for Size
impl<'de> Deserialize<'de> for Size
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Size
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Component for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.