game_util_objects

View Source
import os.path, random

from game_object import GameObject, FACING_DIRS
from collision import CST_NONE, CST_CIRCLE, CST_AABB, CST_TILE, CT_NONE, CT_GENERIC_STATIC, CT_GENERIC_DYNAMIC, CT_PLAYER, CTG_STATIC, CTG_DYNAMIC

class GameObjectAttachment(GameObject):
    "GameObject that doesn't think about anything, just renders"
    collision_type = CT_NONE
    should_save = False
    selectable = False
    exclude_from_class_list = True
    physics_move = False
    offset_x, offset_y, offset_z = 0., 0., 0.
    "Offset from parent object's origin"
    fixed_z = False
    "If True, Z will not be locked to GO we're attached to"
    editable = GameObject.editable + ['offset_x', 'offset_y', 'offset_z']
    
    def attach_to(self, game_object):
        "Attach this object to given object."
        self.parent = game_object
    
    def update(self):
        # very minimal update!
        if not self.art.updated_this_tick:
            self.art.update()
    
    def post_update(self):
        # after parent has moved, snap to its location
        self.x = self.parent.x + self.offset_x
        self.y = self.parent.y + self.offset_y
        if not self.fixed_z:
            self.z = self.parent.z + self.offset_z


class BlobShadow(GameObjectAttachment):
    "Generic blob shadow attachment class"
    art_src = 'blob_shadow'
    alpha = 0.5

class StaticTileBG(GameObject):
    "Generic static world object with tile-based collision"
    collision_shape_type = CST_TILE
    collision_type = CT_GENERIC_STATIC
    physics_move = False

class StaticTileObject(GameObject):
    collision_shape_type = CST_TILE
    collision_type = CT_GENERIC_STATIC
    physics_move = False
    y_sort = True

class StaticBoxObject(GameObject):
    "Generic static world object with AABB-based (rectangle) collision"
    collision_shape_type = CST_AABB
    collision_type = CT_GENERIC_STATIC
    physics_move = False

class DynamicBoxObject(GameObject):
    collision_shape_type = CST_AABB
    collision_type = CT_GENERIC_DYNAMIC
    y_sort = True

class Pickup(GameObject):
    collision_shape_type = CST_CIRCLE
    collision_type = CT_GENERIC_DYNAMIC
    y_sort = True
    attachment_classes = { 'shadow': 'BlobShadow' }

class Projectile(GameObject):
    "Generic projectile class"
    fast_move_steps = 1
    collision_type = CT_GENERIC_DYNAMIC
    collision_shape_type = CST_CIRCLE
    move_accel_x = move_accel_y = 400.
    noncolliding_classes = ['Projectile']
    lifespan = 10.
    "Projectiles should be transient, limited max life"
    should_save = False
    
    def __init__(self, world, obj_data=None):
        GameObject.__init__(self, world, obj_data)
        self.fire_dir_x, self.fire_dir_y = 0, 0
    
    def fire(self, firer, dir_x=0, dir_y=1):
        self.set_loc(firer.x, firer.y, firer.z)
        self.reset_last_loc()
        self.fire_dir_x, self.fire_dir_y = dir_x, dir_y
    
    def update(self):
        if (self.fire_dir_x, self.fire_dir_y) != (0, 0):
            self.move(self.fire_dir_x, self.fire_dir_y)
        GameObject.update(self)

class Character(GameObject):
    "Generic character class"
    state_changes_art = True
    stand_if_not_moving = True
    move_state = 'walk'
    "Move state name - added to valid_states in init so subclasses recognized"
    collision_shape_type = CST_CIRCLE
    collision_type = CT_GENERIC_DYNAMIC
    
    def __init__(self, world, obj_data=None):
        if not self.move_state in self.valid_states:
            self.valid_states.append(self.move_state)
        GameObject.__init__(self, world, obj_data)
        # assume that character should start idling, if its art animates
        if self.art.frames > 0:
            self.start_animating()
    
    def update_state(self):
        GameObject.update_state(self)
        if self.state_changes_art and abs(self.vel_x) > 0.1 or abs(self.vel_y) > 0.1:
            self.state = self.move_state

class Player(Character):
    "Generic player class"
    log_move = False
    collision_type = CT_PLAYER
    editable = Character.editable + ['move_accel_x', 'move_accel_y',
                                         'ground_friction', 'air_friction',
                                         'bounciness', 'stop_velocity']
    
    def pre_first_update(self):
        if self.world.player is None:
            self.world.player = self
            if self.world.player_camera_lock:
                self.world.camera.focus_object = self
            else:
                self.world.camera.focus_object = None
    
    def button_pressed(self, button_index):
        pass
    
    def button_unpressed(self, button_index):
        pass


class TopDownPlayer(Player):
    
    y_sort = True
    attachment_classes = { 'shadow': 'BlobShadow' }
    facing_changes_art = True
    
    def get_facing_dir(self):
        return FACING_DIRS[self.facing]


class WorldPropertiesObject(GameObject):
    "Special magic singleton object that stores and sets GameWorld properties"
    art_src = 'world_properties_object'
    visible = deleteable = selectable = False
    locked = True
    physics_move = False
    exclude_from_object_list = True
    exclude_from_class_list = True
    world_props = ['game_title', 'gravity_x', 'gravity_y', 'gravity_z',
                   'hud_class_name', 'globals_object_class_name',
                   'camera_x', 'camera_y', 'camera_z',
                   'bg_color_r', 'bg_color_g', 'bg_color_b', 'bg_color_a',
                   'player_camera_lock', 'object_grid_snap', 'draw_hud',
                   'collision_enabled', 'show_collision_all', 'show_bounds_all',
                   'show_origin_all', 'show_all_rooms',
                   'room_camera_changes_enabled', 'draw_debug_objects'
    ]
    """
    Properties we serialize on behalf of GameWorld
    TODO: figure out how to make these defaults sync with those in GW?
    """
    serialized = world_props
    editable = []
    "All visible properties are serialized, not editable"
    def __init__(self, world, obj_data=None):
        GameObject.__init__(self, world, obj_data)
        world_class = type(world)
        for v in self.serialized:
            if obj_data and v in obj_data:
                # if world instance has property from loaded data, use it
                if hasattr(self.world, v):
                    setattr(self.world, v, obj_data[v])
                setattr(self, v, obj_data[v])
            # use world class (default) property if loaded data lacks it
            elif hasattr(world_class, v):
                setattr(self, v, getattr(world_class, v))
            else:
                # set explicitly as float, for camera & bg color
                setattr(self, v, 0.0)
        # special handling of bg color (a list)
        self.world.bg_color = [self.bg_color_r, self.bg_color_g, self.bg_color_b, self.bg_color_a]
        self.world.camera.set_loc(self.camera_x, self.camera_y, self.camera_z)
        # TODO: figure out why collision_enabled seems to default False!
    
    def set_object_property(self, prop_name, new_value):
        setattr(self, prop_name, new_value)
        # special handling for some values, eg bg color and camera
        if prop_name.startswith('bg_color_'):
            component = {'r': 0, 'g': 1, 'b': 2, 'a': 3}[prop_name[-1]]
            self.world.bg_color[component] = float(new_value)
        elif prop_name.startswith('camera_') and len(prop_name) == len('camera_x'):
            setattr(self.world.camera, prop_name[-1], new_value)
        # some properties have unique set methods in GW
        elif prop_name == 'show_collision_all':
            self.world.toggle_all_collision_viz()
        elif prop_name == 'show_bounds_all':
            self.world.toggle_all_bounds_viz()
        elif prop_name == 'show_origin_all':
            self.world.toggle_all_origin_viz()
        elif prop_name == 'player_camera_lock':
            self.world.toggle_player_camera_lock()
        # normal properties you can just set: set em
        elif hasattr(self.world, prop_name):
            setattr(self.world, prop_name, new_value)
    
    def update_from_world(self):
        self.camera_x = self.world.camera.x
        self.camera_y = self.world.camera.y
        self.camera_z = self.world.camera.z


