def __init__(self, screen, imgPath=None, name=None, highlight=False): self.screen = screen self.name = name or f'Name {random.randint(1111, 9999)}' self.highlight = highlight Physics.__init__( self, rect=(0, 0, 100, 100), initAngularVelocity=3000, friction=0, # acceleration in per second angularFriction=100, # acceleration in degrees per second ) if isinstance(imgPath, str): self.imgBase = pygame.image.load(imgPath or r'parts\1.png') else: self.imgBase = imgPath self.imgBase = self.imgBase.convert_alpha() self.imgBase = pygame.transform.scale(self.imgBase, self.size) self.image = self.imgBase self.edgeFriction = 100 self._mask = None self.angVelocityLimit = 500 self._UpdateMask() self.font = pygame.font.Font( None, 16) if not self.highlight else pygame.font.Font(None, 32) self.fontColor = pygame.color.Color( 'white') if not self.highlight else pygame.color.Color('cyan') avgColor = pygame.transform.average_color(self.imgBase) font = pygame.font.Font(None, int(self.height / 3)) self.surfTitle = font.render(self.name, True, avgColor)
def __init__(self, location, speed): """ The location is an (x,y) coordinate pair, and speed is the player's speed in pixels per frame. Speed should be an integer. """ Physics.__init__(self) pg.sprite.Sprite.__init__(self) self.image = pg.Surface((30, 55)).convert() self.image.fill(pg.Color("red")) self.rect = self.image.get_rect(topleft=location) self.speed = speed self.jump_power = -9.0 self.jump_cut_magnitude = -3.0 self.on_moving = False self.collide_below = False self.weapons = { 1: MachineGun(), } self.weapon = self.weapons[1]
def __init__(self): Physics.__init__(self) pg.sprite.Sprite.__init__(self) self.width = con.RUNNER_WIDTH self.height = con.RUNNER_HEIGHT self.right_image = setup.GFX['knightsprite_right'] self.right_image = pg.transform.scale(self.right_image, (80, 80)).convert_alpha() self.left_image = setup.GFX['knightsprite_left'] self.left_image = pg.transform.scale(self.left_image, (80, 80)).convert_alpha() self.image = self.right_image self.rect = self.image.get_rect() self.rect.width *= .75 self.name = con.RUNNER_NAME self.speed = con.RUNNER_SPEED self.jump_power = con.JUMP_POWER self.moving_right = True self.ok_to_jump = True self.dead = False self.on_mover = False self.mover = None
def __init__(self, physics): Physics.__init__(self, physics)