Ejemplo n.º 1
0
class NextStageSelectScene:
    def __init__(self, parent, currentStage, clearedMap):
        self.parent = parent
        self.currentStage = currentStage
        self.clearedMap = clearedMap
        if self.clearedMap == None:
            self.clearedMap = {}
        self.stageManager = stage.StageLinkManager()
        self.nextStageList = self.stageManager.findNextStageList(self.currentStage)
        self.nextStageMap = {}
        for stageInfo in self.nextStageList:
            self.nextStageMap[stageInfo.stage] = stageInfo
        
        self.currentStageInfo = None        # self.stageManager.findStage(self.currentStage)
        self.currentIndex = 0
        self.state = 0
        self.cnt = 0
        self.star_pos = 0
        self.mouseManager = MouseManager()

    def init(self):
        pyxel.image(1).load(0,0,"assets/stageList.png")

    def update(self):
        self.star_pos -= 0.25
        if self.star_pos<0:
            self.star_pos += 256
        self.mouseManager.update()
        if self.state == 0:
            if self.cnt == 20:
                BGM.play(BGM.STAGE_SELECT)
            if self.cnt > 20:
                if gcommon.checkUpP():
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    self.currentIndex -= 1
                    if self.currentIndex < 0:
                        self.currentIndex = len(self.nextStageList) -1
                elif gcommon.checkDownP():
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    self.currentIndex += 1
                    if self.currentIndex >= len(self.nextStageList):
                        self.currentIndex = 0
                elif gcommon.checkShotKeyP():
                    BGM.stop()
                    BGM.sound(gcommon.SOUND_GAMESTART)
                    self.state = 1
                    self.cnt = 0
                else:
                    for i, stageInfo in enumerate(self.nextStageList):
                        rect = gcommon.Rect.createWH(stageInfo.x + StageSelect.nodeBaseX, stageInfo.y + StageSelect.nodeBaseY, 32, 16)
                        if rect.contains(pyxel.mouse_x, pyxel.mouse_y):
                            self.currentIndex = i

        else:
            #print(str(self.cnt))
            if self.cnt > 40:
                gcommon.app.startNextStage(self.nextStageList[self.currentIndex].stage)
        self.currentStageInfo = self.nextStageList[self.currentIndex]
        self.cnt += 1


    def draw(self):
        pyxel.cls(0)
        #self.drawStar()
        gcommon.drawStar(self.star_pos)

        if len(self.nextStageList) == 1:
            # 選択できない
            Drawing.showTextHCenter(20, "GET READY FOR THE NEXT STAGE")
        else:
            Drawing.showTextHCenter(20, "SELECT NEXT STAGE")

        stageInfo = self.stageManager.stageRoot
        stageInfo.setDrawFlag(False)
        highlight = True
        if self.state == 0:
            if self.cnt & 16 == 0:
                highlight = False
        elif self.state == 1:
            if self.cnt & 2 == 0:
                highlight = False
        StageSelect.drawNode(stageInfo, self.currentStageInfo, self.nextStageMap, self.clearedMap, highlight)
        
        px = self.currentStageInfo.imageX  * 64
        py = self.currentStageInfo.imageY  * 56
        pyxel.blt(32, 108, 1, px, py, 64, 56)

        Drawing.showTextHCenter(180, "PUSH SHOT KEY")
  
        if self.mouseManager.visible:
            self.mouseManager.drawMenuCursor()