class WorldGlobalsObject(GameObject):
    """
    Invisible object holding global state, variables etc in GameWorld.globals.
    Subclass can be specified in WorldPropertiesObject.
    NOTE: this object is spawned from scratch every load, it's never serialized!
    """
    should_save = False
    visible = deleteable = selectable = False
    locked = True
    exclude_from_object_list = True
    exclude_from_class_list = True
    physics_move = False
    serialized = []
    editable = []


class LocationMarker(GameObject):
    "Very simple GameObject that marks an XYZ location for eg camera points"
    art_src = 'loc_marker'
    serialized = ['name', 'x', 'y', 'z', 'visible', 'locked']
    editable = []
    alpha = 0.5
    physics_move = False
    is_debug = True


class StaticTileTrigger(GameObject):
    """
    Generic static trigger with tile-based collision.
    Overlaps but doesn't collide.
    """
    is_debug = True
    collision_shape_type = CST_TILE
    collision_type = CT_GENERIC_STATIC
    noncolliding_classes = ['GameObject']
    physics_move = False
    serialized = ['name', 'x', 'y', 'z', 'art_src', 'visible', 'locked']
    
    def started_overlapping(self, other):
        #self.app.log('Trigger overlapped with %s' % other.name)
        pass

class WarpTrigger(StaticTileTrigger):
    "Trigger that warps object to a room/marker when they touch it."
    is_debug = True
    art_src = 'trigger_default'
    alpha = 0.5
    destination_marker_name = None
    "If set, warp to this location marker"
    destination_room_name = None
    "If set, make this room the world's current"
    use_marker_room = True
    "If True, change to destination marker's room"
    warp_class_names = ['Player']
    "List of class names to warp on contact with us."
    serialized = StaticTileTrigger.serialized + ['destination_room_name',
                                                 'destination_marker_name',
                                                 'use_marker_room']
    
    def __init__(self, world, obj_data=None):
        StaticTileTrigger.__init__(self, world, obj_data)
        self.warp_classes = [self.world.get_class_by_name(class_name) for class_name in self.warp_class_names]
    
    def started_overlapping(self, other):
        if other.warped_recently():
            return
        # bail if object's class isn't allowed
        valid_class = False
        for c in self.warp_classes:
            if isinstance(other, c):
                valid_class = True
                break
        if not valid_class:
            return
        if self.destination_room_name:
            if other is self.world.player:
                # if overlapping object is player, change current room
                # to destination room
                self.world.change_room(self.destination_room_name)
            else:
                # if object is only in one room, move them to destination room
                if len(other.rooms) == 1:
                    old_room = other.rooms.values()[0]
                    old_room.remove_object(other)
                self.destination_room.add_object(other)
        elif self.destination_marker_name:
            marker = self.world.objects.get(self.destination_marker_name, None)
            if not marker:
                self.app.log('Warp destination object %s not found' % self.destination_marker_name)
                return
            other.set_loc(marker.x, marker.y, marker.z)
            # warp to marker's room if specified, pick a random one if multiple
            if self.use_marker_room and len(marker.rooms) == 1:
                room = random.choice(list(marker.rooms.values()))
                # warn if both room and marker are set but they conflict
                if self.destination_room_name and \
                   room.name != self.destination_room_name:
                    self.app.log("Marker %s's room differs from destination room %s" % (marker.name, self.destination_room_name))
                self.world.change_room(room.name)
        other.last_warp_update = self.world.updates


class ObjectSpawner(LocationMarker):
    "Simple object that spawns an object when triggered"
    is_debug = True
    spawn_class_name = None
    spawn_obj_name = ''
    spawn_random_in_bounds = False
    "If True, spawn somewhere in this object's bounds, else spawn at location"
    spawn_obj_data = {}
    "Dict of properties to set on newly spawned object"
    times_to_fire = -1
    "Number of times we can fire, -1 = infinite"
    trigger_on_room_enter = True
    "Set False for any subclass that triggers in some other way"
    destroy_on_room_exit = True
    "if True, spawned object will be destroyed when player leaves its room"
    serialized = LocationMarker.serialized + ['spawn_class_name', 'spawn_obj_name',
                                              'times_to_fire', 'destroy_on_room_exit'
    ]
    
    def __init__(self, world, obj_data=None):
        LocationMarker.__init__(self, world, obj_data)
        self.times_fired = 0
        # list of objects we've spawned
        self.spawned_objects = []
    
    def get_spawn_class_name(self):
        "Return class name of object to spawn."
        return self.spawn_class_name
    
    def get_spawn_location(self):
        "Return x,y location we should spawn a new object at."
        if not self.spawn_random_in_bounds:
            return self.x, self.y
        left, top, right, bottom = self.get_edges()
        x = left + random.random() * (right - left)
        y = top + random.random() * (bottom - top)
        return x, y
    
    def can_spawn(self):
        "Return True if spawner is allowed to spawn."
        return True
    
    def do_spawn(self):
        "Spawn and returns object."
        class_name = self.get_spawn_class_name()
        if not class_name:
            return None
        x, y = self.get_spawn_location()
        new_obj = self.world.spawn_object_of_class(class_name, x, y)
        if self.spawn_obj_name:
            self.world.rename_object(new_obj, self.spawn_obj_name)
        # new object should be in same rooms as us
        new_obj.rooms.update(self.rooms)
        self.spawned_objects.append(new_obj)
        # save a reference to us, the spawner
        new_obj.spawner = self
        # TODO: put new object in our room(s), apply spawn_obj_data
        return new_obj
    
    def trigger(self):
        "Poke this spawner to do its thing, returns an object if spawned"
        if self.times_to_fire != -1 and self.times_fired >= self.times_to_fire:
            return None
        if not self.can_spawn():
            return None
        if self.times_fired != -1:
            self.times_fired += 1
        return self.do_spawn()
    
    def room_entered(self, room, old_room):
        if self.trigger_on_room_enter:
            self.trigger()
    
    def room_exited(self, room, new_room):
        if not self.destroy_on_room_exit:
            return
        for obj in self.spawned_objects:
            obj.destroy()


