def __init__(self, x, y, space): #Tlaloc attributes self.thunder = [ SFX(pygame.mixer.Sound("audio/sfx/gods/tlaloc/lightning_1.wav"), 19), SFX(pygame.mixer.Sound("audio/sfx/gods/tlaloc/lightning_2.wav"), 19), SFX(pygame.mixer.Sound("audio/sfx/gods/tlaloc/lightning_3.wav"), 19), ] random.seed() self.idle = load_image("sprites/gods/tlaloc/idle.png", True) self.cloud_attack = Animate([ load_image("sprites/gods/tlaloc/cloud_attack_1.png", True), load_image("sprites/gods/tlaloc/cloud_attack_2.png", True), load_image("sprites/gods/tlaloc/cloud_attack_3.png", True), load_image("sprites/gods/tlaloc/cloud_attack_4.png", True),], 3) self.being_invoked = Animate([ load_image("sprites/gods/tlaloc/invoked_1.png", True), load_image("sprites/gods/tlaloc/invoked_2.png", True), load_image("sprites/gods/tlaloc/invoked_3.png", True), load_image("sprites/gods/tlaloc/invoked_4.png", True), load_image("sprites/gods/tlaloc/invoked_5.png", True),], 2) self.cloud = Animate([ load_image("sprites/gods/tlaloc/cloud_1.png", True), load_image("sprites/gods/tlaloc/cloud_2.png", True), load_image("sprites/gods/tlaloc/cloud_3.png", True), load_image("sprites/gods/tlaloc/cloud_4.png", True),], 1) #Super class attributes super(Tlaloc, self).__init__(x, y, space)
def __init__(self, x, y, space): #Huitzilopochtli attributes self.idle = load_image("sprites/gods/huitzilopochtli/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/huitzilopochtli/invoked_1.png", True), load_image("sprites/gods/huitzilopochtli/invoked_2.png", True), load_image("sprites/gods/huitzilopochtli/invoked_3.png", True), load_image("sprites/gods/huitzilopochtli/invoked_4.png", True), load_image("sprites/gods/huitzilopochtli/invoked_5.png", True),], 2) self.breathing_right = Animate([ load_image("sprites/gods/huitzilopochtli/right_breath_1.png", True), load_image("sprites/gods/huitzilopochtli/right_breath_1.png", True), load_image("sprites/gods/huitzilopochtli/right_breath_2.png", True) ], 0.4) self.breathing_left = Animate([ load_image("sprites/gods/huitzilopochtli/left_breath_1.png", True), load_image("sprites/gods/huitzilopochtli/left_breath_1.png", True), load_image("sprites/gods/huitzilopochtli/left_breath_2.png", True), ], 0.4) self.looking_right = Animate([ load_image("sprites/gods/huitzilopochtli/right_walk_1.png", True), load_image("sprites/gods/huitzilopochtli/right_walk_2.png", True), load_image("sprites/gods/huitzilopochtli/right_walk_3.png", True), load_image("sprites/gods/huitzilopochtli/right_walk_2.png", True), ], 2) self.looking_left = Animate([ load_image("sprites/gods/huitzilopochtli/left_walk_1.png", True), load_image("sprites/gods/huitzilopochtli/left_walk_2.png", True), load_image("sprites/gods/huitzilopochtli/left_walk_3.png", True), load_image("sprites/gods/huitzilopochtli/left_walk_2.png", True), ], 2) self.attacking_right_1 = load_image("sprites/gods/huitzilopochtli/right_attack_1.png", True) self.attacking_right_2 = load_image("sprites/gods/huitzilopochtli/right_attack_2.png", True) self.attacking_right_3 = load_image("sprites/gods/huitzilopochtli/right_attack_3.png", True) self.attacking_right_4 = load_image("sprites/gods/huitzilopochtli/right_attack_4.png", True) self.attacking_right_air = load_image("sprites/gods/huitzilopochtli/right_attack_air.png", True) self.attacking_left_1 = load_image("sprites/gods/huitzilopochtli/left_attack_1.png", True) self.attacking_left_2 = load_image("sprites/gods/huitzilopochtli/left_attack_2.png", True) self.attacking_left_3 = load_image("sprites/gods/huitzilopochtli/left_attack_3.png", True) self.attacking_left_4 = load_image("sprites/gods/huitzilopochtli/left_attack_4.png", True) self.attacking_left_air = load_image("sprites/gods/huitzilopochtli/left_attack_air.png", True) self.jumping_right = load_image("sprites/gods/huitzilopochtli/right_jump.png", True) self.jumping_left = load_image("sprites/gods/huitzilopochtli/left_jump.png", True) self.invoking = load_image("sprites/gods/huitzilopochtli/invoke.png", True) self.covered = load_image("sprites/gods/huitzilopochtli/cover.png", True) self.died = load_image("sprites/gods/huitzilopochtli/die.png", True) self.stunned = load_image("sprites/gods/huitzilopochtli/die.png", True) self.damaged = load_image("sprites/gods/huitzilopochtli/damaged.png", True) #Super class attributes super(Huitzilopochtli, self).__init__(x, y, space)
class Ehecatl(God): def __init__(self, x, y, space): #Ehecatl attributes self.wind = SFX(pygame.mixer.Sound("audio/sfx/gods/ehecatl/wind.wav")) self.idle = load_image("sprites/gods/ehecatl/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/ehecatl/invoked_1.png", True), load_image("sprites/gods/ehecatl/invoked_2.png", True), load_image("sprites/gods/ehecatl/invoked_3.png", True), load_image("sprites/gods/ehecatl/invoked_4.png", True), load_image("sprites/gods/ehecatl/invoked_5.png", True),], 3) self.tornado = Animate([ load_image("sprites/gods/ehecatl/tornado_1.png", True), load_image("sprites/gods/ehecatl/tornado_2.png", True), load_image("sprites/gods/ehecatl/tornado_3.png", True), load_image("sprites/gods/ehecatl/tornado_4.png", True), load_image("sprites/gods/ehecatl/tornado_5.png", True), load_image("sprites/gods/ehecatl/tornado_6.png", True),], 2.5) #Super class attributes super(Ehecatl, self).__init__(x, y, space) def update(self, invoker, enemies): #Super class actions super(Ehecatl, self).update(invoker, enemies) #Ehecatl actions if self.on_action == True: if self.health > 0: if self.wind.is_playing() == False: self.wind.get_sfx().play() self.tornado.play() self.image = self.tornado.get_current_image() #Tornado animation #Make invoker jump longer invoker.gravity = 0.8 #Ehecatl will always attack self.on_sub_action = True self.rect.centerx = invoker.rect.centerx - 20 self.rect.bottom = invoker.rect.bottom + 1 if self.sub_action_duration > 0: for enemy in enemies: if abs(enemy.rect.centerx - self.rect.centerx) < 250: self.sub_action_target = enemy self.sub_action_duration -= 1 else: self.sub_action_duration = 10 self.health -= 1 else: self.wind.get_sfx().fadeout(100) self.on_sub_action = False self.on_action = False self.image = self.none invoker.gravity = 1.3
def __init__(self, x, y, space): #SFX self.asteroid_sound = SFX(pygame.mixer.Sound("audio/sfx/gods/xiuhtecuhtli/fireball_1.wav")) self.asteroid_explosion = SFX(pygame.mixer.Sound("audio/sfx/gods/xiuhtecuhtli/explosion_1.wav")) #Sprites self.idle = load_image("sprites/gods/xiuhtecuhtli/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/xiuhtecuhtli/invoked_1.png", True), load_image("sprites/gods/xiuhtecuhtli/invoked_2.png", True), load_image("sprites/gods/xiuhtecuhtli/invoked_3.png", True), load_image("sprites/gods/xiuhtecuhtli/invoked_4.png", True), load_image("sprites/gods/xiuhtecuhtli/invoked_5.png", True), ], 2) self.asteroid_left = Animate([ load_image("sprites/gods/xiuhtecuhtli/asteroid_left_1.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_left_2.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_left_3.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_left_4.png", True), ],4) self.asteroid_right = Animate([ load_image("sprites/gods/xiuhtecuhtli/asteroid_right_1.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_right_2.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_right_3.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_right_4.png", True), ],4) self.explode = Animate([ load_image("sprites/gods/xiuhtecuhtli/explotion_1.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_2.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_3.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_4.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_5.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_6.png", True), ],4) #Super class attributes super(Xiuhtecuhtli,self).__init__(x, y, space) self.ground = self.HEIGHT - 50 self.explode_duration = 50 self.speed_x = 0 self.speed_y = 8
class Mictlantecuhtli(God): def __init__(self, x, y, space): #Mictlantecuhtli attributes self.idle = load_image("sprites/gods/mictlantecuhtli/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/mictlantecuhtli/invoked_1.png", True), load_image("sprites/gods/mictlantecuhtli/invoked_2.png", True), load_image("sprites/gods/mictlantecuhtli/invoked_3.png", True), load_image("sprites/gods/mictlantecuhtli/invoked_4.png", True), load_image("sprites/gods/mictlantecuhtli/invoked_5.png", True),], 3) self.killing = Animate([ load_image("sprites/gods/mictlantecuhtli/kill_1.png", True), load_image("sprites/gods/mictlantecuhtli/kill_2.png", True), load_image("sprites/gods/mictlantecuhtli/kill_3.png", True), load_image("sprites/gods/mictlantecuhtli/kill_4.png", True), load_image("sprites/gods/mictlantecuhtli/kill_5.png", True), ],3) #Super class attributes super(Mictlantecuhtli, self).__init__(x, y, space) def update(self, invoker, enemies): #Super class actions super(Mictlantecuhtli, self).update(invoker, enemies) #Mictlantcuhtli actions if self.on_action == True: if self.health > 0: self.killing.play() self.image = self.killing.get_current_image() self.rect.centerx = invoker.rect.centerx - 15 self.rect.centery = invoker.rect.centery + 1 if self.sub_action_duration > 0: self.sub_action_duration -= 1 else: self.sub_action_duration = 1 self.health -= 5 else: self.on_action = False invoker.health = 0 self.image = self.none
class Quetzalcoatl(God): def __init__(self, x, y, space): #Quetzalcoatl attributes self.idle = load_image("sprites/gods/quetzalcoatl/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/quetzalcoatl/invoked_1.png", True), load_image("sprites/gods/quetzalcoatl/invoked_2.png", True), load_image("sprites/gods/quetzalcoatl/invoked_3.png", True), load_image("sprites/gods/quetzalcoatl/invoked_4.png", True), load_image("sprites/gods/quetzalcoatl/invoked_5.png", True),], 2) self.healing = Animate([ load_image("sprites/gods/quetzalcoatl/heal_1.png", True), load_image("sprites/gods/quetzalcoatl/heal_2.png", True), load_image("sprites/gods/quetzalcoatl/heal_3.png", True), load_image("sprites/gods/quetzalcoatl/heal_4.png", True), load_image("sprites/gods/quetzalcoatl/heal_5.png", True), ],3) #Super class attributes super(Quetzalcoatl, self).__init__(x, y, space) def update(self, invoker, enemies): #Super class actions super(Quetzalcoatl, self).update(invoker, enemies) #Quetzalcoatl actions if self.on_action == True: if self.health > 0: self.healing.play() self.image = self.healing.get_current_image() self.rect.centerx = invoker.rect.centerx - 15 self.rect.centery = invoker.rect.centery + 1 if self.sub_action_duration > 0: self.sub_action_duration -= 1 else: self.sub_action_duration = 1 self.health -= 5 else: self.on_action = False invoker.health = 100 self.image = self.none
def __init__(self): self.image = load_image("bg/hud/codex_a.png", True) self.flame = Animate([ load_image("bg/hud/flame_1.png", True), load_image("bg/hud/flame_2.png", True), load_image("bg/hud/flame_3.png", True), load_image("bg/hud/flame_4.png", True), load_image("bg/hud/flame_5.png", True), load_image("bg/hud/flame_6.png", True), ], 2) self.rect = self.image.get_rect() self.rect.top = 10 self.flame.rect = self.flame.get_current_image().get_rect() self.health = 100 self.fuel = 0.02
def __init__(self, x, y, space): #Ehecatl attributes self.wind = SFX(pygame.mixer.Sound("audio/sfx/gods/ehecatl/wind.wav")) self.idle = load_image("sprites/gods/ehecatl/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/ehecatl/invoked_1.png", True), load_image("sprites/gods/ehecatl/invoked_2.png", True), load_image("sprites/gods/ehecatl/invoked_3.png", True), load_image("sprites/gods/ehecatl/invoked_4.png", True), load_image("sprites/gods/ehecatl/invoked_5.png", True),], 3) self.tornado = Animate([ load_image("sprites/gods/ehecatl/tornado_1.png", True), load_image("sprites/gods/ehecatl/tornado_2.png", True), load_image("sprites/gods/ehecatl/tornado_3.png", True), load_image("sprites/gods/ehecatl/tornado_4.png", True), load_image("sprites/gods/ehecatl/tornado_5.png", True), load_image("sprites/gods/ehecatl/tornado_6.png", True),], 2.5) #Super class attributes super(Ehecatl, self).__init__(x, y, space)
def __init__(self, x, y, space): #Quetzalcoatl attributes self.idle = load_image("sprites/gods/quetzalcoatl/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/quetzalcoatl/invoked_1.png", True), load_image("sprites/gods/quetzalcoatl/invoked_2.png", True), load_image("sprites/gods/quetzalcoatl/invoked_3.png", True), load_image("sprites/gods/quetzalcoatl/invoked_4.png", True), load_image("sprites/gods/quetzalcoatl/invoked_5.png", True),], 2) self.healing = Animate([ load_image("sprites/gods/quetzalcoatl/heal_1.png", True), load_image("sprites/gods/quetzalcoatl/heal_2.png", True), load_image("sprites/gods/quetzalcoatl/heal_3.png", True), load_image("sprites/gods/quetzalcoatl/heal_4.png", True), load_image("sprites/gods/quetzalcoatl/heal_5.png", True), ],3) #Super class attributes super(Quetzalcoatl, self).__init__(x, y, space)
def __init__(self, x, y, space): #Mictlantecuhtli attributes self.idle = load_image("sprites/gods/mictlantecuhtli/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/mictlantecuhtli/invoked_1.png", True), load_image("sprites/gods/mictlantecuhtli/invoked_2.png", True), load_image("sprites/gods/mictlantecuhtli/invoked_3.png", True), load_image("sprites/gods/mictlantecuhtli/invoked_4.png", True), load_image("sprites/gods/mictlantecuhtli/invoked_5.png", True),], 3) self.killing = Animate([ load_image("sprites/gods/mictlantecuhtli/kill_1.png", True), load_image("sprites/gods/mictlantecuhtli/kill_2.png", True), load_image("sprites/gods/mictlantecuhtli/kill_3.png", True), load_image("sprites/gods/mictlantecuhtli/kill_4.png", True), load_image("sprites/gods/mictlantecuhtli/kill_5.png", True), ],3) #Super class attributes super(Mictlantecuhtli, self).__init__(x, y, space)
class Codex(pygame.sprite.Sprite): def __init__(self): self.image = load_image("bg/hud/codex_a.png", True) self.flame = Animate([ load_image("bg/hud/flame_1.png", True), load_image("bg/hud/flame_2.png", True), load_image("bg/hud/flame_3.png", True), load_image("bg/hud/flame_4.png", True), load_image("bg/hud/flame_5.png", True), load_image("bg/hud/flame_6.png", True), ], 2) self.rect = self.image.get_rect() self.rect.top = 10 self.flame.rect = self.flame.get_current_image().get_rect() self.health = 100 self.fuel = 0.02 def update(self): if self.health > 0: self.health -= self.fuel
class NahuiTochtli(pygame.sprite.Sprite): def __init__(self, x, y, space): pygame.sprite.Sprite.__init__(self) #SFX self.step = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/step.wav"), 4) self.hit = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/hit.wav")) self.swoosh_1 = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/swoosh_1.wav")) self.swoosh_2 = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/swoosh_2.wav")) self.swoosh_3 = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/swoosh_3.wav")) self.swoosh_4 = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/swoosh_4.wav")) #Sprites self.breathing_right = Animate([ load_image("sprites/nahuitochtli/Nahui_right_breath_1.png", True), load_image("sprites/nahuitochtli/Nahui_right_breath_1.png", True), load_image("sprites/nahuitochtli/Nahui_right_breath_2.png", True) ], 0.4) self.breathing_left = Animate([ load_image("sprites/nahuitochtli/Nahui_left_breath_1.png", True), load_image("sprites/nahuitochtli/Nahui_left_breath_1.png", True), load_image("sprites/nahuitochtli/Nahui_left_breath_2.png", True) ], 0.4) self.looking_right = Animate([ load_image("sprites/nahuitochtli/Nahui_right_walk_1.png", True), load_image("sprites/nahuitochtli/Nahui_right_walk_2.png", True), load_image("sprites/nahuitochtli/Nahui_right_walk_3.png", True), ], 2) self.looking_left = Animate([ load_image("sprites/nahuitochtli/Nahui_left_walk_1.png", True), load_image("sprites/nahuitochtli/Nahui_left_walk_2.png", True), load_image("sprites/nahuitochtli/Nahui_left_walk_3.png", True), ], 2) self.invoking = load_image("sprites/nahuitochtli/Nahui_invoke.png", True) self.attacking_left_1 = load_image("sprites/nahuitochtli/Nahui_left_attack_1.png", True) self.attacking_right_1 = load_image("sprites/nahuitochtli/Nahui_right_attack_1.png", True) self.attacking_left_2 = load_image("sprites/nahuitochtli/Nahui_left_attack_2.png", True) self.attacking_right_2 = load_image("sprites/nahuitochtli/Nahui_right_attack_2.png", True) self.attacking_left_3 = load_image("sprites/nahuitochtli/Nahui_left_attack_3.png", True) self.attacking_right_3 = load_image("sprites/nahuitochtli/Nahui_right_attack_3.png", True) self.attacking_left_4 = load_image("sprites/nahuitochtli/Nahui_left_attack_4.png", True) self.attacking_right_4 = load_image("sprites/nahuitochtli/Nahui_right_attack_4.png", True) self.attacking_air_right = load_image("sprites/nahuitochtli/Nahui_right_attack_air.png", True) self.attacking_air_left = load_image("sprites/nahuitochtli/Nahui_left_attack_air.png", True) self.jumping_right = load_image("sprites/nahuitochtli/Nahui_right_jump.png", True) self.jumping_left = load_image("sprites/nahuitochtli/Nahui_left_jump.png", True) self.covered = load_image("sprites/nahuitochtli/Nahui_cover.png", True) self.damaged = Animate([ load_image("sprites/nahuitochtli/Nahui_damaged_1.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_2.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_3.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_4.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_5.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_6.png", True), ], 10) self.cover_damaged = Animate([ load_image("sprites/nahuitochtli/Nahui_cover_damaged_1.png", True), load_image("sprites/nahuitochtli/Nahui_cover_damaged_2.png", True), ], 2) self.died = load_image("sprites/nahuitochtli/Nahui_die.png", True) self.stunned = load_image("sprites/nahuitochtli/Nahui_die.png", True) #Position and space self.WIDTH = space[0] self.HEIGHT = space[1] self.image = self.breathing_right.get_current_image() self.rect = self.image.get_rect() self.rect.bottom = y self.rect.centerx = x #Environment self.gravity = 1.3 self.speed_x = 0.5 self.speed_taken = 0 self.elasticity = -0.4 #Status self.look_left = False self.on_stun = False self.look_right = True self.on_invoke = False self.on_air = False self.on_attack = False self.on_damage = False self.on_cover = False self.on_cover_damage = False self.on_move = False self.on_breath = True self.ready2jump = True self.ready2attack = True self.ready2invoke = True self.combo_attack = 0 #Attributes self.power = 6 self.health = 100 self.resistance = 0.55 def move(self,time,key): if self.health > 0 and self.on_damage == False and self.on_cover == False and self.on_invoke == False and self.on_stun == False: if self.on_attack == False: #Up if self.rect.bottom>(self.HEIGHT - 70): if key[K_UP]: self.on_move = True if self.look_right == True: self.looking_right.play() self.image = self.looking_right.get_current_image() elif self.look_left == True: self.looking_left.play() self.image = self.looking_left.get_current_image() self.rect.centery -= self.speed_x * time #Down if self.rect.bottom<self.HEIGHT: if key[K_DOWN]: self.on_move = True if self.look_right == True: self.looking_right.play() self.image = self.looking_right.get_current_image() elif self.look_left == True: self.looking_left.play() self.image = self.looking_left.get_current_image() self.rect.centery += self.speed_x * time #Right if self.rect.right<self.WIDTH: if key[K_RIGHT]: self.look_left = False self.look_right = True if self.on_air == True: self.image = self.jumping_right else: self.on_move = True #Animation self.looking_right.play() self.image = self.looking_right.get_current_image() self.rect.centerx += self.speed_x * time #Left if self.rect.left>0: if key[K_LEFT]: self.look_left = True self.look_right = False if self.on_air == True: self.image = self.jumping_left else: self.on_move = True self.looking_left.play() self.image = self.looking_left.get_current_image() self.rect.centerx -= self.speed_x * time #Jump if self.ready2jump == True: if self.on_air == False: if key[K_SPACE]: self.on_air = True self.ready2jump = False if self.look_right == True: self.image = self.jumping_right elif self.look_left == True: self.image = self.jumping_left self.ground = self.rect.centery self.speed_taken = 0 self.speed_y = -20 #Cover / Invoke if self.on_air == False: if key[K_RSHIFT]: self.image = self.covered self.on_cover = True #Attack if self.ready2attack == True and self.combo_attack < 4: if key[K_RCTRL]: self.ready2attack = False self.on_cover = False if self.on_air == False: #Combo 1 if self.combo_attack == 0: self.combo_attack = 1 #SFX swoosh 2 self.swoosh_2.get_sfx().play() if self.look_right == True: self.image = self.attacking_right_1 elif self.look_left == True: self.image = self.attacking_left_1 #Combo 2 elif self.combo_attack == 1: self.combo_attack = 2 if self.look_right == True: self.image = self.attacking_right_2 elif self.look_left == True: self.image = self.attacking_left_2 #Combo 3 elif self.combo_attack == 2: self.combo_attack = 3 if self.look_right == True: self.image = self.attacking_right_3 elif self.look_left == True: self.image = self.attacking_left_3 #Combo 4 elif self.combo_attack == 3: self.combo_attack = 4 self.power = 11 #SFX swoosh 4 self.swoosh_4.get_sfx().play() if self.look_right == True: self.image = self.attacking_right_4 elif self.look_left == True: self.image = self.attacking_left_4 else: #SFX swoosh self.swoosh_3.get_sfx().play() if self.look_right == True: self.image = self.attacking_air_right elif self.look_left == True: self.image = self.attacking_air_left self.attack_duration = 20 self.on_attack = True def invoke(self, god): if self.ready2invoke == True: self.power += (god.power / 2) self.on_invoke = True self.invoke_duration = 60 self.image = self.invoking self.ready2invoke = False def hitBy(self, enemy): if self.health > 0 and self.on_air == False and self.on_damage == False and self.on_invoke == False and self.on_stun == False and self.on_cover_damage == False: self.speed_y = 0 self.damaged.play() if self.on_air == False: self.ground = self.rect.centery if enemy.look_right == True: self.look_right = True self.look_left = False if enemy.look_left == True: self.look_right = False self.look_left = True if self.on_cover == False: #Non blocked hit self.image = self.damaged.get_current_image() self.health -= enemy.power - (enemy.power * self.resistance) self.on_damage = True self.speed_taken = (enemy.power) - (enemy.power * self.resistance) self.speed_y = -1 * (enemy.power) self.on_air = True if self.on_cover == True: #Blocked hit self.speed_taken = enemy.power - (enemy.power * self.resistance + 0.2) self.health -= (enemy.power - (enemy.power * self.resistance + 0.2)) self.on_cover_damage = True self.cover_damage_duration = 30 self.on_air = False if enemy.power - (enemy.power * self.resistance) >= 8: #Stun hit self.image = self.stunned self.ground = self.rect.bottom - 30 self.speed_taken = enemy.power * 2.3 self.stun_duration = enemy.power * 10 self.speed_taken = (enemy.power * 2) - (enemy.power * self.resistance) self.speed_y = -1 * (enemy.power * 2) self.on_damage = False self.on_stun = True self.on_air = True if self.health <= 0: #Dead character self.image = self.died self.ground = self.rect.centery self.speed_taken = enemy.power * 2.3 self.speed_y = -1 * enemy.power * 2.3 self.on_damage = False self.on_air = True def update(self, rel_key): #Force death when health reaches 0 if self.health <= 0: self.image = self.died self.on_attack = False else: #Breath when static if self.on_move == False: if self.on_attack == False: if self.on_air == False: if self.on_damage == False: if self.on_cover == False: if self.look_right == True: self.breathing_right.play() self.image = self.breathing_right.get_current_image() else: self.breathing_left.play() self.image = self.breathing_left.get_current_image() #Released keys if rel_key == K_UP or rel_key == K_DOWN or rel_key == K_RIGHT or rel_key == K_LEFT: self.on_move = False if self.health > 0: if rel_key == K_SPACE: self.ready2jump = True if rel_key == K_RCTRL: self.ready2attack = True if rel_key == K_RSHIFT: if self.on_invoke == False: self.on_cover = False if self.look_left == True: self.image = self.looking_left.get_current_image() else: self.image = self.looking_right.get_current_image() #On invoke if self.on_invoke == True: if self.invoke_duration > 0: self.invoke_duration -= 1 else: #Reset values after invoke self.on_cover = False self.on_invoke = False if self.look_left == True: self.image = self.looking_left.get_current_image() else: self.image = self.looking_right.get_current_image() self.power = 6 self.ready2invoke = True #On attack if self.on_attack == True: if self.attack_duration > 0: self.attack_duration -= 1 else: if self.look_left == True: self.image = self.looking_left.get_current_image() else: self.image = self.looking_right.get_current_image() self.combo_attack = 0 self.power = 6 self.on_attack = False #On air if self.on_air == True: if self.rect.centery + self.speed_y < self.ground: self.rect.centery += self.speed_y self.speed_y += self.gravity if self.look_right == True and self.rect.right < self.WIDTH: self.rect.centerx += self.speed_taken elif self.look_left == True and self.rect.left > 0: self.rect.centerx -= self.speed_taken else: if self.health <= 0 or self.on_stun == True: if self.speed_y > 11: self.speed_y *= self.elasticity else: if self.on_damage == True: self.on_damage = False #if self.on_cover == True: #self.on_cover = True self.rect.centery = self.ground self.on_air = False #On cover_damage if self.on_cover_damage == True: self.cover_damaged.play() if self.cover_damage_duration > 0: self.image = self.cover_damaged.get_current_image() self.cover_damage_duration -= 1 if self.look_right == True and self.rect.right < self.WIDTH: self.rect.centerx += self.speed_taken elif self.look_left == True and self.rect.left > 0: self.rect.centerx -= self.speed_taken else: if self.on_cover == True: self.image = self.covered else: if self.look_right == True: self.image = self.looking_right.get_current_image() elif self.look_left == True: self.image = self.looking_left.get_current_image() self.on_cover_damage = False #On stun if self.on_stun == True: if self.stun_duration > 0: self.stun_duration -= 1 else: self.ground = self.rect.top + 30 self.on_stun = False if self.look_left == True: self.image = self.looking_left.get_current_image() else: self.image = self.looking_right.get_current_image()
dx = 0.02 x_length = N * dx x = np.linspace(0, x_length, N) x1 = x[int(N / 4)] x2 = x[int(3 * N / 4)] # Defining Psi and V k_initial = 4 psi_x = two_gauss(x, x1, x2, k_initial, -k_initial, d=1) V_x = np.zeros(N) # Defining K range dk = dx / (2 * np.pi) k = fftfreq(N, dk) ks = fftshift(k) # Defining time steps t = 0 dt = 0.01 step = 2 sch = Schrodinger(x, psi_x, V_x, k) # plt.plot(sch.x, sch.mod_square_x(True)) # plt.show() a = Animate(sch, V_x, step, dt, lim1=((0, x_length), (0, max(np.real(psi_x)+0.2))), lim2=((-2*k_initial, 2*k_initial), (0, abs(max(sch.psi_k)))), title='Two Packet Interferance') a.make_fig()
dt = 10**-7 dk = 2 * np.pi / (N * dx) k_lim = np.pi / dx k1 = -k_lim + (dk) * np.arange(N) # x = np.array([i * dx for i in range(N)]) x = np.arange(-lim, lim, dx) x0 = -1 * 10**-5 x1 = x[int(N / 2)] x2 = x1 + Len sig = 1 * 10**-6 k0 = 5 * 10**6 E = (hbar**2 / 2 * m) * (k0**2 + 1 / (4 * sig**2)) print(E) Psi_x = gauss_init(x, k0, x0=x0, d=sig) V_x = barrier(x, 10**-30, x1, x2) sch = Schrodinger(x, Psi_x, V_x, hbar=hbar, m=m, args=x1) # plt.plot(x, sch.psi_squared) plt.plot(x, V_x) plt.show() a = Animate(sch, V_x, 1000, dt, lim1=((-lim, lim), (0, max(sch.psi_squared)))) a.make_fig()
# Defining Psi and V k_initial = 10 psi_x = gauss_init(x, k_initial, x0, d=d) V_x = np.zeros(N) for n, v in enumerate(V_x): if n > round(0.4 * N) and n < round(0.41 * N): V_x[n] = 1E100 # Defining K range dk = dx / (2 * np.pi) k = fftfreq(N, dk) ks = fftshift(k) # Defining time steps t = 0 dt = 0.01 step = 2 sch = Schrodinger(x, psi_x, V_x, k) a = Animate(sch, V_x, step, dt, lim1=((0, x_length), (0, max(psi_x))), lim2=((ks[0], ks[N - 1]), (0, 30)), title='Tunneling') a.make_fig()
# Barrier Definitions A = 1 x1 = int(0.5 * N) * dx W = 1 sig = 0.1 mu = 1 args = (A, W, x1, sig, mu) k0 = 4 x0 = x[int(N / 4)] sig = 4 k_init = 5 Psi_x = gauss_init(x, k0, x0=x0, d=sig) sch = Schrodinger(x, Psi_x, noisyBarrier, hbar=hbar, m=m, args=args) print("Width :", sig) print(sch.x_width()) # print(sch.impedence()) dt = 0.001 step = 100 finalt = 40 c = Constants(A, dt, dx, k0) a = Animate(sch, noisyBarrier, step, dt) a.make_fig()
class Data: animate = Animate() def __init__(self): self.data = {} self.training_X = None self.training_Y = np.zeros((1, 10)) self.test_X = None self.test_Y = np.zeros((1, 10)) self.read() def read(self): if os.path.isfile("./data.pkl"): with open('data.pkl', 'rb') as file: Data.animate.start("loading data...") self.data = pickle.load(file) Data.animate.end() return # extracting from zip if not os.path.isdir("./trainingSet"): Data.animate.start("extracting from zip...") tf = tarfile.open("./trainingSet.tar.gz") tf.extractall() Data.animate.end() Data.animate.start("reading all files...") for num in range(10): path = "%s/trainingSet/%d/*.jpg"%(dir_path, num) file_paths = glob.glob(path) print("digit: %d ... files: %d"%(num, len(file_paths))) # x = np.zeros((500, 784)) x = np.zeros((len(file_paths), 784)) # for ind, file in enumerate(file_paths[:500]): for ind, file in enumerate(file_paths): image = plt.imread(file_paths[0]) image = image.reshape(1, -1) # image = image/255 x[ind:] = image self.data[num] = x Data.animate.end() Data.animate.start("writing into data.pkl...") with open('data.pkl', 'wb') as file: pickle.dump(self.data, file, protocol = pickle.HIGHEST_PROTOCOL) Data.animate.end() def split(self, ratio = 0.1): training = {} test = {} Data.animate.start("splitting data...") for y, x in self.data.items(): np.random.shuffle(x) num_files = x.shape[0] test_size = int(num_files * (1 - ratio)) training[y] = x[:test_size] test[y] = x[test_size:] self.training_X = np.vstack((training[y] for y in training.keys())) self.test_X = np.vstack((test[y] for y in test.keys())) for y in training.keys(): tmp = np.zeros((1, 10)) tmp[0][y] = 1 for i in range(training[y].shape[0]): self.training_Y = np.vstack((self.training_Y, tmp)) for y in test.keys(): tmp = np.zeros((1, 10)) tmp[0][y] = 1 for i in range(test[y].shape[0]): self.test_Y = np.vstack((self.test_Y, tmp)) self.training_Y = self.training_Y[1:] self.test_Y = self.test_Y[1:] self.training_Y = self.training_Y.T self.test_Y = self.test_Y.T Data.animate.end() print("\ntraining_X: ", self.training_X.shape) print("training_Y: ", self.training_Y.shape) print("test_X: ", self.test_X.shape) print("test_Y: ", self.test_Y.shape) return self.training_X, self.training_Y, self.test_X, self.test_Y
sch = Schrodinger(x, psi_x, V_x, k, hbar=hbar, m=m, t=t) # print("Numerical Energy :", sch.energy()) # print("Theoretical Energy", (hbar ** 2 * k_initial ** 2) / (2 * m)) # # print("Difference :", sch.energy() - (hbar ** 2 * k_initial ** 2) / (2 * m)) # plt.plot(x, sch.mod_square_x(True)) # plt.plot(x, V_x) # plt.ylim(0, max(np.real(psi_x))) # plt.show() print("here") # a = Animate(sch, V_x, step, dt, lim1=((-x_length / 4, x_length / 4), (-0.1, 0.5)), # lim2=((ks[0], ks[N - 1]), (0, 1)), title="GB_a=10", frames=Ns) a = Animate(sch, V_x, step, dt, lim1=((-x_length / 4, x_length / 4), (-0.1, 0.5)), lim2=((ks[0], ks[N - 1]), (0, 1)), frames=Ns) a.make_fig() # a_list = np.arange(1, 10, 2) # a_list=[10,0.1] # for i in a_list: # print(i) # dat = run(i) # np.savetxt("GBox_{}.txt".format(i), dat) # v0 = V_x = gaussbox(x, w, L, x0=xb, A=1000, a=0) # v1 = V_x = gaussbox(x, w, L, x0=xb, A=1000, a=1) # # plt.plot(x, v0) # plt.title("Gaussian Barrier a=0")
class Application: def __init__(self): pygame.init() #Graphical parameters self.width = 800 self.height = 600 #Application surface self.main_surface = pygame.display.set_mode((self.width, self.height)) #Creating the maze self.maze = Maze(MAZE_SIZE, MAZE_SIZE) self.maze.generateAtRandom2() #Creating the player self.human = Player(self.maze) self.opponent = Player(self.maze) #Create the camera. #The camera width and height defines the size of the image #that the camera gives. cameraWitdh = self.width cameraHeight = self.height self.camera = Camera(cameraWitdh, cameraHeight, 100, self.maze, self.human, self.opponent) #Create the starting animation self.zoom_animate = Animate(200, 10, 5.0) self.camera.add_animation(self.zoom_animate) #Defines the period that is used to send a keydown event when a key #is kept down. pygame.key.set_repeat(200, 150) #We ask the player if they want to play on the network self.multiplayer = self.ask_multiplayer() if self.multiplayer: #We ask if this is the server is_serveur = raw_input('<S>erveur or <C>lient?') if str(is_serveur).upper() == 'S': HOST = socket.gethostname() PORT = 3000 self.start_server(HOST, PORT) #Sending the maze to the other player print("Sending game data... Please wait.") encoded_maze = jsonpickle.encode(self.maze) print("Size of data is " + str(sys.getsizeof(encoded_maze)/1000) + "k.") self.connection.send(encoded_maze) #Creation des deux joueurs self.human = PlayerReseau(self.maze, self.connection) self.opponent = OpponentReseau(self.maze, self.connection) self.opponent.start() elif ask_multiplayer == 'C': HOST = input('Host?') PORT = 3000 self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.connection.connect((HOST, PORT)) except socket.error: print("Connection has failed.") sys.exit() print("Connection has been established with the server.") #Receiving the maze msg = self.connection.recv(200*1024) self.maze = jsonpickle.decode(msg) self.human = PlayerReseau(self.maze, self.connection) self.opponent = OpponentReseau(self.maze, self.connection) self.opponent.start() # self.human = Player(self.maze); #Start the main loop self.main_loop() def ask_multiplayer(self): s = input('Partie réseau?(Y/N)').upper() return s == 'Y' def start_server(self, host, port): """This function starts the server, by create a socket, listening and then accepting connections.""" print('Adresse serveur: ' + HOST + ", PORT " + str(PORT)) mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: mySocket.bind((HOST, PORT)) except socket.error: print("Connection failed.") sys.exit() print("Server is ready") mySocket.listen(1) connection, address = mySocket.accept() return connection def main_loop(self): #We start a zoom animation for the camera. self.zoom_animate.start_animation() while True: #Gestion des évènements for evt in pygame.event.get(): self.handle_event(evt) #Màj de l'affichage #Get the maze drawing self.camera.updateCamera() maze_surface = self.camera.getCameraView() self.main_surface.blit(maze_surface, (0,0)) pygame.display.update() def handle_event(self, event): if event.type == pygame.QUIT: self.connection.close() pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if self.human is not None: if event.key == pygame.K_RIGHT: self.human.move('E') elif event.key == pygame.K_DOWN: self.human.move('S') elif event.key == pygame.K_LEFT: self.human.move('O') elif event.key == pygame.K_UP: self.human.move('N') if event.key == pygame.K_s: self.camera.setShowSolution(True)
def __init__(self): pygame.init() #Graphical parameters self.width = 800 self.height = 600 #Application surface self.main_surface = pygame.display.set_mode((self.width, self.height)) #Creating the maze self.maze = Maze(MAZE_SIZE, MAZE_SIZE) self.maze.generateAtRandom2() #Creating the player self.human = Player(self.maze) self.opponent = Player(self.maze) #Create the camera. #The camera width and height defines the size of the image #that the camera gives. cameraWitdh = self.width cameraHeight = self.height self.camera = Camera(cameraWitdh, cameraHeight, 100, self.maze, self.human, self.opponent) #Create the starting animation self.zoom_animate = Animate(200, 10, 5.0) self.camera.add_animation(self.zoom_animate) #Defines the period that is used to send a keydown event when a key #is kept down. pygame.key.set_repeat(200, 150) #We ask the player if they want to play on the network self.multiplayer = self.ask_multiplayer() if self.multiplayer: #We ask if this is the server is_serveur = raw_input('<S>erveur or <C>lient?') if str(is_serveur).upper() == 'S': HOST = socket.gethostname() PORT = 3000 self.start_server(HOST, PORT) #Sending the maze to the other player print("Sending game data... Please wait.") encoded_maze = jsonpickle.encode(self.maze) print("Size of data is " + str(sys.getsizeof(encoded_maze)/1000) + "k.") self.connection.send(encoded_maze) #Creation des deux joueurs self.human = PlayerReseau(self.maze, self.connection) self.opponent = OpponentReseau(self.maze, self.connection) self.opponent.start() elif ask_multiplayer == 'C': HOST = input('Host?') PORT = 3000 self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.connection.connect((HOST, PORT)) except socket.error: print("Connection has failed.") sys.exit() print("Connection has been established with the server.") #Receiving the maze msg = self.connection.recv(200*1024) self.maze = jsonpickle.decode(msg) self.human = PlayerReseau(self.maze, self.connection) self.opponent = OpponentReseau(self.maze, self.connection) self.opponent.start() # self.human = Player(self.maze); #Start the main loop self.main_loop()
hbar = 1 m = 1 omega = 0.01 sigma = np.sqrt(hbar / (2 * m * omega)) # Defining Wavefunction psi = wave_init(x, sigma, x0-50) V_x = harmonic_potential(x, m, omega, x0) #V_x = np.zeros(N) # Defining k dk = dx / (2 * np.pi) k = fftfreq(N, dk) ks = fftshift(k) # Defining time steps t = 0 dt = 5 step = 1 sch = Schrodinger(x, psi, V_x, k, hbar, m, t) print(sch.norm_x()) x_limits = ((x[0],x[N-1]), (0, 0.16)) k_limits = ((-5, 5), (0, max(abs(sch.psi_k)+0.5))) a = Animate(sch, V_x, step, dt, lim1=x_limits, lim2=k_limitsq) a.make_fig()
class Huitzilopochtli(God): def __init__(self, x, y, space): #Huitzilopochtli attributes self.idle = load_image("sprites/gods/huitzilopochtli/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/huitzilopochtli/invoked_1.png", True), load_image("sprites/gods/huitzilopochtli/invoked_2.png", True), load_image("sprites/gods/huitzilopochtli/invoked_3.png", True), load_image("sprites/gods/huitzilopochtli/invoked_4.png", True), load_image("sprites/gods/huitzilopochtli/invoked_5.png", True),], 2) self.breathing_right = Animate([ load_image("sprites/gods/huitzilopochtli/right_breath_1.png", True), load_image("sprites/gods/huitzilopochtli/right_breath_1.png", True), load_image("sprites/gods/huitzilopochtli/right_breath_2.png", True) ], 0.4) self.breathing_left = Animate([ load_image("sprites/gods/huitzilopochtli/left_breath_1.png", True), load_image("sprites/gods/huitzilopochtli/left_breath_1.png", True), load_image("sprites/gods/huitzilopochtli/left_breath_2.png", True), ], 0.4) self.looking_right = Animate([ load_image("sprites/gods/huitzilopochtli/right_walk_1.png", True), load_image("sprites/gods/huitzilopochtli/right_walk_2.png", True), load_image("sprites/gods/huitzilopochtli/right_walk_3.png", True), load_image("sprites/gods/huitzilopochtli/right_walk_2.png", True), ], 2) self.looking_left = Animate([ load_image("sprites/gods/huitzilopochtli/left_walk_1.png", True), load_image("sprites/gods/huitzilopochtli/left_walk_2.png", True), load_image("sprites/gods/huitzilopochtli/left_walk_3.png", True), load_image("sprites/gods/huitzilopochtli/left_walk_2.png", True), ], 2) self.attacking_right_1 = load_image("sprites/gods/huitzilopochtli/right_attack_1.png", True) self.attacking_right_2 = load_image("sprites/gods/huitzilopochtli/right_attack_2.png", True) self.attacking_right_3 = load_image("sprites/gods/huitzilopochtli/right_attack_3.png", True) self.attacking_right_4 = load_image("sprites/gods/huitzilopochtli/right_attack_4.png", True) self.attacking_right_air = load_image("sprites/gods/huitzilopochtli/right_attack_air.png", True) self.attacking_left_1 = load_image("sprites/gods/huitzilopochtli/left_attack_1.png", True) self.attacking_left_2 = load_image("sprites/gods/huitzilopochtli/left_attack_2.png", True) self.attacking_left_3 = load_image("sprites/gods/huitzilopochtli/left_attack_3.png", True) self.attacking_left_4 = load_image("sprites/gods/huitzilopochtli/left_attack_4.png", True) self.attacking_left_air = load_image("sprites/gods/huitzilopochtli/left_attack_air.png", True) self.jumping_right = load_image("sprites/gods/huitzilopochtli/right_jump.png", True) self.jumping_left = load_image("sprites/gods/huitzilopochtli/left_jump.png", True) self.invoking = load_image("sprites/gods/huitzilopochtli/invoke.png", True) self.covered = load_image("sprites/gods/huitzilopochtli/cover.png", True) self.died = load_image("sprites/gods/huitzilopochtli/die.png", True) self.stunned = load_image("sprites/gods/huitzilopochtli/die.png", True) self.damaged = load_image("sprites/gods/huitzilopochtli/damaged.png", True) #Super class attributes super(Huitzilopochtli, self).__init__(x, y, space) def update(self, invoker, enemies): #Super class actions super(Huitzilopochtli, self).update(invoker, enemies) #Huitzilopotchtli actions if self.on_action == True: invoker.power = 10 invoker.resistance = 0.85 if self.health > 0: self.rect.centerx = invoker.rect.centerx self.rect.centery = invoker.rect.centery #Huitzilopochtli copies invoker moves #Invoker actions #Force death when health reaches 0 if invoker.health <= 0: invoker.image = self.died else: #Breath when static if invoker.on_move == False: if invoker.on_attack == False: if invoker.on_air == False: if invoker.on_damage == False: if invoker.on_cover == False: if invoker.look_right == True: self.breathing_right.play() invoker.image = self.breathing_right.get_current_image() else: self.breathing_left.play() invoker.image = self.breathing_left.get_current_image() #Moving right or left if invoker.on_move == True: if invoker.look_right == True: self.looking_right.play() invoker.image = self.looking_right.get_current_image() else: self.looking_left.play() invoker.image = self.looking_left.get_current_image() #Jumping if invoker.on_air == True and invoker.health > 0: if invoker.on_damage == False and invoker.on_stun == False: if invoker.look_right == True: invoker.image = self.jumping_right elif invoker.look_left == True: invoker.image = self.jumping_left #Attacking if invoker.on_attack == True: #Right if invoker.look_right == True: if invoker.combo_attack == 1: invoker.image = self.attacking_right_1 if invoker.combo_attack == 2: invoker.image = self.attacking_right_2 if invoker.combo_attack == 3: invoker.image = self.attacking_right_3 if invoker.combo_attack == 4: invoker.power = 12 invoker.image = self.attacking_right_4 if invoker.on_air == True: invoker.image = self.attacking_right_air #Left if invoker.look_left == True: if invoker.combo_attack == 1: invoker.image = self.attacking_left_1 if invoker.combo_attack == 2: invoker.image = self.attacking_left_2 if invoker.combo_attack == 3: invoker.image = self.attacking_left_3 if invoker.combo_attack == 4: invoker.power = 12 invoker.image = self.attacking_left_4 if invoker.on_air == True: invoker.image = self.attacking_left_air #Damaged or Stunned if invoker.on_damage == True: invoker.image = self.damaged if invoker.on_stun == True: invoker.image = self.stunned #Covered or Invoking if invoker.on_invoke == True: invoker.image = self.invoking if invoker.on_cover == True: invoker.image = self.covered if self.sub_action_duration > 0: self.sub_action_duration -= 1 else: self.sub_action_duration = 10 self.health -= 1 else: self.on_action = False invoker.power = 6 invoker.resistance = 0.55 self.image = self.none
class Xiuhtecuhtli(God): def __init__(self, x, y, space): #SFX self.asteroid_sound = SFX(pygame.mixer.Sound("audio/sfx/gods/xiuhtecuhtli/fireball_1.wav")) self.asteroid_explosion = SFX(pygame.mixer.Sound("audio/sfx/gods/xiuhtecuhtli/explosion_1.wav")) #Sprites self.idle = load_image("sprites/gods/xiuhtecuhtli/idle.png", True) self.being_invoked = Animate([ load_image("sprites/gods/xiuhtecuhtli/invoked_1.png", True), load_image("sprites/gods/xiuhtecuhtli/invoked_2.png", True), load_image("sprites/gods/xiuhtecuhtli/invoked_3.png", True), load_image("sprites/gods/xiuhtecuhtli/invoked_4.png", True), load_image("sprites/gods/xiuhtecuhtli/invoked_5.png", True), ], 2) self.asteroid_left = Animate([ load_image("sprites/gods/xiuhtecuhtli/asteroid_left_1.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_left_2.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_left_3.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_left_4.png", True), ],4) self.asteroid_right = Animate([ load_image("sprites/gods/xiuhtecuhtli/asteroid_right_1.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_right_2.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_right_3.png", True), load_image("sprites/gods/xiuhtecuhtli/asteroid_right_4.png", True), ],4) self.explode = Animate([ load_image("sprites/gods/xiuhtecuhtli/explotion_1.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_2.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_3.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_4.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_5.png", True), load_image("sprites/gods/xiuhtecuhtli/explotion_6.png", True), ],4) #Super class attributes super(Xiuhtecuhtli,self).__init__(x, y, space) self.ground = self.HEIGHT - 50 self.explode_duration = 50 self.speed_x = 0 self.speed_y = 8 def update(self, invoker, enemies): #Super class actions super(Xiuhtecuhtli, self).update(invoker, enemies) #Xiuhtecuhtli actions if self.on_action == True: if self.health > 0: #Reload if self.reload_time > 0: self.image = self.none #Hidden while reloading self.reload_time -= 1 #Attack else: #Continue to attack if self.on_sub_action == True: self.asteroid_sound.get_sfx().play() #Verify direction if self.speed_x <= 0: self.asteroid_left.play() self.image = self.asteroid_left.get_current_image() else: self.asteroid_right.play() self.image = self.asteroid_right.get_current_image() #Line equation while falling: m = y/x if self.rect.bottom < self.ground: self.rect.centerx += self.speed_x self.rect.bottom += self.speed_y #Explode else: self.asteroid_explosion.get_sfx().play() self.asteroid_sound.get_sfx().stop() self.asteroid_left.stop() self.asteroid_right.stop() self.explode.play() if self.explode_duration > 0: for enemy in enemies: if abs(enemy.rect.centerx - self.rect.centerx) < 400: self.sub_action_target = enemy self.image = self.explode.get_current_image() self.explode_duration -= 1 else: self.on_sub_action = False #Prepare new attack else: i = 0 while i < len(enemies): #Select enemy randomly rdm = random.randint(0, len(enemies)-1) if enemies[rdm].health > 0 and enemies[rdm].on_stun == False: #Verify that enemy is visible if abs(enemies[rdm].rect.centerx - invoker.rect.centerx) < 500: break i += 1 self.sub_action_target = enemies[rdm] #Set lock on target self.sub_action_target_pos = self.sub_action_target.rect.centerx self.rect.centerx = self.WIDTH / 2 self.rect.bottom = 0 self.speed_x = float((self.speed_y) * (self.sub_action_target_pos - self.rect.centerx)) / self.ground #Restart timers self.reload_time = 100 self.explode_duration = 10 self.on_sub_action = True self.health -= 10 else: self.on_action = False self.image = self.none
def __init__(self, x, y, space): pygame.sprite.Sprite.__init__(self) #SFX self.step = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/step.wav"), 4) self.hit = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/hit.wav")) self.swoosh_1 = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/swoosh_1.wav")) self.swoosh_2 = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/swoosh_2.wav")) self.swoosh_3 = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/swoosh_3.wav")) self.swoosh_4 = SFX(pygame.mixer.Sound("audio/sfx/nahuitochtli/swoosh_4.wav")) #Sprites self.breathing_right = Animate([ load_image("sprites/nahuitochtli/Nahui_right_breath_1.png", True), load_image("sprites/nahuitochtli/Nahui_right_breath_1.png", True), load_image("sprites/nahuitochtli/Nahui_right_breath_2.png", True) ], 0.4) self.breathing_left = Animate([ load_image("sprites/nahuitochtli/Nahui_left_breath_1.png", True), load_image("sprites/nahuitochtli/Nahui_left_breath_1.png", True), load_image("sprites/nahuitochtli/Nahui_left_breath_2.png", True) ], 0.4) self.looking_right = Animate([ load_image("sprites/nahuitochtli/Nahui_right_walk_1.png", True), load_image("sprites/nahuitochtli/Nahui_right_walk_2.png", True), load_image("sprites/nahuitochtli/Nahui_right_walk_3.png", True), ], 2) self.looking_left = Animate([ load_image("sprites/nahuitochtli/Nahui_left_walk_1.png", True), load_image("sprites/nahuitochtli/Nahui_left_walk_2.png", True), load_image("sprites/nahuitochtli/Nahui_left_walk_3.png", True), ], 2) self.invoking = load_image("sprites/nahuitochtli/Nahui_invoke.png", True) self.attacking_left_1 = load_image("sprites/nahuitochtli/Nahui_left_attack_1.png", True) self.attacking_right_1 = load_image("sprites/nahuitochtli/Nahui_right_attack_1.png", True) self.attacking_left_2 = load_image("sprites/nahuitochtli/Nahui_left_attack_2.png", True) self.attacking_right_2 = load_image("sprites/nahuitochtli/Nahui_right_attack_2.png", True) self.attacking_left_3 = load_image("sprites/nahuitochtli/Nahui_left_attack_3.png", True) self.attacking_right_3 = load_image("sprites/nahuitochtli/Nahui_right_attack_3.png", True) self.attacking_left_4 = load_image("sprites/nahuitochtli/Nahui_left_attack_4.png", True) self.attacking_right_4 = load_image("sprites/nahuitochtli/Nahui_right_attack_4.png", True) self.attacking_air_right = load_image("sprites/nahuitochtli/Nahui_right_attack_air.png", True) self.attacking_air_left = load_image("sprites/nahuitochtli/Nahui_left_attack_air.png", True) self.jumping_right = load_image("sprites/nahuitochtli/Nahui_right_jump.png", True) self.jumping_left = load_image("sprites/nahuitochtli/Nahui_left_jump.png", True) self.covered = load_image("sprites/nahuitochtli/Nahui_cover.png", True) self.damaged = Animate([ load_image("sprites/nahuitochtli/Nahui_damaged_1.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_2.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_3.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_4.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_5.png", True), load_image("sprites/nahuitochtli/Nahui_damaged_6.png", True), ], 10) self.cover_damaged = Animate([ load_image("sprites/nahuitochtli/Nahui_cover_damaged_1.png", True), load_image("sprites/nahuitochtli/Nahui_cover_damaged_2.png", True), ], 2) self.died = load_image("sprites/nahuitochtli/Nahui_die.png", True) self.stunned = load_image("sprites/nahuitochtli/Nahui_die.png", True) #Position and space self.WIDTH = space[0] self.HEIGHT = space[1] self.image = self.breathing_right.get_current_image() self.rect = self.image.get_rect() self.rect.bottom = y self.rect.centerx = x #Environment self.gravity = 1.3 self.speed_x = 0.5 self.speed_taken = 0 self.elasticity = -0.4 #Status self.look_left = False self.on_stun = False self.look_right = True self.on_invoke = False self.on_air = False self.on_attack = False self.on_damage = False self.on_cover = False self.on_cover_damage = False self.on_move = False self.on_breath = True self.ready2jump = True self.ready2attack = True self.ready2invoke = True self.combo_attack = 0 #Attributes self.power = 6 self.health = 100 self.resistance = 0.55
class Tlaloc(God): def __init__(self, x, y, space): #Tlaloc attributes self.thunder = [ SFX(pygame.mixer.Sound("audio/sfx/gods/tlaloc/lightning_1.wav"), 19), SFX(pygame.mixer.Sound("audio/sfx/gods/tlaloc/lightning_2.wav"), 19), SFX(pygame.mixer.Sound("audio/sfx/gods/tlaloc/lightning_3.wav"), 19), ] random.seed() self.idle = load_image("sprites/gods/tlaloc/idle.png", True) self.cloud_attack = Animate([ load_image("sprites/gods/tlaloc/cloud_attack_1.png", True), load_image("sprites/gods/tlaloc/cloud_attack_2.png", True), load_image("sprites/gods/tlaloc/cloud_attack_3.png", True), load_image("sprites/gods/tlaloc/cloud_attack_4.png", True),], 3) self.being_invoked = Animate([ load_image("sprites/gods/tlaloc/invoked_1.png", True), load_image("sprites/gods/tlaloc/invoked_2.png", True), load_image("sprites/gods/tlaloc/invoked_3.png", True), load_image("sprites/gods/tlaloc/invoked_4.png", True), load_image("sprites/gods/tlaloc/invoked_5.png", True),], 2) self.cloud = Animate([ load_image("sprites/gods/tlaloc/cloud_1.png", True), load_image("sprites/gods/tlaloc/cloud_2.png", True), load_image("sprites/gods/tlaloc/cloud_3.png", True), load_image("sprites/gods/tlaloc/cloud_4.png", True),], 1) #Super class attributes super(Tlaloc, self).__init__(x, y, space) def update(self, invoker, enemies): #Super class actions super(Tlaloc, self).update(invoker, enemies) #Tlaloc actions if self.on_action == True: if self.health > 0: self.rect.top = 0 #Reload if self.reload_time > 0: self.cloud.play() self.image = self.cloud.get_current_image() self.rect = self.image.get_rect() self.rect.centerx = invoker.rect.centerx self.reload_time -= 1 #Attack else: #Continue to attack if self.sub_action_duration > 0: #SFX thunder rdm = random.randint(0,2) if self.thunder[rdm].is_playable(): self.thunder[rdm].get_sfx().play() for t in self.thunder: t.update() self.cloud_attack.play() self.image = self.cloud_attack.get_current_image() self.rect = self.image.get_rect() self.rect.centerx = self.sub_action_target_pos self.on_sub_action = True self.sub_action_duration -= 1 #Prepare new attack else: i = 0 while i < len(enemies): #Select enemy randomly rdm = random.randint(0, len(enemies)-1) if enemies[rdm].health > 0 and enemies[rdm].on_stun == False: #Verify that enemy is visible if abs(enemies[rdm].rect.centerx - invoker.rect.centerx) < 500: break i += 1 self.sub_action_target = enemies[rdm] self.cloud_attack.stop() #Set lock on target self.sub_action_target_pos = self.sub_action_target.rect.centerx #Restart timers self.sub_action_duration = 10 self.reload_time = 100 self.on_sub_action = False self.health -= 1 else: self.on_action = False self.on_sub_action = False self.image = self.none
print("Numerical Energy :", sch.energy()) print("Theoretical Energy", (hbar**2 * k_initial**2) / (2 * m)) print("Difference :", sch.energy() - (hbar**2 * k_initial**2) / (2 * m)) psi_init2 = gauss_init(x, k_initial, x0=x0, d=d) psis2 = np.real(psi_init2 * np.conj(psi_init2)) # plt.plot(x, sch.mod_square_x(True)) # plt.plot(x, V_x) # plt.ylim(0, max(np.real(psi_x))) # plt.show() a = Animate(sch, V_x, step, dt, lim1=((0, x_length), (0, max(np.real(psi_x)))), lim2=((ks[0], ks[N - 1]), (0, 30))) a.make_fig() t_list = [] norm_x = [] expec_x = [] expec_xs = [] expec_k = [] for i in range(Ns): if i != 0: sch.evolve_t(step, dt) t_list.append(sch.t) norm_x.append(sch.norm_x() - 1)
pygame.init() #inter game clock and frame per sec setup clock = pygame.time.Clock() fps = 60 #set screen sizes and create screen screen_width = 1000 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) #Set tile size for game. Will be used to setup floor, item, and enemy positions tile_size = 50 #create player object and image. Also rezises player image, and position it inside the screen Player1R = Animate('playerImgs', 'R', 4, 'png', False, tile_size) Player1L = Animate('playerImgs', 'R', 4, 'png', True, tile_size) Player1RNew = Animate('playerImgs2', 'G', 4, 'png', False, tile_size) Player1LNew = Animate('playerImgs2', 'G', 4, 'png', True, tile_size) Player1 = Player.Player(screen, Player1R, Player1L, 0, 450) #load player image files for animation """ #function draws grid on screen #NOT PART OF THE GAME. HELP TO LAYOUT THE PLATFORM def draw_grid(): for line in range(0, 20): pygame.draw.line(screen, (255, 255, 255), (0, line * tile_size), (screen_width, line * tile_size)) pygame.draw.line(screen, (255, 255, 255), (line * tile_size, 0), (line * tile_size, screen_height)) """