64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
|
# 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, x, y, left_up=True):
|
||
|
self.__dict__.update(locals())
|
||
|
worldobject.WorldObject.__init__(self, level, x, y)
|
||
|
|
||
|
self.in_rotation = False
|
||
|
|
||
|
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
|
||
|
self.left_up = not self.left_up
|
||
|
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
|
||
|
|
||
|
worldobject.WorldObject.update(self, e, t, dt)
|
||
|
|
||
|
def draw(self, window):
|
||
|
fn = self.frame + 1 if not self.left_up else self.frame + self._half_anim_len
|
||
|
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))
|