class SoundBlaster(LocationMarker):
    "Simple object that plays sound when triggered"
    is_debug = True
    sound_name = ''
    "String name of sound to play, minus any extension"
    can_play = True
    "If False, won't play sound when triggered"
    play_on_room_enter = True
    loops = -1
    "Number of times to loop, if -1 loop indefinitely"
    serialized = LocationMarker.serialized + ['sound_name', 'can_play',
                                              'play_on_room_enter']
    
    def __init__(self, world, obj_data=None):
        LocationMarker.__init__(self, world, obj_data)
        # find file, try common extensions
        for ext in ['', '.ogg', '.wav']:
            filename = self.sound_name + ext
            if self.world.sounds_dir and os.path.exists(self.world.sounds_dir + filename):
                self.sound_filenames[self.sound_name] = filename
                return
        self.world.app.log("Couldn't find sound file %s for SoundBlaster %s" % (self.sound_name, self.name))
    
    def room_entered(self, room, old_room):
        self.play_sound(self.sound_name, self.loops)
    
    def room_exited(self, room, new_room):
        self.stop_sound(self.sound_name)
class GameObjectAttachment(game_object.GameObject):
View Source
class GameObjectAttachment(GameObject):
    "GameObject that doesn't think about anything, just renders"
    collision_type = CT_NONE
    should_save = False
    selectable = False
    exclude_from_class_list = True
    physics_move = False
    offset_x, offset_y, offset_z = 0., 0., 0.
    "Offset from parent object's origin"
    fixed_z = False
    "If True, Z will not be locked to GO we're attached to"
    editable = GameObject.editable + ['offset_x', 'offset_y', 'offset_z']
    
    def attach_to(self, game_object):
        "Attach this object to given object."
        self.parent = game_object
    
    def update(self):
        # very minimal update!
        if not self.art.updated_this_tick:
            self.art.update()
    
    def post_update(self):
        # after parent has moved, snap to its location
        self.x = self.parent.x + self.offset_x
        self.y = self.parent.y + self.offset_y
        if not self.fixed_z:
            self.z = self.parent.z + self.offset_z

GameObject that doesn't think about anything, just renders

collision_type = 0

Type of collision (static, dynamic)

should_save = False

If True, write this object to state save files

selectable = False

If True, user can select this object in edit mode

exclude_from_class_list = True

If True, do not list class in edit mode UI - system use only!

physics_move = False

If False, don't do move physics updates for this object

fixed_z = False

If True, Z will not be locked to GO we're attached to

editable = ['show_collision', 'col_radius', 'col_width', 'col_height', 'mass', 'bounciness', 'stop_velocity', 'offset_x', 'offset_y', 'offset_z']

Members that don't need to be serialized, but should be exposed to object edit UI

def attach_to(self, game_object):
View Source
    def attach_to(self, game_object):
        "Attach this object to given object."
        self.parent = game_object

Attach this object to given object.

def update(self):
View Source
    def update(self):
        # very minimal update!
        if not self.art.updated_this_tick:
            self.art.update()

Apply movement/physics, update state and facing, keep our Collideable's location locked to us. Self-destroy if a timer is up or we've fallen out of the world.

def post_update(self):
View Source
    def post_update(self):
        # after parent has moved, snap to its location
        self.x = self.parent.x + self.offset_x
        self.y = self.parent.y + self.offset_y
        if not self.fixed_z:
            self.z = self.parent.z + self.offset_z

Run after all objects have updated this simulation tick.

offset_x = 0.0
offset_y = 0.0
offset_z = 0.0
Inherited Members
game_object.GameObject
GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
collision_shape_type
col_layer_name
draw_col_layer
col_radius
serialized
set_methods
deleteable
is_debug
exclude_from_object_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
fast_move
get_time_since_last_update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
View Source
class BlobShadow(GameObjectAttachment):
    "Generic blob shadow attachment class"
    art_src = 'blob_shadow'
    alpha = 0.5

Generic blob shadow attachment class

art_src = 'blob_shadow'

If specified, this art file will be loaded from disk and used as object's default appearance. If object has states/facings, this is the "base" filename prefix, eg "hero" in "hero_stand_front.psci".

alpha = 0.5
Inherited Members
game_object.GameObject
GameObject
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
locked
show_origin
show_bounds
show_collision
collision_shape_type
col_layer_name
draw_col_layer
col_radius
serialized
set_methods
deleteable
is_debug
exclude_from_object_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
fast_move
get_time_since_last_update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class StaticTileBG(game_object.GameObject):
View Source
class StaticTileBG(GameObject):
    "Generic static world object with tile-based collision"
    collision_shape_type = CST_TILE
    collision_type = CT_GENERIC_STATIC
    physics_move = False

Generic static world object with tile-based collision

collision_shape_type = 3

Collision shape: tile, circle, AABB - see the CST_* enum values

collision_type = 2

Type of collision (static, dynamic)

physics_move = False

If False, don't do move physics updates for this object

Inherited Members
game_object.GameObject
GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
serialized
editable
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class StaticTileObject(game_object.GameObject):
View Source
class StaticTileObject(GameObject):
    collision_shape_type = CST_TILE
    collision_type = CT_GENERIC_STATIC
    physics_move = False
    y_sort = True

Base class game object. GameObjects (GOs) are spawned into and managed by a GameWorld. All GOs render and collide via a single Renderable and Collideable, respectively. GOs can have states and facings. GOs are serialized in game state save files. Much of Playscii game creation involves creating flavors of GameObject. See game_util_object module for some generic subclasses for things like a player, spawners, triggers, attachments etc.

collision_shape_type = 3

Collision shape: tile, circle, AABB - see the CST_* enum values

collision_type = 2

Type of collision (static, dynamic)

physics_move = False

If False, don't do move physics updates for this object

y_sort = True

If True, object will sort according to its Y position a la Zelda LttP

Inherited Members
game_object.GameObject
GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
serialized
editable
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class StaticBoxObject(game_object.GameObject):
View Source
class StaticBoxObject(GameObject):
    "Generic static world object with AABB-based (rectangle) collision"
    collision_shape_type = CST_AABB
    collision_type = CT_GENERIC_STATIC
    physics_move = False

Generic static world object with AABB-based (rectangle) collision

collision_shape_type = 2

Collision shape: tile, circle, AABB - see the CST_* enum values

collision_type = 2

Type of collision (static, dynamic)

physics_move = False

If False, don't do move physics updates for this object

Inherited Members
game_object.GameObject
GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
serialized
editable
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class DynamicBoxObject(game_object.GameObject):
View Source
class DynamicBoxObject(GameObject):
    collision_shape_type = CST_AABB
    collision_type = CT_GENERIC_DYNAMIC
    y_sort = True

Base class game object. GameObjects (GOs) are spawned into and managed by a GameWorld. All GOs render and collide via a single Renderable and Collideable, respectively. GOs can have states and facings. GOs are serialized in game state save files. Much of Playscii game creation involves creating flavors of GameObject. See game_util_object module for some generic subclasses for things like a player, spawners, triggers, attachments etc.

collision_shape_type = 2

Collision shape: tile, circle, AABB - see the CST_* enum values

collision_type = 3

Type of collision (static, dynamic)

y_sort = True

If True, object will sort according to its Y position a la Zelda LttP

Inherited Members
game_object.GameObject
GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
lifespan
kill_distance_from_origin
spawner
physics_move
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
serialized
editable
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class Pickup(game_object.GameObject):
View Source
class Pickup(GameObject):
    collision_shape_type = CST_CIRCLE
    collision_type = CT_GENERIC_DYNAMIC
    y_sort = True
    attachment_classes = { 'shadow': 'BlobShadow' }

