コード例 #1
0
 def got_hit(self, enemy):
     """Called on collision with enemy."""
     if not self.hit_state:
         damage = max(enemy.attack, 1)
         self.health = max(self.health - damage, 0)
         self.hit_state = tools.Timer(50, 10)
         knock_dir = self.get_collision_direction(enemy)
         self.knock_state = (knock_dir, tools.Timer(100, 1))
コード例 #2
0
 def reset_timer(self):
     """
     This timer is reset every time the player leaves the screen to
     prevent projectiles from syncronizing.
     """
     self.timer = tools.Timer(self.speed)
     self.timer.check_tick(pg.time.get_ticks())
コード例 #3
0
 def startup(self, now, persistant):
     self.persist = persistant
     self.start_time = now
     self.timer = tools.Timer(DELAY_UNTIL_SCROLL, 1)
     self.timer.check_tick(now)
     self.scrolling = False
     self.elements = self.make_elements()
     self.star_field.reset()
コード例 #4
0
 def __init__(self, *groups):
     player.Player.__init__(self, prepare.DEFAULT_PLAYER, *groups)
     self.inventory = equips.make_equips()
     self.speed = 3.5
     self.dancing = False
     self.done_dancing = False
     self.dance_timer = tools.Timer(1000, 1)
     self.prepare()
コード例 #5
0
 def __init__(self):
     status_machine.State.__init__(self)
     self.next = "SELECT"
     self.timer = tools.Timer(300)
     self.blink = False
     msg_center = (prepare.SCREEN_RECT.centerx, 630)
     self.ne_key = self.render_font(FONT_BIG, "Press Any Key",
                                    pg.Color("white"), msg_center)
コード例 #6
0
 def __init__(self, *groups):
     pg.sprite.Sprite.__init__(self, *groups)
     self.raw_image = render_font("Fixedsys500c", 30, "Are You Sure? Press (Y/N)", (255, 255, 0))
     self.null_image = pg.Surface((1, 1)).convert_alpha()
     self.null_image.fill((0, 0, 0, 0))
     self.image = self.raw_image
     center = (prepare.SCREEN_RECT.centerx, 650)
     self.rect = self.image.get_rect(center=center)
     self.blink = False
     self.timer = tools.Timer(200)
コード例 #7
0
 def dance(self, now):
     if not (self.done_dancing or self.dancing) and 100 < self.rect.x < 110:
         self.old_direction = self.direction
         self.dancing = True
         self.direction_stack[0] = "front"
         self.dance_timer.check_tick(now)
     if self.dancing and self.dance_timer.check_tick(now):
         self.dancing = False
         self.done_dancing = True
         self.dance_timer = tools.Timer(1000, 1)
         self.direction_stack[0] = self.old_direction
コード例 #8
0
 def __init__(self, sound, *attack_info):
     pg.sprite.Sprite.__init__(self)
     self.sound = sound
     self.anims, self.anim_rects = self.get_attack_info(*attack_info)
     self.anim = None
     self.image = None
     self.rect = None
     self.player = None
     self.attacking = False
     self.delay_timer = tools.Timer(300)
     self.frame_speed = [0, 0]
コード例 #9
0
 def __init__(self, pos, *groups):
     pg.sprite.Sprite.__init__(self, *groups)
     if not self.frames:
         sheet = prepare.GFX["objects"]["projectiles"]
         self.frames.extend(tools.strip_from_sheet(sheet, (300, 0), (30, 30), 3))
         self.frames += [self.frames[1]]
     self.frame = 0
     self.image = self.frames[self.frame]
     self.rect = self.image.get_rect(center=pos)
     self.blink_timer = tools.Timer(100)
     self.blink_timer.check_tick(pg.time.get_ticks())
     self.delay = random.randrange(200, 3000)
     self.delay_timer = 0.0
     self.animate = random.random() < 0.1
コード例 #10
0
 def got_hit(self, player, obstacles, *item_groups):
     """
     Called from the level class if the player is attacking and the
     weapon rect collides with the sprite.
     """
     if not self.hit_state and self.state != "spawn":
         self.health -= player.strength
         if self.health > 0:
             self.state = "hit"
             self.hit_state = tools.Timer(300, 1)
             self.knock_state = True
             self.knock_dir = player.direction
             self.got_knocked_collision(obstacles)
         elif self.state != "die":
             self.drop_item(*item_groups)
             self.state = "die"
コード例 #11
0
 def __init__(self, name, pos, duration, chest=False, ident=None, *groups):
     """
     The argument name is the type of item corresponding to the ITEMS dict;
     pos is the location on the map the item is located; if the item is in
     a treasure chest, pass chest=True; if the player can only get this item
     once, pass a unique (to the map) ident string to be stored in the
     player's identifiers attribute.
     """
     pg.sprite.Sprite.__init__(self, *groups)
     coords, size = ITEM_COORDS[name], prepare.CELL_SIZE
     self.frames = tools.strip_coords_from_sheet(ITEM_SHEET, coords, size)
     self.anim = tools.Anim(self.frames, 7)
     self.image = self.anim.get_next_frame(pg.time.get_ticks())
     # Subtract 1 from y axis to make item drop appear behind death anim.
     self.rect = pg.Rect((pos[0], pos[1] - 1), prepare.CELL_SIZE)
     self.exact_position = list(self.rect.topleft)
     self.old_position = self.exact_position[:]
     self.mask = pg.Mask(prepare.CELL_SIZE)
     self.mask.fill()
     self.timer = tools.Timer(duration * 1000, 1) if duration else None
     self.from_chest = chest
     self.identifier = ident  # Used to stop respawning of unique items.
     self.height = 0  # Used when item rises from chest.
     self.sound_effect = None
コード例 #12
0
 def __init__(self):
     menu_functions.BidirectionalMenu.__init__(self, ALPHA_GRID_SIZE)
     self.next = "SELECT"
     self.timer = tools.Timer(333)
     self.blink = True
     self.letter_images = {}