def instantiate(position): ''' ''' if Blood.total_objects < 40: Screen.get_current_screen().object_handler.instantiate( Blood(position)) Blood.total_objects += 1
def on_shooting(self): ''' ''' sound_manager.play_effect('shotgun') self.owner.animator.play('shotgun_shoot') # spawn bullets for i in range(35): Screen.get_current_screen().instantiate( Bullet(self, self.bullet_speed, self.bullet_max_distance)) super().on_shooting()
def on_shooting(self): ''' ''' # spawn bullet Screen.get_current_screen().instantiate( Bullet(self, self.bullet_speed, self.bullet_max_distance)) if self.bullets != 0 and self.bullets % self.magazine_size == 0: self.reload() self.bullets -= 1 elif self.bullets > 0: self.bullets -= 1 self.can_shoot = False
def update(self, delta_time): ''' ''' super().update(delta_time) if self.is_dead: return # update current gun self.current_gun.update(delta_time) # handle movement self._movement(delta_time) # shoot if event_handler.is_mouse_down(1): self.attack() # switch weapons self._swith_weapons() # get the camera in current screen camera = Screen.get_current_screen().camera # look at mouse self.transform.look_at( camera.screen_to_world_point( Vector2.tuple_to_vector2(pygame.mouse.get_pos()))) # make the camera follow player self._camera_follow(camera)
def spawn_enemy(self, enemy): ''' ''' self.current_wave_index += 1 enemy_type = None position = Vector2(enemy[2], enemy[3]) if enemy[1] == 'normal_zombie': enemy_type = Zombie(self.player, position) elif enemy[1] == 'big_zombie': enemy_type = BigZombie(self.player, position) Screen.get_current_screen().instantiate(enemy_type) self.spawned_enemies.append(enemy_type)
def die(self): ''' ''' super().die() Screen.load_screen(DeathScreen(Screen.get_current_screen())) sound_manager.play_effect('player_death')
def main() -> None: ''' The main function of the program that contains the gameLoop ''' # ---------------------- GameLoop while not utils.quit_game: # --------------------UPDATE-------------------- event_handler.update() Screen.get_current_screen().update( clock.get_time()) # update everything in the current screen # ---------------------DRAW--------------------- utils.window.fill((20, 20, 20)) # clear screen Screen.get_current_screen().draw( utils.window) # draw everything in the current screen pygame.display.update() # render everything clock.tick(100) # set the FPS to 100
def on_render(self, surface): super().on_render(surface) # display weapon name weapon = self.current_gun bullets = weapon.bullets % weapon.magazine_size + 1 if not weapon.reloading else 0 magazines = weapon.bullets // weapon.magazine_size * weapon.magazine_size if not weapon.reloading else weapon.bullets // weapon.magazine_size * weapon.magazine_size + weapon.magazine_size text = f'{self.current_gun.name} | {bullets}/{magazines}' position = Screen.get_current_screen().camera.world_to_screen_point( self.transform.position - Vector2(len(text) * 0.25 * 11, 55)).to_tuple() utils.draw_font(surface, text, (255, 255, 255), position, size=11, bold=True)