Base class game object. GameObjects (GOs) are spawned into and managed by a GameWorld. All GOs render and collide via a single Renderable and Collideable, respectively. GOs can have states and facings. GOs are serialized in game state save files. Much of Playscii game creation involves creating flavors of GameObject. See game_util_object module for some generic subclasses for things like a player, spawners, triggers, attachments etc.

collision_shape_type = 1

Collision shape: tile, circle, AABB - see the CST_* enum values

collision_type = 3

Type of collision (static, dynamic)

y_sort = True

If True, object will sort according to its Y position a la Zelda LttP

attachment_classes = {'shadow': 'BlobShadow'}

Objects to spawn as attachments: key is member name, value is class

Inherited Members
game_object.GameObject
GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
lifespan
kill_distance_from_origin
spawner
physics_move
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
serialized
editable
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class Projectile(game_object.GameObject):
View Source
class Projectile(GameObject):
    "Generic projectile class"
    fast_move_steps = 1
    collision_type = CT_GENERIC_DYNAMIC
    collision_shape_type = CST_CIRCLE
    move_accel_x = move_accel_y = 400.
    noncolliding_classes = ['Projectile']
    lifespan = 10.
    "Projectiles should be transient, limited max life"
    should_save = False
    
    def __init__(self, world, obj_data=None):
        GameObject.__init__(self, world, obj_data)
        self.fire_dir_x, self.fire_dir_y = 0, 0
    
    def fire(self, firer, dir_x=0, dir_y=1):
        self.set_loc(firer.x, firer.y, firer.z)
        self.reset_last_loc()
        self.fire_dir_x, self.fire_dir_y = dir_x, dir_y
    
    def update(self):
        if (self.fire_dir_x, self.fire_dir_y) != (0, 0):
            self.move(self.fire_dir_x, self.fire_dir_y)
        GameObject.update(self)

Generic projectile class

Projectile(world, obj_data=None)
View Source
    def __init__(self, world, obj_data=None):
        GameObject.__init__(self, world, obj_data)
        self.fire_dir_x, self.fire_dir_y = 0, 0

Create new GameObject in world, from serialized data if provided.

fast_move_steps = 1

If >0, subdivide high-velocity moves into fractions-of-this-object-sized steps to avoid tunneling. turn this up if you notice an object tunneling.

1 = each step is object's full size

2 = each step is half object's size

N = each step is 1/N object's size

collision_type = 3

Type of collision (static, dynamic)

collision_shape_type = 1

Collision shape: tile, circle, AABB - see the CST_* enum values

noncolliding_classes = ['Projectile']

Blacklist of string names for classes to ignore collisions with

lifespan = 10.0

Projectiles should be transient, limited max life

should_save = False

If True, write this object to state save files

def fire(self, firer, dir_x=0, dir_y=1):
View Source
    def fire(self, firer, dir_x=0, dir_y=1):
        self.set_loc(firer.x, firer.y, firer.z)
        self.reset_last_loc()
        self.fire_dir_x, self.fire_dir_y = dir_x, dir_y
def update(self):
View Source
    def update(self):
        if (self.fire_dir_x, self.fire_dir_y) != (0, 0):
            self.move(self.fire_dir_x, self.fire_dir_y)
        GameObject.update(self)

Apply movement/physics, update state and facing, keep our Collideable's location locked to us. Self-destroy if a timer is up or we've fallen out of the world.

move_accel_x = 400.0
move_accel_y = 400.0
Inherited Members
game_object.GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
kill_distance_from_origin
spawner
physics_move
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
serialized
editable
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
attachment_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class Character(game_object.GameObject):
View Source
class Character(GameObject):
    "Generic character class"
    state_changes_art = True
    stand_if_not_moving = True
    move_state = 'walk'
    "Move state name - added to valid_states in init so subclasses recognized"
    collision_shape_type = CST_CIRCLE
    collision_type = CT_GENERIC_DYNAMIC
    
    def __init__(self, world, obj_data=None):
        if not self.move_state in self.valid_states:
            self.valid_states.append(self.move_state)
        GameObject.__init__(self, world, obj_data)
        # assume that character should start idling, if its art animates
        if self.art.frames > 0:
            self.start_animating()
    
    def update_state(self):
        GameObject.update_state(self)
        if self.state_changes_art and abs(self.vel_x) > 0.1 or abs(self.vel_y) > 0.1:
            self.state = self.move_state

Generic character class

Character(world, obj_data=None)
View Source
    def __init__(self, world, obj_data=None):
        if not self.move_state in self.valid_states:
            self.valid_states.append(self.move_state)
        GameObject.__init__(self, world, obj_data)
        # assume that character should start idling, if its art animates
        if self.art.frames > 0:
            self.start_animating()

Create new GameObject in world, from serialized data if provided.

state_changes_art = True

If True, art will change with current state; depends on file naming.

stand_if_not_moving = True

If True, object will go to stand state any time velocity is zero.

move_state = 'walk'

Move state name - added to valid_states in init so subclasses recognized

collision_shape_type = 1

Collision shape: tile, circle, AABB - see the CST_* enum values

collision_type = 3

Type of collision (static, dynamic)

def update_state(self):
View Source
    def update_state(self):
        GameObject.update_state(self)
        if self.state_changes_art and abs(self.vel_x) > 0.1 or abs(self.vel_y) > 0.1:
            self.state = self.move_state

Update object state based on current context, eg movement.

Inherited Members
game_object.GameObject
art_src
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
physics_move
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
serialized
editable
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
View Source
class Player(Character):
    "Generic player class"
    log_move = False
    collision_type = CT_PLAYER
    editable = Character.editable + ['move_accel_x', 'move_accel_y',
                                         'ground_friction', 'air_friction',
                                         'bounciness', 'stop_velocity']
    
    def pre_first_update(self):
        if self.world.player is None:
            self.world.player = self
            if self.world.player_camera_lock:
                self.world.camera.focus_object = self
            else:
                self.world.camera.focus_object = None
    
    def button_pressed(self, button_index):
        pass
    
    def button_unpressed(self, button_index):
        pass

Generic player class

log_move = False
collision_type = 1

Type of collision (static, dynamic)

editable = ['show_collision', 'col_radius', 'col_width', 'col_height', 'mass', 'bounciness', 'stop_velocity', 'move_accel_x', 'move_accel_y', 'ground_friction', 'air_friction', 'bounciness', 'stop_velocity']

Members that don't need to be serialized, but should be exposed to object edit UI

def pre_first_update(self):
View Source
    def pre_first_update(self):
        if self.world.player is None:
            self.world.player = self
            if self.world.player_camera_lock:
                self.world.camera.focus_object = self
            else:
                self.world.camera.focus_object = None

Run before first update; use this for any logic that depends on init/creation being done ie all objects being present.

def button_pressed(self, button_index):
View Source
    def button_pressed(self, button_index):
        pass
def button_unpressed(self, button_index):
View Source
    def button_unpressed(self, button_index):
        pass
