2012-08-12 17:01:58 +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/>.
|
|
|
|
#
|
|
|
|
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
|
|
|
#
|
|
|
|
# laser.py
|
|
|
|
# --------------------
|
|
|
|
# date created : Sun Aug 12 2012
|
|
|
|
# copyright : (C) 2012 Niels G. W. Serup
|
|
|
|
# maintained by : Niels G. W. Serup <ns@metanohi.name>
|
|
|
|
|
|
|
|
"""
|
|
|
|
A laser for drawing.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pygame
|
|
|
|
|
|
|
|
import worldobject
|
2012-08-13 21:42:46 +02:00
|
|
|
import robotgame.logic.lasermirror as lm
|
2012-08-12 17:01:58 +02:00
|
|
|
|
|
|
|
class Laser(worldobject.WorldObject):
|
2012-08-13 21:42:46 +02:00
|
|
|
def __init__(self, level, line, first_laser=False):
|
2012-08-12 17:01:58 +02:00
|
|
|
self.__dict__.update(locals())
|
2012-08-13 16:20:45 +02:00
|
|
|
(self.x0, self.y0), (self.x1, self.y1) = line
|
|
|
|
self.x0d, self.y0d, self.x1d, self.y1d \
|
|
|
|
= self.x0 * 64, (self.y0 + 4) * 48, self.x1 * 64, (self.y1 + 4) * 48
|
2012-08-13 21:42:46 +02:00
|
|
|
if self.y0d > self.y1d:
|
|
|
|
self.y0d, self.y1d = self.y1d, self.y0d
|
|
|
|
if self.x0d > self.x1d:
|
|
|
|
self.x0d, self.x1d = self.x1d, self.x0d
|
2012-08-13 16:20:45 +02:00
|
|
|
worldobject.WorldObject.__init__(self, level, self.x0d,
|
|
|
|
max(self.y0d, self.y1d))
|
2012-08-12 17:01:58 +02:00
|
|
|
|
2012-08-13 21:42:46 +02:00
|
|
|
x0de = 31
|
|
|
|
y0de = -48
|
|
|
|
x1de = 31
|
|
|
|
y1de = -48
|
|
|
|
|
|
|
|
if self.x0 < 0:
|
|
|
|
x0de += 32
|
|
|
|
if self.y0 < 0:
|
|
|
|
y0de += 24
|
|
|
|
if self.x1d >= self.level.size[0]:
|
|
|
|
x1de -= 32
|
|
|
|
if self.first_laser and self.y0 == 0 and self.y0 != self.y1:
|
|
|
|
y0de += 6
|
|
|
|
if self.level.playfield.get((self.x0, self.y0)) is lm.Target and self.x0 < self.x1:
|
|
|
|
x0de += 20
|
|
|
|
if self.level.playfield.get((self.x1, self.y1)) is lm.Target and self.x0 < self.x1:
|
|
|
|
x1de -= 20
|
|
|
|
self.x0d += x0de
|
|
|
|
self.y0d += y0de
|
|
|
|
self.x1d += x1de
|
|
|
|
self.y1d += y1de
|
|
|
|
|
|
|
|
self.start_dark = 0
|
2012-08-12 17:01:58 +02:00
|
|
|
|
2012-08-20 19:51:02 +02:00
|
|
|
self.surf = pygame.Surface(self.level.game.window.get_size(),
|
|
|
|
pygame.SRCALPHA)
|
|
|
|
|
2012-08-13 21:42:46 +02:00
|
|
|
def update(self, e, t, dt):
|
|
|
|
self.start_dark = (t % 200) / 100
|
2012-08-12 17:01:58 +02:00
|
|
|
worldobject.WorldObject.update(self, e, t, dt)
|
|
|
|
|
|
|
|
def draw(self, window):
|
2012-08-20 19:51:02 +02:00
|
|
|
self.surf.fill((0, 0, 0, 0))
|
|
|
|
|
2012-08-13 21:42:46 +02:00
|
|
|
colors = [(155, 0, 0), (255, 0, 0)]
|
|
|
|
c = self.start_dark
|
|
|
|
if self.x0d != self.x1d:
|
|
|
|
length = self.x1d - self.x0d
|
|
|
|
for i in range(0, length, 8):
|
|
|
|
x0d = self.x0d + i
|
2012-08-20 19:51:02 +02:00
|
|
|
pygame.draw.line(self.surf, colors[c],
|
2012-08-13 21:42:46 +02:00
|
|
|
(x0d - self.level.camera_x,
|
|
|
|
self.y0d - self.level.camera_y),
|
|
|
|
(x0d + min(8, length - i) - self.level.camera_x,
|
|
|
|
self.y1d - self.level.camera_y), 2)
|
|
|
|
c ^= 1
|
|
|
|
else:
|
|
|
|
length = self.y1d - self.y0d
|
|
|
|
for i in range(0, length, 8):
|
|
|
|
y0d = self.y0d + i
|
2012-08-20 19:51:02 +02:00
|
|
|
pygame.draw.line(self.surf, colors[c],
|
2012-08-13 21:42:46 +02:00
|
|
|
(self.x0d - self.level.camera_x,
|
|
|
|
y0d - self.level.camera_y),
|
|
|
|
(self.x0d - self.level.camera_x,
|
|
|
|
y0d + min(8, length - i) - self.level.camera_y), 2)
|
|
|
|
c ^= 1
|
2012-08-20 19:51:02 +02:00
|
|
|
|
|
|
|
window.blit(self.surf, (0, 0))
|