def main_loop(self): """ Our game loop. It calls the event loop; updates the display; restricts the framerate; and loops. """ while not self.done: self.event_loop() # Run the event loop every frame. self.game.update() self.get_sprites() self.screen.fill([0, 0, 0]) self.screen.blit(self.game.map.image, (self.window.x, self.window.y)) self.sprites.draw(self.screen) self.screen.blit(self.game.map.overlay, (self.window.x, self.window.y)) self.top_sprites.draw(self.screen) gold = utils.draw_font('Gold: ' + str(self.game.gold), 24, settings.FONT) self.screen.blit(gold, (self.screen.get_width() - gold.get_width(), self.screen.get_height() - gold.get_height())) all_gold = utils.draw_font('All Gold: ' + str(self.game.all_gold), 24, settings.FONT) self.screen.blit(all_gold, (self.screen.get_width() - all_gold.get_width(), self.screen.get_height() - all_gold.get_height() - gold.get_height() - 4)) pygame.display.update() # Make updates to screen every frame. self.clock.tick(self.fps) # Restrict framerate of program.
def draw(self) -> None: ''' Draws everything to the screen :returns: NoReturn :rtype: None ''' self.Water0.draw() self.Water1.draw() config.window.blit(sprites.img_vignette, (0, 0)) config.window.blit( sprites.txt_game_name, ((config.SCREEN_WIDTH - sprites.txt_game_name.get_width()) * 0.5, 20)) config.window.blit(sprites.img_boat2, (320 - self.boat2_x, 100 - self.boat2_y)) config.window.blit(sprites.img_boat1, (-400, 200 - self.boat1_y)) config.window.blit(sprites.img_boat3, (500, 280 - self.boat3_y)) config.window.blit(sprites.img_chopper, (1000 - self.heli_x, 0 - self.heli_y)) utils.draw_font('Music', (255, 255, 255), (523, 550)) utils.draw_font('Effects', (255, 255, 255), (444, 550)) super().draw()
def draw(self, surface): ''' ''' #super().draw(surface) self.last.draw(surface) # draw background img surface.blit(sprite_manager.get('death_screen'), (0, 0)) # wave text utils.draw_font(surface, f'you survived {self.last._current_wave - 1} waves', (255, 255, 255), (395, 240), size=24)
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)
def __init__(self, text, x, y, color=settings.BUTTON_COLOR): pygame.sprite.Sprite.__init__(self) font_size = 24 text = utils.draw_font(text, font_size) self.image = pygame.Surface( [text.get_width() + 16, text.get_height() + 8]) self.image.fill(color) self.image.blit(text, (8, 6)) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y
def draw(self, surface): ''' ''' super().draw(surface) #surface.blit(sprite_manager.get('vignette'), (0, 0)) if self._wave_text_timer > 0: utils.draw_font(surface, f'WAVE {self._current_wave}', (255, 255, 255), (433, 97), size=40) else: utils.draw_font(surface, f'{self._current_wave}', (255, 255, 255), (5, 5), size=20) # ui # health pygame.draw.rect(surface, (20, 20, 20), (0, 680, 1024, 20)) healthbar_width = (self.player.health / self.player.max_health) * 1024 pygame.draw.rect(surface, (255, 50, 50), (0, 680, healthbar_width, 20)) utils.draw_font(surface, 'press 1-8 to switch weapons', (255, 255, 255), (408, 680), size=15)
def __init__(self, x, y, message, window): pygame.sprite.Sprite.__init__(self) font_size = 16 self.text = utils.draw_font(message, font_size) self.image = pygame.Surface( [self.text.get_width() + 16, self.text.get_height() + 8]) self.image.fill([23, 38, 38]) self.image.blit(self.text, (8, 6)) self.rect = self.image.get_rect() self.x = x - self.text.get_width() / 2 self.y = y - 16 - self.text.get_height() self.position(window)