Added get/set methods to the BaseActor class.

This commit is contained in:
2013-01-09 12:02:21 -04:30
parent 063ec6d22b
commit 3701def3cc

View File

@@ -4,17 +4,63 @@
import pygame import pygame
from animation import Animation from animation import Animation
class Actor: ACTOR_STATES = { 'IDLE': 0, 'MOVING': 1 }
""" Represents any game object. """
def __init__(self): 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. """ """ 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. # 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 = [] self.sprites = []
# Animations are stored as a key (animation name), # Animations are stored as a key (Animation angle),
# value (list of sprite indices) pairs. # value (Animation object) pairs. Animations are added with the
# add_animation method.
self.animations = {} self.animations = {}
# Parameters. # Parameters for direction and movement.
self.angle = 0 self.position = list(position)
self.speed = [0, 0] # [X speed, Y speed]. self.speed = [0, 0] # [X speed, Y speed].
self.acceleration = [0, 0] # Ditto. 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.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)