Inherited Members
game_object.GameObject
art_src
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
physics_move
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
serialized
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class TopDownPlayer(game_util_objects.Player):
View Source
class TopDownPlayer(Player):
    
    y_sort = True
    attachment_classes = { 'shadow': 'BlobShadow' }
    facing_changes_art = True
    
    def get_facing_dir(self):
        return FACING_DIRS[self.facing]

Generic player class

y_sort = True

If True, object will sort according to its Y position a la Zelda LttP

attachment_classes = {'shadow': 'BlobShadow'}

Objects to spawn as attachments: key is member name, value is class

facing_changes_art = True

If True, art will change based on facing AND state

def get_facing_dir(self):
View Source
    def get_facing_dir(self):
        return FACING_DIRS[self.facing]
Inherited Members
game_object.GameObject
art_src
valid_states
generate_art
use_art_instance
animating
lifespan
kill_distance_from_origin
spawner
physics_move
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
serialized
set_methods
selectable
deleteable
is_debug
exclude_from_object_list
exclude_from_class_list
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class WorldPropertiesObject(game_object.GameObject):
View Source
class WorldPropertiesObject(GameObject):
    "Special magic singleton object that stores and sets GameWorld properties"
    art_src = 'world_properties_object'
    visible = deleteable = selectable = False
    locked = True
    physics_move = False
    exclude_from_object_list = True
    exclude_from_class_list = True
    world_props = ['game_title', 'gravity_x', 'gravity_y', 'gravity_z',
                   'hud_class_name', 'globals_object_class_name',
                   'camera_x', 'camera_y', 'camera_z',
                   'bg_color_r', 'bg_color_g', 'bg_color_b', 'bg_color_a',
                   'player_camera_lock', 'object_grid_snap', 'draw_hud',
                   'collision_enabled', 'show_collision_all', 'show_bounds_all',
                   'show_origin_all', 'show_all_rooms',
                   'room_camera_changes_enabled', 'draw_debug_objects'
    ]
    """
    Properties we serialize on behalf of GameWorld
    TODO: figure out how to make these defaults sync with those in GW?
    """
    serialized = world_props
    editable = []
    "All visible properties are serialized, not editable"
    def __init__(self, world, obj_data=None):
        GameObject.__init__(self, world, obj_data)
        world_class = type(world)
        for v in self.serialized:
            if obj_data and v in obj_data:
                # if world instance has property from loaded data, use it
                if hasattr(self.world, v):
                    setattr(self.world, v, obj_data[v])
                setattr(self, v, obj_data[v])
            # use world class (default) property if loaded data lacks it
            elif hasattr(world_class, v):
                setattr(self, v, getattr(world_class, v))
            else:
                # set explicitly as float, for camera & bg color
                setattr(self, v, 0.0)
        # special handling of bg color (a list)
        self.world.bg_color = [self.bg_color_r, self.bg_color_g, self.bg_color_b, self.bg_color_a]
        self.world.camera.set_loc(self.camera_x, self.camera_y, self.camera_z)
        # TODO: figure out why collision_enabled seems to default False!
    
    def set_object_property(self, prop_name, new_value):
        setattr(self, prop_name, new_value)
        # special handling for some values, eg bg color and camera
        if prop_name.startswith('bg_color_'):
            component = {'r': 0, 'g': 1, 'b': 2, 'a': 3}[prop_name[-1]]
            self.world.bg_color[component] = float(new_value)
        elif prop_name.startswith('camera_') and len(prop_name) == len('camera_x'):
            setattr(self.world.camera, prop_name[-1], new_value)
        # some properties have unique set methods in GW
        elif prop_name == 'show_collision_all':
            self.world.toggle_all_collision_viz()
        elif prop_name == 'show_bounds_all':
            self.world.toggle_all_bounds_viz()
        elif prop_name == 'show_origin_all':
            self.world.toggle_all_origin_viz()
        elif prop_name == 'player_camera_lock':
            self.world.toggle_player_camera_lock()
        # normal properties you can just set: set em
        elif hasattr(self.world, prop_name):
            setattr(self.world, prop_name, new_value)
    
    def update_from_world(self):
        self.camera_x = self.world.camera.x
        self.camera_y = self.world.camera.y
        self.camera_z = self.world.camera.z

Special magic singleton object that stores and sets GameWorld properties

WorldPropertiesObject(world, obj_data=None)
View Source
    def __init__(self, world, obj_data=None):
        GameObject.__init__(self, world, obj_data)
        world_class = type(world)
        for v in self.serialized:
            if obj_data and v in obj_data:
                # if world instance has property from loaded data, use it
                if hasattr(self.world, v):
                    setattr(self.world, v, obj_data[v])
                setattr(self, v, obj_data[v])
            # use world class (default) property if loaded data lacks it
            elif hasattr(world_class, v):
                setattr(self, v, getattr(world_class, v))
            else:
                # set explicitly as float, for camera & bg color
                setattr(self, v, 0.0)
        # special handling of bg color (a list)
        self.world.bg_color = [self.bg_color_r, self.bg_color_g, self.bg_color_b, self.bg_color_a]
        self.world.camera.set_loc(self.camera_x, self.camera_y, self.camera_z)
        # TODO: figure out why collision_enabled seems to default False!

Create new GameObject in world, from serialized data if provided.

art_src = 'world_properties_object'

If specified, this art file will be loaded from disk and used as object's default appearance. If object has states/facings, this is the "base" filename prefix, eg "hero" in "hero_stand_front.psci".

locked = True

If True, location is protected from edit mode drags, can't click to select

physics_move = False

If False, don't do move physics updates for this object

exclude_from_object_list = True

If True, do not list object in edit mode UI - system use only!

exclude_from_class_list = True

If True, do not list class in edit mode UI - system use only!

world_props = ['game_title', 'gravity_x', 'gravity_y', 'gravity_z', 'hud_class_name', 'globals_object_class_name', 'camera_x', 'camera_y', 'camera_z', 'bg_color_r', 'bg_color_g', 'bg_color_b', 'bg_color_a', 'player_camera_lock', 'object_grid_snap', 'draw_hud', 'collision_enabled', 'show_collision_all', 'show_bounds_all', 'show_origin_all', 'show_all_rooms', 'room_camera_changes_enabled', 'draw_debug_objects']

Properties we serialize on behalf of GameWorld TODO: figure out how to make these defaults sync with those in GW?

serialized = ['game_title', 'gravity_x', 'gravity_y', 'gravity_z', 'hud_class_name', 'globals_object_class_name', 'camera_x', 'camera_y', 'camera_z', 'bg_color_r', 'bg_color_g', 'bg_color_b', 'bg_color_a', 'player_camera_lock', 'object_grid_snap', 'draw_hud', 'collision_enabled', 'show_collision_all', 'show_bounds_all', 'show_origin_all', 'show_all_rooms', 'room_camera_changes_enabled', 'draw_debug_objects']

List of members to serialize (no weak refs!)

editable = []

All visible properties are serialized, not editable

