agb/examples/the-dungeon-puzzlers-lament/src/level.rs

168 lines
5.2 KiB
Rust
Raw Normal View History

2023-07-20 02:41:17 +10:00
use agb::{display::object::Tag, fixnum::Vector2D};
use crate::{game::Direction, map::Map, resources};
2023-09-06 07:52:10 +10:00
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
2023-07-20 02:41:17 +10:00
pub enum Item {
Sword,
Slime,
Hero,
Stairs,
Door,
Key,
SwitchedOpenDoor,
SwitchedClosedDoor,
Switch,
SwitchPressed,
SpikesUp,
SpikesDown,
SquidUp,
SquidDown,
2023-08-28 01:47:00 +10:00
Ice,
2023-08-28 04:49:37 +10:00
MovableBlock,
Glove,
2023-08-30 06:24:30 +10:00
Teleporter,
2023-09-01 09:42:43 +10:00
Hole,
RotatorRight,
RotatorLeft,
RotatorUp,
RotatorDown,
2023-07-20 02:41:17 +10:00
}
impl Item {
pub fn shadow_tag(&self) -> &'static Tag {
match self {
Item::Sword => resources::SWORD_SHADOW,
Item::Slime => resources::SLIME_SHADOW,
Item::Hero => resources::HERO,
Item::Stairs => resources::STAIRS,
Item::Door => resources::DOOR,
Item::Key => resources::KEY_SHADOW,
Item::SwitchedOpenDoor => resources::SWITCHED_DOOR_OPEN,
Item::SwitchedClosedDoor => resources::SWITCHED_DOOR_CLOSED,
Item::Switch => resources::BUTTON_OFF,
Item::SwitchPressed => resources::BUTTON_ON,
Item::SpikesUp => resources::SPIKES_ON,
Item::SpikesDown => resources::SPIKES_OFF,
Item::SquidUp => resources::SQUID_UP_SHADOW,
Item::SquidDown => resources::SQUID_DOWN_SHADOW,
2023-08-28 01:47:00 +10:00
Item::Ice => resources::ICE,
2023-08-28 18:32:48 +10:00
Item::MovableBlock => resources::ROCK_SHADOW,
Item::Glove => resources::POW_GLOVE_SHADOW,
2023-08-30 06:52:58 +10:00
Item::Teleporter => resources::TELEPORTER_SHADOW,
2023-09-01 09:42:43 +10:00
Item::Hole => resources::HOLE,
2023-09-02 02:56:50 +10:00
Item::RotatorRight => resources::ROTATOR_RIGHT_SHADOW,
Item::RotatorLeft => resources::ROTATOR_LEFT_SHADOW,
Item::RotatorUp => resources::ROTATOR_UP_SHADOW,
Item::RotatorDown => resources::ROTATOR_DOWN_SHADOW,
2023-07-20 02:41:17 +10:00
}
}
pub fn tag(&self) -> &'static Tag {
match self {
Item::Sword => resources::SWORD,
Item::Slime => resources::SLIME,
Item::Hero => resources::HERO,
Item::Stairs => resources::STAIRS,
Item::Door => resources::DOOR,
Item::Key => resources::KEY,
Item::SwitchedOpenDoor => resources::SWITCHED_DOOR_OPEN,
Item::SwitchedClosedDoor => resources::SWITCHED_DOOR_CLOSED,
Item::Switch => resources::BUTTON_OFF,
Item::SwitchPressed => resources::BUTTON_ON,
Item::SpikesUp => resources::SPIKES_ON,
Item::SpikesDown => resources::SPIKES_OFF,
Item::SquidUp => resources::SQUID_UP,
Item::SquidDown => resources::SQUID_DOWN,
2023-08-28 01:47:00 +10:00
Item::Ice => resources::ICE,
2023-08-28 18:32:48 +10:00
Item::MovableBlock => resources::ROCK,
Item::Glove => resources::POW_GLOVE,
2023-08-30 06:24:30 +10:00
Item::Teleporter => resources::TELEPORTER,
2023-09-01 09:42:43 +10:00
Item::Hole => resources::HOLE,
Item::RotatorRight => resources::ROTATOR_RIGHT,
Item::RotatorLeft => resources::ROTATOR_LEFT,
Item::RotatorUp => resources::ROTATOR_UP,
Item::RotatorDown => resources::ROTATOR_DOWN,
2023-07-20 02:41:17 +10:00
}
}
pub fn map_entity_offset(&self) -> Vector2D<i32> {
const STANDARD: Vector2D<i32> = Vector2D::new(0, -3);
const ZERO: Vector2D<i32> = Vector2D::new(0, 0);
match self {
Item::Sword => STANDARD,
Item::Slime => STANDARD,
Item::Hero => STANDARD,
Item::Stairs => ZERO,
Item::Door => ZERO,
Item::Key => STANDARD,
Item::SwitchedOpenDoor => ZERO,
Item::SwitchedClosedDoor => ZERO,
Item::Switch => ZERO,
Item::SwitchPressed => ZERO,
Item::SpikesUp => ZERO,
Item::SpikesDown => ZERO,
Item::SquidUp => STANDARD,
Item::SquidDown => STANDARD,
2023-08-28 01:47:00 +10:00
Item::Ice => ZERO,
Item::MovableBlock => ZERO,
2023-08-28 04:49:37 +10:00
Item::Glove => STANDARD,
2023-08-30 06:24:30 +10:00
Item::Teleporter => ZERO,
2023-09-01 09:42:43 +10:00
Item::Hole => ZERO,
Item::RotatorRight => STANDARD,
Item::RotatorLeft => STANDARD,
Item::RotatorUp => STANDARD,
Item::RotatorDown => STANDARD,
2023-07-20 02:41:17 +10:00
}
}
}
pub struct Entity(pub Item, pub Vector2D<i32>);
pub struct Level {
pub map: Map<'static>,
pub entities: &'static [Entity],
2023-09-06 07:52:10 +10:00
#[cfg(test)]
pub solution: &'static [Entity],
2023-07-20 02:41:17 +10:00
pub directions: &'static [Direction],
pub items: &'static [Item],
pub name: &'static str,
}
impl Level {
2023-09-06 07:52:10 +10:00
#[allow(unused_variables)]
2023-07-20 02:41:17 +10:00
const fn new(
map: Map<'static>,
entities: &'static [Entity],
2023-09-06 07:52:10 +10:00
solution: &'static [Entity],
2023-07-20 02:41:17 +10:00
directions: &'static [Direction],
items: &'static [Item],
name: &'static str,
) -> Self {
Self {
map,
entities,
2023-09-06 07:52:10 +10:00
#[cfg(test)]
solution,
2023-07-20 02:41:17 +10:00
directions,
items,
name,
}
}
pub const fn get_level(level_number: usize) -> &'static Level {
&levels::LEVELS[level_number]
}
pub const fn num_levels() -> usize {
levels::LEVELS.len()
}
}
mod levels {
use super::*;
include!(concat!(env!("OUT_DIR"), "/levels.rs"));
}