Beispiel #1
0
class Bit_text(object):
   """used to display text in 8 bit font"""

   #each letter is made up of scaled rectangles along the x and y axis.
   #char_list[i] = y pos, char_list[i][j] = x pos
   #all the chars don't surpass 6 pixels in width/height for this game, but you can
   #add your own.

   char_list = {'.': [[], [], [], [], [], [0, 1], [0, 1]],
               '(': [[3, 4], [1, 2], [0, 1], [0], [0, 1], [1, 2], [3, 4]],
               ')': [[3, 2], [5, 4], [6, 5], [6], [6, 5], [5, 4], [3, 2]],
               '©': [[2, 3, 4], [1, 5], [0, 3, 4, 6], [0, 2, 6], [0, 3, 4, 6], [1, 5], [2, 3, 4]],
               ',': [[], [], [], [2, 3], [2, 3], [3], [2]],
               '-': [[], [], [], [0, 1, 2, 3, 4, 5, 6], [], [], []],
               '_': [[], [], [], [], [], [], [0, 1, 2, 3, 4, 5, 6]],
               ':': [[3, 4], [3, 4], [], [], [], [3, 4], [3, 4]],
               '>': [[0,1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3], [0, 1, 2], [0, 1]],
               '0': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 4, 5, 6], [0, 1, 3, 5, 6], [0, 1, 2, 5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               '1': [[2, 3, 4], [1, 2, 3, 4], [2, 3, 4], [2, 3, 4], [2, 3, 4], [2, 3, 4], [2, 3, 4]],
               '2': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [5, 6], [3, 4, 5], [1, 2], [0, 1], [0, 1, 2, 3, 4, 5, 6]],
               '3': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [5, 6], [2, 3, 4, 5], [5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               '4': [[0, 1, 4, 5], [0, 1, 4, 5], [0, 1, 4, 5], [0, 1, 4, 5], [0, 1, 2, 3, 4, 5, 6], [4, 5], [4, 5]],
               '5': [[0, 1, 2, 3, 4, 5, 6], [0, 1], [0, 1, 2, 3, 4, 5], [5, 6], [5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               '6': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1], [0, 1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               '7': [[0, 1, 2, 3, 4, 5, 6], [5, 6], [4, 5], [3, 4], [2, 3, 4], [2, 3, 4], [2, 3, 4]],
               '8': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               '9': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5, 6], [5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               'a': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6]],
               'b': [[0, 1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 2, 3, 4, 5]],
               'c': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1], [0, 1], [0, 1], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               'd': [[0, 1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 2, 3, 4, 5]],
               'e': [[0, 1, 2, 3, 4, 5, 6], [0, 1], [0, 1], [0, 1, 2, 3, 4, 5], [0, 1], [0, 1], [0, 1, 2, 3, 4, 5, 6]],
               'f': [[0, 1, 2, 3, 4, 5, 6], [0, 1], [0, 1], [0, 1, 2, 3, 4, 5], [0, 1], [0, 1], [0, 1]],
               'g': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1], [0, 1, 3, 4, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               'h': [[0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6]],
               'i': [[3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4]],
               'j': [[4, 5], [4, 5], [4, 5], [4, 5], [1, 2, 4, 5], [1, 2, 4, 5], [2, 3, 4]],
               'k': [[0, 1, 4, 5], [0, 1, 3, 4], [0, 1, 2, 3], [0, 1, 2], [0, 1, 2, 3], [0, 1, 3, 4], [0, 1, 4, 5]],
               'l': [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1, 2, 3, 4, 5]],
               'm': [[0, 1, 5, 6], [0, 1, 2, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 3, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6]],
               'n': [[0, 1, 5, 6], [0, 1, 2, 5, 6], [0, 1, 2, 3, 5, 6], [0, 1, 3, 4, 5, 6], [0, 1, 4, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6]],
               'o': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               'p': [[0, 1, 2, 3, 4, 5], [0, 1, 5, 6,], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 2, 3, 4, 5], [0, 1], [0, 1]],
               'q': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 3, 4, 5, 6], [0, 1, 4, 5, 6], [1, 2, 3, 4, 5]],
               'r': [[0, 1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 2, 3, 4, 5], [0, 1, 4, 5], [0, 1, 5, 6]],
               's': [[1, 2, 3, 4, 5], [0, 1, 5, 6], [0, 1], [1, 2, 3, 4, 5], [5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               't': [[0, 1, 2, 3, 4, 5], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3]],
               'u': [[0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [1, 2, 3, 4, 5]],
               'v': [[0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [1, 2, 4, 5], [2, 3, 4], [3]],
               'w': [[0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 5, 6], [0, 1, 3, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 4, 5, 6], [0, 1, 5, 6]],
               'x': [[1, 2, 5, 6], [1, 2, 5, 6], [2, 3, 4, 5], [3, 4], [2, 3, 4, 5], [1, 2, 5, 6], [1, 2, 5, 6]],
               'y': [[0, 1, 4, 5], [0, 1, 4, 5], [0, 1, 4, 5], [1, 2, 3, 4], [2, 3], [2, 3], [2, 3]],
               'z': [[0, 1, 2, 3, 4, 5], [0, 4, 5], [3, 4], [2, 3], [1, 2], [0, 1, 5], [0, 1, 2, 3, 4, 5]],
               ' ': [[], [], [], [], [], [], []]}

   def __init__(self, string, x, y, width, height, colour=(255,255,255), pattern_interval=30):
      self.string = string
      self.x = x
      self.y = y
      self.width = width
      self.height = height
      self.colour = colour
      self.pattern_timers = Timer()
      self.pattern_timers.add_ID('flash_interval', pattern_interval)
      self.pattern_timers.add_ID('add_letter_interval', pattern_interval)
      self.pattern_interval = pattern_interval
      self.show_letters_up_to = 0
   

   def flash(self, surf, pattern_interval=None):
      if pattern_interval != None:
         self.pattern_timers.all_timers['flash_interval']['origin'] = pattern_interval

      if self.pattern_timers.is_almost_finished('flash_interval', self.pattern_timers.get_ID('flash_interval')['origin']//2) != True:
         Bit_text.display_text(surf, (self.x,self.y), self.string, self.width, self.height, self.colour)

      elif self.pattern_timers.is_finished('flash_interval'):
         self.pattern_timers.replenish_timer('flash_interval', self.pattern_interval)

      self.pattern_timers.countdown('flash_interval')


   def show_letter_sequence(self, surf, pattern_interval=None):
      if pattern_interval != None:
         self.pattern_timers.all_timers['add_letter_interval']['origin'] = pattern_interval
      s = self.string[0:self.show_letters_up_to]
      if self.show_letters_up_to == len(self.string):
         s = self.string
      else:
         if self.pattern_timers.is_finished('add_letter_interval') != True:
            self.pattern_timers.countdown('add_letter_interval')
         else:
            self.show_letters_up_to += 1
            self.pattern_timers.replenish_timer('add_letter_interval', self.pattern_interval)
            
      Bit_text.display_text(surf, (self.x,self.y), s, self.width, self.height, self.colour)


   def display(self, surf, pattern=None, pattern_interval=None, min_char_width=6, char_seperation=2):
      if pattern == None:
         Bit_text.display_text(surf, (self.x,self.y), self.string, self.width, self.height, self.colour,
                               min_char_width, char_seperation)
      elif pattern == 'flash':
         self.flash(surf, pattern_interval)
      elif pattern == 'letter_sequence':
         self.show_letter_sequence(surf, pattern_interval)


   @staticmethod
   def display_text(surf, coordinates, string, width=1, height=1, colour=(255,255,255), min_char_width=6, char_seperation=2):
      """Display String on a surface.
         Width and Height refer to width and height of each pixel (rectangle) per letter
         """

      all_chars = list(str(string))
      x_pos_offset = 0 #where each character will be drawn

      for char in all_chars:
         y = coordinates[1]
         longest_pixel_x = 0
         for pixel_array in Bit_text.char_list[char.lower()]: #going through every pixel_array in 
                                                              #characters and making a rectangle at 
                                                              #each number in the pixel_array
            if len(pixel_array) != 0:
               for i in range(len(pixel_array)):
                  x = coordinates[0] + (pixel_array[i] * width) + x_pos_offset
                  pygame.draw.rect(surf, colour, (x, y, width, height))
                  if pixel_array[i] > longest_pixel_x:
                     longest_pixel_x = pixel_array[i]

            y += height
         if longest_pixel_x < min_char_width:
            longest_pixel_x = min_char_width
         x_pos_offset += (longest_pixel_x + char_seperation) * width
Beispiel #2
0
import pygame
from bit_text import Bit_text
from timer import Timer
import sys
clock = pygame.time.Clock()

s = input()

screen = pygame.display.set_mode((600,600))

run = True

text = Bit_text(s, 600, 250, 4, 4, pattern_interval=40)
text2 = Bit_text(s, 130, 250, 4, 4, pattern_interval=15, colour=(0,0,0))
myt = Timer()
myt.add_ID('inc', 5)

while run:
   screen.fill((0,0,0))
   for e in pygame.event.get():
      if e.type == pygame.QUIT:
         run = False

   keys = pygame.key.get_pressed()
   if True in [keys[pygame.K_RIGHT], keys[pygame.K_LEFT], keys[pygame.K_UP], keys[pygame.K_DOWN]] and myt.is_finished('inc') != True:
      myt.countdown('inc')
   elif myt.is_finished('inc'):
      myt.replenish_timer('inc')

      if keys[pygame.K_RIGHT]:
         text.width += 1
Beispiel #3
0
class Concrete_shot(Projectile):
    all_p_stack = mega_stack.Stack()
    all_p_lst = []

    def __init__(self):
        width = 60
        height = 50
        x, y = 0, 0
        concrete_shot_liquid = [
            universal_var.projectiles['concrete_shot_1'],
            universal_var.projectiles['concrete_shot_2']
        ]
        concrete_shot_solid = [
            universal_var.projectiles['concrete_block_1'],
            universal_var.projectiles['concrete_block_2']
        ]
        concrete_shatter = [
            universal_var.projectiles['concrete_block_3'],
            universal_var.projectiles['concrete_block_4']
        ]
        bullet_sprite = sprite.Sprite(
            universal_var.main_sprite, x, y, width, height,
            [('concrete_shot_liquid', concrete_shot_liquid, 6),
             ('concrete_shot_solid', concrete_shot_solid, 6),
             ('concrete_block_shatter', concrete_shatter, 14)])

        main_coll_box = sprite.Collision_box(universal_var.hitbox,
                                             0,
                                             0,
                                             width - 20,
                                             height - 17, (240, 240, 0),
                                             x_offset=10)
        ground_collbox = sprite.Collision_box('ground_collbox',
                                              x,
                                              y,
                                              width - 30,
                                              15, (150, 180, 100),
                                              x_offset=15,
                                              y_offset=height - 17)

        super().__init__('Enemy_projectile_1',
                         x,
                         y, [bullet_sprite], [main_coll_box, ground_collbox],
                         width=width,
                         height=height,
                         display_layer=4)
        self.damage_points = 13
        self.grounded = False
        self.solidified = False
        self.is_shattered = False
        self.all_timers = Timer()
        self.all_timers.add_ID('shatter', 28)
        Concrete_shot.all_p_stack.push(self)
        Concrete_shot.add_to_class_lst(self, Concrete_shot.all_p_lst, self.ID)

    @classmethod
    def set(cls, x, y, vel=0, angle=0, gravity=0):
        if cls.all_p_stack.is_empty() != True:
            p = cls.all_p_stack.pop()
            Concrete_shot.add_to_class_lst(p, Megaman_object.hazards, p.ID)
            p.grounded = False
            p.is_shattered = False
            Projectile.set(p, x, y, vel, angle=angle, gravity=gravity)

    def display(self, surf):
        if self.is_active:
            if self.grounded != True:
                if universal_var.game_pause != True:
                    self.update_sprite(universal_var.main_sprite)
                self.display_animation(universal_var.main_sprite, surf,
                                       'concrete_shot_liquid')

            else:
                if self.is_shattered != True:
                    self.display_animation(universal_var.main_sprite, surf,
                                           'concrete_shot_solid')
                else:
                    self.display_animation(universal_var.main_sprite, surf,
                                           'concrete_block_shatter')

                if universal_var.game_pause != True:
                    self.update_sprite(universal_var.main_sprite,
                                       auto_reset=False,
                                       loop_amount=1)

    def ground_collision(self):
        #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 not (isinstance(platform, Concrete_shot)):
                    Megaman_object.push_vert(self, platform, 'ground_collbox',
                                             universal_var.hitbox)
                    #play_sound('big_stomper_landing', universal_var.megaman_sounds, channel=2, volume=universal_var.sfx_volume - 0.1)
                    return True
        return False

    def wall_collision(self):
        #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 not (isinstance(wall,
                               Concrete_shot)) and self.is_shattered != True:
                self.shatter()
                self.launched = False
                return True
        return False

    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)

    def shatter(self):
        self.all_timers.replenish_timer('shatter', 10)
        self.is_shattered = True
        if self in Megaman_object.platforms:
            Megaman_object.platforms.remove(self)

    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)