def set_object_property(self, prop_name, new_value):
View Source
    def set_object_property(self, prop_name, new_value):
        setattr(self, prop_name, new_value)
        # special handling for some values, eg bg color and camera
        if prop_name.startswith('bg_color_'):
            component = {'r': 0, 'g': 1, 'b': 2, 'a': 3}[prop_name[-1]]
            self.world.bg_color[component] = float(new_value)
        elif prop_name.startswith('camera_') and len(prop_name) == len('camera_x'):
            setattr(self.world.camera, prop_name[-1], new_value)
        # some properties have unique set methods in GW
        elif prop_name == 'show_collision_all':
            self.world.toggle_all_collision_viz()
        elif prop_name == 'show_bounds_all':
            self.world.toggle_all_bounds_viz()
        elif prop_name == 'show_origin_all':
            self.world.toggle_all_origin_viz()
        elif prop_name == 'player_camera_lock':
            self.world.toggle_player_camera_lock()
        # normal properties you can just set: set em
        elif hasattr(self.world, prop_name):
            setattr(self.world, prop_name, new_value)

Set property by given name to given value.

def update_from_world(self):
View Source
    def update_from_world(self):
        self.camera_x = self.world.camera.x
        self.camera_y = self.world.camera.y
        self.camera_z = self.world.camera.z
visible = False
selectable = False

If True, user can select this object in edit mode

deleteable = False

If True, user can delete this object in edit mode

Inherited Members
game_object.GameObject
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
alpha
show_origin
show_bounds
show_collision
collision_shape_type
collision_type
col_layer_name
draw_col_layer
col_radius
should_save
set_methods
is_debug
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class WorldGlobalsObject(game_object.GameObject):
View Source
class WorldGlobalsObject(GameObject):
    """
    Invisible object holding global state, variables etc in GameWorld.globals.
    Subclass can be specified in WorldPropertiesObject.
    NOTE: this object is spawned from scratch every load, it's never serialized!
    """
    should_save = False
    visible = deleteable = selectable = False
    locked = True
    exclude_from_object_list = True
    exclude_from_class_list = True
    physics_move = False
    serialized = []
    editable = []

Invisible object holding global state, variables etc in GameWorld.globals. Subclass can be specified in WorldPropertiesObject. NOTE: this object is spawned from scratch every load, it's never serialized!

should_save = False

If True, write this object to state save files

locked = True

If True, location is protected from edit mode drags, can't click to select

exclude_from_object_list = True

If True, do not list object in edit mode UI - system use only!

exclude_from_class_list = True

If True, do not list class in edit mode UI - system use only!

physics_move = False

If False, don't do move physics updates for this object

serialized = []

List of members to serialize (no weak refs!)

editable = []

Members that don't need to be serialized, but should be exposed to object edit UI

visible = False
selectable = False

If True, user can select this object in edit mode

deleteable = False

If True, user can delete this object in edit mode

Inherited Members
game_object.GameObject
GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
alpha
show_origin
show_bounds
show_collision
collision_shape_type
collision_type
col_layer_name
draw_col_layer
col_radius
set_methods
is_debug
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class LocationMarker(game_object.GameObject):
View Source
class LocationMarker(GameObject):
    "Very simple GameObject that marks an XYZ location for eg camera points"
    art_src = 'loc_marker'
    serialized = ['name', 'x', 'y', 'z', 'visible', 'locked']
    editable = []
    alpha = 0.5
    physics_move = False
    is_debug = True

Very simple GameObject that marks an XYZ location for eg camera points

art_src = 'loc_marker'

If specified, this art file will be loaded from disk and used as object's default appearance. If object has states/facings, this is the "base" filename prefix, eg "hero" in "hero_stand_front.psci".

serialized = ['name', 'x', 'y', 'z', 'visible', 'locked']

List of members to serialize (no weak refs!)

editable = []

Members that don't need to be serialized, but should be exposed to object edit UI

alpha = 0.5
physics_move = False

If False, don't do move physics updates for this object

is_debug = True

If True, object's visibility can be toggled with View menu option

Inherited Members
game_object.GameObject
GameObject
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
locked
show_origin
show_bounds
show_collision
collision_shape_type
collision_type
col_layer_name
draw_col_layer
col_radius
should_save
set_methods
selectable
deleteable
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class StaticTileTrigger(game_object.GameObject):
View Source
class StaticTileTrigger(GameObject):
    """
    Generic static trigger with tile-based collision.
    Overlaps but doesn't collide.
    """
    is_debug = True
    collision_shape_type = CST_TILE
    collision_type = CT_GENERIC_STATIC
    noncolliding_classes = ['GameObject']
    physics_move = False
    serialized = ['name', 'x', 'y', 'z', 'art_src', 'visible', 'locked']
    
    def started_overlapping(self, other):
        #self.app.log('Trigger overlapped with %s' % other.name)
        pass

Generic static trigger with tile-based collision. Overlaps but doesn't collide.

is_debug = True

If True, object's visibility can be toggled with View menu option

collision_shape_type = 3

Collision shape: tile, circle, AABB - see the CST_* enum values

collision_type = 2

Type of collision (static, dynamic)

noncolliding_classes = ['GameObject']

Blacklist of string names for classes to ignore collisions with

physics_move = False

If False, don't do move physics updates for this object

serialized = ['name', 'x', 'y', 'z', 'art_src', 'visible', 'locked']

List of members to serialize (no weak refs!)

def started_overlapping(self, other):
View Source
    def started_overlapping(self, other):
        #self.app.log('Trigger overlapped with %s' % other.name)
        pass

Run when object begins overlapping with, but does not collide with, another object.

Inherited Members
game_object.GameObject
GameObject
art_src
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
alpha
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
editable
set_methods
selectable
deleteable
exclude_from_object_list
exclude_from_class_list
attachment_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
View Source
class WarpTrigger(StaticTileTrigger):
    "Trigger that warps object to a room/marker when they touch it."
    is_debug = True
    art_src = 'trigger_default'
    alpha = 0.5
    destination_marker_name = None
    "If set, warp to this location marker"
    destination_room_name = None
    "If set, make this room the world's current"
    use_marker_room = True
    "If True, change to destination marker's room"
    warp_class_names = ['Player']
    "List of class names to warp on contact with us."
    serialized = StaticTileTrigger.serialized + ['destination_room_name',
                                                 'destination_marker_name',
                                                 'use_marker_room']
    
    def __init__(self, world, obj_data=None):
        StaticTileTrigger.__init__(self, world, obj_data)
        self.warp_classes = [self.world.get_class_by_name(class_name) for class_name in self.warp_class_names]
    
    def started_overlapping(self, other):
        if other.warped_recently():
            return
        # bail if object's class isn't allowed
        valid_class = False
        for c in self.warp_classes:
            if isinstance(other, c):
                valid_class = True
                break
        if not valid_class:
            return
        if self.destination_room_name:
            if other is self.world.player:
                # if overlapping object is player, change current room
                # to destination room
                self.world.change_room(self.destination_room_name)
            else:
                # if object is only in one room, move them to destination room
                if len(other.rooms) == 1:
                    old_room = other.rooms.values()[0]
                    old_room.remove_object(other)
                self.destination_room.add_object(other)
        elif self.destination_marker_name:
            marker = self.world.objects.get(self.destination_marker_name, None)
            if not marker:
                self.app.log('Warp destination object %s not found' % self.destination_marker_name)
                return
            other.set_loc(marker.x, marker.y, marker.z)
            # warp to marker's room if specified, pick a random one if multiple
            if self.use_marker_room and len(marker.rooms) == 1:
                room = random.choice(list(marker.rooms.values()))
                # warn if both room and marker are set but they conflict
                if self.destination_room_name and \
                   room.name != self.destination_room_name:
                    self.app.log("Marker %s's room differs from destination room %s" % (marker.name, self.destination_room_name))
                self.world.change_room(room.name)
        other.last_warp_update = self.world.updates