Ejemplo n.º 2
0
class CustomStageSelectScene:
    nodeBaseX = 16
    nodeBaseY = 64
    # ステータスによって変える色のテーブル(次ステージ選択と色が違う)
    # 0 : 無効
    # 1 : まだ未達
    # 2 : クリア済み
    # 3 : 選択肢(選択中)
    # 4 : 選択肢(非選択)
    imageColorTable = [
        [[1, 0], [5, 1], [12, 5]],
        [[1, 0], [5, 1], [12, 5]],
        [],
        [[1, 1], [5, 8], [12, 14]],
        [],         #[[5, 2], [12, 2]],
    ]
    textColorTable = [
        [[7, 1]],
        [[7, 12]],
        [[5, 1]],
        [],
        [[5, 1]],       #[[7, 5],[5, 1]],
    ]
    def __init__(self, parent):
        self.parent = parent
        self.clearedMap = {}
        self.stageManager = stage.StageLinkManager()
        
        self.rootStageInfo = self.stageManager.getFirstStage()
        self.currentStageInfo = self.rootStageInfo
        self.currentIndex = 0
        self.state = 0
        self.cnt = 0
        self.star_pos = 0
        self.selectableStageMap = {}
        self.setSelectableStageMap(self.currentStageInfo)
        self.clearedMap = {}
        self.mouseManager = MouseManager()

    def init(self):
        pyxel.image(1).load(0,0,"assets/stageList.png")


    def setSelectableStageMap(self, stageInfo: stage.StageInfo):
        self.selectableStageMap[stageInfo.stage] = stageInfo
        if stageInfo.nextStageList != None:
            for child in stageInfo.nextStageList:
                self.setSelectableStageMap(child)

    def update(self):
        self.star_pos -= 0.25
        if self.star_pos<0:
            self.star_pos += 256
        self.mouseManager.update()
        if self.state == 0:
            if self.cnt == 20:
                BGM.play(BGM.STAGE_SELECT)
            if self.cnt > 20:
                if gcommon.checkUpP():
                    if self.currentStageInfo.parentList != None:
                        lst = self.currentStageInfo.parentList[0].nextStageList
                        if len(lst) > 1:
                            BGM.sound(gcommon.SOUND_MENUMOVE)
                            self.currentIndex -= 1
                            if self.currentIndex < 0:
                                self.currentIndex = len(lst) -1
                            self.currentStageInfo = lst[self.currentIndex]
                elif gcommon.checkDownP():
                    if self.currentStageInfo.parentList != None:
                        lst = self.currentStageInfo.parentList[0].nextStageList
                        if lst != None and len(lst) > 1:
                            BGM.sound(gcommon.SOUND_MENUMOVE)
                            self.currentIndex += 1
                            if self.currentIndex >= len(lst):
                                self.currentIndex = 0
                            self.currentStageInfo = lst[self.currentIndex]
                elif gcommon.checkRightP():
                    lst = self.currentStageInfo.nextStageList
                    if lst != None:
                        BGM.sound(gcommon.SOUND_MENUMOVE)
                        if self.currentIndex >= len(lst):
                            self.currentIndex = len(lst) -1
                        self.currentStageInfo = self.currentStageInfo.nextStageList[self.currentIndex]
                        #gcommon.debugPrint("index = " + str(self.currentIndex) + " " + self.currentStageInfo.stage)
                elif gcommon.checkLeftP():
                    if self.currentStageInfo.parentList != None:
                        BGM.sound(gcommon.SOUND_MENUMOVE)
                        self.currentStageInfo = self.currentStageInfo.parentList[0]
                        self.currentIndex = 0
                        #gcommon.debugPrint("index = " + str(self.currentIndex) + " " + self.currentStageInfo.stage)
                elif gcommon.checkShotKeyP():
                    BGM.stop()
                    BGM.sound(gcommon.SOUND_GAMESTART)
                    self.state = 1
                    self.cnt = 0
                else:
                    if self.mouseManager.visible:
                        stageInfo = self.getMouseSelectedStageInfo(self.rootStageInfo)
                        if stageInfo != None:
                            self.currentStageInfo = stageInfo

        else:
            #print(str(self.cnt))
            if self.cnt > 40:
                gcommon.app.startNextStage(self.currentStageInfo.stage)
        self.cnt += 1

    def getMouseSelectedStageInfo(self, stageInfo : stage.StageInfo):
        rect = gcommon.Rect.createWH(stageInfo.x + StageSelect.nodeBaseX, stageInfo.y + StageSelect.nodeBaseY, 32, 16)
        if rect.contains(pyxel.mouse_x, pyxel.mouse_y):
            return stageInfo
        elif stageInfo.nextStageList != None:
            for nextStage in stageInfo.nextStageList:
                s = self.getMouseSelectedStageInfo(nextStage)
                if s != None:
                    return s
        else:
            return None

    def draw(self):
        pyxel.cls(0)
        #self.drawStar()
        gcommon.drawStar(self.star_pos)

        Drawing.showTextHCenter(20, "SELECT STAGE")

        stageInfo = self.stageManager.stageRoot
        stageInfo.setDrawFlag(False)
        highlight = True
        if self.state == 0:
            if self.cnt & 8 == 0:
                highlight = False
        elif self.state == 1:
            if self.cnt & 2 == 0:
                highlight = False
        self.drawNode(stageInfo, self.currentStageInfo, self.selectableStageMap, self.clearedMap, highlight)

        px = self.currentStageInfo.imageX  * 64
        py = self.currentStageInfo.imageY  * 56
        pyxel.blt(32, 108, 1, px, py, 64, 56)

        Drawing.showTextHCenter(180, "PUSH SHOT KEY")

        if self.mouseManager.visible:
            self.mouseManager.drawMenuCursor()

    # node 描画するステージ(StateInfo)
    # currentStage 現在選択中のステージ(StateInfo)
    # selectableStageMap 選択可能なステージ(string, StateInfo)のマップ
    # cleaedMap クリアしたステージ文字列(stringのマップ)
    #
    def drawNode(self, node: stage.StageInfo, currentStage, selectableStageMap, clearedMap, highlight:bool):
        if node.drawFlag:
            return
        node.drawFlag = True
        # 0 : 無効
        # 1 : まだ未達
        # 2 : クリア済み
        # 3 : 選択肢(選択中)
        # 4 : 選択肢(非選択)
        status = 1
        # 状態種類
        #   無効(実装されてない)  enabled = False
        #   有効
        #     まだ未達
        #     クリア済
        #     選択肢  選択中/非選択
        if node == None or node.enabled == False:
            status = 0
        else:
            # 有効
            if node.stage in clearedMap:
                # クリア済みは色そのまま
                status = 2
                pass
            else:
                if node.stage in selectableStageMap:
                    if node.stage == currentStage.stage:
                        # 選択中
                        status = 3
                        if highlight == False:
                            status = 2
                    else:
                        # 非選択
                        status = 4
                else:
                    status = 1
        for t in __class__.imageColorTable[status]:
            pyxel.pal(t[0], t[1])
        pyxel.blt(node.x +__class__.nodeBaseX, node.y + __class__.nodeBaseY, 0, 0, 224, 32, 16)
        pyxel.pal()
        for t in __class__.textColorTable[status]:
            pyxel.pal(t[0], t[1])
        if node != None:
            Drawing.showText(node.x + 8 +__class__.nodeBaseX, node.y +4 + __class__.nodeBaseY, node.stage)
        pyxel.pal()
        if node != None and node.nextStageList != None:
            for childNode in node.nextStageList:
                self.drawNode(childNode, currentStage, selectableStageMap, clearedMap, highlight)