#----------------------------------------------------------------------
Beispiel #4
0
class Concrete_man(Megaman_object):
   sprite_imgs = load_images('resources/enemies/concrete_man')

   def __init__(self, x, y, trigger_coll_box, spawn=False):
      width, height = 130, 105

      idle_imgs = [Concrete_man.sprite_imgs['idle']]
      intro_imgs = [Concrete_man.sprite_imgs['intro_1'], Concrete_man.sprite_imgs['intro_2'], Concrete_man.sprite_imgs['intro_3']]
      falling_imgs = [Concrete_man.sprite_imgs['falling']]
      charge_imgs = [Concrete_man.sprite_imgs['charge_1'], Concrete_man.sprite_imgs['charge_2']]
      shoot_imgs = [Concrete_man.sprite_imgs['shoot']]
      jump_imgs = [Concrete_man.sprite_imgs['jump']]
      prepare_jump_imgs = [Concrete_man.sprite_imgs['prepare_jump']]
      landing_imgs = [Concrete_man.sprite_imgs['landing_1'], Concrete_man.sprite_imgs['landing_2'], Concrete_man.sprite_imgs['landing_3']]

      sprite = Sprite(universal_var.main_sprite, x, y, width, height, active_frames=[
                                                                          ('idle', idle_imgs, 1),
                                                                          ('introduction', intro_imgs, 33),
                                                                          ('falling', falling_imgs, 100),
                                                                          ('charge', charge_imgs, 10),
                                                                          ('shoot', shoot_imgs, 1),
                                                                          ('prepare_jump', prepare_jump_imgs, 1),
                                                                          ('jump', jump_imgs, 1),
                                                                          ('landing', landing_imgs, 25)
                                                                       ])

      effects = Sprite('effects', x, y, 100, 90, active_frames=[
                                                                        ('spark_effect', [universal_var.misc_images['spark']], 1)
                                                                     ])

      main_collbox = Collision_box(universal_var.hitbox, x, y, width-40, height-30, (40, 80, 100), x_offset=20, y_offset=15)
      ground_collbox = Collision_box("ground_collbox", x, y, width-80, 15, (150, 180, 100), x_offset=40, y_offset=height-15)

      super().__init__('concrete_man', x, y, [sprite, effects], [main_collbox, ground_collbox], 
                       width=width, height=height, is_active=False, direction=False, display_layer=3)

      Death_orb.init(16)
      projectile.Projectile.init_projectile_properties(self)
      for i in range(3):
         Concrete_shot()

      self.trigger_coll_box = Boss_room(self, trigger_coll_box.x, trigger_coll_box.y, trigger_coll_box.width, trigger_coll_box.height)
      self.health_points = 440 #440
      self.original_health_points = self.health_points
      self.damage_points = 15
      self.original_damage_points = self.damage_points
      self.battle_has_init = False
      self.grounded = False
      self.health_bar = Energy_bar('health_bar', x=70, y=20, points=self.health_points, colour1=(242, 138, 0), colour2=(255, 255, 255))
      self.health_bar.points = 0 #upon introduction it will change to self.health_points
      self.action_list = ['idle', 'charge', 'introduction', 'shoot', 'stomp']
                        #these are all the actions he can do. The list and it's elements will change
                        #depending on the current action but they are all here just to know.

      self.current_action = 'introduction'
      self.all_timers = Timer()
      self.all_timers.add_ID('idle_time', 25)
      self.all_timers.add_ID('damage_taken', 0)
      self.all_timers.add_ID('shake_camera', 20)

      #--timers and variables for action methods--

      #charge action
      self.all_timers.add_ID('time_till_charge', 15)
      self.all_timers.add_ID('time_till_wall_detect', 2)
      self.collided_with_wall = False

      #shoot action
      self.all_timers.add_ID('shoot_time', 20)

      #stomp action
      self.all_timers.add_ID('time_till_jump', 10)
      self.all_timers.add_ID('time_till_fall', 15)
      self.all_timers.add_ID('landing_time', 30)
      self.falling = False
      self.jump_destination = [0, 190]

      Concrete_man.add_to_class_lst(self, Megaman_object.hazards, self.ID)
      if spawn:
         self.spawn()

