def __init__(self, position, width=20, height=30, name='', collisionGroupNames=None, transferName='', image=None): """ Standard constructor takes in position and can override width and height. @type position: C{(int, int)} or L{Vector<Utilities.vector.Vector>} @param position: The world coordinates of the top left corner of the object's bounding box @type width: C{int} @param width: The width of the object's bounding box in pixels. @type height: C{int} @param height: The height of the object's bounding box in pixels. @type collisionGroupNames: C{list} @param collisionGroupNames: List of names (C{str}) of L{CollisionGroup<CollisionGroup.CollisionGroup>} that this Actor should be part of. @type image: U{C{pygame.Surface}<http://www.pygame.org/docs/ref/surface.html>} @param image: The static image that should be drawn at the object's L{Position} """ # animation # list of tuples ('name', Animation, draw offset) animationMappings = [] animationMappings.append(('idle', Animation('../content/gfx/sprites/HulkGreen.png', pygame.Rect((0, 0, 160, 124)), 8, 3, -1, pygame.Color(49, 115, 255)), Vector((-60, -80)))) animationMappings.append(('fall', Animation('../content/gfx/sprites/HulkGreen.png', pygame.Rect((0, 247, 130, 225)), 2, 3, -1, pygame.Color(49, 115, 255)), Vector((-54, -180)))) animationMappings.append(('land', Animation('../content/gfx/sprites/HulkGreen.png', pygame.Rect((0, 127, 140, 120)), 4, 3, 3, pygame.Color(49, 115, 255)), Vector((-54, -80 + 4)))) self.color = pygame.Color(0, 0, 0) PlatformerActor.__init__(self, position, width, height, name, collisionGroupNames, transferName, [('idle', NPCIdle(self)), ('fall', NPCFall(self)), ('land', NPCLand(self))], 'fall', image, animationMappings) # blink self.ApplyEffect(BlinkEffect(self, 1.0, 0.25))
def __init__(self, position, width, height, name, collisionGroupNames, transferName, playerNum, controller): ''' Constructor ''' # override width and height width = 30 height = 94 stateMappings = [('idle', IdleState(self)), ('run', RunState(self)), ('jump', JumpState(self)), ('fall', FallState(self)), ('land', LandState(self)), ('throw', ThrowState(self)), ('thrown', ThrownState(self)), ('dead', DeadState(self)), ('win', WinState(self)), ('lose', LoseState(self))] startStateName = 'fall' # respawn time for dead state self.respawnTime = 2.0 self.RespawnPosition = position self.RespawnFacingRight = True image = None # player will be a box for now self.image = pygame.Surface((width, height)) self.image = self.image.convert_alpha() self._color = Constants.GameObjectConstants.DEBUG_COLOR self.image.fill(self._color) # animation # list of tuples ('name', Animation, draw offset) sheetPath = os.path.normpath(os.path.realpath('../content/gfx/sprites/PlayerSheet' + str(playerNum+1) + '.png')) clearColor = None alpha = True # animations animationMappings = [] animationMappings.append(('idle', Animation(sheetPath, pygame.Rect((0, 0, 45, 96)), 17, 4, -1, clearColor, alpha), Vector((-7, 0)))) animationMappings.append(('run', Animation(sheetPath, pygame.Rect((0, 110, 100, 100)), 8, 1, -1, clearColor, alpha), Vector((-32, 0)))) animationMappings.append(('launch', Animation(sheetPath, pygame.Rect((0, 218, 69, 94)), 1, 1, 1, clearColor, alpha), Vector((0, 0)))) animationMappings.append(('jump', Animation(sheetPath, pygame.Rect((0, 321, 66, 107)), 2, 3, -1, clearColor, alpha), Vector((-18, 0)))) animationMappings.append(('fall', Animation(sheetPath, pygame.Rect((0, 430, 81, 105)), 4, 3, -1, clearColor, alpha), Vector((-25, 0)))) animationMappings.append(('land', Animation(sheetPath, pygame.Rect((0, 535, 76, 96)), 2, 1, 1, clearColor, alpha), Vector((-25, 0)))) animationMappings.append(('throw', Animation(sheetPath, pygame.Rect((0, 632, 130, 102)), 4, 1, 3, clearColor, alpha), Vector((-50, 0)))) animationMappings.append(('thrown', Animation(sheetPath, pygame.Rect((0, 735, 80, 95)), 5, 1, -1, clearColor, alpha), Vector((-24, 0)))) animationMappings.append(('win', Animation(sheetPath, pygame.Rect((0, 828, 62, 110)), 4, 1, 3, clearColor, alpha), Vector((-15, -12)))) animationMappings.append(('dead', Animation(sheetPath, pygame.Rect((0, 940, 105, 95)), 8, 1, 7, clearColor, alpha), Vector((-30, 10)))) # sounds soundMappings = [] #soundMappings.append(('throw', Sound('../resources/sounds/dp_finalfight.ogg', Constants.GameConstants.SOUND_VOLUME))) soundMappings.append(('hit', Sound('../content/sounds/hit.ogg', Constants.GameConstants.SOUND_VOLUME))) soundMappings.append(('jump', Sound('../content/sounds/jump.ogg', Constants.GameConstants.SOUND_VOLUME))) soundMappings.append(('swipe', Sound('../content/sounds/swipe.ogg', Constants.GameConstants.SOUND_VOLUME))) soundMappings.append(('land', Sound('../content/sounds/thud.ogg', Constants.GameConstants.SOUND_VOLUME))) soundMappings.append(('win', Sound('../content/sounds/win.ogg', Constants.GameConstants.SOUND_VOLUME))) #soundMappings.append(('count down', Sound('../resources/sounds/countdown.ogg', 0.1))) PlatformerActor.__init__(self, position, width, height, name, collisionGroupNames, transferName, stateMappings, startStateName, self.image, animationMappings, soundMappings) Player.__init__(self, position, width, height, name, collisionGroupNames, transferName, playerNum, controller, stateMappings, startStateName, self.image, animationMappings, soundMappings) # set some speeds for the player self._maxXVel = Constants.PlayerConstants.MAX_X_VELOCITY self._maxYVel = Constants.PlayerConstants.MAX_Y_VELOCITY self._maxFallVel = Constants.PlayerConstants.MAX_FALL_VELOCITY self._jumpVel = Constants.PlayerConstants.MAX_JUMP_VELOCITY self._runVel = Constants.PlayerConstants.MAX_RUN_VELOCITY # to test map transfer self._numjumps = 0 # test throw self.isThrowing = False self.isThrown = False throwBoxWidth = 48 throwBoxHeight = 18 self._throwBoxCenterOffset = Vector((32, -8)) self.ThrowBox = pygame.Rect((self.boundingBox.centerx + self._throwBoxCenterOffset.x, self.boundingBox.centery + self._throwBoxCenterOffset.y), (throwBoxWidth, throwBoxHeight)) # throw hit box self.ThrowFrames = self._animations['throw'].LoopLength self.AirThrow = False self.ThrowVel = Vector((10000, 1000)) self.ThrowVector = Vector((0, 0)) self._throwCoolDown = 0 # some goal variables self._win = False self._lose = False # restricted changes test self._restrictedStateTrans = [('dead', 'land'), ('dead', 'jump'), ('win', 'fall'), ('win', 'idle'), ('win', 'dead'), ('win', 'thrown'), ('lose', 'fall'), ('lose', 'idle'), ('lose', 'dead'), ('lose', 'thrown')] self._drawDebug = False