Пример #1
0
def check_game_pause():
    k = pygame.key.get_pressed()
    if k[pygame.K_p] and game_has_started == True and megaman.is_alive(
    ) and not (camera.camera_transitioning()):  #pause game
        if universal_var.game_pause == False:
            play_sound('pause',
                       universal_var.megaman_sounds,
                       channel=2,
                       volume=universal_var.sfx_volume + 0.1)
            universal_var.songs.toggle()
        universal_var.game_pause = True

    elif k[pygame.K_o] and megaman.is_alive() and not (
            camera.camera_transitioning()):  #unpause
        if universal_var.game_pause == True:
            play_sound('pause',
                       universal_var.megaman_sounds,
                       channel=2,
                       volume=universal_var.sfx_volume + 0.1)
            universal_var.songs.toggle()
        universal_var.game_pause = False

    if k[pygame.K_v] and k[pygame.K_b]:  #debug
        universal_var.debug = True
    elif k[pygame.K_c]:
        universal_var.debug = False
Пример #2
0
    def display(self, surf):
        self.update_sprite(universal_var.main_sprite, auto_reset=False)
        if camera.Transition_box.current_box == self.transition_collbox and camera.camera_transitioning(
        ):
            if camera.transition_start():
                self.display_animation(universal_var.main_sprite, surf,
                                       "gate_open")
                if self.play_gate_sound:
                    misc_function.play_sound('gate',
                                             universal_var.megaman_sounds,
                                             channel=1,
                                             volume=universal_var.sfx_volume)
                    self.play_gate_sound = False

            elif camera.transition_end():
                self.display_animation(universal_var.main_sprite, surf,
                                       "gate_close")
                if self.play_gate_sound:
                    misc_function.play_sound('gate',
                                             universal_var.megaman_sounds,
                                             channel=1,
                                             volume=universal_var.sfx_volume)
                    self.play_gate_sound = False

            else:
                self.play_gate_sound = True
        else:
            self.display_animation(universal_var.main_sprite, surf,
                                   "gate_idle")
            self.play_gate_sound = True
Пример #3
0
 def update(self):
    if self.is_active:
       megaman_collision = self.check_collision_lst(Megaman.all_sprite_surfaces, universal_var.hitbox, universal_var.hitbox)
       if megaman_collision.is_empty() != True:
          m = megaman_collision.pop()
          m.lives += 1
          self.is_active = False
          play_sound('extra_life', universal_var.megaman_sounds, channel=4, volume=universal_var.sfx_volume - 0.2)
    Item.update(self)