#--main methods--

   def is_alive(self):
      return self.health_points > 0


   def spawn(self):
      self.x, self.y = self.spawn_point[0], self.spawn_point[1]
      self.is_active = True
      self.direction = False
      self.reset_atrributes()
      Sprite_surface.update(self)
      for ID in self.all_timers:
         if ID != 'damage_taken':
            self.all_timers.replenish_timer(ID)

   def display(self, surf):
      if self.all_timers.is_finished('damage_taken', include_loop=True) != True:
         self.display_animation('effects', surf, 'spark_effect', x_offset=16, y_offset=20)
         self.update_sprite('effects')
         if universal_var.game_pause != True:
            self.all_timers.countdown('damage_taken', loop=True, loop_amount=7)

      no_sprite_flicker = self.all_timers.is_almost_finished('damage_taken', self.all_timers.get_ID('damage_taken')['origin']//2)

      if no_sprite_flicker:
         if self.current_action == 'introduction':
            self.display_intro_animation(surf)

         elif self.current_action == 'idle':
            self.display_idle_animation(surf)

         elif self.current_action == 'charge':
            self.display_charge_animation(surf)

         elif self.current_action == 'shoot':
            self.display_shoot_animation(surf)

         elif self.current_action == 'stomp':
            self.display_stomp_animation(surf)


   def carry_out_action(self):
      if self.current_action == 'introduction':
         self.introduction_action()

      elif self.is_alive() and universal_var.game_pause != True:
         if self.current_action == 'idle':
            self.idle_action()

         elif self.current_action == 'charge':
            self.charge_action()

         elif self.current_action == 'shoot':
            self.shoot_action()

         elif self.current_action == 'stomp':
            self.stomp_action()


   def update(self):
      self.carry_out_action()
         
      self.check_collisions()

      if self.grounded == False and self.is_active and self.launched != True:
         self.apply_gravity()

      if universal_var.game_reset:
         self.is_active = False
         self.reset_atrributes()

      if self.trigger_coll_box.battle_has_init:
         self.health_bar.points = self.health_points
         if self.is_alive() != True and self.is_active:
            self.explode()

      #Sprite_surface.update(self)


#--collision detection functions--
   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)