Trigger that warps object to a room/marker when they touch it.

WarpTrigger(world, obj_data=None)
View Source
    def __init__(self, world, obj_data=None):
        StaticTileTrigger.__init__(self, world, obj_data)
        self.warp_classes = [self.world.get_class_by_name(class_name) for class_name in self.warp_class_names]

Create new GameObject in world, from serialized data if provided.

is_debug = True

If True, object's visibility can be toggled with View menu option

art_src = 'trigger_default'

If specified, this art file will be loaded from disk and used as object's default appearance. If object has states/facings, this is the "base" filename prefix, eg "hero" in "hero_stand_front.psci".

alpha = 0.5
destination_marker_name = None

If set, warp to this location marker

destination_room_name = None

If set, make this room the world's current

use_marker_room = True

If True, change to destination marker's room

warp_class_names = ['Player']

List of class names to warp on contact with us.

serialized = ['name', 'x', 'y', 'z', 'art_src', 'visible', 'locked', 'destination_room_name', 'destination_marker_name', 'use_marker_room']

List of members to serialize (no weak refs!)

def started_overlapping(self, other):
View Source
    def started_overlapping(self, other):
        if other.warped_recently():
            return
        # bail if object's class isn't allowed
        valid_class = False
        for c in self.warp_classes:
            if isinstance(other, c):
                valid_class = True
                break
        if not valid_class:
            return
        if self.destination_room_name:
            if other is self.world.player:
                # if overlapping object is player, change current room
                # to destination room
                self.world.change_room(self.destination_room_name)
            else:
                # if object is only in one room, move them to destination room
                if len(other.rooms) == 1:
                    old_room = other.rooms.values()[0]
                    old_room.remove_object(other)
                self.destination_room.add_object(other)
        elif self.destination_marker_name:
            marker = self.world.objects.get(self.destination_marker_name, None)
            if not marker:
                self.app.log('Warp destination object %s not found' % self.destination_marker_name)
                return
            other.set_loc(marker.x, marker.y, marker.z)
            # warp to marker's room if specified, pick a random one if multiple
            if self.use_marker_room and len(marker.rooms) == 1:
                room = random.choice(list(marker.rooms.values()))
                # warn if both room and marker are set but they conflict
                if self.destination_room_name and \
                   room.name != self.destination_room_name:
                    self.app.log("Marker %s's room differs from destination room %s" % (marker.name, self.destination_room_name))
                self.world.change_room(room.name)
        other.last_warp_update = self.world.updates

Run when object begins overlapping with, but does not collide with, another object.

Inherited Members
game_object.GameObject
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
locked
show_origin
show_bounds
show_collision
col_layer_name
draw_col_layer
col_radius
should_save
editable
set_methods
selectable
deleteable
exclude_from_object_list
exclude_from_class_list
attachment_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
room_entered
room_exited
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class ObjectSpawner(game_util_objects.LocationMarker):
View Source
class ObjectSpawner(LocationMarker):
    "Simple object that spawns an object when triggered"
    is_debug = True
    spawn_class_name = None
    spawn_obj_name = ''
    spawn_random_in_bounds = False
    "If True, spawn somewhere in this object's bounds, else spawn at location"
    spawn_obj_data = {}
    "Dict of properties to set on newly spawned object"
    times_to_fire = -1
    "Number of times we can fire, -1 = infinite"
    trigger_on_room_enter = True
    "Set False for any subclass that triggers in some other way"
    destroy_on_room_exit = True
    "if True, spawned object will be destroyed when player leaves its room"
    serialized = LocationMarker.serialized + ['spawn_class_name', 'spawn_obj_name',
                                              'times_to_fire', 'destroy_on_room_exit'
    ]
    
    def __init__(self, world, obj_data=None):
        LocationMarker.__init__(self, world, obj_data)
        self.times_fired = 0
        # list of objects we've spawned
        self.spawned_objects = []
    
    def get_spawn_class_name(self):
        "Return class name of object to spawn."
        return self.spawn_class_name
    
    def get_spawn_location(self):
        "Return x,y location we should spawn a new object at."
        if not self.spawn_random_in_bounds:
            return self.x, self.y
        left, top, right, bottom = self.get_edges()
        x = left + random.random() * (right - left)
        y = top + random.random() * (bottom - top)
        return x, y
    
    def can_spawn(self):
        "Return True if spawner is allowed to spawn."
        return True
    
    def do_spawn(self):
        "Spawn and returns object."
        class_name = self.get_spawn_class_name()
        if not class_name:
            return None
        x, y = self.get_spawn_location()
        new_obj = self.world.spawn_object_of_class(class_name, x, y)
        if self.spawn_obj_name:
            self.world.rename_object(new_obj, self.spawn_obj_name)
        # new object should be in same rooms as us
        new_obj.rooms.update(self.rooms)
        self.spawned_objects.append(new_obj)
        # save a reference to us, the spawner
        new_obj.spawner = self
        # TODO: put new object in our room(s), apply spawn_obj_data
        return new_obj
    
    def trigger(self):
        "Poke this spawner to do its thing, returns an object if spawned"
        if self.times_to_fire != -1 and self.times_fired >= self.times_to_fire:
            return None
        if not self.can_spawn():
            return None
        if self.times_fired != -1:
            self.times_fired += 1
        return self.do_spawn()
    
    def room_entered(self, room, old_room):
        if self.trigger_on_room_enter:
            self.trigger()
    
    def room_exited(self, room, new_room):
        if not self.destroy_on_room_exit:
            return
        for obj in self.spawned_objects:
            obj.destroy()

Simple object that spawns an object when triggered

ObjectSpawner(world, obj_data=None)
View Source
    def __init__(self, world, obj_data=None):
        LocationMarker.__init__(self, world, obj_data)
        self.times_fired = 0
        # list of objects we've spawned
        self.spawned_objects = []

Create new GameObject in world, from serialized data if provided.

is_debug = True

If True, object's visibility can be toggled with View menu option

spawn_class_name = None
spawn_obj_name = ''
spawn_random_in_bounds = False

If True, spawn somewhere in this object's bounds, else spawn at location

spawn_obj_data = {}

Dict of properties to set on newly spawned object

times_to_fire = -1

Number of times we can fire, -1 = infinite

trigger_on_room_enter = True

Set False for any subclass that triggers in some other way

destroy_on_room_exit = True

if True, spawned object will be destroyed when player leaves its room

serialized = ['name', 'x', 'y', 'z', 'visible', 'locked', 'spawn_class_name', 'spawn_obj_name', 'times_to_fire', 'destroy_on_room_exit']

List of members to serialize (no weak refs!)

def get_spawn_class_name(self):
View Source
    def get_spawn_class_name(self):
        "Return class name of object to spawn."
        return self.spawn_class_name

Return class name of object to spawn.

