Exemplo n.º 1
0
 def __init__(self, font, text, **kwargs):
     """Initialize the game object."""
     GameObject.__init__(self, GameObject.Priority.BACKGROUND.value - 10)
     self.__blink_state = True
     self.visible = True
     self.__surface, self.__rect = font.render(font, text, **kwargs)
     self.__stamps = []
Exemplo n.º 2
0
 def __init__(self, font, position, **kwargs):
     """Initialize the game object."""
     GameObject.__init__(self, GameObject.Priority.BACKGROUND.value - 10)
     self.__position = position
     self.__digits = [Label(font, str(i), (0, 0)) for i in range(10)]
     self.__show_highscore = kwargs.get('highscore', False)
     self.restart()
Exemplo n.º 3
0
 def __init__(self, pos, scale=1, **kw):
     """Initialize the game object."""
     Collider.__init__(self, kw.get('shape', Collider.ELLIPSE))
     Controllable.__init__(self, ConstantController(-1, 0))
     Movable.__init__(self, pos)
     GameObject.__init__(self, GameObject.Priority.BOSS)
     self.__sprite = Sprite('media/images/asteroid.png',
                            scale=scale, rotate=0)
Exemplo n.º 4
0
 def __init__(self, canvas_size, count=300):
     """Create the starfield stars."""
     GameObject.__init__(self, GameObject.Priority.BACKGROUND)
     self.__width, self.__height = canvas_size
     self.__stars = [
         self.__create_star(randrange(0, self.__width - 1))
         for star in range(count)
     ]
Exemplo n.º 5
0
 def __init__(self, creator, color, origin, target, size=8):
     """Initialize the object."""
     Collider.__init__(self, Collider.LINE)
     Controllable.__init__(self, self.__controller(origin, target, size))
     Movable.__init__(self, origin)
     Hideable.__init__(self)
     GameObject.__init__(self, GameObject.Priority.PROJECTILE)
     self.__creator = type(creator)
     self.__color = color
     self.__next = None
Exemplo n.º 6
0
 def __init__(self, position, type=SMALL, **kwargs):
     """Initialize the object."""
     Hideable.__init__(self)
     GameObject.__init__(self, GameObject.Priority.DEFAULT)
     ts = kwargs.get('time_scale', 1.0)
     self.__sprite = Sprite(type, animate=True, time_scale=ts, loop=True)
     self.__ttl = self.__sprite.duration + pygame.time.get_ticks()
     _, _, w, h, *_ = list(map(lambda i: i // 2, self.__sprite.bounds))
     x, y = position
     self.__position = (x - w, y - h)
     self.should_collide = False
Exemplo n.º 7
0
 def __init__(self, canvas, image, **kw):
     """Initialize Enemy object."""
     Controllable.__init__(self,
                           kw.get('controller', ConstantController(-1, 0)))
     Collider.__init__(self, kw.get('bounding_shape', Collider.RECT))
     Movable.__init__(
         self,
         kw.get('position', (canvas[0] + 10, randint(50, canvas[1] - 50))))
     GameObject.__init__(self, kw.get('priority', GameObject.Priority.NPC))
     self.__sprite = Sprite(image, **kw)
     x, y, *_ = self.__sprite.bounds
     self.move(x, y)
Exemplo n.º 8
0
 def __init__(self, creator, color, origin, direction, **kwargs):
     """Initialize the object."""
     Collider.__init__(self, Collider.LINE)
     Controllable.__init__(self, direction)
     Movable.__init__(self, origin)
     Hideable.__init__(self)
     GameObject.__init__(self, GameObject.Priority.PROJECTILE)
     self.__size = kwargs.get("size", 8)
     self.__creator = type(creator)
     self.__color = color
     self.__next = None
     self.__ignore_colision = tuple(kwargs.get('ignore_colision', ()))
Exemplo n.º 9
0
 def __init__(self, canvas, image, **kw):
     """Initialize Enemy object."""
     Controllable.__init__(self,
                           kw.get('controller',
                                  ConstantController(-1, 0)))
     Collider.__init__(self, kw.get('shape', Collider.RECT))
     Movable.__init__(self, kw.get('position', (canvas[0] + 10,
                                   randint(50, canvas[1] - 50))))
     Killable.__init__(self, Explosion.SMALL, time_scale=0.5)
     GameObject.__init__(self, GameObject.Priority.NPC)
     self. __sprite = Sprite(image,
                             animate=kw.get('animate', False),
                             cast_shadow=kw.get('cast_shadow', True))
Exemplo n.º 10
0
 def __init__(self, position, speed=5, controller=ConstantController(0, 0)):
     """Initialize the object."""
     Collider.__init__(self, Collider.RECT)
     Controllable.__init__(self, controller)
     Movable.__init__(self, position)
     Killable.__init__(self, Explosion.BIG)
     GameObject.__init__(self, GameObject.Priority.PLAYER)
     self.__original_position = position
     self.__sprite = Sprite('media/images/f18.png')
     self.__lives = 3
     self.__points = 0
     self.__speed = speed
     self.__move = (0, 0)