Ejemplo n.º 3
0
class TitleScene:
    colorTable1 = (3, 4, 8, 9, 10, 11, 13, 14, 15)
    colorTable2 = (2, 1, 5, 6, 7, 12)
    colorTable1a = (1, 5, 5, 12, 12, 6, 6, 7, 7)
    # 文字内側が光る
    colorTable3 = (
        ((2, 1), (1, 5), (5, 12), (12, 6), (6, 7)),
        ((2, 5), (1, 12), (5, 6), (12, 7), (6, 7)),
        ((2, 12), (1, 6), (5, 7), (12, 7), (6, 7)),
        ((2, 6), (1, 7), (5, 7), (12, 7), (6, 7)),
        ((2, 7), (1, 7), (5, 7), (12, 7), (6, 7)),
    )
    polyPoints = [[0, 0], [24, 0], [0, 72], [-24, 72]]

    title_y = 16
    menu_top_y = 105

    def __init__(self):
        gcommon.map_y = 0
        self.cnt = 0
        pyxel.image(1).load(0, 0, "assets/title.png")
        pyxel.tilemap(0).refimg = 1
        self.menuPos = 0
        self.timer = 0
        # 0 - タイトルデモ
        # 100 メニュー選択
        # 200 ゲーム開始
        self.state = 0
        self.star_pos = 0
        self.subState = 0
        self.subCnt = 0
        self.rnd = gcommon.ClassicRand()
        self.py = 0
        self.ey = 24
        self.cntLimit = 70
        self.objs = []
        self.difficulty = Settings.difficulty
        self.credits = Settings.credits
        self.mouseManager = MouseManager()
        self.menuRects = []
        for i in range(5):
            self.menuRects.append(
                gcommon.Rect.create(48, __class__.menu_top_y - 2 + i * 15,
                                    48 + 160 - 1, __class__.menu_top_y - 2 +
                                    i * 15 + 12 - 1))
        self.difficultyRects = [
            gcommon.Rect.createWH(128 - 8 - 48 - 4, 120, 8, 8),
            gcommon.Rect.createWH(128 + 48 + 4, 120, 8, 8),
        ]

    def init(self):
        BGM.play(BGM.TITLE)

    def update(self):
        self.star_pos -= 0.25
        if self.star_pos < 0:
            self.star_pos += 200

        if self.state < 100:
            self.updateDemo()
        else:
            self.update100()
        newObjs = []
        for obj in self.objs:
            if obj.removeFlag == False:
                obj.update()
                newObjs.append(obj)
        self.objs = newObjs

    def updateDemo(self):
        if self.state == 0:
            if self.cnt > 180:
                self.cnt = 0
                self.state = 1
        elif self.state == 1:
            self.py += 0.15
            #self.py += 0.5
            if self.subCnt >= self.cntLimit:
                self.subState += 1
                self.cntLimit = int(self.cntLimit * 0.8)
                self.subCnt = 0
                if self.subState == 9:
                    self.state = 2
                    self.subCnt = 0
                    self.cnt = 0
        elif self.state == 2:
            # ちょっと待ち
            if self.cnt > 1:
                self.state = 3
                self.subState = 0
                self.subCnt = 0
                self.cnt = 0
        elif self.state == 3:
            # 明るくなる
            if self.subCnt > 3:
                self.subState += 1
                self.subCnt = 0
                if self.subState == len(TitleScene.colorTable3):
                    self.subState = len(TitleScene.colorTable3) - 1
                    self.state = 4
        elif self.state == 4:
            # 戻る
            if self.subCnt > 3:
                self.subState -= 1
                self.subCnt = 0
                if self.subState == 0:
                    self.state = 5
                    self.cnt = 0
        elif self.state == 5:
            if self.subCnt > 32:
                self.state = 6
                self.cnt = 0
        elif self.state == 6:
            #self.objs.append(enemy.Particle1(220 - self.cnt * 10, 60, 0, 8, 50))
            # 文字がせり出す
            if self.cnt > 20:
                self.setUpdate100()
                return
        self.subCnt += 1
        self.cnt = (self.cnt + 1) & 1023
        if gcommon.checkShotKeyP():
            self.setUpdate100()

    # メニュー処理へ移行
    def setUpdate100(self):
        self.state = 100
        self.cnt = 0

    # メニュー処理があるupdate
    def update100(self):
        self.mouseManager.update()
        if self.state >= 100 and self.state < 200:

            if self.mouseManager.visible:
                n = gcommon.checkMouseMenuPos(self.menuRects)
                if n != -1:
                    self.menuPos = n

            if gcommon.checkUpP():
                BGM.sound(gcommon.SOUND_MENUMOVE)
                self.menuPos = (self.menuPos - 1) % 5
            elif gcommon.checkDownP():
                BGM.sound(gcommon.SOUND_MENUMOVE)
                self.menuPos = (self.menuPos + 1) % 5
            elif pyxel.btnp(pyxel.KEY_T):
                gcommon.app.startStageSelect()
                return

            if self.menuPos == TITLEMENU_START:
                n = -1
                if self.mouseManager.visible:
                    n = gcommon.checkMouseMenuPos(self.difficultyRects)
                if gcommon.checkLeftP() or (gcommon.checkShotKeyP()
                                            and n == 0):
                    if self.difficulty > 0:
                        BGM.sound(gcommon.SOUND_MENUMOVE)
                        self.difficulty -= 1
                    return
                elif gcommon.checkRightP() or (gcommon.checkShotKeyP()
                                               and n == 1):
                    if self.difficulty < 2:
                        BGM.sound(gcommon.SOUND_MENUMOVE)
                        self.difficulty += 1
                    return
                elif gcommon.checkShotKeyRectP(
                        self.menuRects[TITLEMENU_START]):
                    BGM.stop()
                    BGM.sound(gcommon.SOUND_GAMESTART)
                    # ここですぐにはゲームスタートしない
                    self.state = 200
                    self.cnt = 0
                    return
            elif self.menuPos == TITLEMENU_CUSTOMSTART:
                if gcommon.checkShotKeyRectP(
                        self.menuRects[TITLEMENU_CUSTOMSTART]):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    gcommon.app.startCustomStartMenu()
                    return
            elif self.menuPos == TITLEMENU_BOSSRUSHSTART:
                if gcommon.checkShotKeyRectP(
                        self.menuRects[TITLEMENU_BOSSRUSHSTART]):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    gcommon.app.startBossRushStartMenu()
                    return
            elif self.menuPos == TITLEMENU_OPTION:
                if gcommon.checkShotKeyRectP(self.menuRects[TITLEMENU_OPTION]):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    gcommon.app.startOption()
                    return
            elif self.menuPos == TITLEMENU_EXIT:
                if gcommon.checkShotKeyRectP(self.menuRects[TITLEMENU_EXIT]):
                    pyxel.quit()

        if self.state == 102:
            # 明るくなる
            if self.subCnt > 3:
                self.subState += 1
                self.subCnt = 0
                if self.subState == len(TitleScene.colorTable3):
                    self.subState = len(TitleScene.colorTable3) - 1
                    self.state = 103
            self.subCnt += 1
        elif self.state == 103:
            # 戻る
            if self.subCnt > 3:
                self.subState -= 1
                self.subCnt = 0
                if self.subState == 0:
                    self.state = 104
                    self.cnt = 0
                    return
            self.subCnt += 1
        elif self.state == 104:
            if self.subCnt > 32:
                self.state = 100
                self.cnt = 0
                return
            self.subCnt += 1
        elif self.state == 200:
            # GAME START
            if self.cnt > 40:
                gcommon.app.startNormalGame(self.difficulty)

        self.cnt += 1
        if self.cnt >= 5 * 60:
            self.cnt = 0
            if self.state == 100:
                self.state = 102
                self.subState = 0
                self.subCnt = 0

    def draw(self):
        pyxel.cls(0)
        if self.state < 100:
            self.drawDemo()
        else:
            self.draw100()
        for obj in self.objs:
            if obj.removeFlag == False:
                obj.draw()

    def drawStar(self):
        for i in range(0, 96):
            pyxel.pset(gcommon.star_ary[i][0],
                       int(i * 2 + self.star_pos) % 200,
                       gcommon.star_ary[i][1])

    def drawDemo(self):
        pyxel.cls(0)
        pyxel.pal()
        self.drawStar()
        if self.state == 0:
            pass
        elif self.state == 1:
            color = TitleScene.colorTable1a[self.subState]
            # 文字中
            n = int(self.rnd.rand() % (30 - self.subState * 3))
            for c in TitleScene.colorTable2:
                if n == 0:
                    pyxel.pal(c, color)
                else:
                    pyxel.pal(c, 0)

            # 文字枠
            for c in TitleScene.colorTable1:
                pyxel.pal(c, 0)
            if self.cnt & 1 == 0:
                cc = self.rnd.rand() % len(TitleScene.colorTable1)
                for i in range(self.subState + 1):
                    pyxel.pal(
                        TitleScene.colorTable1[(cc + i) %
                                               len(TitleScene.colorTable1)],
                        color)
            w = (10 - self.subState)
            for i in range(80):
                pyxel.blt(((self.rnd.rand() % w) - w / 2) * 3,
                          __class__.title_y + 36 - self.py + i, 1, 0, 40 + i,
                          256, 1, 0)
        elif self.state == 2:
            self.drawTitleNormal()
        elif self.state == 3 or self.state == 4:
            pyxel.pal()
            # 文字枠
            for c in TitleScene.colorTable1:
                pyxel.pal(c, 7)
            table = TitleScene.colorTable3[self.subState]
            for t in table:
                pyxel.pal(t[0], t[1])
            pyxel.blt(0, __class__.title_y, 1, 0, 40, 256, 80, 0)
        elif self.state == 5:
            self.drawTitleNormal()
            self.drawFlash(self.subCnt * 8, __class__.title_y)
        elif self.state == 6:
            self.drawTitleNormal()
            self.drawMenu(False, self.cnt / 20)
        else:
            self.drawTitleNormal()

    # タイトル通常描画
    def drawTitleNormal(self):
        pyxel.pal()
        # 文字枠
        for c in TitleScene.colorTable1:
            pyxel.pal(c, 7)
        pyxel.pal(2, 0)
        pyxel.blt(0, __class__.title_y, 1, 0, 40, 256, 80, 0)

    def draw100(self):
        self.drawStar()

        if self.state in (100, 200):
            self.drawTitleNormal()
        elif self.state == 102 or self.state == 103:
            pyxel.pal()
            # 文字枠
            for c in TitleScene.colorTable1:
                pyxel.pal(c, 7)
            table = TitleScene.colorTable3[self.subState]
            for t in table:
                pyxel.pal(t[0], t[1])
            pyxel.blt(0, __class__.title_y, 1, 0, 40, 256, 80,
                      0)  # pyxel.pal()
        elif self.state == 104:
            self.drawTitleNormal()
            self.drawFlash(self.subCnt * 8, 32)

        self.drawMenu(self.state == 200, 1.0)

        pyxel.text(200, 188, "CREDIT(S) " + str(self.credits), 7)
        pyxel.blt(10, 186, 0, 88, 120, 8, 8, 0)
        pyxel.text(20, 188, "2021 ONTAKE44", 7)

        Drawing.showTextHCentor2(188, "VER " + gcommon.VERSION, 7)

        pyxel.pal()
        if self.mouseManager.visible:
            self.mouseManager.drawMenuCursor()
        #pyxel.blt(78, 120 + self.menuPos * 15, 0, 8, 32, 8, 8, gcommon.TP_COLOR)

    def drawFlash(self, x, y):
        pyxel.pal()
        for c in range(1, 15):
            pyxel.pal(c, 7)
        #pyxel.blt(self.subCnt*8, 24, 4, self.subCnt*8, 24, 40, 80, 0)
        Drawing.drawPolygonSystemImage(
            gcommon.getShitPoints([x, y], TitleScene.polyPoints))
        pyxel.pal()

    def drawMenu(self, startFlag, rate):
        pyxel.pal()
        y = __class__.menu_top_y
        if rate < 1.0:
            gcommon.setMenuColor(0, -1)
        else:
            if (startFlag and self.cnt & 2 == 0) or (startFlag == False
                                                     and self.menuPos == 0
                                                     and self.cnt & 16 == 0):
                pyxel.pal(7, 8)
                pyxel.pal(5, 4)
            else:
                gcommon.setMenuColor(0, self.menuPos)
        text = gcommon.difficultyText[self.difficulty] + " START"
        Drawing.showTextRateHCenter(y, text, rate)
        if rate == 1.0 and self.menuPos == 0:
            Drawing.drawLeftMarker(128 - 8 - 48 - 4, y, self.difficulty > 0)
            Drawing.drawRightMarker(128 + 48 + 4, y, self.difficulty < 2)
        pyxel.pal()

        y += 15
        gcommon.setMenuColor(1, self.menuPos)
        Drawing.showTextRateHCenter(y, "CUSTOM START", rate)

        y += 15
        gcommon.setMenuColor(2, self.menuPos)
        Drawing.showTextRateHCenter(y, "BOSS RUSH START", rate)

        y += 15
        gcommon.setMenuColor(3, self.menuPos)
        Drawing.showTextRateHCenter(y, "OPTION", rate)

        y += 15
        gcommon.setMenuColor(4, self.menuPos)
        Drawing.showTextRateHCenter(y, "EXIT", rate)

        if rate == 1.0:
            Drawing.setBrightness1()
            pyxel.blt(48, __class__.menu_top_y - 2 + self.menuPos * 15, 4, 48,
                      __class__.menu_top_y - 2 + self.menuPos * 15, 160, 12)
            pyxel.pal()