def get_spawn_location(self):
View Source
    def get_spawn_location(self):
        "Return x,y location we should spawn a new object at."
        if not self.spawn_random_in_bounds:
            return self.x, self.y
        left, top, right, bottom = self.get_edges()
        x = left + random.random() * (right - left)
        y = top + random.random() * (bottom - top)
        return x, y

Return x,y location we should spawn a new object at.

def can_spawn(self):
View Source
    def can_spawn(self):
        "Return True if spawner is allowed to spawn."
        return True

Return True if spawner is allowed to spawn.

def do_spawn(self):
View Source
    def do_spawn(self):
        "Spawn and returns object."
        class_name = self.get_spawn_class_name()
        if not class_name:
            return None
        x, y = self.get_spawn_location()
        new_obj = self.world.spawn_object_of_class(class_name, x, y)
        if self.spawn_obj_name:
            self.world.rename_object(new_obj, self.spawn_obj_name)
        # new object should be in same rooms as us
        new_obj.rooms.update(self.rooms)
        self.spawned_objects.append(new_obj)
        # save a reference to us, the spawner
        new_obj.spawner = self
        # TODO: put new object in our room(s), apply spawn_obj_data
        return new_obj

Spawn and returns object.

def trigger(self):
View Source
    def trigger(self):
        "Poke this spawner to do its thing, returns an object if spawned"
        if self.times_to_fire != -1 and self.times_fired >= self.times_to_fire:
            return None
        if not self.can_spawn():
            return None
        if self.times_fired != -1:
            self.times_fired += 1
        return self.do_spawn()

Poke this spawner to do its thing, returns an object if spawned

def room_entered(self, room, old_room):
View Source
    def room_entered(self, room, old_room):
        if self.trigger_on_room_enter:
            self.trigger()

Run when a room we're in is entered.

def room_exited(self, room, new_room):
View Source
    def room_exited(self, room, new_room):
        if not self.destroy_on_room_exit:
            return
        for obj in self.spawned_objects:
            obj.destroy()

Run when a room we're in is exited.

Inherited Members
game_object.GameObject
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
locked
show_origin
show_bounds
show_collision
collision_shape_type
collision_type
col_layer_name
draw_col_layer
col_radius
should_save
set_methods
selectable
deleteable
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y
class SoundBlaster(game_util_objects.LocationMarker):
View Source
class SoundBlaster(LocationMarker):
    "Simple object that plays sound when triggered"
    is_debug = True
    sound_name = ''
    "String name of sound to play, minus any extension"
    can_play = True
    "If False, won't play sound when triggered"
    play_on_room_enter = True
    loops = -1
    "Number of times to loop, if -1 loop indefinitely"
    serialized = LocationMarker.serialized + ['sound_name', 'can_play',
                                              'play_on_room_enter']
    
    def __init__(self, world, obj_data=None):
        LocationMarker.__init__(self, world, obj_data)
        # find file, try common extensions
        for ext in ['', '.ogg', '.wav']:
            filename = self.sound_name + ext
            if self.world.sounds_dir and os.path.exists(self.world.sounds_dir + filename):
                self.sound_filenames[self.sound_name] = filename
                return
        self.world.app.log("Couldn't find sound file %s for SoundBlaster %s" % (self.sound_name, self.name))
    
    def room_entered(self, room, old_room):
        self.play_sound(self.sound_name, self.loops)
    
    def room_exited(self, room, new_room):
        self.stop_sound(self.sound_name)

Simple object that plays sound when triggered

SoundBlaster(world, obj_data=None)
View Source
    def __init__(self, world, obj_data=None):
        LocationMarker.__init__(self, world, obj_data)
        # find file, try common extensions
        for ext in ['', '.ogg', '.wav']:
            filename = self.sound_name + ext
            if self.world.sounds_dir and os.path.exists(self.world.sounds_dir + filename):
                self.sound_filenames[self.sound_name] = filename
                return
        self.world.app.log("Couldn't find sound file %s for SoundBlaster %s" % (self.sound_name, self.name))

Create new GameObject in world, from serialized data if provided.

is_debug = True

If True, object's visibility can be toggled with View menu option

sound_name = ''

String name of sound to play, minus any extension

can_play = True

If False, won't play sound when triggered

play_on_room_enter = True
loops = -1

Number of times to loop, if -1 loop indefinitely

serialized = ['name', 'x', 'y', 'z', 'visible', 'locked', 'sound_name', 'can_play', 'play_on_room_enter']

List of members to serialize (no weak refs!)

def room_entered(self, room, old_room):
View Source
    def room_entered(self, room, old_room):
        self.play_sound(self.sound_name, self.loops)

Run when a room we're in is entered.

def room_exited(self, room, new_room):
View Source
    def room_exited(self, room, new_room):
        self.stop_sound(self.sound_name)

Run when a room we're in is exited.

Inherited Members
game_object.GameObject
state_changes_art
stand_if_not_moving
valid_states
facing_changes_art
generate_art
use_art_instance
animating
y_sort
lifespan
kill_distance_from_origin
spawner
fast_move_steps
ground_friction
air_friction
mass
bounciness
stop_velocity
log_move
log_load
log_spawn
visible
locked
show_origin
show_bounds
show_collision
collision_shape_type
collision_type
col_layer_name
draw_col_layer
col_radius
should_save
set_methods
selectable
deleteable
exclude_from_object_list
exclude_from_class_list
attachment_classes
noncolliding_classes
sound_filenames
looping_state_sounds
update_if_outside_room
handle_key_events
handle_mouse_events
consume_mouse_events
rooms
state
facing
flip_x
world
app
destroy_time
timer_functions_pre_update
timer_functions_update
timer_functions_post_update
last_update_failed
arts
origin_renderable
bounds_renderable
orig_collision_type
should_destroy
pre_first_update_run
last_warp_update
get_unique_name
pre_first_update
load_arts
is_point_inside
get_edges
distance_to_object
distance_to_point
normal_to_object
normal_to_point
get_render_offset
is_dynamic
is_entering_state
is_exiting_state
play_sound
stop_sound
stop_all_sounds
enable_collision
disable_collision
started_overlapping
started_colliding
stopped_colliding
resolve_collision_momentum
check_finished_contacts
get_contacting_objects
get_collisions
is_overlapping
are_bounds_overlapping
get_tile_at_point
get_tiles_overlapping_box
overlapped
get_tile_loc
get_layer_z
get_all_art
start_animating
stop_animating
set_object_property
get_art_for_state
set_art
set_art_src
set_loc
reset_last_loc
set_scale
allow_move
allow_move_x
allow_move_y
move
is_on_ground
get_friction
is_affected_by_gravity
get_gravity
get_acceleration
apply_move
moved_this_frame
warped_recently
handle_key_down
handle_key_up
clicked
unclicked
hovered
unhovered
mouse_wheeled
set_timer_function
stop_timer_function
update_state
update_facing
update_state_sounds
frame_begin
frame_update
pre_update
post_update
fast_move
get_time_since_last_update
update
update_renderables
get_debug_text
should_collide
can_collide_with
is_in_room
is_in_current_room
render_debug
render
get_dict
reset_in_place
set_destroy_timer
destroy
art_width
art_height
art_charset
art_palette
move_accel_x
move_accel_y
col_offset_x
col_offset_y
col_width
col_height
art_off_pct_x
art_off_pct_y