#=================================================


#--action methods--
   def introduction_action(self):
      if self.health_bar.is_full():
         self.trigger_coll_box.battle_has_init = True
         self.choose_action(['charge', 'stomp'])


   def idle_action(self):
      self.damage_points = 17
      if self.all_timers.is_finished('idle_time') != True:
         self.all_timers.countdown('idle_time')
      else:
         m = Megaman.all_sprite_surfaces[0]
         if m.x + m.width//2 > self.x + self.width//2:
            self.direction = True
         else:
            self.direction = False
         self.choose_action(self.action_list)
         self.all_timers.replenish_timer('time_till_wall_detect')


   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'


   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'


   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'
                  
#========================================


#--display action methods--
   def display_idle_animation(self, surf):
      if self.grounded != True:
         self.display_animation(universal_var.main_sprite, surf, 'falling', flip=self.direction)
      else:
         self.display_animation(universal_var.main_sprite, surf, 'idle', flip=self.direction)


   def display_intro_animation(self, surf):
      if self.grounded != True:
         self.display_animation(universal_var.main_sprite, surf, 'falling', flip=self.direction)
         self.update_sprite(universal_var.main_sprite)
      else:
         self.display_animation(universal_var.main_sprite, surf, 'introduction', flip=self.direction)
         if universal_var.game_pause != True:
            self.update_sprite(universal_var.main_sprite, auto_reset=False, loop_amount=2)


   def display_charge_animation(self, surf):
      if self.grounded != True:
         self.display_animation(universal_var.main_sprite, surf, 'falling', flip=self.direction)
      else:
         self.display_animation(universal_var.main_sprite, surf, 'charge', flip=self.direction)

      if universal_var.game_pause != True:
         self.update_sprite(universal_var.main_sprite)

   def display_shoot_animation(self, surf):
      self.display_animation(universal_var.main_sprite, surf, 'shoot', flip=self.direction)


   def display_stomp_animation(self, surf):
      if self.all_timers.is_finished('time_till_jump') != True:
         self.display_animation(universal_var.main_sprite, surf, 'prepare_jump', flip=self.direction)
      else:

         if self.falling != True:
            self.display_animation(universal_var.main_sprite, surf, 'jump', flip=self.direction)
         else:

            if self.grounded != True:
               self.display_animation(universal_var.main_sprite, surf, 'falling', flip=self.direction)

            else:
               if universal_var.game_pause != True:
                  self.update_sprite(universal_var.main_sprite, auto_reset=False, loop_amount=1)
               self.display_animation(universal_var.main_sprite, surf, 'landing', flip=self.direction)

