class BossEnemyHpBar: def __init__(self, spriteGroup, enemy): self.enemy = enemy self.enemyMaxHp = enemy.hp self.enemyPrevHp = enemy.hp self.spriteGroup = spriteGroup self.hpGuageBarBg = Object(0, 0, "assets/images/hp_bar_guage2.png") self.hpGuageBar = Object(0, 0, "assets/images/hp_bar_guage.png") self.originalHpGuageBarImage = self.hpGuageBar.image self.hpGuageBarEdge = Object(0, 0, "assets/images/hp_bar_edge.png") screenSize = pygame.display.get_surface().get_size() self.hpGuageBarBg.x = screenSize[0] / 2 + 17 self.hpGuageBarBg.y = 55 self.hpGuageBar.x = screenSize[0] / 2 + 17 self.originalHpGuageBarX = self.hpGuageBar.x self.hpGuageBar.y = 55 self.hpGuageBarEdge.x = screenSize[0] / 2 self.hpGuageBarEdge.y = 55 self.spriteGroup.add(self.hpGuageBarBg) self.spriteGroup.add(self.hpGuageBar) self.spriteGroup.add(self.hpGuageBarEdge) self.hpGuageBarBg.update() self.hpGuageBar.update() self.hpGuageBarEdge.update() def __del__(self): self.spriteGroup.remove(self.hpGuageBarBg) self.spriteGroup.remove(self.hpGuageBar) self.spriteGroup.remove(self.hpGuageBarEdge) def update(self): # 적 Hp에 변화가 생겼다면 if self.enemyPrevHp is not self.enemy.hp: hpGuageBarWidth = int( self.lerp(self.originalHpGuageBarImage.get_rect().width, 0, 1.0 - self.enemy.hp / self.enemyMaxHp)) self.hpGuageBar.image = pygame.transform.scale( self.originalHpGuageBarImage, (hpGuageBarWidth, self.originalHpGuageBarImage.get_rect().height)) self.hpGuageBar.x = self.originalHpGuageBarX - ( self.originalHpGuageBarImage.get_rect().width - self.hpGuageBar.image.get_rect().width) / 2 self.enemyPrevHp = self.enemy.hp def lerp(self, fromValue, toValue, t): return fromValue + (toValue - fromValue) * t
class TitleScene: def __init__(self, screen): print("********** Init TitleScene **********") self.screenX, self.screenY = pygame.display.get_surface().get_size() self.allSprites = pygame.sprite.Group() #allSprites 객체 생성 self.prevTime = pygame.time.get_ticks() self.elapsedTime = 0.0 self.bg = Object(self.screenX / 2, self.screenY / 2, 'assets/images/titleSceneBg.png') self.titleImage = Object(self.screenX / 2, 190, 'assets/images/title.png') self.allSprites.add(self.bg) self.allSprites.add(self.titleImage) self.sceneManager = sceneManager.SceneManager() self.screen = screen self.buttonImage1 = "assets/images/buttonPlay.png" self.buttonImage2 = "assets/images/buttonOptions.png" self.buttonImage3 = "assets/images/buttonQuit.png" self.menu = ["Play", "HowToPlay", "Quit"] for i in range(3): if i == 0: self.menu[i] = (Object(0, 0, self.buttonImage1)) elif i == 1: self.menu[i] = (Object(0, 0, self.buttonImage2)) else: self.menu[i] = (Object(0, 0, self.buttonImage3)) self.menu[i].x = 0.5 * self.screenX self.menu[i].y = 0.55 * self.screenY + i * 110 self.menu[i].update() Mixer.init() Mixer.music.load("assets/sounds/title.mp3") Mixer.music.play() def update(self): self.titleImage.update() self.elapsedTime += (pygame.time.get_ticks() - self.prevTime) / 500.0 self.titleImage.y = 190.0 + math.cos(self.elapsedTime) * 10.0 self.prevTime = pygame.time.get_ticks() self.mousePos = pygame.mouse.get_pos() click = pygame.mouse.get_pressed() for i in range(3): if i == 0: if 155 < self.mousePos[0] < 325 and 405 < self.mousePos[1] < 475: self.menu[i] = (Object(0, 0, "assets/images/buttonPlayHover.png")) else: self.menu[i] = (Object(0, 0, self.buttonImage1)) elif i == 1: if 57 < self.mousePos[0] < 423 and 515 < self.mousePos[1] < 585: self.menu[i] = (Object(0, 0, "assets/images/buttonOptionsHover.png")) else: self.menu[i] = (Object(0, 0, self.buttonImage2)) else: if 173 < self.mousePos[0] < 307 and 625 < self.mousePos[1] < 695: self.menu[i] = (Object(0, 0, "assets/images/buttonQuitHover.png")) else: self.menu[i] = (Object(0, 0, self.buttonImage3)) self.menu[i].x = 0.5 * self.screenX self.menu[i].y = 0.55 * self.screenY + i * 110 self.menu[i].update() if 155 < self.mousePos[0] < 325 and 405 < self.mousePos[1] < 475 and click[0] == 1: self.sceneManager.setScene(stageOneScene.StageOneScene(self.screen, self.sceneManager.gameLevel)) if 57 < self.mousePos[0] < 423 and 515 < self.mousePos[1] < 585 and click[0] == 1: self.sceneManager.setScene(optionsScene.OptionsScene(self.screen)) if 173 < self.mousePos[0] < 307 and 625 < self.mousePos[1] < 695 and click[0] == 1: exit() def render(self): self.allSprites.draw(self.screen) for i in range(3): self.menu[i].render(self.screen)