X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=koperkapel%2Fvehicles%2Fbase.py;h=3d7765c11f53094273bfc310b1f6816d118e956a;hb=ed7b7dbe49f3962132f0db806552a5873d6fc113;hp=dec2aca44e3d2ea2b87c17a5d594ad1a171944a5;hpb=208b0bfa93ce450a3d1e686d0bd0b2c93104f7b8;p=koperkapel.git diff --git a/koperkapel/vehicles/base.py b/koperkapel/vehicles/base.py index dec2aca..3d7765c 100644 --- a/koperkapel/vehicles/base.py +++ b/koperkapel/vehicles/base.py @@ -1,18 +1,23 @@ """ Base class for vehicles. """ import math +import random from itertools import chain, islice, repeat from pygame.constants import BLEND_RGBA_MULT from pgzero.loaders import images from ..actors.orientatedsurf import OrientatedSurfActor from ..actors.animsurf import AnimatedSurfActor +from ..weapons import default_weapons +from ..util import safepath class Vehicle: """ Vehicle base class. """ vehicle_type = None + overlay_frame_no = None approximate_radius = 200 + weapons_taped_on = True selected_seat_overlay_color = (255, 0, 0, 255) def __init__(self): @@ -20,7 +25,13 @@ class Vehicle: self.game_pos = (0, 0) def roach_management_overlay(self): - return images.load("vehicles/%s/background" % (self.vehicle_type,)) + return images.load(safepath("vehicles/walking/background")) + + def roach_management_frame(self): + if self.overlay_frame_no is None: + return None + return images.load(safepath("vehicle_big/%s_%d") % ( + self.vehicle_type, self.overlay_frame_no)) def init_seats(self): raise NotImplementedError("Vehicles should specify a list of seats") @@ -66,6 +77,10 @@ class Vehicle: def register(cls, vehicle_cls): cls._vehicle_types[vehicle_cls.__name__.lower()] = vehicle_cls + @classmethod + def random(cls): + return random.choice(list(cls._vehicle_types.keys())) + @classmethod def register_all(cls): from .walking import Walking @@ -77,15 +92,18 @@ class Vehicle: cls.register(Robot) cls.register(Roomba) - def _avatar_frame(self, i, suffix="_tiles"): - vehicle = images.load("vehicle%s/%s_%d" % ( + def _avatar_frame(self, i, weapon, suffix="_tiles"): + vehicle = images.load(safepath("vehicle%s/%s_%d") % ( suffix, self.vehicle_type, i + 1)) frame = vehicle.copy() + frame.blit(weapon.surf, (0, 0)) return frame def get_avatar(self, world): - frames = [self._avatar_frame(i) for i in range(4)] - return AnimatedSurfActor(frames) + weapon = default_weapons.assemble( + world.weapons.current, tape=self.weapons_taped_on) + frames = [self._avatar_frame(i, weapon) for i in range(4)] + return AnimatedSurfActor(frames, anchor=(0, 0)) class Seat: @@ -108,8 +126,7 @@ class Seat: self.vehicle_pos = (pos[0] * vrad, pos[1] * vrad) def actor(self): - seat = images.load( - "vehicles/%s/seat" % (self.vehicle.vehicle_type,)) + seat = images.load(safepath("vehicles/walking/seat")) selected_seat = seat.copy() selected_seat.fill( self.vehicle.selected_seat_overlay_color, None, BLEND_RGBA_MULT)