Пример #4
0
   def shoot_action(self):
      if Concrete_shot.all_p_stack.is_empty() and self.all_timers.is_full('shoot_time'):
         self.all_timers.replenish_timer('shoot_time')
         self.collided_with_wall = False

         self.action_list = ['charge', 'stomp']
         self.all_timers.replenish_timer('idle_time', 35)
         self.current_action = 'idle'

      else:
         self.damage_points = 16
         if self.all_timers.is_full('shoot_time'):
            play_sound('concrete_man_shoot', universal_var.megaman_sounds, channel=2, volume=universal_var.sfx_volume - 0.1)
            megaman = Megaman.all_sprite_surfaces[0]
            x_dist = abs(self.x + self.width//2 - megaman.x + megaman.width//2)
            vel = 0
            angle = 0

            if x_dist <= 40: #when player is very close shoot 1 bullet
               vel, angle = 45, 77
               if self.direction == True:
                  Concrete_shot.set(self.x + self.width - 40, self.y + 20, vel, angle, 22)
               else:
                  angle = 180 - angle
                  Concrete_shot.set(self.x - 20, self.y + 20, vel, angle, 22)

            else:
               if x_dist <= 150:    #choose from 3 distances
                  vel, angle = 35, 70

               elif x_dist <= 350:
                  vel, angle = 38, 65

               elif x_dist <= 600:
                  vel, angle = 55, 65

               if self.direction == True:
                  Concrete_shot.set(self.x + self.width - 40, self.y + 20, vel, angle, 24)
                  Concrete_shot.set(self.x + self.width - 40, self.y + 20, vel+32, angle+5, 24)
                  Concrete_shot.set(self.x + self.width - 40, self.y + 20, vel+30, angle-10, 24)
               else:
                  angle = 180 - angle
                  Concrete_shot.set(self.x - 20, self.y + 20, vel, angle, 24)
                  Concrete_shot.set(self.x - 20, self.y + 20, vel+32, angle-5, 24)
                  Concrete_shot.set(self.x - 20, self.y + 20, vel+27, angle+10, 24)


         if self.all_timers.is_finished('shoot_time') != True:
            self.all_timers.countdown('shoot_time')
         else:
            self.all_timers.replenish_timer('shoot_time')
            self.collided_with_wall = False

            self.action_list = ['charge', 'stomp']
            self.all_timers.replenish_timer('idle_time', 35)
            self.current_action = 'idle'
Пример #5
0
   def stomp_action(self):

      self.damage_points = 18
      megaman = Megaman.all_sprite_surfaces[0]
      if self.all_timers.is_finished('time_till_jump') != True:
         self.all_timers.countdown('time_till_jump')
         self.jump_destination[0] = megaman.x

      else:
         x_dest, y_dest = self.jump_destination[0], self.jump_destination[1]
         if self.falling != True:
            if self.all_timers.is_finished('time_till_jump') and universal_var.game_pause != True:
               self.hone_in(x_dest, y_dest, 10, min_x_vel=3, min_y_vel=4, max_x_vel=10, max_y_vel=10)

            if self.y == y_dest:
               self.all_timers.countdown('time_till_fall')
               if self.all_timers.is_finished('time_till_fall'):
                  self.falling = True
                  projectile.Projectile.set(self, self.x, self.y, 20, 270, 23)
                  self.grounded = False

         else:
            if self.grounded != True:
               self.all_timers.replenish_timer('shake_camera', 20)
               if universal_var.game_pause != True:
                  projectile.Projectile.move(self)
            else:
               if self.all_timers.is_full('landing_time'):
                  play_sound('concrete_man_impact', universal_var.megaman_sounds, channel=2, volume=universal_var.sfx_volume - 0.1)
                  for p in Concrete_shot.all_p_lst:
                     p.shatter()
                  if megaman.is_grounded:
                     megaman.freeze(60)

               self.all_timers.countdown('landing_time')
               self.launched = False
               self.shake_camera()

               if self.all_timers.is_finished('landing_time'):
                  self.all_timers.replenish_timer('time_till_jump')
                  self.all_timers.replenish_timer('time_till_fall')
                  self.all_timers.replenish_timer('landing_time')
                  self.falling = False
                  self.collided_with_wall = False

                  self.action_list = ['shoot', 'shoot', 'stomp', 'charge']
                  self.all_timers.replenish_timer('idle_time')
                  self.current_action = 'idle'
Пример #6
0
   def explode(self):
      start_times = [0, 15]
      speeds = [15, 10]
      angles = [0, 45, 90, 135, 180, 225, 270, 315]
      i = 0
      for j in range(2):
         Death_orb.set_orb_active(self.x + 20, self.y + 20, start_times[j], angles[i], speeds[j])
         Death_orb.set_orb_active(self.x + 20, self.y + 20, start_times[j], angles[i+1], speeds[j])
         Death_orb.set_orb_active(self.x + 20, self.y + 20, start_times[j], angles[i+2], speeds[j])
         Death_orb.set_orb_active(self.x + 20, self.y + 20, start_times[j], angles[i+3], speeds[j])
         Death_orb.set_orb_active(self.x + 20, self.y + 20, start_times[j], angles[i+4], speeds[j])
         Death_orb.set_orb_active(self.x + 20, self.y + 20, start_times[j], angles[i+5], speeds[j])
         Death_orb.set_orb_active(self.x + 20, self.y + 20, start_times[j], angles[i+6], speeds[j])
         Death_orb.set_orb_active(self.x + 20, self.y + 20, start_times[j], angles[i+7], speeds[j])

      play_sound('death', universal_var.megaman_sounds, channel=5, volume=universal_var.sfx_volume + 0.1)
      self.is_active = False
Пример #7
0
    def check_pshooter_contact(self):
        collision = False
        pshooter_collisions = self.check_collision_lst(P_shooter.all_p_lst,
                                                       universal_var.hitbox,
                                                       universal_var.hitbox,
                                                       quota=1)

        if pshooter_collisions.is_empty() != True and self.is_alive():
            collision = True
            p = pshooter_collisions.pop()
            if p.reflected == False:
                if p.x < self.x:
                    Projectile.set(p, p.x, p.y, vel=90, angle=130)
                else:
                    Projectile.set(p, p.x, p.y, vel=90, angle=70)
                p.reflected = True
                play_sound('p_reflected',
                           universal_var.megaman_sounds,
                           channel=1,
                           volume=universal_var.sfx_volume + 0.1)
Пример #8
0
    def refill(self, amount=1):
        if self.all_timers.is_finished('play_sound') != True:
            self.all_timers.countdown('play_sound')
        else:
            play_sound('health_regeneration',
                       universal_var.megaman_sounds,
                       channel=4,
                       volume=universal_var.sfx_volume - 0.2)
            self.all_timers.replenish_timer('play_sound')

        if self.all_timers.is_finished('time_till_increment'):
            self.all_timers.replenish_timer('time_till_increment')
        else:
            self.all_timers.countdown('time_till_increment')

        if self.is_full() != True and self.all_timers.is_full(
                'time_till_increment'):
            self.points += amount
            return True
        else:
            return False
Пример #9
0
   def check_collisions(self):
      if self.is_active:
         #touched ground
         if self.grounded == False:
            ground_collision = self.check_collision_lst(Megaman_object.platforms, 'ground_collbox', universal_var.hitbox, quota=1)
            if ground_collision.is_empty() != True:
               platform = ground_collision.pop()
               if isinstance(platform, Concrete_shot) and self.current_action == 'stomp' and self.falling:
                  platform.shatter()
               else:
                  self.push_vert(platform, 'ground_collbox', universal_var.hitbox)
                  self.grounded = True

         #touch wall
         wall_collision = self.check_collision_lst(Megaman_object.platforms, universal_var.hitbox, universal_var.hitbox, quota=1)
         if wall_collision.is_empty() != True:
            wall = wall_collision.pop()
            if isinstance(wall, Concrete_shot) and self.current_action == 'charge':
               wall.shatter()
            else:
               self.push_hori(wall, universal_var.hitbox, universal_var.hitbox)
               if self.all_timers.is_finished('time_till_wall_detect'):
                  self.collided_with_wall = True
                  self.all_timers.replenish_timer('time_till_wall_detect')
               else:
                  self.all_timers.countdown('time_till_wall_detect')

      #player pshooter
      pshooter_collisions = self.check_collision_lst(P_shooter.all_p_lst, universal_var.hitbox, universal_var.hitbox, quota=1)
      if pshooter_collisions.is_empty() != True and self.is_alive():
         collision = True
         p = pshooter_collisions.pop()
         if p.reflected == False:
            self.health_points -= p.damage_points
            self.health_bar.points -= p.damage_points
            p.is_active = False
            p.launched = False
            play_sound('impact_p', universal_var.megaman_sounds, channel=2, volume=universal_var.sfx_volume - 0.1)
            if self.is_alive() and self.all_timers.is_finished('damage_taken', include_loop=True):
                  self.all_timers.replenish_timer('damage_taken', 5)
Пример #10
0
    def update(self):
        #print(self.is_active, self.x, self.y)
        if self.is_active:
            self.wall_collision()

            if self.ground_collision() and self.solidified != True:
                play_sound('concrete_shot_solidify',
                           universal_var.megaman_sounds,
                           channel=2,
                           volume=universal_var.sfx_volume - 0.3)
                self.grounded = True
                self.launched = False
                self.solidified = True
                Concrete_shot.add_to_class_lst(self, Megaman_object.platforms,
                                               self.ID)
                Megaman_object.hazards.remove(self)

            if self.solidified:
                self.check_pshooter_contact()

            if self.all_timers.is_finished('shatter') and self.is_shattered:
                self.is_active = False
            elif universal_var.game_pause != True:
                self.all_timers.countdown('shatter')

        elif self not in Concrete_shot.all_p_stack.lst:  #reset properties
            self.is_shatter = False
            self.solidified = False
            Concrete_shot.all_p_stack.push(self)
            if self in Megaman_object.platforms:
                Megaman_object.platforms.remove(self)
            if self in Megaman_object.hazards:
                Megaman_object.hazards.remove(self)

        if universal_var.game_pause != True:
            Projectile.update(self)


#----------------------------------------------------------------------
Пример #11
0
    def run(cls):
        k = pygame.key.get_pressed()
        if cls.all_timers.is_finished('show_text') != True:
            cls.all_timers.countdown('show_text')

        else:
            if k[pygame.K_x] and cls.confirmation == False:
                play_sound('select',
                           universal_var.megaman_sounds,
                           channel=2,
                           volume=universal_var.sfx_volume - 0.1)
                cls.confirmation = True

            if cls.confirmation != True:
                cls.begin_game.display(cls.screen, 'flash')
                Bit_text.display_text(cls.screen, (20, 530),
                                      '©capcom co.,  ltd', 3, 3)
                Bit_text.display_text(cls.screen, (20, 560),
                                      'a short pygame project', 3, 3)
                if Title_screen.music_lock != True:
                    universal_var.songs.play_list(song_number=4, loop=True)
                    Title_screen.music_lock = True

        if cls.confirmation != True:
            cls.title_logo.follow(x=50, y=-20, x_vel=20, y_vel=20)
            cls.megaman_face.follow(x=340, y=230, x_vel=20, y_vel=20)

        else:
            if cls.all_timers.is_finished('move_logo_offscreen') != True:
                cls.all_timers.countdown('move_logo_offscreen')
            else:
                cls.title_logo.follow(x=50, y=1000, x_vel=20, y_vel=20)
            cls.megaman_face.follow(x=-200, y=230, x_vel=20, y_vel=20)
            universal_var.songs.stop()
            if cls.all_timers.is_finished('blackout_screen') != True:
                cls.all_timers.countdown('blackout_screen')
            else:
                cls.is_running = False
Пример #12
0
   def charge_action(self):
      self.damage_points = 19
      if self.direction == True:
         vel = 8
         angle = 96
      else:
         angle = 84
         vel = -8

      if self.all_timers.is_finished('time_till_charge') != True: #wait for a bit before charging forward
         self.all_timers.countdown('time_till_charge')
         self.all_timers.replenish_timer('time_till_wall_detect')
      else:
         if self.collided_with_wall != True:
            if universal_var.game_pause != True:
               self.x += vel

         elif self.launched != True and self.collided_with_wall: #hit the wall
            play_sound('concrete_man_impact', universal_var.megaman_sounds, channel=2, volume=universal_var.sfx_volume - 0.1)
            self.grounded = False
            self.y -= 1
            self.all_timers.replenish_timer('shake_camera', 10)
            projectile.Projectile.set(self, self.x, self.y, 80, angle, 23)

         else:
            if self.grounded != True:
               if universal_var.game_pause != True:
                  projectile.Projectile.move(self)
                  self.shake_camera()

            else: #landed and reset
               self.launched = False
               self.collided_with_wall = False
               self.all_timers.replenish_timer('time_till_charge', 10)

               self.action_list = ['shoot', 'shoot', 'stomp', 'stomp', 'charge']
               self.all_timers.replenish_timer('idle_time')
               self.current_action = 'idle'
Пример #13
0
def game_over():
    global game
    global screen
    global option
    global play_again_text
    global exit_text
    global megaman
    global game_has_started

    screen.fill((0, 0, 0))
    if game_timers.is_finished('game_over') != True:
        universal_var.songs.play_list(song_number=1)
        Bit_text.display_text(screen, (180, 140), 'game over', 3, 3)
        game_timers.countdown('game_over')
        game_setup.clear_all_lists()
    else:
        universal_var.songs.play_list(song_number=2)
        play_again_text.display(screen)
        exit_text.display(screen)
        arrow.display(screen, pattern='flash', pattern_interval=20)
        k = pygame.key.get_pressed()

        if k[pygame.K_UP]:
            if option != 'play_again':
                play_sound('pause',
                           universal_var.megaman_sounds,
                           channel=2,
                           volume=universal_var.sfx_volume)
            option = 'play_again'
            arrow.x, arrow.y = play_again_text.x - 40, play_again_text.y

        elif k[pygame.K_DOWN]:
            if option != 'exit':
                play_sound('pause',
                           universal_var.megaman_sounds,
                           channel=2,
                           volume=universal_var.sfx_volume)
            option = 'exit'
            arrow.x, arrow.y = exit_text.x - 40, exit_text.y

        elif k[pygame.K_x]:
            universal_var.songs.stop()
            play_sound('pause',
                       universal_var.megaman_sounds,
                       channel=2,
                       volume=universal_var.sfx_volume)
            if option == 'exit':
                game = False
            else:
                load_level('concrete_man')