From 3701def3cc878994c24c9928dd7aa1fbbbc969a8 Mon Sep 17 00:00:00 2001 From: Miguel Angel Astor Romero Date: Wed, 9 Jan 2013 12:02:21 -0430 Subject: [PATCH] Added get/set methods to the BaseActor class. --- actor.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/actor.py b/actor.py index 0f1f496..e809a85 100644 --- a/actor.py +++ b/actor.py @@ -4,17 +4,63 @@ import pygame from animation import Animation -class Actor: - """ Represents any game object. """ - def __init__(self): +ACTOR_STATES = { 'IDLE': 0, 'MOVING': 1 } + +class BaseActor: + """ Represents any game object. This is the parent class for the actor + category of objects. It's behaviors are empty. """ + def __init__(self, name, visible, solid, position): """ Initializes the actor object. """ + # Conditions and parameters. + self.name = name + self.alive = True # The Actor should be updated. + self.animated = False # The Actor has animations. + self.visible = visible # The Actor should be rendered. + self.solid = solid # The actor can collide with other actors # All sprites for an actor are stored as a list of pygame sprites. + # The list starts empty. Sprites must be added with the add_sprite method. self.sprites = [] - # Animations are stored as a key (animation name), - # value (list of sprite indices) pairs. + # Animations are stored as a key (Animation angle), + # value (Animation object) pairs. Animations are added with the + # add_animation method. self.animations = {} - # Parameters. - self.angle = 0 - self.speed = [0, 0] # [X speed, Y speed]. - self.acceleration = [0, 0] # Ditto. + # Parameters for direction and movement. + self.position = list(position) + self.speed = [0, 0] # [X speed, Y speed]. + self.max_speed = [100, 100] # 100 pixels per second. + self.acceleration = [0, 0] # Ditto. + # Collision detection information. AABB and Bounding circle. self.b_box = [0, 0] # [X length, Y length]. + self.radius = 0.0 + # Parameters for rendering. + self.angle = 0 + self.scale = 1.0 + + def is_alive(self): + return self.alive + + def is_animated(self): + return self.animated + + def is_visible(self): + return self.visible + + def is_solid(self): + return self.solid + + def destroy(self): + self.alive = False + + def set_visible(self, visible): + self.visible = visible + + def toggle_visible(self): + self.visible = not self.visible + + def set_solid(self, solid): + self.solid = solid + + def toggle_solid(self): + self.solid = not self.solid + + def add_sprite(self, filename)