2012-08-11 02:22:29 +02:00
|
|
|
# This file is part of ROBOTGAME
|
|
|
|
#
|
|
|
|
# ROBOTGAME is free software: you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# ROBOTGAME is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# ROBOTGAME. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
|
|
|
#
|
|
|
|
# mirror.py
|
|
|
|
# --------------------
|
|
|
|
# date created : Fri Aug 10 2012
|
|
|
|
# copyright : (C) 2012 Niels G. W. Serup
|
|
|
|
# maintained by : Niels G. W. Serup <ns@metanohi.name>
|
|
|
|
|
|
|
|
"""
|
|
|
|
A generic mirror for drawing.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pygame
|
|
|
|
|
|
|
|
import worldobject
|
|
|
|
|
|
|
|
class Mirror(worldobject.WorldObject):
|
2012-08-11 21:47:38 +02:00
|
|
|
def __init__(self, level, x, y, left_up=True, links=[]):
|
2012-08-11 02:22:29 +02:00
|
|
|
self.__dict__.update(locals())
|
|
|
|
worldobject.WorldObject.__init__(self, level, x, y)
|
|
|
|
|
|
|
|
self.in_rotation = False
|
2012-08-11 14:30:46 +02:00
|
|
|
self.left_up_aim = self.left_up
|
2012-08-11 02:22:29 +02:00
|
|
|
|
|
|
|
self.frame = 7
|
|
|
|
self.anim_speed = 12
|
|
|
|
self._half_anim_len = len(self.level.imgs['mirror']) / 2
|
|
|
|
|
|
|
|
def rotate(self):
|
|
|
|
if self.in_rotation:
|
|
|
|
return
|
|
|
|
self.in_rotation = True
|
2012-08-11 14:30:46 +02:00
|
|
|
self.left_up_aim = not self.left_up_aim
|
2012-08-11 02:22:29 +02:00
|
|
|
self.frame = 0
|
|
|
|
|
|
|
|
def update(self, e, t, dt):
|
|
|
|
if self.in_rotation:
|
|
|
|
top = self._half_anim_len - 1
|
|
|
|
self.frame = min(self.frame + self.anim_speed * dt, top)
|
|
|
|
if self.frame == top:
|
|
|
|
self.in_rotation = False
|
2012-08-11 14:30:46 +02:00
|
|
|
self.left_up = not self.left_up
|
2012-08-11 21:47:38 +02:00
|
|
|
for link in self.links:
|
|
|
|
link(self.left_up)
|
2012-08-11 02:22:29 +02:00
|
|
|
|
|
|
|
worldobject.WorldObject.update(self, e, t, dt)
|
|
|
|
|
|
|
|
def draw(self, window):
|
2012-08-11 14:30:46 +02:00
|
|
|
fn = self.frame + 1 if not self.left_up_aim else self.frame + self._half_anim_len
|
2012-08-11 02:22:29 +02:00
|
|
|
self.img = self.level.imgs['mirror'][int(fn)]
|
|
|
|
window.blit(self.img, (self.x - 32 - self.level.camera_x,
|
|
|
|
self.y - self.img.get_size()[1] + 24
|
|
|
|
- self.level.camera_y))
|