Index

Package: Worlds

Description

package Worlds is

Classes

World_Object (abstract)

type World_Object is abstract new Object and Event_Listener and Process with private;

Ancestors:

Immediate Children:

Primitive operations:

Adjust (overriding Objects.Adjust)
Construct
Delete (overriding Objects.Delete)
Events.Listeners.To_String (Inherited)
Get_Filename
Get_Process_Name (overriding Processes.Get_Process_Name)
Handle
Handle
Handle
Handle
Handle
Handle
Handle
Handle
Handle
Handle
Handle_Event (overriding Events.Listeners.Handle_Event)
Initialize
Object_Input
Object_Read (overriding Objects.Object_Read)
Object_Write (overriding Objects.Object_Write)
Objects.Construct (Inherited)
Objects.To_String (Inherited)
On_Attach
On_Detach
Queue_Load_Events
Set_Property
Spawn_Entity
Tick (overriding Processes.Tick)
A World is an object which contains a map and entities. It can be created, loaded and saved as a simple data object and it can be copied. Worlds are also Processes and Event_Listeners which can be attached to the game framework. Only one World at a time can be attached. This is enforced by the Game logic. Attaching a World to the game framework means giving it a Corral so it can register to receive events and attaching it to a Process_Manager so it can execute code. An attached World object then has behavior because it listens for events, queues events, and executes code as a Process. When a world is attached, its dispatching On_Attach procedure is called, which may queue load-time events and register the object as an event listener. When a world is detached from the game framework, its dispatching On_Detach procedure is called to unregister the object as an event listener, etc. A World object can't be copied while it is attached to the Game framework. An unattached World should not have any independent behavior and should only do as it is instructed by calling the class procedures.

Types

A_World

type A_World is access all World_Object'Class;

Constants & Global variables

FILE_NOT_FOUND

FILE_NOT_FOUND,
    READ_EXCEPTION,
    WRITE_EXCEPTION : exception;

READ_EXCEPTION

READ_EXCEPTION,
    WRITE_EXCEPTION : exception;

WRITE_EXCEPTION

WRITE_EXCEPTION : exception;

Subprograms & Entries

Create_World

function Create_World
( width, height: Positive;
libName, domain: String ) return A_World;
Creates a new empty world. An exception is raised on error.

Load_World

function Load_World
( name: String ) return A_World;
Loads a world from disk. An exception is raised on error.

Attach_To_Framework

procedure Attach_To_Framework
( this: not null access World_Object'Class;
game: not null A_Game_State;
corral: not null A_Corral;
pman: not null A_Process_Manager );
Attaches the world to the game framework to send and receive events and execute as a process.

Detach_From_Framework

procedure Detach_From_Framework
( this: not null access World_Object'Class );
Detaches the world from the game framework, removing itself as an event listener and ceasing execution as a process.

Examine_Entities

procedure Examine_Entities
( this: not null access World_Object'Class;
examine: not null access procedure( e : not null A_Entity ) );
Iterate through all of the entities in the world, examining each.

Get_Entity

function Get_Entity
( this: access World_Object;
id: Entity_Id ) return A_Entity;
Returns a reference to an entity with the given id, or null if the entity doesn't exist.

Get_Filename

function Get_Filename
( this: access World_Object ) return String;
The name of the file that this world was loaded from (including the file extension), if it was loaded. If this world was not loaded from disk or has not been saved to the disk yet then an empty string will be returned.

Get_Game_State

function Get_Game_State
( this: not null access World_Object'Class ) return A_Game_State;
Returns the World's attached Game class, if it has been attached to the framework.

Get_Height

function Get_Height
( this: not null access World_Object'Class ) return Positive;
Returns the actual map height in pixels.

Get_Height_Tiles

function Get_Height_Tiles
( this: not null access World_Object'Class ) return Positive;
Returns the height of the map in tiles.

Get_Library

function Get_Library
( this: not null access World_Object'Class ) return A_Tile_Library;
Returns the world's reference to its tile library. Do not modify it.

Get_Music

function Get_Music
( this: not null access World_Object'Class ) return String;
Returns the name of the background music track.

Get_Player

function Get_Player
( this: not null access World_Object'Class ) return A_Player;
Returns a reference to the world's current player entity. Do not modify it.

Get_Tile_Id

function Get_Tile_Id
( this: not null access World_Object'Class;
layer, x, y: Integer ) return Natural;
Returns the id of the tile at the specified location.

Get_Title

function Get_Title
( this: not null access World_Object'Class ) return String;
Returns the title of the world.

Get_Width

function Get_Width
( this: not null access World_Object'Class) return Positive;
Returns the actual map width in pixels.

Get_Width_Tiles

function Get_Width_Tiles
( this: not null access World_Object'Class ) return Positive;
Returns the width of the map in tiles.

Resize

procedure Resize
( this: not null access World_Object'Class;
width, height: Positive );
Resizes the map. An exception is raised on error.

Save

procedure Save
( this: not null access World_Object'Class;
name: String;
overwrite: Boolean := True );
Writes the world in its current state to a file on disk. An exception is raised on error.

Set_Property

procedure Set_Property
( this: access World_Object;
name, value: String );
basic properties: "filename" : the filename "domain" : determines player movement, physical rules "title" : the readable name of the world "music" : the background music track name

Set_Tile

procedure Set_Tile
( this: access World_Object;
layer: Integer;
x, y: Integer;
id: Natural;
notify: Boolean := True );
If 'notify' is True, Tile_Changed and World_Modified events will be sent.

Set_Tile

procedure Set_Tile
( this: access World_Object;
layer: Integer;
x, y: Float;
id: Natural;
notify: Boolean := True );
x, y are in pixel coordinates, not tile coordinates. If 'notify' is True, Tile_Changed and World_Modified events will be sent.

Spawn_Entity

procedure Spawn_Entity
( this: access World_Object;
id: String;
x, y: Float;
width, height: Natural := 0;
xv, yv: Float := 0.0 );
Spawns an entity of the given class id into the world. If 'width' or 'height' are equal to 0, the entity's natural width and height will be used.

Tile_Width

function Tile_Width
( this: not null access World_Object'Class ) return Positive;
Returns the width of each tile in the world, in pixels.

Object_Input (abstract)

function Object_Input
( stream: access Root_Stream_Type'Class ) return World_Object is abstract;
Implement this function to Construct and Read instances of the concrete subclass from a stream.

Copy

function Copy
( src: A_World ) return A_World;
Returns a deep copy of 'src'.

Delete

procedure Delete
( this: in out A_World );
Deletes the World.

Valid_Domain

function Valid_Domain
( domain: String ) return Boolean;
Returns True if 'domain' is a registered domain name. Case sensitive.

World_Extension

function World_Extension return String;
Returns the file extension for World files, without a leading dot.