예제 #1
0
    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()
예제 #2
0
    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()
예제 #3
0
    def __init__(self, screen):
        print("********** Init OptionsScene **********")
        self.img = 'assets/images/buttonOptions.png'
        self.image = pygame.transform.scale(pygame.image.load(self.img),
                                            (480, 200))
        self.rect = self.image.get_rect()
        self.x = self.image.get_width()
        self.y = self.image.get_height()
        self.screen = screen
        self.player = None
        self.screenX, self.screenY = pygame.display.get_surface().get_size()
        self.sceneManager = sceneManager.SceneManager()
        self.buttonImage1 = "assets/images/buttonOptionsEasy.png"
        self.buttonImage2 = "assets/images/buttonOptionsNormal.png"
        self.buttonImage3 = "assets/images/buttonOptionsHard.png"
        self.buttonImage4 = "assets/images/buttonQuit.png"
        self.selectOptionImage = "assets/images/bullet01.png"
        self.menu = ["Easy", "Normal", "Hard", "Quit"]

        self.selectOption = (Object(0, 0, self.selectOptionImage))

        for i in range(4):
            if i == 0:
                self.menu[i] = (Object(0, 0, self.buttonImage1))
            elif i == 1:
                self.menu[i] = (Object(0, 0, self.buttonImage2))
            elif i == 2:
                self.menu[i] = (Object(0, 0, self.buttonImage3))
            else:
                self.menu[i] = (Object(0, 0, self.buttonImage4))
            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()
예제 #4
0
    def __init__(self, screen, gameLevel=1):
        print("********** Init StageThreeScene **********")
        self.allSprites = pygame.sprite.Group()  #allSprites 객체 생성
        self.now = "stageThree"
        self.screen = screen
        self.screenX, self.screenY = pygame.display.get_surface().get_size()
        self.enemyList = []
        self.stageStartTime = pygame.time.get_ticks()  # 스테이지 시작 시간
        self.nextEnemyGenTime = 1.0
        self.gameClear = Object(self.screenX / 2, self.screenY / 2,
                                "assets/images/gameClear.png")
        self.stageClearYn = False
        self.gameLevel = gameLevel
        self.sceneManager = sceneManager.SceneManager()
        self.enemyGenInfoList = []
        self.lastTime = 1600.0

        self.initializeEnemyGenInfoList()
        self.initializeBackground()
        self.initializeBGM()
        self.initializePlayer()
        self.initializeItem()
예제 #5
0
    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()
예제 #6
0
    def __init__(self, screen, gameLevel=1):
        print("********** Init StageOneScene **********")
        self.allSprites = pygame.sprite.Group()  #allSprites 객체 생성
        self.now = "stageOne"
        self.screen = screen
        self.screenX, self.screenY = pygame.display.get_surface().get_size()
        self.enemyList = []
        self.stageStartTime = pygame.time.get_ticks()  # 스테이지 시작 시간
        self.gameClear = Object(self.screenX / 2, self.screenY / 2,
                                "assets/images/gameClear.png")
        self.stageClearYn = False
        self.gameLevel = gameLevel
        self.sceneManager = sceneManager.SceneManager()
        self.lastTime = 1600.0
        # 일반 적이 출현하는 정보를 적어놓는 리스트
        # Tuple 값 해석
        # 튜플 요소 0번째: 적이 출현하는 시간대 (초 단위)
        # 튜플 요소 1번째: 적의 Type (0: 일반 적, 1: 보스)
        # 튜플 요소 2번째: 적이 출현하는 x 좌표
        # 튜플 요소 3번째: 적이 출현하는 y 좌표
        self.enemyGenInfoList = [
            (1.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (1.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (5.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (8.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (9.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (9.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (12.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (14.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (15.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (15.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (17.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (18.5, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (20.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (22.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (22.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (23.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (28.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (31.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (32.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (32.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (35.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (37.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (38.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (38.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (40.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (41.5, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (43.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (45.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (45.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (46.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (49.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (50.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (50.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (52.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (55.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (56.0, 0, random.randrange(50.0, self.screenX - 50.0), -15.0),
            (56.0, 1, self.screenX / 2.0, -15.0),
        ]

        self.initializeBackground()
        self.initializeBGM()
        self.initializePlayer()
        self.initializeItem()
예제 #7
0
    def update(self):
        if self.image is not None:
            self.rect = self.image.get_rect()
            self.rect.center = (self.x * 0.5, self.y * 0.5)

        self.mousePos = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()

        if self.sceneManager.gameLevel == 1:
            self.selectOption.x = self.menu[0].x + 150
            self.selectOption.y = self.menu[0].y
        elif self.sceneManager.gameLevel == 2:
            self.selectOption.x = self.menu[1].x + 150
            self.selectOption.y = self.menu[1].y
        elif self.sceneManager.gameLevel == 3:
            self.selectOption.x = self.menu[2].x + 150
            self.selectOption.y = self.menu[2].y
        self.selectOption.update()

        for i in range(4):
            if i == 0:
                if 155 < self.mousePos[0] < 325 and 260 < self.mousePos[
                        1] < 310:
                    self.menu[i] = (Object(
                        0, 0, "assets/images/buttonOptionsEasyHover.png"))

                    if click[0] == 1:
                        self.sceneManager.gameLevel = 1
                else:
                    self.menu[i] = (Object(0, 0, self.buttonImage1))
            elif i == 1:
                if 57 < self.mousePos[0] < 423 and 370 < self.mousePos[1] < 420:
                    self.menu[i] = (Object(
                        0, 0, "assets/images/buttonOptionsNormalHover.png"))

                    if click[0] == 1:
                        self.sceneManager.gameLevel = 2
                else:
                    self.menu[i] = (Object(0, 0, self.buttonImage2))
            elif i == 2:
                if 173 < self.mousePos[0] < 307 and 480 < self.mousePos[
                        1] < 530:
                    self.menu[i] = (Object(
                        0, 0, "assets/images/buttonOptionsHardHover.png"))

                    if click[0] == 1:
                        self.sceneManager.gameLevel = 3
                else:
                    self.menu[i] = (Object(0, 0, self.buttonImage3))
            else:
                if 173 < self.mousePos[0] < 307 and 580 < self.mousePos[
                        1] < 630:
                    self.menu[i] = (Object(
                        0, 0, "assets/images/buttonQuitHover.png"))

                    if click[0] == 1:
                        self.sceneManager.setScene(
                            titleScene.TitleScene(self.screen))
                else:
                    self.menu[i] = (Object(0, 0, self.buttonImage4))

            self.menu[i].x = 0.5 * self.screenX
            self.menu[i].y = 0.35 * self.screenY + i * 110
            self.menu[i].update()