Index

Package: Worlds

Description

package Worlds is
Copyright (c) 2012 Kevin Wellwood All rights reserved. This source code is distributed under the Modified BSD License. For terms and conditions, see license.txt.

Classes

World_Object (abstract)

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

Ancestors:

Immediate Children:

Primitive operations:

Adjust (overriding Adjust)
Construct (Inherited)
Construct
Delete (overriding Delete)
Evaluate_Function (overriding Evaluate_Function)
Evaluate_Symbol (overriding Evaluate_Symbol)
Get_Process_Name (overriding Get_Process_Name)
Handle_Delete_Entity
Handle_Entity_Face
Handle_Entity_Grounded
Handle_Entity_Hit_Wall
Handle_Entity_Moved
Handle_Entity_Resized
Handle_Event (overriding Handle_Event)
Handle_Set_Entity_Attribute
Handle_Spawn_Entity
Initialize
Object_Input
Object_Read (overriding Object_Read)
Object_Write (overriding Object_Write)
On_Attach
On_Detach
Queue_Load_Events
Set_Property
Tick (overriding Tick)
To_String (Inherited)
To_String (Inherited)
To_String (Inherited)
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 that can be attached to the game framework. Only one World at a time can be attached: the game session's currently active world. This is enforced by the Game logic that owns the active world. Attaching a World to the game framework means giving it a Corral so it can register to receive events, evaluating all its entities' OnAttach actions, and queueing events to notify the view of the world. An attached World object has behavior; it listens for events, queues events, and executes as a Process. When a world is attached, its On_Attach procedure is called, which queues load-time events and register the object as an event listener. When a world is detached from the game framework, its On_Detach procedure is called to unregister the object as an event listener, etc. A World object can't be copied while it is the current active world. An unattached World is a "dumb" object, not having any autonomous behavior.

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 );
Attaches the world to the game framework to send and receive events.

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.

Evaluate_Function

function Evaluate_Function
( this: access World_Object;
name: String;
arguments: Value_Array ) return A_Value;
Evaluates the script function 'name', given 'arguments'. The value of the evaluated function will be returned, or null if the function name is not recognized. todo: make this private (public due to 6.2.0w bug)

Evaluate_Symbol

function Evaluate_Symbol
( this: access World_Object;
symbol: String ) return A_Value;
Evaluates the symbol named 'symbol', resolving it as a game session variable. null will be returned if the symbol can't be resolved. todo: make this private (public due to 6.2.0w bug)

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: not null access World_Object'Class;
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: not null access World_Object'Class ) 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: not null access World_Object'Class;
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: not null access World_Object'Class;
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: not null access World_Object'Class;
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;
Worlds can't be copied; Raises COPY_NOT_ALLOWED.

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.