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-13 16:20:45 +02:00
|
|
|
def __init__(self, level, x0, y0, left_up=True, links=[]):
|
2012-08-11 02:22:29 +02:00
|
|
|
self.__dict__.update(locals())
|
2012-08-13 16:20:45 +02:00
|
|
|
self.xd, self.yd = self.x0 * 64, (self.y0 + 4) * 48
|
|
|
|
worldobject.WorldObject.__init__(self, level, self.xd, self.yd)
|
2012-08-11 02:22:29 +02:00
|
|
|
|
|
|
|
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)]
|
2012-08-13 16:20:45 +02:00
|
|
|
window.blit(self.img, (self.xd - 32 - self.level.camera_x,
|
|
|
|
self.yd - self.img.get_size()[1] + 24
|
2012-08-11 02:22:29 +02:00
|
|
|
- self.level.camera_y))
|