def __init__(self, avatar): self.done = False self.avatar = avatar self.currentAnim = Anim('subWalkSquash', 5) #img = data.pngs['avatar.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) events.AddListener(self) self.blinkingCounter = 0.0 self.yoyo = yoyo.YoYo() self.shadow = ShadowSprite() self.shadow.scale = float(self.width)/self.shadow.width self.shadow.opacity = 128 self.on_key_press = window.window.event(self.on_key_press) self.on_key_release = window.window.event(self.on_key_release) self.mouseButton = None self.on_mouse_press = window.window.event(self.on_mouse_press) self.on_mouse_release = window.window.event(self.on_mouse_release) self.attackImgs = {Facing.left: data.pngs[self.avatar.attackImg +'_left'], Facing.right: data.pngs[self.avatar.attackImg]} self.deadImgs = {Facing.left: data.pngs[self.avatar.deadImg +'_left'], Facing.right: data.pngs[self.avatar.deadImg]}
def __init__(self, square_size, obstacles, sprites): self.square_size = square_size self.obstacles = obstacles self.sprites = sprites self.move_anim = Anim(sprites["moving"]["right"], speed=0.12) self.death_anim = Anim(sprites["death"], speed=0.1) self.font = pygame.font.SysFont("coopbl", 55) self.timer = {"move": 0} self.move_time = 0.02 self.portals = {1: None, 2: None, "space_pressed": False} # initial amount of lives self.lives = 3 # the player will move 2 pixel every move_time sec self.reset_move_speed = self.move_speed = 3 self.color = (211, 144, 11) self.direction = {"current": "left", "next": None, "previous": None, "right": (1, 0), "left": (-1, 0), "down": (0, 1), "up": (0, -1)} self.killed = False self.make_death_anim = False self.make_ghost_respawn = False self.start_pos = [self.square_size * 9, self.square_size * 11] self.rect = pygame.Rect(self.start_pos[0], self.start_pos[1], self.square_size, self.square_size) self.define_current_tile() self.score = 0
def __init__(self, sprites, start_tile, exit_spawn_path, square_size, map, player_rect, move_time, move_speed, choose_target_tile, start_at_power_points): self.sprites = sprites self.start_tile = start_tile self.exit_spawn_path = exit_spawn_path self.square_size = square_size self.map = map self.move_time = move_time self.reset_move_speed = self.move_speed = move_speed self.state = "normal" # the other state is "chased" self.chassed_sprite_kind = "chased" self.move_anim = Anim(self.sprites["right"], speed=0.12) self.start_at_power_points = start_at_power_points # will start if less than X power points are eaten self.move_timer = 0 self.chased_change_color_timer = 0 self.pos = [ self.start_tile[0] * self.square_size, self.start_tile[1] * self.square_size ] self.rect = pygame.Rect(self.pos[0], self.pos[1], self.square_size, self.square_size) level_nb = 1 self.timer = Timer(level_nb) # "Scatter" # Scatter -> fixed tile to reach (outside screen) | Chase -> attack pac man | Frightened -> random self.mode = self.timer.phases[self.timer.current_phase_index][0] self.move_direction = "left" self.moving_to = ( 8, 7 ) # the first move after the ghost left the spawn (going to the left tile) self.choose_target_tile = choose_target_tile self.direction_conversion = { "right": (1, 0), "left": (-1, 0), "down": (0, 1), "up": (0, -1) }
def __init__(self, enemy): self.enemy = enemy events.AddListener(self) self.currentAnim = Anim(self.imgPrefix + 'Walk', 5) #img = data.pngs['enemy.png'] pyglet.sprite.Sprite.__init__(self, self.currentAnim.animation, 0, 0) self.blinkingCounter = 0.0 self.shadow = ShadowSprite() self.shadow.scale = float(self.width) / self.shadow.width self.shadow.opacity = 100 self.hugImgs = { Facing.left: data.pngs[self.imgPrefix + 'Hug_left'], Facing.right: data.pngs[self.imgPrefix + 'Hug'] } self.stunImgs = { Facing.left: data.pngs[self.imgPrefix + 'Stun_left'], Facing.right: data.pngs[self.imgPrefix + 'Stun'] } self.idleImg = data.pngs[self.imgPrefix + 'Stand'] self.walkImg = self.currentAnim.animation
bulletDir = 1 bonusItem = [] bonusItemDropRate = 100 # Higher value is less drops, default 120 # Audio effects snd_select = sounds.select_8b snd_bonus = sounds.bonus_8b snd_extralife = sounds.extralife_8b snd_extratime = sounds.extratime_8b snd_freeze = sounds.freeze_8b snd_hurt = sounds.injury_8b snd_shoot = sounds.shoot_8b snd_complete = sounds.complete_8b # Animation setup - Array of graphic images and the speed of the animation (lower = faster) playerAnimWalk = Anim([graphics.g_player.ply01, graphics.g_player.ply02, graphics.g_player.ply03, graphics.g_player.ply04, graphics.g_player.ply05], 4 // moveSpeed) playerIdle = graphics.g_player.ply03 playerWarp = graphics.g_player.ply06 enemy1 = Anim([graphics.g_enemies.enemy0_0, graphics.g_enemies.enemy0_1, graphics.g_enemies.enemy0_2], 4) enemy2 = Anim([graphics.g_enemies.enemy1_0, graphics.g_enemies.enemy1_1, graphics.g_enemies.enemy1_2], 2) enemy3 = Anim([graphics.g_enemies.enemy2_0, graphics.g_enemies.enemy2_1, graphics.g_enemies.enemy2_2], 4) item_stop = Anim([graphics.g_collectibles.stop_0, graphics.g_collectibles.stop_1], 20) item_heart = Anim([graphics.g_collectibles.heart_0, graphics.g_collectibles.heart_1], 5) item_clock = Anim([graphics.g_collectibles.clock_0, graphics.g_collectibles.clock_1], 7) item_bonus = Anim([graphics.g_collectibles.bonus_0, graphics.g_collectibles.bonus_1, graphics.g_collectibles.bonus_2], 1) instructionsGraphic1 = [graphics.g_player.ply01, graphics.g_player.arrow_left, graphics.g_player.arrow_right, graphics.g_player.arrow_up] instructionsGraphic4 = [graphics.g_collectibles.stop_0, graphics.g_collectibles.heart_0, graphics.g_collectibles.clock_0, graphics.g_collectibles.bonus_0, graphics.g_imps.imp0_0] imp1Anim = Anim([graphics.g_imps.imp0_0, graphics.g_imps.imp0_1], 10) imp2Anim = Anim([graphics.g_imps.imp1_0, graphics.g_imps.imp1_1], 11) imp3Anim = Anim([graphics.g_imps.imp2_0, graphics.g_imps.imp2_1], 12) imp4Anim = Anim([graphics.g_imps.imp3_0, graphics.g_imps.imp3_1], 13)
monsterPos = [110, 3, False, 30 + random.getrandbits(4) ] # Monster x/y pos, shooting bool and shooting timer smokePos = [50, 0, 5] # Smoke plume, smoke speed scoreSaved = False gameOverY = -88 # Start pos for game over bg pos sfxPlaying = False # Used for checking sfx is playing sfxTimer = 23 # Timer for sfx # Init classes player = Player(playerX, playerY, playerHeight) audio = Audio(g_sound, isThisRealHardware) shake = Shake() # Animation setup - Array of graphic images and the speed of the animation (lower = faster) playerAnim = Anim([ graphics.g_player.man01, graphics.g_player.man02, graphics.g_player.man03, graphics.g_player.man04 ], 1) birdAnimList = [] ###################################### # Sprites, images, objects ###################################### logo = graphics.g_logo.logo gameBg = graphics.g_background.gameBg gameBg2 = graphics.g_background.gameBg2 gameOverBg = graphics.g_background.gameOver floors = [ graphics.g_tiles.floor01, graphics.g_tiles.floor02, graphics.g_tiles.floor03, graphics.g_tiles.floor04 ] walls = [
graphics.g_explosion.explode03, graphics.g_explosion.explode04, graphics.g_explosion.explode05, graphics.g_explosion.explode06, graphics.g_explosion.explode07, graphics.g_explosion.explode08, graphics.g_explosion.explode09 ] popFrames = [ graphics.g_explosion.pop01, graphics.g_explosion.pop02, graphics.g_explosion.pop03, graphics.g_explosion.pop04, graphics.g_explosion.pop05 ] # Init classes player = Player(playerPos[0], playerPos[1], 20, 75, 1) audio = Audio(g_sound) waves = Anim(oceanWaves, 8) # Animation setup - Array of graphic images and the speed of the animation (lower = faster) #playerAnimTurnLeft = Anim([graphics.g_player., graphics.g_player., graphics.g_player.], 4) #playerAnimTurnRight = Anim([graphics.g_player., graphics.g_player., graphics.g_player.], 4) print("free", gc.mem_free()) ################################################################################################################# # Init Game ################################################################################################################# def startLevel(level): global enemyList, enemyShips, milkStations, kittyList, dropItem, kittyBoatX, levelComplete enemyList = [] milkStations = []
rho = rho1 + rho2 vx = (vx1 + vx2) / 2 vy = (vy1 + vy2) / 2 vsq = vx**2 + vy**2 W = 1 / np.sqrt(1 - vsq) KE = rho * W * (W - 1) return KE if __name__ == '__main__': # Model Comparison if not 'Ideal' in locals(): Ideal = Anim('Ideal/HighRes/Data/TimeSeries/UserDef/') idealT = Ideal.t.index(min(Ideal.t, key=lambda x: abs(x - 3.0))) Nideal = Ideal.final.c['nx'] // 2 KESpecIdeal = getPowerSpectrumSq(Ideal.final, GetKESF(Ideal, Ideal.frame[idealT])) if not 'Resistive' in locals(): Resistive = Anim('Resistive/Sigma10/HighRes/Data/TimeSeries/UserDef/') resistiveT = Resistive.t.index( min(Resistive.t, key=lambda x: abs(x - 3.0))) Nresistive = Resistive.final.c['nx'] // 2 KESpecResistive = getPowerSpectrumSq( Resistive.final, GetKESF(Resistive, Resistive.frame[resistiveT])) if not 'TwoFluid' in locals(): TwoFluid = Anim(
gameOverPlayed = False # Trigger to pay gameover sound when dead aquariumBg = [ graphics.bg1, graphics.bg2, graphics.bg3, graphics.bg4, graphics.bg5 ] # Init classes interface = Interface() bg = Background() player = Player() food = Food() hunger = Hunger(hungerMax) audio = Audio(g_sound) tmusic = Music(g_sound, isThisRealHardware) # Animation setup - Array of graphic images and the speed of the animation (lower = faster) coinAnim = Anim([graphics.coin, graphics.coin1], 3) fish1AnimSpeed = random.getrandbits(3) + 1 fish1AnimLeft = Anim([graphics.fish1_left, graphics.fish1_left1], fish1AnimSpeed) fish1AnimRight = Anim([graphics.fish1_right, graphics.fish1_right1], fish1AnimSpeed) fish2AnimLeft = Anim([graphics.fish2_left, graphics.fish2_left1], fish1AnimSpeed) fish2AnimRight = Anim([graphics.fish2_right, graphics.fish2_right1], fish1AnimSpeed) jellyAnim = Anim([graphics.jelly1, graphics.jelly2], fish1AnimSpeed) playerAnimLeft = Anim([graphics.crab1_left, graphics.crab2_left], 3) playerAnimRight = Anim([graphics.crab1_right, graphics.crab2_right], 3) playerAnimIdle = Anim( [graphics.crab_idle1, graphics.crab_idle2, graphics.crab_idle1], 20)