2022-01-21 15:55:13 -05:00
|
|
|
//! Roguelike
|
|
|
|
//!
|
|
|
|
//! An implementation of a rogue-like dungeon-crawler game.
|
2022-01-20 11:48:58 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
2022-01-11 09:24:20 -05:00
|
|
|
mod ai;
|
2021-12-17 16:35:30 -05:00
|
|
|
pub mod camera;
|
2022-01-14 12:19:46 -05:00
|
|
|
mod colors;
|
2021-10-22 10:05:06 -04:00
|
|
|
mod components;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod damage_system;
|
2022-01-20 11:48:58 -05:00
|
|
|
mod effects;
|
2021-11-04 10:44:52 -04:00
|
|
|
mod game_log;
|
2022-01-03 15:21:12 -05:00
|
|
|
mod gamesystem;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod gui;
|
2021-11-18 10:28:49 -05:00
|
|
|
mod hunger_system;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod inventory_system;
|
2022-01-10 10:21:19 -05:00
|
|
|
mod lighting_system;
|
2021-10-22 10:05:06 -04:00
|
|
|
mod map;
|
2021-12-01 10:47:41 -05:00
|
|
|
pub mod map_builders;
|
2021-11-03 16:04:36 -04:00
|
|
|
mod map_indexing_system;
|
|
|
|
mod melee_combat_system;
|
2022-01-18 11:00:13 -05:00
|
|
|
mod movement_system;
|
2021-11-16 11:33:58 -05:00
|
|
|
mod particle_system;
|
2021-10-22 10:05:06 -04:00
|
|
|
mod player;
|
2022-01-20 11:48:58 -05:00
|
|
|
mod random_table;
|
|
|
|
mod raws;
|
2021-10-22 10:05:06 -04:00
|
|
|
mod rect;
|
2021-11-29 14:59:46 -05:00
|
|
|
mod rex_assets;
|
2022-01-20 11:48:58 -05:00
|
|
|
mod saveload_system;
|
2022-01-12 10:45:13 -05:00
|
|
|
mod spatial;
|
2021-11-03 16:04:36 -04:00
|
|
|
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;
|
2021-11-03 16:04:36 -04:00
|
|
|
|
2021-12-24 10:20:29 -05:00
|
|
|
use ::specs::prelude::*;
|
|
|
|
use ::specs::saveload::{SimpleMarker, SimpleMarkerAllocator};
|
2021-11-05 14:32:14 -04:00
|
|
|
use components::*;
|
2021-11-04 10:44:52 -04:00
|
|
|
pub use game_log::GameLog;
|
2021-11-03 16:04:36 -04:00
|
|
|
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
|
|
|
|
2021-11-04 11:27:44 -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>();
|
|
|
|
/// ```
|
2021-11-04 11:27:44 -04:00
|
|
|
macro_rules! register {
|
2022-01-19 09:38:41 -05:00
|
|
|
// $state is needed to get the scope at the usage point
|
2021-11-04 11:27:44 -04:00
|
|
|
// $Type is the Component type that is being registered
|
2022-01-19 09:38:41 -05:00
|
|
|
($state: ident <- $( $Type: ty ),*,) => {
|
2021-11-04 11:27:44 -04:00
|
|
|
$(
|
2022-01-19 09:38:41 -05:00
|
|
|
$state.ecs.register::<$Type>();
|
2021-11-04 11:27:44 -04:00
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 15:55:13 -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)
|
2022-01-20 15:58:08 -05:00
|
|
|
fn init_state() -> State {
|
2022-01-19 09:38:41 -05:00
|
|
|
let mut state = State::new();
|
2021-10-21 12:54:39 -04:00
|
|
|
|
2021-11-04 11:27:44 -04:00
|
|
|
register!(
|
2022-01-19 09:38:41 -05:00
|
|
|
state <-
|
2022-01-28 13:47:16 -05:00
|
|
|
AlwaysTargetsSelf,
|
2022-01-18 11:00:13 -05:00
|
|
|
ApplyMove,
|
|
|
|
ApplyTeleport,
|
2021-11-05 13:12:22 -04:00
|
|
|
AreaOfEffect,
|
2022-01-24 09:56:42 -05:00
|
|
|
AttributeBonus,
|
2022-01-05 11:46:39 -05:00
|
|
|
Attributes,
|
|
|
|
BlocksTile,
|
|
|
|
BlocksVisibility,
|
2022-01-11 15:35:59 -05:00
|
|
|
Chasing,
|
2021-11-05 14:32:14 -04:00
|
|
|
Confusion,
|
2022-01-05 11:46:39 -05:00
|
|
|
Consumable,
|
2022-01-21 11:18:53 -05:00
|
|
|
CursedItem,
|
2022-01-25 13:45:44 -05:00
|
|
|
DamageOverTime,
|
2022-01-05 11:46:39 -05:00
|
|
|
Door,
|
2022-01-06 10:00:42 -05:00
|
|
|
DMSerializationHelper,
|
2022-01-24 10:58:37 -05:00
|
|
|
Duration,
|
2022-01-05 11:46:39 -05:00
|
|
|
EntityMoved,
|
|
|
|
EntryTrigger,
|
2021-11-15 09:19:22 -05:00
|
|
|
Equippable,
|
2021-11-15 09:45:12 -05:00
|
|
|
Equipped,
|
2022-01-13 10:14:13 -05:00
|
|
|
EquipmentChanged,
|
2022-01-11 14:16:23 -05:00
|
|
|
Faction,
|
2022-01-05 11:46:39 -05:00
|
|
|
Hidden,
|
|
|
|
HungerClock,
|
2022-01-19 11:04:10 -05:00
|
|
|
IdentifiedItem,
|
2022-01-05 11:46:39 -05:00
|
|
|
InBackpack,
|
|
|
|
InflictsDamage,
|
2022-01-11 09:28:45 -05:00
|
|
|
Initiative,
|
2022-01-05 11:46:39 -05:00
|
|
|
Item,
|
2022-01-25 09:58:30 -05:00
|
|
|
KnownSpells,
|
2022-01-10 10:21:19 -05:00
|
|
|
LightSource,
|
2022-01-05 11:46:39 -05:00
|
|
|
LootTable,
|
2022-01-19 09:38:41 -05:00
|
|
|
MagicItem,
|
2022-01-05 11:46:39 -05:00
|
|
|
MagicMapper,
|
2022-01-04 10:08:06 -05:00
|
|
|
MeleeWeapon,
|
2022-01-11 14:16:23 -05:00
|
|
|
MoveMode,
|
2022-01-11 09:33:21 -05:00
|
|
|
MyTurn,
|
2022-01-05 11:46:39 -05:00
|
|
|
Name,
|
|
|
|
NaturalAttackDefense,
|
2022-01-19 10:15:51 -05:00
|
|
|
ObfuscatedName,
|
2022-01-28 13:47:16 -05:00
|
|
|
OnDeath,
|
2022-01-06 09:34:17 -05:00
|
|
|
OtherLevelPosition,
|
2021-11-16 11:33:58 -05:00
|
|
|
ParticleLifetime,
|
2022-01-05 11:46:39 -05:00
|
|
|
Player,
|
|
|
|
Pools,
|
|
|
|
Position,
|
2021-11-18 15:25:29 -05:00
|
|
|
ProvidesFood,
|
2022-01-05 11:46:39 -05:00
|
|
|
ProvidesHealing,
|
2022-01-21 15:13:31 -05:00
|
|
|
ProvidesIdentification,
|
2022-01-25 11:42:02 -05:00
|
|
|
ProvidesMana,
|
2022-01-21 11:57:36 -05:00
|
|
|
ProvidesRemoveCurse,
|
2022-01-03 10:49:12 -05:00
|
|
|
Quips,
|
2022-01-05 11:46:39 -05:00
|
|
|
Ranged,
|
|
|
|
Renderable,
|
|
|
|
SerializationHelper,
|
|
|
|
SimpleMarker<SerializeMe>,
|
|
|
|
SingleActivation,
|
2022-01-03 15:24:38 -05:00
|
|
|
Skills,
|
2022-01-25 13:45:44 -05:00
|
|
|
Slow,
|
2022-01-20 16:31:03 -05:00
|
|
|
SpawnParticleBurst,
|
|
|
|
SpawnParticleLine,
|
2022-01-25 15:04:00 -05:00
|
|
|
SpecialAbilities,
|
2022-01-25 09:58:30 -05:00
|
|
|
SpellTemplate,
|
2022-01-24 10:58:37 -05:00
|
|
|
StatusEffect,
|
2022-01-25 13:39:43 -05:00
|
|
|
TeachesSpell,
|
2022-01-18 11:00:13 -05:00
|
|
|
TeleportTo,
|
2022-01-28 11:48:25 -05:00
|
|
|
TileSize,
|
2022-01-18 11:00:13 -05:00
|
|
|
TownPortal,
|
2022-01-13 11:29:20 -05:00
|
|
|
Vendor,
|
2022-01-05 11:46:39 -05:00
|
|
|
Viewshed,
|
2022-01-11 14:16:23 -05:00
|
|
|
WantsToApproach,
|
2022-01-25 09:58:30 -05:00
|
|
|
WantsToCastSpell,
|
2022-01-05 11:46:39 -05:00
|
|
|
WantsToDropItem,
|
2022-01-11 14:16:23 -05:00
|
|
|
WantsToFlee,
|
2022-01-05 11:46:39 -05:00
|
|
|
WantsToMelee,
|
|
|
|
WantsToPickupItem,
|
|
|
|
WantsToRemoveItem,
|
|
|
|
WantsToUseItem,
|
|
|
|
Wearable,
|
2021-11-04 11:27:44 -04:00
|
|
|
);
|
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
|
|
|
|
2021-12-23 11:00:37 -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(GameLog::new("Welcome to Rusty Roguelike"));
|
|
|
|
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);
|
2021-12-01 14:45:27 -05:00
|
|
|
|
2022-01-20 15:58:08 -05:00
|
|
|
state
|
|
|
|
}
|
|
|
|
|
2022-01-21 15:55:13 -05:00
|
|
|
/// The entry point
|
2022-01-20 15:58:08 -05:00
|
|
|
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
|
|
|
}
|