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

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

Ancestors:

Primitive operations:

Adjust (overriding Objects.Adjust)
Construct (overriding Objects.Construct)
Construct
Delete (overriding Objects.Delete)
Evaluate_Function (overriding Scripting.Evaluate_Function)
Evaluate_Symbol (overriding Scripting.Evaluate_Symbol)
Events.Listeners.To_String (Inherited)
Get_Process_Name (overriding Processes.Get_Process_Name)
Handle_Delete_Entity
Handle_Entity_Grounded
Handle_Entity_Hit_Wall
Handle_Entity_Moved
Handle_Entity_Resized
Handle_Event (overriding Events.Listeners.Handle_Event)
Handle_Set_Entity_Attribute
Handle_Spawn_Entity
Initialize
Object_Input
Object_Read (overriding Objects.Object_Read)
Object_Write (overriding Objects.Object_Write)
Objects.To_String (Inherited)
On_Attach
On_Detach
Tick (overriding Processes.Tick)
A World is an object which contains a map and entities. It can be created, loaded, saved, and handles its own state and execution during gameplay. A World acts as a Process and as an Event_Listener that can be attached to the game framework. Only one World at a time can be attached as 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, evaluate all its entities' OnAttach actions, and queue 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. An unattached World has no behavior until it is attached.

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;
physicalLayers: Maps.Boolean_Array;
library, 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;
gameState: 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 Value_Ptr;
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 Value_Ptr;
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_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_Layers

function Get_Layers
( this: not null access World_Object'Class ) return Positive;
Returns the number of layers in the world's map.

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_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_Property

function Get_Property
( this: not null access World_Object'Class;
name: String ) return Value_Ptr;
Returns the property of the world named 'name', or Null if the property has not been defined.

Get_Tile_Id

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

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: not null access World_Object'Class;
name: String;
value: Value_Ptr'Class );
Sets the value of a property named 'name' to 'value'. A World_Property_Changed event and a World_Modified event will be fired.

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

function Spawn_Entity
( this: not null access World_Object'Class;
id: String;
x, y: Float;
width, height: Natural := 0;
xv, yv: Float := 0.0 ) return Entity_Id;
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. If the world is attached to the game framework, Entity_Created and World_Modified events will be generated. The id of the new entity will be returned, or INVALID_ID if the

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

function Object_Input
( stream: access Root_Stream_Type'Class ) return World_Object;

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.