roguelike-game/src/main.rs
2022-01-21 11:18:53 -05:00

155 lines
3.3 KiB
Rust

#[macro_use]
extern crate lazy_static;
mod ai;
pub mod camera;
mod colors;
mod components;
mod damage_system;
mod effects;
mod game_log;
mod gamesystem;
mod gui;
mod hunger_system;
mod inventory_system;
mod lighting_system;
mod map;
pub mod map_builders;
mod map_indexing_system;
mod melee_combat_system;
mod movement_system;
mod particle_system;
mod player;
mod random_table;
mod raws;
mod rect;
mod rex_assets;
mod saveload_system;
mod spatial;
mod spawner;
mod state;
mod trigger_system;
mod visibility_system;
use ::specs::prelude::*;
use ::specs::saveload::{SimpleMarker, SimpleMarkerAllocator};
use components::*;
pub use game_log::GameLog;
pub use map::*;
pub use rect::Rect;
pub use state::*;
/// Cut down on the amount of syntax to register components
macro_rules! register {
// $state is needed to get the scope at the usage point
// $Type is the Component type that is being registered
($state: ident <- $( $Type: ty ),*,) => {
$(
$state.ecs.register::<$Type>();
)*
}
}
fn init_state() -> State {
let mut state = State::new();
register!(
state <-
ApplyMove,
ApplyTeleport,
AreaOfEffect,
Attributes,
BlocksTile,
BlocksVisibility,
Chasing,
Confusion,
Consumable,
CursedItem,
Door,
DMSerializationHelper,
EntityMoved,
EntryTrigger,
Equippable,
Equipped,
EquipmentChanged,
Faction,
Hidden,
HungerClock,
IdentifiedItem,
InBackpack,
InflictsDamage,
Initiative,
Item,
LightSource,
LootTable,
MagicItem,
MagicMapper,
MeleeWeapon,
MoveMode,
MyTurn,
Name,
NaturalAttackDefense,
ObfuscatedName,
OtherLevelPosition,
ParticleLifetime,
Player,
Pools,
Position,
ProvidesFood,
ProvidesHealing,
Quips,
Ranged,
Renderable,
SerializationHelper,
SimpleMarker<SerializeMe>,
SingleActivation,
Skills,
SpawnParticleBurst,
SpawnParticleLine,
TeleportTo,
TownPortal,
Vendor,
Viewshed,
WantsToApproach,
WantsToDropItem,
WantsToFlee,
WantsToMelee,
WantsToPickupItem,
WantsToRemoveItem,
WantsToUseItem,
Wearable,
);
state
.ecs
.insert(SimpleMarkerAllocator::<SerializeMe>::new());
raws::load_raws();
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());
let player_entity = spawner::player(&mut state.ecs, 0, 0);
state.ecs.insert(player_entity);
state.ecs.insert(RunState::MapGeneration {});
state.ecs.insert(GameLog::new("Welcome to Rusty Roguelike"));
state.ecs.insert(particle_system::ParticleBuilder::new());
state.ecs.insert(rex_assets::RexAssets::new());
state.generate_world_map(1, 0);
state
}
fn main() -> ::rltk::BError {
let context = ::rltk::RltkBuilder::simple(80, 60)
.unwrap()
.with_title("Roguelike Tutorial")
.build()?;
::rltk::main_loop(context, init_state())
}