def increment_score(self, value, textPosition, text_group): if self.combo_bonus and value <= 250: self.combo_bonus += int(.2 * FRAMES_PER_SECOND) self.combo_kills += 1 temp_image = text.Text(FONT_PATH, 30, FONT_COLOR, 'x' + str(self.combo_kills) + '!').image help_bubble = infobubble.InfoBubble(temp_image, self, 0.5 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.bullet_group.add(help_bubble) if self.point_bonus: value *= 2 temp_text = text.Text(FONT_PATH, 36, FONT_COLOR, str(value), 15) temp_text.set_alignment(CENTER_MIDDLE) temp_text.position = vector.Vector2d(textPosition) text_group.add(temp_text) self.score += value self.score_board.set_text(self.score) if self.score >= self.next_bonus: utility.play_sound(self.extraLifeSound, OW_CHANNEL) temp_image = text.TextSurface(FONT_PATH, 30, FONT_COLOR, 'Extra Life!').image help_bubble = infobubble.InfoBubble(temp_image, self, 1.5 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) text_group.add(help_bubble) self.lives += 1 self.life_board.set_text('x' + str(self.lives)) self.next_bonus += 50000
def bullet_collide(self, bullet): utility.play_sound(self.bullet_sound, BAAKE_CHANNEL) if bullet.collide_style == COLLIDE_STYLE_HURT: bullet.die() elif bullet.collide_style == COLLIDE_STYLE_REFLECT: if bullet.position.x < self.position.x - 64: bullet.position = vector.Vector2d(self.position.x - 112, bullet.position.y) bullet.velocity *= -1.0, 1.0 elif bullet.position.x > self.position.x + 64: bullet.position = vector.Vector2d(self.position.x + 112, bullet.position.y) bullet.velocity *= -1.0, 1.0 if bullet.position.y < self.position.y - 64: bullet.position = vector.Vector2d(bullet.position.x, self.position.y - 14) bullet.velocity *= 1.0, -1.0 elif bullet.position.y > self.position.y + 64: bullet.position = vector.Vector2d(bullet.position.x, self.position.y + 140) bullet.velocity *= 1.0, -1.0 elif bullet.collide_style == COLLIDE_STYLE_NOVA: if not self.stunned: self.stunned = 2 * FRAMES_PER_SECOND self.hurt(1)
def collide(self): if self.object_collided_with.actor_type == ACTOR_BULLET: utility.play_sound(Bokko.bullet_sound, BAAKE_CHANNEL) elif self.object_collided_with.actor_type == ACTOR_PLAYER: if self.object_collided_with.position.x < self.position.x - 64: self.object_collided_with.position = vector.Vector2d( (self.position.x - 94), self.object_collided_with.position.y) if self.object_collided_with.velocity: self.object_collided_with.velocity *= -1.0, 1.0 elif self.object_collided_with.position.x > self.position.x + 64: self.object_collided_with.position = vector.Vector2d( (self.position.x + 94), self.object_collided_with.position.y) if self.object_collided_with.velocity: self.object_collided_with.velocity *= -1.0, 1.0 if self.object_collided_with.position.y < self.position.y - 32: self.object_collided_with.position = vector.Vector2d( self.object_collided_with.position.x, self.position.y - 76) if self.object_collided_with.velocity: self.object_collided_with.velocity *= 1.0, -1.0 elif self.object_collided_with.position.y > self.position.y + 32: self.object_collided_with.position = vector.Vector2d( self.object_collided_with.position.x, self.position.y + 108) if self.object_collided_with.velocity: self.object_collided_with.velocity *= 1.0, -1.0
def collide(self): if self.object_collided_with.actor_type == ACTOR_BULLET: utility.play_sound(Bokko.bullet_sound, BAAKE_CHANNEL) elif self.object_collided_with.actor_type == ACTOR_PLAYER: if self.object_collided_with.position.x < self.position.x - 64: self.object_collided_with.position = vector.Vector2d((self.position.x - 94), self.object_collided_with.position.y) if self.object_collided_with.velocity: self.object_collided_with.velocity *= -1.0, 1.0 elif self.object_collided_with.position.x > self.position.x + 64: self.object_collided_with.position = vector.Vector2d((self.position.x + 94), self.object_collided_with.position.y) if self.object_collided_with.velocity: self.object_collided_with.velocity *= -1.0, 1.0 if self.object_collided_with.position.y < self.position.y - 32: self.object_collided_with.position = vector.Vector2d(self.object_collided_with.position.x, self.position.y - 76) if self.object_collided_with.velocity: self.object_collided_with.velocity *= 1.0, -1.0 elif self.object_collided_with.position.y > self.position.y + 32: self.object_collided_with.position = vector.Vector2d(self.object_collided_with.position.x, self.position.y + 108) if self.object_collided_with.velocity: self.object_collided_with.velocity *= 1.0, -1.0
def hurt(self, damage): self.health -= damage self.animation_list.play('hurt') utility.play_sound(self.hurt_sound, BOSS_CHANNEL) if self.health <= 0: for actor in self.enemy_group: actor.leave_screen = True
def die(self): utility.play_sound(self.death_sound) particle.DeathEmitter(self.position, self.effects_group).run() self.item_drop() self.active = False self.emitter = None self.death_emitter = None self.kill() del self
def hurt(self, damage): self.health -= damage utility.play_sound(self.hurt_sound, BOSS_CHANNEL) self.animation_list.play('hurt') if self.health <= self.world.level and self.health != 0: self.enemy_group.add(yurei.Yurei(self.group_list)) if self.health <= 0: for actor in self.enemy_group: actor.leave_screen = True
def hurt(self, value): if self.stun_timer <= 0: self.animation_list.play('HurtIdle', self.animation_list.current_frame) self.lives -= value sound_to_play = random.randint(0, 2) if self.lives != 0: utility.play_sound(self.lose_life_sound[sound_to_play], OW_CHANNEL) self.life_board.set_text('x' + str(self.lives)) self.stun_timer = 1.5 * FRAMES_PER_SECOND
def fire(self): if self.stun_timer: self.animation_list.play('HurtFire', self.animation_list.current_frame) else: self.animation_list.play('Fire') if self.fire_timer <= 0: utility.play_sound(self.fire_sound[random.randint(0, 2)], PLAYER_CHANNEL) if self.velocity[:] != vector.Vector2d.zero: bullet_velocity = vector.Vector2d(self.velocity) bullet_velocity.set_magnitude(self.bullet_speed) new_bullet = bullet.Bullet(self.position, bullet_velocity, self.effects_group, self.bullet_damage, self.bullet_bound_style, self.bullet_collide_style) new_bullet.set_owner(self) if self.reflect_bonus and self.damage_bonus: new_bullet.animation_list.play('DamageReflect') elif self.bullet_collide_style == COLLIDE_STYLE_REFLECT: new_bullet.animation_list.play('Reflect') elif self.bullet_damage > 1: new_bullet.animation_list.play('Damage') self.bullet_group.add(new_bullet) self.fire_timer = self.reset_fire_timer if self.dual_shot: if self.velocity: bullet_velocity = vector.Vector2d(self.velocity * -1) bullet_velocity.set_magnitude(self.bullet_speed) new_bullet = bullet.Bullet( (self.position), (bullet_velocity), self.effects_group, self.bullet_damage, self.bullet_bound_style, self.bullet_collide_style) new_bullet.set_owner(self) if self.reflect_bonus and self.damage_bonus: new_bullet.animation_list.play('DamageReflect') elif self.bullet_collide_style == COLLIDE_STYLE_REFLECT: new_bullet.animation_list.play('Reflect') elif self.bullet_damage > 1: new_bullet.animation_list.play('Damage') self.bullet_group.add(new_bullet)
def fire(self): if self.stun_timer: self.animation_list.play('HurtFire', self.animation_list.current_frame) else: self.animation_list.play('Fire') if self.fire_timer <= 0: utility.play_sound(self.fire_sound[random.randint(0, 2)], PLAYER_CHANNEL) if self.velocity[:] != vector.Vector2d.zero: bullet_velocity = vector.Vector2d(self.velocity) bullet_velocity.set_magnitude(self.bullet_speed) new_bullet = bullet.Bullet(self.position, bullet_velocity, self.effects_group, self.bullet_damage, self.bullet_bound_style, self.bullet_collide_style) new_bullet.set_owner(self) if self.reflect_bonus and self.damage_bonus: new_bullet.animation_list.play('DamageReflect') elif self.bullet_collide_style == COLLIDE_STYLE_REFLECT: new_bullet.animation_list.play('Reflect') elif self.bullet_damage > 1: new_bullet.animation_list.play('Damage') self.bullet_group.add(new_bullet) self.fire_timer = self.reset_fire_timer if self.dual_shot: if self.velocity: bullet_velocity = vector.Vector2d(self.velocity * -1) bullet_velocity.set_magnitude(self.bullet_speed) new_bullet = bullet.Bullet((self.position), (bullet_velocity), self.effects_group, self.bullet_damage, self.bullet_bound_style, self.bullet_collide_style) new_bullet.set_owner(self) if self.reflect_bonus and self.damage_bonus: new_bullet.animation_list.play('DamageReflect') elif self.bullet_collide_style == COLLIDE_STYLE_REFLECT: new_bullet.animation_list.play('Reflect') elif self.bullet_damage > 1: new_bullet.animation_list.play('Damage') self.bullet_group.add(new_bullet)
def increment_score_no_text(self, value): self.score += value self.score_board.set_text(self.score) if self.score > self.next_bonus: utility.play_sound(self.extraLifeSound, OW_CHANNEL) temp_image = text.TextSurface(FONT_PATH, 30, FONT_COLOR, 'Extra Life!').image help_bubble = infobubble.InfoBubble(temp_image, self, 1.5 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.effects_group.add(help_bubble) self.lives += 1 self.life_board.set_text('x' + str(self.lives)) self.next_bonus += 50000
def die(self): utility.play_sound(self.death_sound) particle.DeathEmitter(self.position, self.effects_group).run() if self.drop_balloon: self.powerup_group.add( balloon.Bonus250(self.position, self.text_group)) elif self.drop_reflect: self.powerup_group.add(gem.Reflect(self.position, self.text_group)) else: self.item_drop() self.kill() del self
def bullet_collide(self, bullet): if not self.stunned: utility.play_sound(self.bullet_sound, BAAKE_CHANNEL) if bullet.collide_style == COLLIDE_STYLE_HURT: bullet.die() elif bullet.collide_style == COLLIDE_STYLE_REFLECT: if bullet.position.x < self.position.x - 64: bullet.position = vector.Vector2d(self.position.x - 112, bullet.position.y) bullet.velocity *= (-1.0, 1.0) elif bullet.position.x > self.position.x + 64: bullet.position = vector.Vector2d(self.position.x + 112, bullet.position.y) bullet.velocity *= (-1.0, 1.0) if bullet.position.y < self.position.y - 64: bullet.position = vector.Vector2d(bullet.position.x, self.position.y - 14) bullet.velocity *= (1.0, -1.0) elif bullet.position.y > self.position.y + 64: bullet.position = vector.Vector2d(bullet.position.x, self.position.y + 140) bullet.velocity *= (1.0, -1.0) elif bullet.collide_style == COLLIDE_STYLE_NOVA: utility.play_sound(self.shieldBreak, BAAKE_CHANNEL) self.stunned = 2 * FRAMES_PER_SECOND self.animation_list.play('vulnerable') stars_to_create = 15 while stars_to_create: stars_to_create -= 1 temp_bullet = particle.StarParticle() temp_vector = vector.Vector2d(120, 0) temp_vector.set_angle(stars_to_create * 24) temp_bullet.position = vector.Vector2d(self.position + temp_vector) temp_bullet.life_timer = .5 * FRAMES_PER_SECOND temp_bullet.velocity = vector.Vector2d(3.0, 0.0) temp_bullet.velocity.set_angle(stars_to_create * 24) self.effects_group.add(temp_bullet) elif bullet.collide_style != COLLIDE_STYLE_NOVA: bullet.die() self.hurt(1)
def actor_update(self): utility.play_music(self.music, True) if not self.active and self.health > 0: self.active = True if self.life_timer <= 30 * FRAMES_PER_SECOND and self.health == (self.world.level + 1) * 25: if self.life_timer == 30 * FRAMES_PER_SECOND: temp_image = self.how_to_kill help_bubble = infobubble.InfoBubble(temp_image, self.target, 5 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.text_group.add(help_bubble) self.life_timer += 1 if self.active: if self.stunned: if self.charging: self.speed -= 0.2 if self.speed <= 1.75: self.speed = 1.75 self.charging = False self.time_until_charge = 10 * FRAMES_PER_SECOND self.velocity.make_normal() self.velocity *= self.speed self.stunned -= 1 self.animation_list.play('vulnerable') if not self.stunned: utility.play_sound(self.shieldRestore, PICKUP_CHANNEL) self.animation_list.play('idle') else: self.current_sequence = 0 self.process_ai() if self.health <= 0: self.active = False self.die() if not self.gave_bonus: self.world.give_bonus() self.gave_bonus = True
def give_bonus(self): increment_bonus = self.player.lives * 50 if self.bonus == -1: self.boss_fight = False self.bonus = 0 self.bonus_text = text.Text(FONT_PATH, 64, FONT_COLOR, 'Bonus Points!') self.bonus_text.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 50)) self.bonus_text.set_alignment(CENTER_MIDDLE) self.text_group.add(self.bonus_text) self.bonus_amount = text.Text(FONT_PATH, 48, FONT_COLOR) self.bonus_amount.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 50)) self.bonus_amount.set_alignment(CENTER_MIDDLE) self.text_group.add(self.bonus_amount) if self.bonus < self.player.lives * 5000 - increment_bonus: self.bonus += increment_bonus self.bonus_amount.set_text(self.bonus) else: self.bonus_amount.set_text(self.player.lives * 5000) if self.level < MAX_LEVEL: self.bonus_text.set_timer(FRAMES_PER_SECOND) self.bonus_amount.set_timer(FRAMES_PER_SECOND) self.bonus = -1 self.after_bonus_pause = 1.1 * FRAMES_PER_SECOND if self.level < MAX_LEVEL: self.level += 1 self.boss_fight = False utility.fade_music() utility.play_music(self.music, True) utility.play_sound(self.bonus_tally_sound, BAAKE_CHANNEL) self.player.increment_score_no_text(increment_bonus) self.pause_spawning = 1.5 * FRAMES_PER_SECOND
def load_level(self): if self.done: return utility.fade_music() utility.play_music(self.music, True) self.stage = 0 self.pause_spawning = 3 * FRAMES_PER_SECOND self.player.bullet_bonus = 0 self.player.reflect_bonus = 0 self.powerup_group.empty() self.enemy_group.empty() self.effects_group.empty() # Display Level text display_name = text.Text(FONT_PATH, 64, FONT_COLOR, self.world_name, 90) display_name.set_alignment(CENTER_MIDDLE) display_name.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)) self.group_list[TEXT_GROUP].add(display_name) display_level = text.Text(FONT_PATH, 32, FONT_COLOR, 'Level ' + str(self.level + 1), 90) display_level.position = vector.Vector2d( (SCREEN_WIDTH / 2, SCREEN_HEIGHT * (2.0 / 3.0))) display_level.set_alignment(CENTER_MIDDLE) self.group_list[TEXT_GROUP].add(display_level) # Reset all information for the new level self.enemy_list = [] self.load_stage() utility.play_sound(self.get_ready_sound, OW_CHANNEL) temp_image = text.TextSurface(FONT_PATH, 36, FONT_COLOR, 'Get Ready...').image help_bubble = infobubble.InfoBubble(temp_image, self.player, 2 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.effects_group.add(help_bubble)
def die(self): if self.dying == 0: death_type = int(random.random() * 3) if death_type == 0: temp_image = text.TextSurface(FONT_PATH, 30, FONT_COLOR, 'Blast!').image utility.play_sound(self.death_sound[0], OW_CHANNEL) elif death_type == 1: temp_image = text.TextSurface(FONT_PATH, 30, FONT_COLOR, 'Oh No!').image utility.play_sound(self.death_sound[1], OW_CHANNEL) elif death_type == 2: temp_image = text.TextSurface(FONT_PATH, 30, FONT_COLOR, 'Bother!').image utility.play_sound(self.death_sound[2], OW_CHANNEL) self.animation_list.play('Die') self.bounds = -1000, -1000, SCREEN_WIDTH + 1000, SCREEN_HEIGHT + 32 self.bound_style = BOUND_STYLE_CUSTOM help_bubble = infobubble.InfoBubble(temp_image, self, 5 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.bullet_group.add(help_bubble) self.dying += 1 if settings_list[PARTICLES] and not self.dying % 2: puffs_to_create = 4 while puffs_to_create: puffs_to_create -= 1 temp_puff = particle.SmokeParticle(self.position, (1, 0)) temp_puff.velocity.set_angle(359 * random.random()) self.effects_group.add(temp_puff)
def give_bonus(self): increment_bonus = self.player.lives * 50 if self.bonus == -1: self.boss_fight = False self.bonus = 0 self.bonus_text = text.Text(FONT_PATH, 64, FONT_COLOR, 'Bonus Points!') self.bonus_text.position = vector.Vector2d((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 50)) self.bonus_text.set_alignment(CENTER_MIDDLE) self.text_group.add(self.bonus_text) self.bonus_amount = text.Text(FONT_PATH, 48, FONT_COLOR) self.bonus_amount.position = vector.Vector2d((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 50)) self.bonus_amount.set_alignment(CENTER_MIDDLE) self.text_group.add(self.bonus_amount) if self.bonus < self.player.lives * 5000 - increment_bonus: self.bonus += increment_bonus self.bonus_amount.set_text(self.bonus) else: self.bonus_amount.set_text(self.player.lives * 5000) if self.level < MAX_LEVEL: self.bonus_text.set_timer(FRAMES_PER_SECOND) self.bonus_amount.set_timer(FRAMES_PER_SECOND) self.bonus = -1 self.after_bonus_pause = 1.1 * FRAMES_PER_SECOND if self.level < MAX_LEVEL: self.level += 1 self.boss_fight = False utility.fade_music() utility.play_music(self.music, True) utility.play_sound(self.bonus_tally_sound, BAAKE_CHANNEL) self.player.increment_score_no_text(increment_bonus) self.pause_spawning = 1.5 * FRAMES_PER_SECOND
def load_level(self): if self.done: return utility.fade_music() utility.play_music(self.music, True) self.stage = 0 self.pause_spawning = 3 * FRAMES_PER_SECOND self.player.bullet_bonus = 0 self.player.reflect_bonus = 0 self.powerup_group.empty() self.enemy_group.empty() self.effects_group.empty() # Display Level text display_name = text.Text(FONT_PATH, 64, FONT_COLOR, self.world_name, 90) display_name.set_alignment(CENTER_MIDDLE) display_name.position = vector.Vector2d((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)) self.group_list[TEXT_GROUP].add(display_name) display_level = text.Text(FONT_PATH, 32, FONT_COLOR, 'Level ' + str(self.level + 1), 90) display_level.position = vector.Vector2d((SCREEN_WIDTH / 2, SCREEN_HEIGHT * (2.0 / 3.0))) display_level.set_alignment(CENTER_MIDDLE) self.group_list[TEXT_GROUP].add(display_level) # Reset all information for the new level self.enemy_list = [] self.load_stage() utility.play_sound(self.get_ready_sound, OW_CHANNEL) temp_image = text.TextSurface(FONT_PATH, 36, FONT_COLOR, 'Get Ready...').image help_bubble = infobubble.InfoBubble(temp_image, self.player, 2 * FRAMES_PER_SECOND) help_bubble.offset = vector.Vector2d(0.0, -100.0) self.effects_group.add(help_bubble)
def show(self): self.menu_selection_pointer[self.current_selection].set_font(48, FONT_COLOR, FONT_PATH) pygame.mouse.get_rel() mouse_timeout = 10 sample_mouse = True while True: # Music Stuff utility.play_music(self.music_list) # Drawing Stuff self.screen.fill(FILL_COLOR) self.menu_group.update() self.menu_tooltip_group.update() self.cursor_group.update() try: self.screen.blit(self.background_image, self.background_image.get_rect()) except: self.background_image.draw(self.screen) self.menu_group.draw(self.screen) self.menu_tooltip_pointer[self.current_selection].draw(self.screen) self.cursor_group.draw(self.screen) pygame.display.flip() self.cursor.position = vector.Vector2d(pygame.mouse.get_pos()) + vector.Vector2d(32, 32) # Event Handling for event in pygame.event.get(): if event.type == pygame.KEYDOWN and (event.key == pygame.K_SPACE or event.key == pygame.K_RETURN): utility.play_sound(self.menu_forward_sound) return list(self.menu_dictionary.keys())[self.current_selection] elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: utility.play_sound(self.menu_forward_sound) return list(self.menu_dictionary.keys())[self.current_selection] elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: utility.play_sound(self.menu_back_sound) return False elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 3: utility.play_sound(self.menu_back_sound) return False elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: self.menu_selection_pointer[self.current_selection].set_font(32, FONT_INACTIVE_COLOR, FONT_PATH) self.current_selection -= 1 if self.current_selection < 0: self.current_selection = len(self.menu_dictionary) - 1 self.menu_selection_pointer[self.current_selection].set_font(48, FONT_COLOR, FONT_PATH) utility.play_sound(self.menu_beep_sound) elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: self.menu_selection_pointer[self.current_selection].set_font(32, FONT_INACTIVE_COLOR, FONT_PATH) self.current_selection += 1 if self.current_selection > len(self.menu_dictionary) - 1: self.current_selection = 0 self.menu_selection_pointer[self.current_selection].set_font(48, FONT_COLOR, FONT_PATH) utility.play_sound(self.menu_beep_sound) elif event.type == pygame.MOUSEMOTION: for element in self.menu_group: if element.mouse_over(): if element.text_index != self.current_selection: self.menu_selection_pointer[self.current_selection].set_font(32, FONT_INACTIVE_COLOR, FONT_PATH) mouse_selection = element.text_index self.current_selection = mouse_selection self.menu_selection_pointer[self.current_selection].set_font(48, FONT_COLOR, FONT_PATH) utility.play_sound(self.menu_beep_sound) """ elif event.type == pygame.KEYDOWN and event.key == pygame.K_q: for element in self.menuTooltipGroup: print 'ELEMENT: ', element.text_index element.mouseOverDump() elif event.type == pygame.MOUSEMOTION: mouseInput = list(pygame.mouse.get_rel()) if sample_mouse: if mouseInput[1] < -10: self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) self.currentSelection -= 1 if self.currentSelection < 0: self.currentSelection = len(self.menuDictionary) - 1 self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) sample_mouse = False utility.playSound(self.menuBeep) elif mouseInput[1] > 10: self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) self.currentSelection += 1 if self.currentSelection > len(self.menuDictionary) - 1: self.currentSelection = 0 self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) sample_mouse = False utility.playSound(self.menuBeep) """ if not sample_mouse: mouse_timeout -= 1 if mouse_timeout == 0: sample_mouse = True mouse_timeout = 3 self.timer.tick(30)
def collide(self): if self.object_collided_with.actor_type == ACTOR_PLAYER: utility.play_sound(self.pickup_sound, PICKUP_CHANNEL) self.display_text() self.give_bonus() self.die()
def collide(self): if self.object_collided_with.actor_type == ACTOR_PLAYER: utility.play_sound(self.pickup_sound) self.die()
def show(self): self.menu_selection_pointer[self.current_selection].set_font( 48, FONT_COLOR, FONT_PATH) pygame.mouse.get_rel() mouse_timeout = 10 sample_mouse = True while True: # Music Stuff utility.play_music(self.music_list) # Drawing Stuff self.screen.fill(FILL_COLOR) self.menu_group.update() self.menu_tooltip_group.update() self.cursor_group.update() try: self.screen.blit(self.background_image, self.background_image.get_rect()) except: self.background_image.draw(self.screen) self.menu_group.draw(self.screen) self.menu_tooltip_pointer[self.current_selection].draw(self.screen) self.cursor_group.draw(self.screen) pygame.display.flip() self.cursor.position = vector.Vector2d( pygame.mouse.get_pos()) + vector.Vector2d(32, 32) # Event Handling for event in pygame.event.get(): if event.type == pygame.KEYDOWN and ( event.key == pygame.K_SPACE or event.key == pygame.K_RETURN): utility.play_sound(self.menu_forward_sound) return list( self.menu_dictionary.keys())[self.current_selection] elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: utility.play_sound(self.menu_forward_sound) return list( self.menu_dictionary.keys())[self.current_selection] elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: utility.play_sound(self.menu_back_sound) return False elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 3: utility.play_sound(self.menu_back_sound) return False elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: self.menu_selection_pointer[ self.current_selection].set_font( 32, FONT_INACTIVE_COLOR, FONT_PATH) self.current_selection -= 1 if self.current_selection < 0: self.current_selection = len(self.menu_dictionary) - 1 self.menu_selection_pointer[ self.current_selection].set_font( 48, FONT_COLOR, FONT_PATH) utility.play_sound(self.menu_beep_sound) elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: self.menu_selection_pointer[ self.current_selection].set_font( 32, FONT_INACTIVE_COLOR, FONT_PATH) self.current_selection += 1 if self.current_selection > len(self.menu_dictionary) - 1: self.current_selection = 0 self.menu_selection_pointer[ self.current_selection].set_font( 48, FONT_COLOR, FONT_PATH) utility.play_sound(self.menu_beep_sound) elif event.type == pygame.MOUSEMOTION: for element in self.menu_group: if element.mouse_over(): if element.text_index != self.current_selection: self.menu_selection_pointer[ self.current_selection].set_font( 32, FONT_INACTIVE_COLOR, FONT_PATH) mouse_selection = element.text_index self.current_selection = mouse_selection self.menu_selection_pointer[ self.current_selection].set_font( 48, FONT_COLOR, FONT_PATH) utility.play_sound(self.menu_beep_sound) """ elif event.type == pygame.KEYDOWN and event.key == pygame.K_q: for element in self.menuTooltipGroup: print 'ELEMENT: ', element.text_index element.mouseOverDump() elif event.type == pygame.MOUSEMOTION: mouseInput = list(pygame.mouse.get_rel()) if sample_mouse: if mouseInput[1] < -10: self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) self.currentSelection -= 1 if self.currentSelection < 0: self.currentSelection = len(self.menuDictionary) - 1 self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) sample_mouse = False utility.playSound(self.menuBeep) elif mouseInput[1] > 10: self.menuSelectionPointer[self.currentSelection].setFont(32, FONT_INACTIVE_COLOR, FONT_PATH) self.currentSelection += 1 if self.currentSelection > len(self.menuDictionary) - 1: self.currentSelection = 0 self.menuSelectionPointer[self.currentSelection].setFont(48, FONT_COLOR, FONT_PATH) sample_mouse = False utility.playSound(self.menuBeep) """ if not sample_mouse: mouse_timeout -= 1 if mouse_timeout == 0: sample_mouse = True mouse_timeout = 3 self.timer.tick(30)