def __init__(self): # Bild laden und erste Animation erstellen: self.anim_image_right = Utils.load_image("tileset.png", (255, 0, 255)) self.anim_right = Animation.Animation(self.anim_image_right, 32, 32, 2, 32, 64, 15) # Die Grafik spiegeln und in einer neuen Surface speichern, # dann können wir die linke Animation erstellen. self.anim_image_left = pygame.transform.flip(self.anim_image_right, True, False) self.anim_left = Animation.Animation(self.anim_image_left, 32, 32, 2, 32, 64, 15) # Start-Position des Players festlegen und # merken in welche Richtung wir schauen und ob wir überhaupt laufen. self.move_right = False self.move_left = False self.pos_x = 10 * 32 self.pos_y = 13 * 32 self.pos_x_old = self.pos_x self.dir = 0 self.walking = False # Force of gravity and mass self.v = 8 self.m = 2 self.isjump = False
def create_animations(self): self.background = pygame.image.load( "images\\outerspace.jpg").convert_alpha() self.spritesheet = pygame.image.load( "images\\spritesheet.png").convert_alpha() Global.animations["asteroid_lg"] = Animation(self.spritesheet, 0, 384, 80, 80, 16, 0.15) Global.animations["asteroid_md"] = Animation(self.spritesheet, 0, 464, 60, 60, 16, 0.15) Global.animations["asteroid_sm"] = Animation(self.spritesheet, 0, 524, 40, 40, 16, 0.15) Global.animations["explosion_asteroid"] = Animation( self.spritesheet, 0, 0, 192, 192, 32, 0.4) Global.animations["explosion_ship"] = Animation( self.spritesheet, 0, 192, 192, 192, 32, 0.4) Global.animations["laser"] = Animation(self.spritesheet, 1540, 384, 32, 48, 8, 0.4) Global.animations["laser_saucer"] = Animation(self.spritesheet, 1540, 444, 32, 48, 8, 0.4) Global.animations["saucer"] = Animation(self.spritesheet, 2200, 384, 45, 73, 6, 0.15) Global.animations["ship"] = Animation(self.spritesheet, 1820, 384, 42, 140, 1, 0, -68) Global.animations["ship_thrusting"] = Animation( self.spritesheet, 1862, 384, 42, 140, 6, 0.25, -68)
def __init__(self): """ Constructor function """ # Call the parent's constructor super().__init__() # Create an image of the block, and fill it with a color. # This could also be an image loaded from the disk. self.right_anim = Animation("resources/walking.png", 60, 100, 6, 6) self.left_anim = Animation("resources/walking_left.png", 60, 100, 6, 6) self.current_anim = self.right_anim self.image = self.current_anim.get_current_frame() # Set a reference to the image rect. self.rect = self.image.get_rect() # Set speed vector of player self.change_x = 0 self.change_y = 0 # List of sprites we can bump against self.level = None self.lives = 0 self.reverse_gravity = False self.moving = False
def updateImage(self): # Like the player if self.attributes["state"] == "still": self.displayImage = Animation( self.name + "-" + self.attributes["facing"] + self.attributes["view"] + "-still", 1, 1) elif self.attributes["state"] == "mov": self.displayImage = Animation( self.name + "-" + self.attributes["facing"] + self.attributes["view"] + "-mov", 4, 10)
def updateImage(self): if self.attributes["view"] == "o": if self.attributes["state"] == "still": self.displayImage = Animation( str(self.attributes["gender"]) + "-" + self.attributes["facing"] + "o-still", 1, 1) elif self.attributes["state"] == "mov": self.displayImage = Animation( str(self.attributes["gender"]) + "-" + self.attributes["facing"] + "o-mov", 4, 10)
def WinScreen(screen, characters): clock = pygame.time.Clock() fond = pygame.image.load("Res/FondCombat.jpg") animWin = Animation.Animation(False) animWin._getAll("Res/"+characters[0]+"/AnimGagné", 15, False, [220, 340]) if characters[0] == "Goku": animWin._loopIn(6) elif characters[0] == "Gohan": animWin._loopIn(7) elif characters[0] == "Picolo": animWin._loopIn(7) elif characters[0] == "Végéta": animWin._loopIn(6) elif characters[0] == "Freezer": animWin._loopIn(3) elif characters[0] == "Cell": animWin._loopIn(7) animPer = Animation.Animation(False) animPer._getAll("Res/"+characters[1]+"/AnimPerdu", 15, False, [400, 280]) if characters[1] == "Goku": animPer._loopIn(2) elif characters[1] == "Gohan": animPer._loopIn(4) elif characters[1] == "Picolo": animPer._loopIn(3) elif characters[1] == "Végéta": animPer._loopIn(7) elif characters[1] == "Freezer": animPer._loopIn(2) elif characters[1] == "Cell": animPer._loopIn(2) continuer = True clock.tick() while continuer: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == QUIT: return ["Quit"] elif event.type == KEYDOWN: return ["TitleScreen"] screen.blit(fond, (0, 0)) animWin._update() animWin._draw(screen) animPer._update() animPer._draw(screen) pygame.display.update() w = clock.tick() pygame.time.wait(15-w)
def __init__(self, xy, sounds, textures): self.x, self.y = xy self.sounds = sounds # Split textures self.frames = [textures["enemies"]["boil"].subsurface(i*64-(i//4)*(64*4), (i//4)*64, 64, 64) for i in range(10)][::-1] # Record sound and textures for tears self.tearTextures = textures["tears"] self.tearSounds = sounds["tear"] # How long it takes to grow + current size self.size = 0 self.advanceTime = 0.5 # When the animation was started self.start = cTime() # Animation for grow self.animation = Animation(self.frames, 10, shouldLoop=False) # How long the boil has been full self.sinceFull = -1 # How many tears the boil has active self.tears = []
def go(self): self.actions.append(['end', '', 0]) # create a place for kirby animation self.top = tk.Toplevel() a = Animation.Animation(self.top) # thread = threading.Thread(name='animate', target=a.update) a.update(0) while len(self.actions) > 0: current = self.actions[0][0] print('current =', current) direction = self.actions[0][1] duration = self.actions[0][2] self.actions.pop(0) if current == 'head': self.moveHead(direction, duration) elif current == 'body': self.moveBody(direction, duration) elif current == 'wheels': self.moveWheels(direction, duration) #elif current == 'animation': # self.top = tk.Toplevel() # a = Animation.Animation(self.top) # a.update(0) time.sleep(float(duration)) a.stop() self.clear() return
def posture_chain(postures_list): nb_frames = len(postures_list) positions = np.array([[[0.0] * 3] * 23] * nb_frames) orients = Quaternions(np.array([1.0, 0.0, 0.0, 0.0] * 23)) offsets = np.array([[0.00000, 0.00000, 0.00000], [0.00000, 10.3548, 0.00650000], [0.00000, 10.04358, -0.0132000], [0.00000, 10.03937, 0.00000], [0.00000, 10.03831, 0.00000], [0.00000, 10.56940, 0.00000], [0.00000, 9.71100, -0.0280000], [-3.15720, 10.03675, 0.00000], [-10.44825, 0.00000, 0.00000], [0.00000, -30.17078, 0.00000], [0.00000, -20.56593, 0.00000], [3.15720, 10.03675, 0.00000], [10.44825, 0.00000, 0.00000], [0.00000, -30.17078, 0.00000], [0.00000, -20.56593, 0.00000], [-8.36560, -0.0321000, -0.00320000], [0.00000, -40.39800, 0.00310000], [0.00000, -40.28828, 0.00520000], [0.00000, -4.91550, 10.08263], [8.36560, -0.0321000, -0.00320000], [0.00000, -40.39800, 0.00310000], [0.00000, -40.28828, 0.00520000], [0.00000, -4.91550, 10.08263]]) parents = np.array([ -1, 0, 1, 2, 3, 4, 5, 4, 7, 8, 9, 4, 11, 12, 13, 0, 15, 16, 17, 0, 19, 20, 21 ]) generated_anim = Animation.Animation(Quaternions(postures_list), positions, orients, offsets, parents) return generated_anim
def loop_extender(ext_number, file): anim, names, frametime = BVH.load(file_path + file_name + ".bvh") frames_number = anim.positions.shape[0] new_frames_number = frames_number * ext_number elements_number = anim.positions.shape[1] new_positions = np.zeros( (frames_number * ext_number, elements_number, anim.positions.shape[2])) new_rotations = anim.rotations.copy() for i in range(0, ext_number - 1): new_rotations.qs = np.vstack((new_rotations.qs, anim.rotations.qs)) for i in range(0, new_frames_number - 1): for j in range(0, elements_number - 1): if i >= frames_number: new_positions[i][j] = anim.positions[i % frames_number][j] + ( 0, 0, new_positions[int(i / frames_number) * frames_number - 1][j][2]) new_rotations.qs[i][j] = anim.rotations.qs[i % frames_number][j] else: new_positions[i][j] = anim.positions[i][j] new_rotations.qs[i][j] = anim.rotations.qs[i][j] new_anim = Animation.Animation(new_rotations, new_positions, anim.orients, anim.offsets, anim.parents) BVH.save(file_path + file_name + "_extended.bvh", new_anim, names, frametime) return
def compute_joints_from_dofs(dofs, cam): global j3d, root_rot frame_num = 1 axis_angle = np.zeros((frame_num, 17, 3)) # 28 - (tx, ty, tz, rx, ry, rz) = 22 axis_angle[0, 0] = root_rot axis_angle[0, 1] = dofs[0:3] axis_angle[0, 2, 0] = dofs[3] axis_angle[0, 4] = dofs[4:7] axis_angle[0, 5, 0] = dofs[7] axis_angle[0, 7] = dofs[8:11] axis_angle[0, 9] = dofs[11:14] axis_angle[0, 11] = dofs[14:17] axis_angle[0, 12, 1] = dofs[17] axis_angle[0, 14] = dofs[18:21] axis_angle[0, 15, 1] = dofs[21] quaternions = Quaternions.from_angle_axis( np.sqrt(np.sum(axis_angle**2, axis=-1)), axis_angle) # y-up, z-forward, x-right offsets = input_tpose_j3d - input_tpose_j3d[j17_parents] offsets[0] = j3d[0] * 100 # m -> cm positions = offsets[np.newaxis].repeat(frame_num, axis=0) # (frames, jointsNum, 3) orients = Quaternions.id(0) for i in range(offsets.shape[0]): orients.qs = np.append(orients.qs, np.array([[1, 0, 0, 0]]), axis=0) anim = Animation.Animation(quaternions, positions, orients, offsets, j17_parents) j3d_pre = Animation.positions_global(anim) / 100 # cm -> m j2d_pre = np.dot( np.divide(j3d_pre, j3d_pre[:, :, 2:], where=j3d_pre[:, :, 2:] != 0), cam.T)[:, :, :2] return j3d_pre[0], j2d_pre[0]
def __init__(self): pic = randint(0, 9) if (pic == 0 or pic == 1 or pic == 2): self.anim_image_left = Utils.load_image("images/Bachelor64.png", (0, 0, 0)) elif (pic == 3 or pic == 4): self.anim_image_left = Utils.load_image("images/Aktenkoffer64.png", (0, 0, 0)) elif (pic == 5): self.anim_image_left = Utils.load_image("images/Doktor64.png", (0, 0, 0)) else: self.anim_image_left = Utils.load_image("images/Bomb64.png", (0, 0, 0)) # Bild laden und erste Animation erstellen: self.anim_left = Animation.Animation(self.anim_image_left, 0, 0, 1, 64, 64, 15) # Die Grafik spiegeln und in einer neuen Surface speichern, # dann können wir die linke Animation erstellen. #self.anim_image_right= pygame.transform.flip(self.anim_image_left, True, False) #self.anim_right = Animation.Animation(self.anim_image_right, 0, 0, 1, 64, 124, 15) # Start-Position des Players festlegen und # merken in welche Richtung wir schauen und ob wir überhaupt laufen. self.pos_x = randint(0, 1366) self.pos_y = 3 * 32 self.dir = 0 self.walking = False
def set_animation_gravity(self): right = True if self.current_anim != self.right_anim: right = False if not self.reverse_gravity: self.right_anim = Animation("resources/walking.png", 60, 100, 6, 6) self.left_anim = Animation("resources/walking_left.png", 60, 100, 6, 6) else: self.right_anim = Animation("resources/upside_down_walking.png", 60, 100, 6, 6) self.left_anim = Animation( "resources/upside_down_walking_left.png", 60, 100, 6, 6) if right: self.current_anim = self.right_anim else: self.current_anim = self.left_anim self.image = self.current_anim.get_current_frame()
def make_animation(generated_rots, original_anim): """make a proper animation object from rotations by using a model from the real data for static parameters (orients, offsets ...) """ generated_anim = (Animation.Animation(Quaternions(generated_rots), original_anim.positions, original_anim.orients, original_anim.offsets, original_anim.parents)) return generated_anim
def __init__(self, position, engine, material_group, tiles_list): super(BaseTile, self).__init__(position, engine) # Set material_group (only for physics, see class description) self.material_group = material_group # Create the animation-instance containing all surfaces self.animation = Animation(tiles_list, 10) self.animation.update() # Create owm rect self.rect = pygame.Rect((0, 0), tiles_list[0].get_size())
def __init__(self, canvasWidth, canvasHeight): self.mountain = Animation("Mountain", 2, 15) # Very proud with how this came out self.logo = loadImage("mountaineerLogo.png") # Eventally I'll replace this with something cool looking. For now, just text self.openerStage = 0 # Stages of the menu loading self.width = canvasWidth self.height = canvasHeight self.menuButtons = [Button(self.width/4, self.height*4/5, width/10, height/10, "Play", "play"), Button(self.width*3/5, self.height*4/5, width/10, height/10, "Customize", "customize")] self.bigFont = createFont("zx_spectrum-7.ttf", 96) self.smallFont = createFont("zx_spectrum-7.ttf", 48)
def __init__(self, x, y, cx, cy): num = 8 duration = 3 self.anim_image_right = Utils.load_image( "assets/LPC Base Assets/sprites/people/princess.png") self.anim_right = Animation.Animation(self.anim_image_right, 64, 192, num, 64, 64, duration) self.anim_image_left = Utils.load_image( "assets/LPC Base Assets/sprites/people/princess.png") self.anim_left = Animation.Animation(self.anim_image_left, 64, 64, num, 64, 64, duration) self.anim_image_up = Utils.load_image( "assets/LPC Base Assets/sprites/people/princess.png") self.anim_up = Animation.Animation(self.anim_image_up, 64, 0, num, 64, 64, duration) self.anim_image_down = Utils.load_image( "assets/LPC Base Assets/sprites/people/princess.png") self.anim_down = Animation.Animation(self.anim_image_down, 64, 128, num, 64, 64, duration) # position and direction and running self.pos_x = x * 32 self.pos_y = y * 32 # Sounds self.chop_sound = pygame.mixer.Sound('assets/sound/chop.wav') self.step_sound = pygame.mixer.Sound('assets/sound/step2.wav') self.step_sound_playing = False self.walking = False self.interval = num * duration self.counter = 0 self.__up = 1 self.__down = 2 self.__right = 3 self.__left = 4 self.__still = 0 self.dir = self.__still self.map_x = x + cx self.map_y = y + 1 + cy self.carrying_log = False
def __init__(self, sprites, animations, world_i, name): EntityObject.__init__(self, world_i) self.sprites = sprites self.animations = animations self.command_sprites = [key for key in self.animations.keys()] self.animation = Animation() self.name = name self.target = None self.position = (0, 0)
def __init__(self, paramsFile, player, canvasWidth, canvasHeight): self.canvasWidth = canvasWidth self.canvasHeight = canvasHeight self.readSaveFile( paramsFile ) # I'll have different files for different popup windows throughout the game self.characterDisplay = Animation( str(player.attributes["gender"]) + "-LU", 2, 10) self.player = player self.activePanel = "" # WIP
def __init__(self, x, y, player, image): self.x = x self.y = y pygame.sprite.Sprite.__init__(self) # self.imglist = Animation(image,0,5) # self.heldImage = Animation(image,35, 39, -2) self.imagelist = image self.image = image[3] self.dx, self.dy = 0, 0 self.movex, self.movey = 0, 0 self.rect = self.image.get_rect() self.rect.topleft = (self.x, self.y) self.player = player self.modeStack = [] self.modeStack.append('0') self.heldImage = Animation(image, 48, 52, -1) self.punchedImage = Animation(image, 40, 44, 1)
def __init__(self, xy, sounds, textures): self.x, self.y = xy self.sounds = sounds self.frames = [textures.subsurface(i*64, 0, 64, 64) for i in range(2)] # self.deathFrames = [textures.subsurface(i*128 - ((i//4)*128*4), 128 * (i//4 + 1), 128, 128) for i in range(12)] self.anim = Animation(self.frames, 0.04) self.health = 2
def __init__(self): # Bild laden und erste Animation erstellen: self.anim_image_left = Utils.load_image("images/Papierkorb.png", (0, 0, 0)) self.anim_left = Animation.Animation(self.anim_image_left, 0, 0, 1, 62, 124, 10) # Die Grafik spiegeln und in einer neuen Surface speichern, # dann können wir die linke Animation erstellen. self.anim_image_right = pygame.transform.flip(self.anim_image_left, True, False) self.anim_right = Animation.Animation(self.anim_image_right, 0, 0, 1, 62, 124, 10) # Start-Position des Players festlegen und # merken in welche Richtung wir schauen und ob wir überhaupt laufen. self.pos_x = 10.5 * 32 self.pos_y = 22.75 * 32 self.dir = 0 self.walking = False
def __init__(self): # Bild laden und erste Animation erstellen: self.anim_image_right = Helper.loadImage("res/tileset.png", (255, 0, 255)) self.anim_right = Animation.Animation(self.anim_image_right, 32, 32, 2, 32, 64, 10) # Die Grafik spiegeln und in einer neuen Surface speichern, # dann können wir die linke Animation erstellen. self.anim_image_left = pygame.transform.flip(self.anim_image_right, True, False) self.anim_left = Animation.Animation(self.anim_image_left, 32, 32, 2, 32, 64, 10) # Start-Position des Players festlegen und # merken in welche Richtung wir schauen und ob wir überhaupt laufen. self.pos_x = 5 * 32 self.pos_y = 13 * 32 self.dir = 0 self.walking = False
def __init__(self, right, upside_down): """ Platform constructor. Assumes constructed with user passing in an array of 5 numbers like what's defined at the top of this code. """ super().__init__() if right and not upside_down: self.anim = Animation("resources/idle.png", 60, 100, 6, 6) elif right and upside_down: self.anim = Animation("resources/upside_down_idle.png", 60, 100, 6, 6) elif not right and not upside_down: self.anim = Animation("resources/idle_left.png", 60, 100, 6, 6) else: self.anim = Animation("resources/upside_down_idle_left.png", 60, 100, 6, 6) self.image = self.anim.get_current_frame() # Set a reference to the image rect. self.rect = self.image.get_rect()
def __init__(self, width, height): """ Platform constructor. Assumes constructed with user passing in an array of 5 numbers like what's defined at the top of this code. """ super().__init__() self.anim = Animation("resources/flask.png", 100, 100, 5, 6) self.image = self.anim.get_current_frame() # Set a reference to the image rect. self.rect = self.image.get_rect()
def __init__(self): # Bild laden und erste Animation erstellen: self.__anim_image_right = Utils.loadImage("tileset3.png", (255, 0, 255)) self.__anim_right = Animation.Animation(self.__anim_image_right, 32, 32, 2, 32, 64, 15) # Die Grafik spiegeln und in einer neuen Surface speichern, # dann können wir die linke Animation erstellen. self.__anim_image_left = pygame.transform.flip(self.__anim_image_right, True, False) self.__anim_left = Animation.Animation(self.__anim_image_left, 32, 32, 2, 32, 64, 15) self.__anim_right = Animation.Animation(self.__anim_image_right, 32, 32, 2, 32, 64, 15) #self.__tileset = Tileset.Tileset("tileset3.png", (255, 0, 255), 32, 32) #self.__tileset.addTile("brain", 32, 32) self.__playerImage = pygame.image.load("Player_brain.png") # Start-Position des Players festlegen und # merken in welche Richtung wir schauen und ob wir überhaupt laufen. self.__posX = 128 self.__posY = 112 self.__dir = 0 self.__walking = False self.__radius = 16 self.__speed = 1 self.__modus = "size" self.__shield = 35 self.__HP = 100 self.__angle = 90 self.__rotated = 0 self.maxHP = 150 self.font = pygame.font.Font(None, 30) self.HPtext = self.font.render("HP:", 1, (255, 255, 255)) self.SPEEDtext = self.font.render("Speed:", 1, (255, 255, 255))
def renderPreview(self, screen): if (self.currentIndex == -1): return if (not self.previewEnabled): desc = self.renderDescription() if (not desc == None): screen.blit(desc, (5, 56)) return if (self.useSidebar): xOffset = (128) / 2 yOffset = (128) / 2 if (self.preview_final != None): animPath = None animPath1 = self.preview_final.replace(".png", ".anim.jpg") animPath2 = self.preview_final.replace(".png", ".anim.png") if (os.path.exists(animPath1) and os.path.isfile(animPath1)): animPath = animPath1 elif (os.path.exists(animPath2) and os.path.isfile(animPath2)): animPath = animPath2 if (animPath != None and self.renderAnim): if (self.anim == None): self.anim = Animation.Animation(animPath, (128, 128)) if (self.useSidebar and self.anim != None): self.anim.render(screen, (5, 56)) RenderControl.setDirty() elif ((os.path.exists(self.preview_final) and os.path.isfile(self.preview_final)) or "opk#" in self.preview_final.lower()): if (self.image == None): self.image = Common.loadImage(self.preview_final) self.image = Common.aspect_scale(self.image, 128, 128, False) if (self.useSidebar): xOffset = (128 - self.image.get_width()) / 2 yOffset = (128 - self.image.get_height()) / 2 screen.blit(self.image, (5 + xOffset, 56 + yOffset)) else: if (not self.keyDown): #fallback if image not found desc = self.renderDescription() if (not desc == None): screen.blit(desc, (5, 56))
def __init__(self, x, y, pic = None): self.groups = ALL_SPRITES pygame.sprite.Sprite.__init__(self, self.groups) self.Player = self self.Animation_Standing = Animation() self.Animation_Up = Animation() self.Animation_Down = Animation() self.Animation_Left = Animation() self.Animation_Right = Animation() self.Current_Animation = self.Animation_Standing if pic == None: self.image = pygame.Surface((TILE_SIZE, TILE_SIZE)) self.image.fill(YELLOW) else: self.image = get_image(pic) self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE)) self.rect = self.image.get_rect() self.vel = vec(0, 0) self.pos = vec(x, y) * TILE_SIZE
def __init__(self, xy, sounds, textures): self.x, self.y = xy self.sounds = sounds # Frames and death frames self.frames = [textures.subsurface(i*64, 0, 64, 64) for i in range(2)] self.deathFrames = [textures.subsurface(i*128 - ((i//4)*128*4), 128 * (i//4 + 1), 128, 128) for i in range(12)] self.anim = Animation(self.frames, 0.04) # Speed ratio self.speed = 1.5/GRATIO
def __init__(self, canvasWidth, canvasHeight, player): self.mountain = Animation("Mountain", 2, 15) self.lad = Animation("m-LU", 2, 10) self.lass = Animation("f-RU", 2, 10) self.canvasWidth = canvasWidth self.canvasHeight = canvasHeight self.player = player self.customizeButtons = [ Button(canvasWidth * 9 / 20, canvasHeight * 6 / 7, canvasWidth / 10, canvasHeight / 10, "Save\nChanges", "saveCustomize"), Button(canvasWidth * 4 / 5, canvasHeight / 3, canvasWidth / 10, canvasHeight / 5, "", "toLad"), Button(canvasWidth / 10, canvasHeight / 3, canvasWidth / 10, canvasHeight / 5, "", "toLass"), Button(canvasWidth / 100, canvasHeight / 100, canvasWidth / 25, canvasHeight / 25, "Back", "menu") ] self.namePlate = TextBox(self.canvasWidth * 2 / 5, self.canvasHeight * 3 / 4, self.canvasWidth / 5, self.canvasHeight / 30, self.player.attributes["name"])