Ejemplo n.º 4
0
class BossRushStartMenuScene:
    def __init__(self):
        self.star_pos = 0
        oy = 16
        self.menuYList = (50 +oy, 70 +oy, 90 +oy, 110+oy, 130+oy)		#, 158 +oy)
        self.menuPos = 0
        self.state = 0
        self.cnt = 0
        self.mouseManager = MouseManager()

        self.menuRects = []
        for y in self.menuYList:
            self.menuRects.append(gcommon.Rect.create(
                16, y, 16 +224 -1, y +12-1))
        self.playerStockRects = [
            gcommon.Rect.createWH(MENU_VALUE_X -10, self.menuYList[MENU_PLAYER_STOCK], 8, 8),
            gcommon.Rect.createWH(MENU_VALUE_X -10+26, self.menuYList[MENU_PLAYER_STOCK], 8, 8)
        ]
        self.weaponTypeRects = [
            gcommon.Rect.createWH(MENU_VALUE_X -10, self.menuYList[MENU_WEAPON_TYPE], 8, 8),
            gcommon.Rect.createWH(MENU_VALUE_X + 6 * 8 +2, self.menuYList[MENU_WEAPON_TYPE], 8, 8)
        ]
        self.multipleRects = [
            gcommon.Rect.createWH(MENU_VALUE_X -10, self.menuYList[MENU_WEAPON_OPTION], 8, 8),
            gcommon.Rect.createWH(MENU_VALUE_X -10+26, self.menuYList[MENU_WEAPON_OPTION], 8, 8)
        ]

    def init(self):
        self.menuPos = 0

    def update(self):
        self.star_pos -= 0.25
        if self.star_pos<0:
            self.star_pos += 200
        self.mouseManager.update()
        if self.cnt >= 6*60:
            self.cnt = 0
        if self.state == 0:
            if gcommon.checkUpP():
                BGM.sound(gcommon.SOUND_MENUMOVE)
                self.menuPos -= 1
                if self.menuPos == MENU_WEAPON_OPTION and Settings.weaponType == gcommon.WeaponType.TYPE_A:
                    self.menuPos = MENU_WEAPON_TYPE
                if self.menuPos < 0:
                    self.menuPos = 4
            if gcommon.checkDownP():
                BGM.sound(gcommon.SOUND_MENUMOVE)
                self.menuPos += 1
                if self.menuPos == MENU_WEAPON_OPTION and Settings.weaponType == gcommon.WeaponType.TYPE_A:
                    self.menuPos = MENU_GAME_START
                if self.menuPos > 4:
                    self.menuPos = 0
            
            if self.mouseManager.visible:
                n = gcommon.checkMouseMenuPos(self.menuRects)
                if n != -1:
                    self.menuPos = n

            if self.menuPos == MENU_PLAYER_STOCK:
                n = -1
                if self.mouseManager.visible:
                    n = gcommon.checkMouseMenuPos(self.playerStockRects)
                if gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    Settings.playerStock += 1
                    if Settings.playerStock > 99:
                        Settings.playerStock = 99
                elif gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    Settings.playerStock -= 1
                    if Settings.playerStock < 1:
                        Settings.playerStock = 1

            elif self.menuPos == MENU_WEAPON_TYPE:
                n = -1
                if self.mouseManager.visible:
                    n = gcommon.checkMouseMenuPos(self.weaponTypeRects)
                if gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    Settings.weaponType = gcommon.WeaponType.TYPE_B
                elif gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    Settings.weaponType = gcommon.WeaponType.TYPE_A

            elif self.menuPos == MENU_WEAPON_OPTION:
                n = -1
                if self.mouseManager.visible:
                    n = gcommon.checkMouseMenuPos(self.multipleRects)
                if gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    Settings.multipleCount += 1
                    if Settings.multipleCount > 20:
                        Settings.multipleCount = 20
                elif gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0):
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    Settings.multipleCount -= 1
                    if Settings.multipleCount < 0:
                        Settings.multipleCount = 0

            elif self.menuPos == MENU_GAME_START:
                n = -1
                if gcommon.checkShotKeyP():
                    BGM.stop()
                    BGM.sound(gcommon.SOUND_GAMESTART)
                    Settings.saveSettings()
                    self.state = 1
                    self.cnt = 0
            
            elif self.menuPos == MENU_EXIT:
                if gcommon.checkShotKeyRectP(self.menuRects[MENU_EXIT]):
                    Settings.saveSettings()
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    gcommon.app.startTitle()
        else:
            # GAME START
            if self.cnt > 40:
                gcommon.app.startBossRushGame()
        self.cnt += 1

    def draw(self):
        pyxel.cls(0)
        self.drawStar()
        Drawing.showTextHCenter(32, "BOSS RUSH START")
        
        x1 = 48
        x2 = MENU_VALUE_X
        x3 = START_X

        idx = 0
        self.setOptionColor(MENU_PLAYER_STOCK)
        Drawing.showText(x1, self.menuYList[MENU_PLAYER_STOCK], "PLAYER STOCK")
        Drawing.showText(x2, self.menuYList[MENU_PLAYER_STOCK], str(Settings.playerStock).rjust(2))
        if MENU_PLAYER_STOCK == self.menuPos:
            Drawing.drawUpDownMarker2(x2 -10, self.menuYList[idx], 1, 99, Settings.playerStock)

        idx += 1
        self.setOptionColor(MENU_WEAPON_TYPE)
        Drawing.showText(x1, self.menuYList[MENU_WEAPON_TYPE], "WEAPON")
        if Settings.weaponType == gcommon.WeaponType.TYPE_A:
            Drawing.showText(x2, self.menuYList[MENU_WEAPON_TYPE], "TYPE A")
        else:
            Drawing.showText(x2, self.menuYList[MENU_WEAPON_TYPE], "TYPE B")
        if MENU_WEAPON_TYPE == self.menuPos:
            typeA = (Settings.weaponType == gcommon.WeaponType.TYPE_A)
            Drawing.drawLeftMarker(x2 -10, self.menuYList[MENU_WEAPON_TYPE], not typeA)
            Drawing.drawRightMarker(x2 +6*8 +2, self.menuYList[MENU_WEAPON_TYPE], typeA)

        if Settings.weaponType == gcommon.WeaponType.TYPE_B:
            self.setOptionColor(MENU_WEAPON_OPTION)
            Drawing.showText(x1, self.menuYList[MENU_WEAPON_OPTION], " MULTIPLE")
            Drawing.showText(x2, self.menuYList[MENU_WEAPON_OPTION], str(Settings.multipleCount).rjust(2))
            if MENU_WEAPON_OPTION == self.menuPos:
                Drawing.drawUpDownMarker2(x2 -10, self.menuYList[MENU_WEAPON_OPTION], 0, 99, Settings.multipleCount)

        # idx += 1
        # self.setOptionColor(MENU_START_STAGE)
        # Drawing.showText(x1, self.menuYList[MENU_START_STAGE], "START STAGE")
        # Drawing.showText(x2, self.menuYList[MENU_START_STAGE], gcommon.stageList[self.stageIndex])
        # if MENU_START_STAGE == self.menuPos:
        # 	Drawing.drawUpDownMarker2(x2 -10, self.menuYList[MENU_START_STAGE], 0, len(gcommon.stageList)-1, self.stageIndex)
        idx += 1

        text = "START"
        if self.state == 0:
            if self.state == 0 and self.menuPos == MENU_GAME_START and self.cnt & 16 == 0:
                pyxel.pal(7, 8)
                pyxel.pal(5, 4)
            else:
                self.setOptionColor(MENU_GAME_START)
            Drawing.showTextHCenter(self.menuYList[MENU_GAME_START], text)
        else:
            if self.cnt & 2 == 0:
                pyxel.pal(7, 8)
                pyxel.pal(5, 4)
            Drawing.showTextHCenter(self.menuYList[MENU_GAME_START], text)
        pyxel.pal()
        idx += 1

        # if self.state == 0:
        # 	self.setOptionColor(MENU_GAME_START)
        # 	Drawing.showTextHCenter(self.menuYList[3], "GAME START")
        # else:
        # 	if self.cnt & 2 == 0:
        # 		pyxel.pal(7, 8)
        # 	Drawing.showTextHCenter(self.menuYList[3], "GAME START")
        # 	if self.cnt & 2 == 0:
        # 		pyxel.pal()
        
        self.setOptionColor(MENU_EXIT)
        Drawing.showTextHCenter(self.menuYList[MENU_EXIT], "EXIT")
        
        Drawing.setBrightness1()
        y = self.menuYList[self.menuPos] -2
        pyxel.blt(16, y, 4, 16, y, 224, 12)
        pyxel.pal()
        if self.mouseManager.visible:
            self.mouseManager.drawMenuCursor()

    def setOptionColor(self, index):
        if index == self.menuPos:
            pyxel.pal()
        else:
            pyxel.pal(7, 12)

    def drawStar(self):
        for i in range(0,96):
            pyxel.pset(gcommon.star_ary[i][0], int(i*2 +self.star_pos) % 200, gcommon.star_ary[i][1])