#=====================================================


   #--misc methods--
   def choose_action(self, lst):
      index = randint(0, len(lst)-1)
      self.current_action = lst[index]

   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


   def reset_atrributes(self):
      self.trigger_coll_box.battle_has_init = False
      self.grounded = False
      self.health_points = self.original_health_points
      self.damage_points = self.original_damage_points
      self.current_action = 'introduction'
      self.collided_with_wall = False
      self.launched = False
      self.falling = False


   def shake_camera(self):
      if self.all_timers.is_finished('shake_camera') != True:
         World_camera.shake(6, 0, 5)
         self.all_timers.countdown('shake_camera')
Beispiel #5
0
class Boss_room(Megaman_object):
    battle_has_end = False

    def __init__(self, boss, x, y, width, height):
        c = [
            Collision_box(universal_var.hitbox, x, y, width, height,
                          (130, 190, 140))
        ]
        super().__init__('Boss_room',
                         x,
                         y,
                         sprites=None,
                         coll_boxes=c,
                         width=width,
                         height=height,
                         display_layer=5)

        self.battle_has_init = False
        self.battle_has_end = False
        self.all_timers = Timer()
        self.all_timers.add_ID('time_till_start', 40)
        self.all_timers.add_ID('time_till_boss_spawn', 60)
        self.all_timers.add_ID('time_till_refill_bar', 130)
        self.all_timers.add_ID('time_till_end', 550)
        self.all_timers.add_ID('time_till_end_song', 160)
        self.boss = boss

    def check_player_collision(self):
        if len(Megaman.all_sprite_surfaces) != 0:
            trigger_box_collision = self.check_collision_lst(
                Megaman.all_sprite_surfaces, universal_var.hitbox,
                universal_var.hitbox)
            if trigger_box_collision.is_empty() != True:
                return True
        return False

    def spawn_boss(self):
        if self.all_timers.is_finished('time_till_start') != True:
            self.all_timers.countdown('time_till_start')
            self.music_lock = False

        else:
            self.boss.health_bar.is_active = True
            universal_var.songs.play_list(song_number=5)
            if self.all_timers.is_finished('time_till_boss_spawn') != True:
                self.all_timers.countdown('time_till_boss_spawn')
            elif self.battle_has_init != True and self.boss.is_active != True:
                self.boss.spawn()

            if self.boss.is_active:
                if self.all_timers.is_finished('time_till_refill_bar') != True:
                    self.all_timers.countdown('time_till_refill_bar')
                elif self.boss.health_bar.is_full() != True:
                    self.boss.health_bar.refill(11)

    def end_level(self):
        if self.all_timers.is_finished('time_till_end') != True:
            self.all_timers.countdown('time_till_end')
        else:
            Boss_room.battle_has_end = True

        if self.all_timers.is_finished('time_till_end_song') != True:
            self.all_timers.countdown('time_till_end_song')
        if self.all_timers.get_ID('time_till_end_song')['curr_state'] == 1:
            universal_var.songs.play_list(song_number=6)

    def update(self):
        if len(Megaman.all_sprite_surfaces) != 0:
            m = Megaman.all_sprite_surfaces[0]
            if self.check_player_collision():
                if self.battle_has_init != True and camera.camera_transitioning(
                ) != True:
                    m.disable_keys()
                    self.spawn_boss()
                elif self.battle_has_init and self.battle_has_end != True:
                    m.enable_keys()

                if self.battle_has_end:
                    m.disable_keys()
                    self.end_level()

                if (self.battle_has_init and
                        self.battle_has_end != True) and self.boss.is_alive(
                        ) != True and self.boss.is_active != True:
                    self.battle_has_end = True
                    universal_var.songs.stop()

            if universal_var.game_reset:
                self.battle_has_init = False
                self.battle_has_end = False
                self.boss.health_bar.points = 0
                m.enable_keys()
                for ID in self.all_timers:
                    self.all_timers.replenish_timer(ID)
        Sprite_surface.update(self)
Beispiel #6
0
import camera
import gate
from megaman import Megaman
import items
import concrete_man
from concrete_shot import Concrete_shot
import projectile
from megaman_death_orb import Death_orb
from p_shooter import P_shooter
import intro_sequence
from title_screen import Title_screen
from timer import Timer

level_dict = {'concrete_man': [concrete_man.props, concrete_man.coll_boxes, concrete_man.enemies, concrete_man.all_items]}
game_timers = Timer()
game_timers.add_ID('time_till_game_start', 550) #550
game_timers.add_ID('init_star_background', 90)
Title_screen.init()

def clear_all_lists():
   sprite.Sprite_surface.all_sprite_surfaces.clear()
   sprite.Sprite_surface.all_name_count.clear()
   megaman_object.Megaman_object.all_sprite_surfaces.clear()
   megaman_object.Megaman_object.platforms.clear()
   megaman_object.Megaman_object.hazards.clear()
   enemy.Enemy.all_sprite_surfaces.clear()
   camera.Camera_box.all_camera_box.clear()
   camera.Transition_box.all_transition_box.clear()
   Megaman.all_sprite_surfaces.clear()
   items.Item.drop_list.clear()
   enemy.Hoohoo_boulder.mini_boulder_1_stack.clear()