roguelike-game/src/main.rs

203 lines
4.5 KiB
Rust
Raw Normal View History

2022-01-21 15:55:13 -05:00
//! Roguelike
//!
//! An implementation of a rogue-like dungeon-crawler game.
#[macro_use]
extern crate lazy_static;
2022-01-11 09:24:20 -05:00
mod ai;
pub mod camera;
mod colors;
2021-10-22 10:05:06 -04:00
mod components;
mod damage_system;
mod effects;
2021-11-04 10:44:52 -04:00
mod game_log;
2022-01-03 15:21:12 -05:00
mod gamesystem;
mod gui;
2021-11-18 10:28:49 -05:00
mod hunger_system;
mod inventory_system;
2022-01-10 10:21:19 -05:00
mod lighting_system;
2021-10-22 10:05:06 -04:00
mod map;
pub mod map_builders;
mod map_indexing_system;
mod melee_combat_system;
mod movement_system;
2021-11-16 11:33:58 -05:00
mod particle_system;
2021-10-22 10:05:06 -04:00
mod player;
mod random_table;
2022-01-31 11:25:36 -05:00
mod ranged_combat_system;
mod raws;
2021-10-22 10:05:06 -04:00
mod rect;
2021-11-29 14:59:46 -05:00
mod rex_assets;
mod saveload_system;
mod spatial;
mod spawner;
2022-01-18 11:40:31 -05:00
mod state;
2021-11-29 16:00:07 -05:00
mod trigger_system;
2021-10-25 15:26:39 -04:00
mod visibility_system;
use ::specs::prelude::*;
use ::specs::saveload::{SimpleMarker, SimpleMarkerAllocator};
2021-11-05 14:32:14 -04:00
use components::*;
pub use map::*;
pub use rect::Rect;
2022-01-18 11:40:31 -05:00
pub use state::*;
2021-10-25 15:26:39 -04:00
/// Cut down on the amount of syntax to register components
2022-01-21 15:55:13 -05:00
///
/// Compare:
/// ```ignore
/// let mut game_state = State::new();
///
/// register!(state <- ComponentA, ComponentB, ...);
/// ```
///
/// Without macro:
/// ```ignore
/// let mut game_state = State::new();
///
/// state.ecs.register::<ComponentA>();
/// state.ecs.register::<ComponentB>();
/// ```
macro_rules! register {
2022-01-19 09:38:41 -05:00
// $state is needed to get the scope at the usage point
// $Type is the Component type that is being registered
2022-01-19 09:38:41 -05:00
($state: ident <- $( $Type: ty ),*,) => {
$(
2022-01-19 09:38:41 -05:00
$state.ecs.register::<$Type>();
)*
}
}
2022-02-01 09:22:23 -05:00
fn register_components(state: &mut State) {
register!(
2022-01-19 09:38:41 -05:00
state <-
2022-01-28 13:47:16 -05:00
AlwaysTargetsSelf,
ApplyMove,
ApplyTeleport,
2021-11-05 13:12:22 -04:00
AreaOfEffect,
AttributeBonus,
Attributes,
BlocksTile,
BlocksVisibility,
Chasing,
2021-11-05 14:32:14 -04:00
Confusion,
Consumable,
2022-01-21 11:18:53 -05:00
CursedItem,
2022-01-25 13:45:44 -05:00
DamageOverTime,
DMSerializationHelper,
Door,
Duration,
EntityMoved,
EntryTrigger,
EquipmentChanged,
2021-11-15 09:19:22 -05:00
Equippable,
Equipped,
2022-01-11 14:16:23 -05:00
Faction,
Hidden,
HungerClock,
IdentifiedItem,
InBackpack,
InflictsDamage,
2022-01-11 09:28:45 -05:00
Initiative,
Item,
2022-01-25 09:58:30 -05:00
KnownSpells,
2022-01-10 10:21:19 -05:00
LightSource,
LootTable,
2022-01-19 09:38:41 -05:00
MagicItem,
MagicMapper,
2022-01-11 14:16:23 -05:00
MoveMode,
2022-01-11 09:33:21 -05:00
MyTurn,
Name,
NaturalAttackDefense,
ObfuscatedName,
2022-01-28 13:47:16 -05:00
OnDeath,
OtherLevelPosition,
2021-11-16 11:33:58 -05:00
ParticleLifetime,
Player,
Pools,
Position,
ProvidesFood,
ProvidesHealing,
ProvidesIdentification,
2022-01-25 11:42:02 -05:00
ProvidesMana,
ProvidesRemoveCurse,
2022-01-03 10:49:12 -05:00
Quips,
Ranged,
Renderable,
SerializationHelper,
SimpleMarker<SerializeMe>,
SingleActivation,
2022-01-03 15:24:38 -05:00
Skills,
2022-01-25 13:45:44 -05:00
Slow,
SpawnParticleBurst,
SpawnParticleLine,
2022-01-25 15:04:00 -05:00
SpecialAbilities,
2022-01-25 09:58:30 -05:00
SpellTemplate,
StatusEffect,
Target,
2022-01-25 13:39:43 -05:00
TeachesSpell,
TeleportTo,
2022-01-28 11:48:25 -05:00
TileSize,
TownPortal,
2022-01-13 11:29:20 -05:00
Vendor,
Viewshed,
2022-01-11 14:16:23 -05:00
WantsToApproach,
2022-01-25 09:58:30 -05:00
WantsToCastSpell,
WantsToDropItem,
2022-01-11 14:16:23 -05:00
WantsToFlee,
WantsToMelee,
WantsToPickupItem,
WantsToRemoveItem,
2022-01-31 11:25:36 -05:00
WantsToShoot,
WantsToUseItem,
Weapon,
Wearable,
);
2022-02-01 09:22:23 -05:00
}
/// Sets up the game.
///
/// * Creates the [`State`] object
/// * Registers [`components`](register!)
/// * Loads the dynamic game entities using the [`raws`](crate::raws::load_raws) module
/// * Generates the map builder environment
/// * Creates the [`Player`](crate::spawner::player)
/// * Generates the first [`map`](crate::state::State::generate_world_map)
fn init_state() -> State {
let mut state = State::new();
register_components(&mut state);
2021-10-21 12:54:39 -04:00
2022-01-19 09:38:41 -05:00
state
.ecs
.insert(SimpleMarkerAllocator::<SerializeMe>::new());
2021-11-08 13:58:40 -05:00
raws::load_raws();
2022-01-19 09:38:41 -05:00
state.ecs.insert(MasterDungeonMap::new());
state.ecs.insert(Map::new(1, 64, 64, "New Map"));
state.ecs.insert(::rltk::Point::zero());
state.ecs.insert(::rltk::RandomNumberGenerator::new());
2021-12-02 14:59:35 -05:00
2022-01-19 09:38:41 -05:00
let player_entity = spawner::player(&mut state.ecs, 0, 0);
state.ecs.insert(player_entity);
2021-12-02 14:59:35 -05:00
2022-01-19 09:38:41 -05:00
state.ecs.insert(RunState::MapGeneration {});
state.ecs.insert(particle_system::ParticleBuilder::new());
state.ecs.insert(rex_assets::RexAssets::new());
2021-10-26 14:38:30 -04:00
2022-01-19 09:38:41 -05:00
state.generate_world_map(1, 0);
state
}
2022-01-21 15:55:13 -05:00
/// The entry point
fn main() -> ::rltk::BError {
let context = ::rltk::RltkBuilder::simple(80, 60)
.unwrap()
.with_title("Roguelike Tutorial")
.build()?;
::rltk::main_loop(context, init_state())
2021-10-21 12:54:39 -04:00
}