Ejemplo n.º 5
0
class RankingDispScene:
    LEFT_MARKER_X = 128 - 8 * 6 - 2
    RIGHT_MARKER_X = 128 + 8 * 5 + 2
    MARKER_Y = 24
    EXIT_Y = 184
    colXList = [8, 56, 128, 208]
    colXList2 = [8, 64, 104, 208, 184, 48]
    colNameList = ["RANK", "NAME", "   SCORE", "STAGE", " @", "}"]
    rankList = [
        " 1ST", " 2ND", " 3RD", " 4TH", " 5TH", " 6TH", " 7TH", " 8TH", " 9TH",
        "10TH"
    ]

    def __init__(self, exitTo):
        self.exitTo = exitTo  # 0:タイトル 1:option
        self.star_pos = 0
        self.menuPos = 0
        self.gameMode = GameSession.gameMode
        self.difficulty = GameSession.difficulty
        self.mouseManager = MouseManager()
        self.markerRects = [
            gcommon.Rect.createWH(__class__.LEFT_MARKER_X, __class__.MARKER_Y,
                                  8, 8),
            gcommon.Rect.createWH(__class__.RIGHT_MARKER_X, __class__.MARKER_Y,
                                  8, 8)
        ]
        self.exitRect = [
            gcommon.Rect.createWH(128 - 8 * 2, __class__.EXIT_Y, 8 * 4, 8),
        ]
        self.menuYList = (__class__.MARKER_Y, __class__.EXIT_Y)
        self.menuRects = [
            gcommon.Rect.create(64, __class__.MARKER_Y - 2, 255 - 64,
                                __class__.MARKER_Y + 10 - 1),
            gcommon.Rect.create(64, __class__.EXIT_Y - 2, 255 - 64,
                                __class__.EXIT_Y + 10 - 1)
        ]

    def init(self):
        self.rakingManager = ranking.RankingManager()
        self.rakingManager.load()

    def update(self):
        self.star_pos -= 0.25
        if self.star_pos < 0:
            self.star_pos += 200
        self.mouseManager.update()

        if gcommon.checkUpP():
            BGM.sound(gcommon.SOUND_MENUMOVE)
            self.menuPos = 0
        if gcommon.checkDownP():
            BGM.sound(gcommon.SOUND_MENUMOVE)
            self.menuPos = 1

        if self.mouseManager.visible:
            n = gcommon.checkMouseMenuPos(self.menuRects)
            if n != -1:
                self.menuPos = n
        if self.menuPos == 0:
            n = -1
            if self.mouseManager.visible:
                n = gcommon.checkMouseMenuPos(self.markerRects)
            if gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0):
                if self.gameMode == gcommon.GAMEMODE_NORMAL:
                    if self.difficulty > 0:
                        BGM.sound(gcommon.SOUND_MENUMOVE)
                        self.difficulty -= 1
                else:
                    # BOSSRUSH
                    BGM.sound(gcommon.SOUND_MENUMOVE)
                    self.gameMode = gcommon.GAMEMODE_NORMAL
                    self.difficulty = gcommon.DIFFICULTY_HARD
            elif gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1):
                if self.gameMode == gcommon.GAMEMODE_NORMAL:
                    if self.difficulty < 2:
                        BGM.sound(gcommon.SOUND_MENUMOVE)
                        self.difficulty += 1
                    else:
                        BGM.sound(gcommon.SOUND_MENUMOVE)
                        self.gameMode = gcommon.GAMEMODE_BOSSRUSH
        elif self.menuPos == 1:  # EXIT
            if gcommon.checkShotKeyRectP(self.menuRects[1]):
                BGM.sound(gcommon.SOUND_MENUMOVE)
                if self.exitTo == 0:
                    gcommon.app.startTitle()
                else:
                    gcommon.app.startOption()

    def draw(self):
        pyxel.cls(0)
        self.drawStar()

        Drawing.showTextHCenter(8, "SCORE RANKING")
        self.setOptionColor(0)
        if self.gameMode == gcommon.GAMEMODE_NORMAL:
            cols = __class__.colXList
            Drawing.showTextHCenter(__class__.MARKER_Y,
                                    gcommon.difficultyText[self.difficulty])
            Drawing.drawLeftMarker(__class__.LEFT_MARKER_X, __class__.MARKER_Y,
                                   self.difficulty > 0)
            Drawing.drawRightMarker(__class__.RIGHT_MARKER_X,
                                    __class__.MARKER_Y, True)
        else:
            cols = __class__.colXList2
            Drawing.showTextHCenter(__class__.MARKER_Y, "BOSS RUSH")
            Drawing.drawLeftMarker(__class__.LEFT_MARKER_X, __class__.MARKER_Y,
                                   True)
            Drawing.drawRightMarker(__class__.RIGHT_MARKER_X,
                                    __class__.MARKER_Y, False)

        self.setOptionColor(1)
        Drawing.showTextHCenter(__class__.EXIT_Y, "EXIT")
        pyxel.pal()

        # カラムヘッダー
        pyxel.pal(7, 12)
        for i, x in enumerate(cols):
            Drawing.showText(x, 40, __class__.colNameList[i])
        pyxel.pal()

        if self.gameMode == gcommon.GAMEMODE_NORMAL:
            if self.difficulty == gcommon.DIFFICULTY_EASY:
                rankingList = self.rakingManager.easyRanking
            elif self.difficulty == gcommon.DIFFICULTY_NORMAL:
                rankingList = self.rakingManager.normalRanking
            else:
                rankingList = self.rakingManager.hardRanking
        else:
            rankingList = self.rakingManager.bossRushRanking
        if rankingList == None:
            rankingList = []
        sy = 56
        dy = 12
        for i in range(10):
            name = "---"
            score = "--------"
            destroyed = "--"
            stage = "  -"
            weaponType = "-"
            if i < len(rankingList):
                name = rankingList[i].name
                score = str(rankingList[i].score).rjust(8)
                destroyed = str(rankingList[i].destroyed).rjust(2)
                if rankingList[i].stage == "-1":
                    stage = "CLEAR"
                else:
                    stage = "  " + str(rankingList[i].stage)
                if rankingList[i].weaponType == "0":
                    weaponType = "A"
                elif rankingList[i].weaponType == "1":
                    weaponType = "B"
            Drawing.showText(cols[0], sy + i * dy, __class__.rankList[i])
            Drawing.showText(cols[1], sy + i * dy, name)
            Drawing.showText(cols[2], sy + i * dy, score)
            Drawing.showText(cols[3], sy + i * dy, stage)
            if self.gameMode == gcommon.GAMEMODE_BOSSRUSH:
                Drawing.showText(cols[4], sy + i * dy, destroyed)
                Drawing.showText(cols[5], sy + i * dy, weaponType)

        Drawing.setBrightness1()
        rect = self.menuRects[self.menuPos]
        pyxel.blt(rect.left, rect.top, 4, rect.left, rect.top, rect.getWidth(),
                  rect.getHeight())
        pyxel.pal()

        # マウスカーソル
        if self.mouseManager.visible:
            self.mouseManager.drawMenuCursor()

    def setOptionColor(self, index):
        if index == self.menuPos:
            pyxel.pal()
        else:
            pyxel.pal(7, 12)

    def drawStar(self):
        for i in range(0, 96):
            pyxel.pset(gcommon.star_ary[i][0],
                       int(i * 2 + self.star_pos) % 200,
                       gcommon.star_ary[i][1])

    # ランキングに載るかどうかをチェック
    def checkRanking(self):
        return True

    def loadRanking(self):
        return False
