a-robots-conundrum/robotgame/mirror.py

69 lines
2.4 KiB
Python
Raw Normal View History

# 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):
def __init__(self, level, x0, y0, left_up=True, links=[]):
self.__dict__.update(locals())
self.xd, self.yd = self.x0 * 64, (self.y0 + 4) * 48
worldobject.WorldObject.__init__(self, level, self.xd, self.yd)
self.in_rotation = False
2012-08-11 14:30:46 +02:00
self.left_up_aim = self.left_up
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
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)
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
self.img = self.level.imgs['mirror'][int(fn)]
window.blit(self.img, (self.xd - 32 - self.level.camera_x,
self.yd - self.img.get_size()[1] + 24
- self.level.camera_y))