Ejemplo n.º 6
0
class OptionMenuScene:
	def __init__(self):
		self.star_pos = 0
		self.menuPos = 0
		self.mouseManager = MouseManager()
		self.menuRects = []
		for i in range(5):
			self.menuRects.append(gcommon.Rect.createWH(
				32, 48 + i * 20, 192, 12))
		# BGM Marker
		self.bgmUpDownRects = [
			gcommon.Rect.createWH(MENU_VALUE_X -10, 50, 8, 8),
			gcommon.Rect.createWH(26 +MENU_VALUE_X -10, 50, 8, 8)
		]
		# SE Marker
		self.seUpDownRects = [
			gcommon.Rect.createWH(MENU_VALUE_X -10, 70, 8, 8),
			gcommon.Rect.createWH(MENU_VALUE_X +8*3+2, 70, 8, 8)
		]
		# Mouse ON/OFF Marker
		self.mouseOnOffRects = [
			gcommon.Rect.createWH(MENU_VALUE_X -10, 90, 8, 8),
			gcommon.Rect.createWH(MENU_VALUE_X +8*3+2, 90, 8, 8)
		]

	def init(self):
		self.menuPos = 0

	def update(self):
		self.star_pos -= 0.25
		if self.star_pos<0:
			self.star_pos += 200
		self.mouseManager.update()
		if gcommon.checkUpP():
			BGM.sound(gcommon.SOUND_MENUMOVE)
			self.menuPos -= 1
			if self.menuPos < 0:
				self.menuPos = 4
		if gcommon.checkDownP():
			BGM.sound(gcommon.SOUND_MENUMOVE)
			self.menuPos += 1
			if self.menuPos > 4:
				self.menuPos = 0

		if self.mouseManager.visible:
			n = gcommon.checkMouseMenuPos(self.menuRects)
			if n != -1:
				self.menuPos = n
		
		if self.menuPos == OPTIONMENU_BGM_VOL:
			n = -1
			if self.mouseManager.visible:
				n = gcommon.checkMouseMenuPos(self.bgmUpDownRects)
			if gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1):
				BGM.sound(gcommon.SOUND_MENUMOVE)
				Settings.bgmVolume += 1
				if Settings.bgmVolume > 10:
					Settings.bgmVolume = 10
			elif gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0):
				BGM.sound(gcommon.SOUND_MENUMOVE)
				Settings.bgmVolume -= 1
				if Settings.bgmVolume < 0:
					Settings.bgmVolume = 0
		elif self.menuPos == OPTIONMENU_SOUND_VOL:
			n = -1
			if self.mouseManager.visible:
				n = gcommon.checkMouseMenuPos(self.seUpDownRects)
			if gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1):
				Settings.soundVolume = 10
				BGM.sound(gcommon.SOUND_MENUMOVE)
			elif gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0):
				Settings.soundVolume = 0
				BGM.sound(gcommon.SOUND_MENUMOVE)

		elif self.menuPos == OPTIONMENU_MOUSE_ENABLED:
			n = -1
			if self.mouseManager.visible:
				n = gcommon.checkMouseMenuPos(self.mouseOnOffRects)
			if gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1):
				Settings.mouseEnabled = True
				BGM.sound(gcommon.SOUND_MENUMOVE)
			elif gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0):
				Settings.mouseEnabled = False
				BGM.sound(gcommon.SOUND_MENUMOVE)

		elif self.menuPos == OPTIONMENU_SCORE_RANKIG and gcommon.checkShotKeyRectP(self.menuRects[OPTIONMENU_SCORE_RANKIG]):
			BGM.sound(gcommon.SOUND_MENUMOVE)
			Settings.saveSettings()
			gcommon.app.startScoreRanking(1)
			#gcommon.app.startEnterPlayerNameScene()

		elif self.menuPos == OPTIONMENU_EXIT and gcommon.checkShotKeyRectP(self.menuRects[OPTIONMENU_EXIT]):
			BGM.sound(gcommon.SOUND_MENUMOVE)
			Settings.saveSettings()
			gcommon.app.startTitle()

	def draw(self):
		pyxel.cls(0)
		self.drawStar()

		pyxel.pal()
		x1 = 72
		x2 = MENU_VALUE_X
		Drawing.showTextHCenter(8, "OPTION")
		y = 50
		gcommon.setMenuColor(OPTIONMENU_BGM_VOL, self.menuPos)
		Drawing.showText(x1, y, "BGM VOLUME")
		Drawing.showText(x2, y, str(Settings.bgmVolume).rjust(2))
		if OPTIONMENU_BGM_VOL == self.menuPos:
			#gcommon.drawUpDownMarker(x2 -10, y)
			Drawing.drawUpDownMarker2(x2 -10, y, 0, 10, Settings.bgmVolume)
		y += 20

		gcommon.setMenuColor(OPTIONMENU_SOUND_VOL, self.menuPos)
		Drawing.showText(x1, y, "SE VOLUME")
		se = "ON " if Settings.soundVolume > 0 else "OFF"
		Drawing.showText(x2, y, se)
		if OPTIONMENU_SOUND_VOL == self.menuPos:
			leftMarker = (Settings.soundVolume > 0)
			Drawing.drawLeftMarker(x2 -10, y, leftMarker)
			Drawing.drawRightMarker(x2 +len(se)*8 + 2, y, not leftMarker)
		y += 20

		gcommon.setMenuColor(OPTIONMENU_MOUSE_ENABLED, self.menuPos)
		Drawing.showText(x1, y, "MOUSE")
		mouseOnOff = "ON " if Settings.mouseEnabled else "OFF"
		Drawing.showText(x2, y, mouseOnOff)
		if OPTIONMENU_MOUSE_ENABLED == self.menuPos:
			leftMarker = (Settings.mouseEnabled == True)
			Drawing.drawLeftMarker(x2 -10, y, leftMarker)
			Drawing.drawRightMarker(x2 +len(se)*8 + 2, y, not leftMarker)
		y += 20

		gcommon.setMenuColor(OPTIONMENU_SCORE_RANKIG, self.menuPos)
		Drawing.showTextHCenter(y, "SCORE RANKING")
		y += 20

		gcommon.setMenuColor(OPTIONMENU_EXIT, self.menuPos)
		Drawing.showTextHCenter(y, "EXIT")
		
		Drawing.setBrightness1()
		pyxel.blt(32, 48 + self.menuPos * 20, 4, 32, 48 + self.menuPos * 20, 192, 12)
		pyxel.pal()

		if self.mouseManager.visible:
			self.mouseManager.drawMenuCursor()

	def drawStar(self):
		for i in range(0,96):
			pyxel.pset(gcommon.star_ary[i][0], int(i*2 +self.star_pos) % 200, gcommon.star_ary[i][1])