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()
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()
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)
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])
class MainGame: def __init__(self, stage, restart=False): self.stage = stage self.restart = restart def init(self): self.mouseManager = MouseManager() ObjMgr.init(GameSession.multipleCount) if GameSession.weaponType == gcommon.WeaponType.TYPE_A: ObjMgr.myShip = MyShipA(self) else: ObjMgr.myShip = MyShipB(self) gcommon.cur_scroll_x = 0.5 gcommon.cur_scroll_y = 0.0 gcommon.cur_map_dx = 0.0 gcommon.cur_map_dy = 0.0 gcommon.eventManager = None self.story_pos = 0 self.event_pos = 0 gcommon.drawMap = None gcommon.game_timer = 0 gcommon.map_x = 0 gcommon.map_y = 0 gcommon.scroll_flag = True self.initStory() self.initEvent() self.pauseMode = 0 # 0:ゲーム中 1:ポーズ 2:CONTINUE確認 self.pauseMenuPos = 0 self.pauseMenuRects = [ gcommon.Rect.createWH(127 - 32 + 10, 192 / 2 - 32 + 15, 80 - 8, 8), gcommon.Rect.createWH(127 - 32 + 10, 192 / 2 - 32 + 25, 80 - 8, 8), gcommon.Rect.createWH(127 - 32 + 10, 192 / 2 - 32 + 35, 80 - 8, 8), gcommon.Rect.createWH(127 - 32 + 10, 192 / 2 - 32 + 45, 80 - 8, 8) ] self.pauseMouseOnOffRects = [ gcommon.Rect.createWH(127 - 32 + 10 + 26, 192 / 2 - 32 + 26 - 1, 8, 8), gcommon.Rect.createWH(127 - 32 + 10 + 48, 192 / 2 - 32 + 26 - 1, 8, 8) ] self.pauseCnt = 0 pyxel.mouse(False) # ステージ初期化 stage.Stage.initStage(self.stage, self.restart) self.skipGameTimer() # デバッグ用のゲームタイマースキップ def skipGameTimer(self): while (gcommon.game_timer < gcommon.START_GAME_TIMER): self.ExecuteEvent() ObjMgr.updateDrawMap0(True) ObjMgr.updateDrawMap(True) self.ExecuteStory() if gcommon.scrollController != None: gcommon.scrollController.update() gcommon.scrollController.cnt += 1 self.updateEnemy() gcommon.game_timer = gcommon.game_timer + 1 #for obj in ObjMgr.objs: # gcommon.debugPrint(str(obj)) def doPause(self): if pyxel.btnp(pyxel.KEY_ESCAPE) or pyxel.btnp(pyxel.GAMEPAD_1_START): self.pauseMode = gcommon.PAUSE_NONE pygame.mixer.music.unpause() elif gcommon.checkUpP(): self.pauseMenuPos = (self.pauseMenuPos - 1) % 4 return elif gcommon.checkDownP(): self.pauseMenuPos = (self.pauseMenuPos + 1) % 4 return if self.mouseManager.visible: n = gcommon.checkMouseMenuPos(self.pauseMenuRects) if n != -1: self.pauseMenuPos = n if self.pauseCnt > 30: if self.pauseMenuPos == 0: # CONTINUE if gcommon.checkShotKeyRectP( self.pauseMenuRects[self.pauseMenuPos]): self.pauseMode = gcommon.PAUSE_NONE pygame.mixer.music.unpause() elif self.pauseMenuPos == 1: # MOUSE OFF/ON n = -1 if self.mouseManager.visible: n = gcommon.checkMouseMenuPos(self.pauseMouseOnOffRects) if gcommon.checkRightP() or (gcommon.checkShotKeyP() and n == 1): Settings.mouseEnabled = True elif gcommon.checkLeftP() or (gcommon.checkShotKeyP() and n == 0): Settings.mouseEnabled = False elif self.pauseMenuPos == 2: if gcommon.checkShotKeyRectP( self.pauseMenuRects[self.pauseMenuPos]): # TITLE gcommon.app.startTitle() elif self.pauseMenuPos == 3: if gcommon.checkShotKeyRectP( self.pauseMenuRects[self.pauseMenuPos]): # EXIT pyxel.quit() self.pauseCnt += 1 # 自機ストックが無くなったとき def OnPlayerStockOver(self): if GameSession.gameMode == gcommon.GAMEMODE_NORMAL: if GameSession.credits == 0: # クレジットが無くなればゲームオーバー gcommon.app.startGameOver() else: # クレジットがあればCONTINUE確認 self.pauseMode = gcommon.PAUSE_CONTINUE self.pauseCnt = 0 else: # カスタムモード時はゲームオーバー gcommon.app.startGameOver() def doConfirmContinue(self): if gcommon.checkUpP(): self.pauseMenuPos = (self.pauseMenuPos - 1) % 2 return elif gcommon.checkDownP(): self.pauseMenuPos = (self.pauseMenuPos + 1) % 2 return if self.mouseManager.visible: n = gcommon.checkMouseMenuPos(self.pauseMenuRects) if n in (0, 1): self.pauseMenuPos = n if self.pauseCnt > 30: if self.pauseMenuPos == 0: # コンティニーする if gcommon.checkShotKeyRectP( self.pauseMenuRects[self.pauseMenuPos]): # YES rankingManager = ranking.RankingManager() # コンティニー時のランキング追加 rankingManager.addContinueRecord() GameSession.execContinue() self.pauseMode = gcommon.PAUSE_NONE ObjMgr.myShip.sub_scene = 3 #pygame.mixer.music.unpause() # # コンティニー時はステージ最初に戻される # # gcommon.app.restartStage() elif self.pauseMenuPos == 1: # ゲームオーバー if gcommon.checkShotKeyRectP( self.pauseMenuRects[self.pauseMenuPos]): # NO gcommon.app.startGameOver() self.pauseCnt += 1 def update(self): self.mouseManager.update() if self.pauseMode == gcommon.PAUSE_PAUSE: self.doPause() return elif self.pauseMode == gcommon.PAUSE_CONTINUE: self.doConfirmContinue() return else: if pyxel.btnp(pyxel.KEY_ESCAPE) or pyxel.btnp( pyxel.GAMEPAD_1_START): self.pauseMode = gcommon.PAUSE_PAUSE self.pauseCnt = 0 pygame.mixer.music.pause() return elif pyxel.btnp(pyxel.KEY_O): ObjMgr.debugListObj() # 星 if gcommon.scroll_flag and gcommon.draw_star: gcommon.star_pos -= 0.2 if gcommon.star_pos < 0: gcommon.star_pos += 255 self.ExecuteEvent() if gcommon.scrollController != None: gcommon.scrollController.update() gcommon.scrollController.cnt += 1 # マップ処理0 if gcommon.scroll_flag: ObjMgr.updateDrawMap0(False) # 自機移動 ObjMgr.myShip.update() # マップ処理 if gcommon.scroll_flag: ObjMgr.updateDrawMap(False) self.ExecuteStory() newShots = [] for shot in ObjMgr.shots: if shot.removeFlag == False: shot.update() if shot.removeFlag == False: newShots.append(shot) ObjMgr.shots = newShots self.updateEnemy() self.Collision() gcommon.game_timer = gcommon.game_timer + 1 def updateEnemy(self): newObjs = [] for obj in ObjMgr.objs: if obj.removeFlag == False: if gcommon.scroll_flag: if obj.ground: obj.x -= gcommon.cur_scroll_x obj.y -= gcommon.cur_scroll_y obj.x -= gcommon.cur_map_dx obj.y -= gcommon.cur_map_dy if obj.nextStateNo != -1: obj.state = obj.nextStateNo obj.nextStateNo = -1 obj.cnt = 0 obj.update() obj.cnt += 1 obj.frameCount += 1 if obj.removeFlag == False: newObjs.append(obj) for obj in ObjMgr.insertObjs: newObjs.append(obj) ObjMgr.insertObjs.clear() ObjMgr.objs = newObjs def draw(self): pyxel.cls(0) pyxel.clip(0, 0, 256, 192) #pyxel.text(55, 41, "Hello, Pyxel!", pyxel.frame_count % 16) #pyxel.blt(61, 66, 0, 0, 0, 38, 16) # 星 if gcommon.draw_star: gcommon.drawStar2(-gcommon.cur_scroll_x) ObjMgr.drawDrawMapBackground() for obj in ObjMgr.objs: if (obj.layer & gcommon.C_LAYER_UNDER_GRD) != 0: if obj.hitcolor1 != 0 and obj.hit: pyxel.pal(obj.hitcolor1, obj.hitcolor2) obj.drawLayer(gcommon.C_LAYER_UNDER_GRD) if obj.hitcolor1 != 0 and obj.hit: pyxel.pal(obj.hitcolor1, obj.hitcolor1) ObjMgr.drawDrawMap() # enemy(ground) for obj in ObjMgr.objs: if (obj.layer & gcommon.C_LAYER_GRD) != 0: if obj.hitcolor1 != 0 and obj.hit: pyxel.pal(obj.hitcolor1, obj.hitcolor2) obj.drawLayer(gcommon.C_LAYER_GRD) if obj.hitcolor1 != 0 and obj.hit: pyxel.pal(obj.hitcolor1, obj.hitcolor1) # my ship ObjMgr.myShip.draw0() # # item # for obj in ObjMgr.objs: # if (obj.layer != gcommon.C_LAYER_ITEM) != 0: # obj.draw() # enemy(sky) for obj in ObjMgr.objs: if (obj.layer & gcommon.C_LAYER_SKY) != 0: if obj.hitcolor1 != 0 and obj.hit: pyxel.pal(obj.hitcolor1, obj.hitcolor2) obj.drawLayer(gcommon.C_LAYER_SKY) if obj.hitcolor1 != 0 and obj.hit: pyxel.pal(obj.hitcolor1, obj.hitcolor1) # enemy shot and explosion(sky) for obj in ObjMgr.objs: if (obj.layer & (gcommon.C_LAYER_EXP_SKY | gcommon.C_LAYER_E_SHOT)) != 0: obj.drawLayer(gcommon.C_LAYER_EXP_SKY | gcommon.C_LAYER_E_SHOT) # my shot for shot in ObjMgr.shots: shot.draw() # my ship ObjMgr.myShip.draw() ObjMgr.drawDrawMap2() for obj in ObjMgr.objs: if (obj.layer & gcommon.C_LAYER_UPPER_SKY) != 0: obj.drawLayer(gcommon.C_LAYER_UPPER_SKY) for obj in ObjMgr.objs: if (obj.layer & gcommon.C_LAYER_TEXT) != 0: obj.drawLayer(gcommon.C_LAYER_TEXT) # 当たり判定描画 if gcommon.ShowCollision: for shot in ObjMgr.shots: if shot.removeFlag == False: self.drawObjRect(shot) self.drawObjRect(ObjMgr.myShip) for obj in ObjMgr.objs: if obj.removeFlag or (obj.shotHitCheck == False and obj.hitCheck == False): continue self.drawObjRect(obj) pyxel.clip() # SCORE表示 Drawing.showText(0, 192, "SC " + str(GameSession.score).rjust(8)) # 残機 pyxel.blt(232, 192, 0, 8, 32, 8, 8, gcommon.TP_COLOR) Drawing.showText(242, 192, str(GameSession.playerStock).rjust(2)) # 武器表示 if GameSession.weaponType == gcommon.WeaponType.TYPE_A: for i in range(0, 3): if i == ObjMgr.myShip.weapon: pyxel.blt(96 + 40 * i, 192, 0, 128 + i * 40, 248, 40, 8) else: pyxel.blt(96 + 40 * i, 192, 0, 128 + i * 40, 240, 40, 8) else: for i in range(0, 4): if i == ObjMgr.myShip.weapon: pyxel.blt(96 + 32 * i, 192, 0, 128 + i * 32, 232, 40, 8) else: pyxel.blt(96 + 32 * i, 192, 0, 128 + i * 32, 224, 40, 8) #pyxel.text(120, 184, str(gcommon.back_map_x), 7) if gcommon.DebugMode: gcommon.Text2(121, 184, str(gcommon.game_timer), 7, 0) gcommon.Text2(160, 184, str(len(ObjMgr.objs)), 7, 0) gcommon.Text2(0, 184, str(gcommon.map_x) + " " + str(gcommon.map_y), 7, 0) #gcommon.Text2(0, 184, str(gcommon.back_map_x), 7, 0) #pyxel.text(160, 184, str(len(ObjMgr.shots)), 7) #pyxel.text(160, 188, str(self.event_pos),7) #pyxel.text(120, 194, str(gcommon.getMapData(ObjMgr.myShip.x, ObjMgr.myShip.y)), 7) # マップ位置表示 #pyxel.text(200, 184, str(gcommon.map_x) + " " +str(gcommon.map_y), 7) if self.pauseMode == gcommon.PAUSE_PAUSE: self.drawPauseMenu() elif self.pauseMode == gcommon.PAUSE_CONTINUE: self.drawContinueMenu() # マウスカーソル if self.mouseManager.visible: pyxel.blt(pyxel.mouse_x - 7, pyxel.mouse_y - 7, 0, 24, 32, 16, 16, 2) def drawObjRect(self, obj): if obj.collisionRects != None: for rect in obj.collisionRects: pyxel.rectb(obj.x + rect.left, obj.y + rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1, 8) else: pyxel.rectb(obj.x + obj.left, obj.y + obj.top, obj.right - obj.left + 1, obj.bottom - obj.top + 1, 8) def drawPauseMenu(self): # PAUSEメニューはベタ描き pyxel.rect(127 - 40, 192 / 2 - 32, 80, 60, 0) pyxel.rectb(127 - 39, 192 / 2 - 31, 78, 58, 7) pyxel.rect(127 - 37, 192 / 2 - 29, 74, 8, 1) pyxel.text(127 - 40 + 28, 192 / 2 - 32 + 4, "PAUSE", 7) pyxel.rect(127 - 40 + 4, 192 / 2 - 32 + 15 + self.pauseMenuPos * 10, 80 - 8, 8, 2) pyxel.text(127 - 32 + 4, 192 / 2 - 32 + 16, "CONTINUE", 7) #MOUSE y = 192 / 2 - 32 + 26 pyxel.text(127 - 32 + 4, y, "MOUSE", 7) leftMarker = (Settings.mouseEnabled == True) pyxel.text(127 - 32 + 10 + 36, y, "ON " if Settings.mouseEnabled else "OFF", 7) Drawing.drawLeftMarker(127 - 32 + 10 + 26, y - 1, leftMarker) Drawing.drawRightMarker(127 - 32 + 10 + 48, y - 1, not leftMarker) pyxel.text(127 - 32 + 4, 192 / 2 - 32 + 36, "TITLE", 7) pyxel.text(127 - 32 + 4, 192 / 2 - 32 + 46, "EXIT", 7) def drawContinueMenu(self): pyxel.rect(127 - 40, 192 / 2 - 32, 80, 48, 0) pyxel.rectb(127 - 39, 192 / 2 - 31, 78, 46, 7) pyxel.rect(127 - 37, 192 / 2 - 29, 74, 8, 1) Drawing.showTextHCentor2(192 / 2 - 32 + 4, "CONTINUE ?", 7) pyxel.rect(127 - 40 + 4, 192 / 2 - 32 + 15 + self.pauseMenuPos * 10, 80 - 8, 8, 2) pyxel.text(127 - 32 + 10, 192 / 2 - 32 + 16, "YES", 7) pyxel.text(127 - 32 + 10, 192 / 2 - 32 + 26, "NO", 7) pyxel.text(127 - 32 + 10, 192 / 2 - 32 + 38, "CREDITS " + str(GameSession.credits), 7) def ExecuteStory(self): while True: if len(self.story) <= self.story_pos: return s = self.story[self.story_pos] if s[0] < gcommon.game_timer: pass elif s[0] != gcommon.game_timer: return else: t = s[1] # [1]はクラス型 obj = t(s) # ここでインスタンス化 ObjMgr.addObj(obj) self.story_pos = self.story_pos + 1 def ExecuteEvent(self): while True: if len(self.eventTable) <= self.event_pos: return s = self.eventTable[self.event_pos] if s[0] < gcommon.game_timer: print("!!ExecuteEvent passed " + str(s[0]) + " " + str(gcommon.game_timer)) pass elif s[0] != gcommon.game_timer: return else: t = s[1] # [1]はクラス型 obj = t(s) # ここでインスタンス化 obj.do() self.event_pos = self.event_pos + 1 # 衝突判定 def Collision(self): # 壁との当たり判定 if ObjMgr.myShip.sub_scene == 1 and \ gcommon.isMapFreePos(ObjMgr.myShip.x+ 9, ObjMgr.myShip.y +7) == False: self.my_broken() return # shot & enemy for obj in ObjMgr.objs: if obj.removeFlag: continue obj.hit = False #if obj.layer!=gcommon.C_LAYER_GRD and obj.layer!=gcommon.C_LAYER_SKY: if obj.shotHitCheck == False: continue for shot in ObjMgr.shots: if obj.checkShotCollision(shot): broken = obj.doShotCollision(shot) shot.hit(obj, broken) if broken or obj.removeFlag: break # enemy shot and wallObj for wallObj in ObjMgr.objs: if wallObj.removeFlag: continue if wallObj.enemyShotCollision == False: continue for shot in ObjMgr.objs: if shot.removeFlag: continue if shot.layer != gcommon.C_LAYER_E_SHOT: continue if wallObj.checkEnemyShotCollision(shot): shot.removeFlag = True break # my ship & enemy for obj in ObjMgr.objs: if obj.removeFlag == False and obj.hitCheck: if obj.checkMyShipCollision() and ObjMgr.myShip.sub_scene == 1: self.my_broken() break def my_broken(self): ObjMgr.myShip.sub_scene = 2 ObjMgr.myShip.cnt = 0 GameSession.destroyed += 1 BGM.sound(gcommon.SOUND_LARGE_EXP, gcommon.SOUND_CH1) def initEvent(self): if self.stage == "1A": self.initEvent1() elif self.stage == "2A": self.initEvent2() elif self.stage == "2B": self.initEventCave() elif self.stage == "3A": self.initEvent3() elif self.stage == "3B": self.initEventWarehouse() elif self.stage == "3C": self.initEventBattileShip() elif self.stage == "4A": self.initEvent4() elif self.stage == "4B": self.initEventLabyrinth() elif self.stage == "5A": self.initEventFactory() elif self.stage == "5B": self.initEventFire() elif self.stage == "6A": self.initEventLast() elif self.stage == "6B": self.initEventEnemyBase() elif self.stage == "B1": self.initEventBossRush() def initEvent1(self): self.eventTable =[ \ #[0, StartBGM, BGM.STAGE1], [660,StartMapDraw1], \ [1560,SetMapScroll, 0.25, -0.25], \ [2180,SetMapScroll, 0.5, 0.0], [3260,SetMapScroll, 0.25, 0.25], [3460,SetMapScroll, 0, 0.5], [3860,SetMapScroll, 0.25, 0.25], [4600,SetMapScroll, 0.5, 0.0], [4800, StartBGM, BGM.BOSS], [6000,EndMapDraw], \ ] def initEvent2(self): self.eventTable =[ \ [0,StartMapDraw2], \ [0, StartBGM, BGM.STAGE2], [736,SetMapScroll, 0.25, 0.25], \ [1104,SetMapScroll, -0.25, 0.25], \ [1856,SetMapScroll, 0.5, 0.0], \ [2208,SetMapScroll, 0.25, 0.25], \ [2572,SetMapScroll, 0.5, 0.0], \ [3104,SetMapScroll, 0.0, -0.5], \ [3408,SetMapScroll, -0.25, -0.25], \ [4000,SetMapScroll, 0.0, -0.5], \ [4128,SetMapScroll, 0.5, 0.0], \ [4608,SetMapScroll, 0.25, -0.25], \ [5216,SetMapScroll, 0.50, 0.0], \ [6300, StartBGM, BGM.BOSS], #[7224,SetMapScroll, 0.0, 0.0], \ ] def initEventCave(self): self.eventTable =[ [0,StartMapDrawCave], [0, StartBGM, BGM.STAGE_CAVE], [1300,SetMapScroll, 0.25, 0.25], \ [3500,SetMapScroll, 0.50, 0.0], \ [5920, StartBGM, BGM.BOSS], [6280,SetMapScroll, 0.0, 0.0], \ ] def initEventWarehouse(self): self.eventTable =[ \ [0, StartBGM, BGM.STAGE_WAREHOUSE], [0,StartMapDraw, MapDrawWarehouse], \ [2184,SetMapScroll, 0.0, 0.5], [3384,SetMapScroll, 0.5, 0.0], [4712,SetMapScroll, 0.0, -0.5], [5504,SetMapScroll, 0.5, 0.0], [6800, StartBGM, BGM.BOSS], [7320,SetMapScroll, 0.0, 0.0], ] def initEvent3(self): self.eventTable =[ \ [0, StartBGM, BGM.STAGE3], [100,StartMapDraw3], \ [3500+128,StartBGM, BGM.BOSS], ] def initEvent4(self): self.eventTable =[ \ [0, StartBGM, BGM.STAGE4], [100+512,StartMapDraw4], \ [3900+512, StartBGM, BGM.BOSS], [4030+512, enemy.Stage4BossAppear1], \ [4120+512, enemy.Stage4BossAppear2], \ [5100+512,EndMapDraw], \ ] def initEventFactory(self): self.eventTable =[ \ [0, StartBGM, BGM.STAGE5], [100,StartMapDrawFactory], \ [2040,SetMapScroll, 0.25, 0.25], \ [3192,SetMapScroll, 0.5, 0.0], \ [4400,SetMapScroll, 0.25, -0.25], \ [5616,SetMapScroll, 0.5, 0.0], \ [6500,StartBGM, BGM.BOSS], \ [7800,EndMapDraw], \ ] def initEventFire(self): self.eventTable =[ [0, StartBGM, BGM.STAGE_FIRE], [0, StartMapDrawFire], \ [5650,StartBGM, BGM.BOSS], \ [5900,SetMapScroll, 0.0, 0.0], ] def initEventLast(self): baseOffset = 1200 self.eventTable =[ \ [0, StartBGM, BGM.STAGE6_1], [2100 +baseOffset,StartMapDrawLast], \ [2100 +baseOffset, StartBGM, BGM.STAGE6_2], [5800 +baseOffset, StartBGM, BGM.STAGE6_3], [8200 +baseOffset, StartBGM, BGM.BOSS], ] def initEventLabyrinth(self): baseOffset = 200 self.eventTable = [ [0, StartBGM, BGM.STAGE_LABYRINTH], [0, StartMapDrawLabyrinth], [baseOffset + 1616, SetMapScroll, 0.0, 0.0], [baseOffset + 1720, SetMapScroll, 0.0, 0.50], [baseOffset + 2728, SetMapScroll, 0.50, 0.0], [baseOffset + 6000, StartBGM, BGM.BOSS], [baseOffset + 6552, SetMapScroll, 0.0, 0.0], ] def initEventBattileShip(self): baseOffset = 0 self.eventTable = [ [0, StartBGM, BGM.STAGE_BATTLESHIP], [0, StartMapDrawBattleShip], [0, SetMapScroll, 1.0, 0.0], #[baseOffset +520, SetMapScroll, 1.0, -0.25], #[baseOffset +1014, SetMapScroll, 1.0, 0.0], #[baseOffset +2800, SetMapScroll, 0.5, 0.25], #[baseOffset +3280, SetMapScroll, 0.25, 0.0], #[baseOffset +6200, SetMapScroll, 0.5, 0.0], ] def initEventEnemyBase(self): baseOffset = 0 self.eventTable = [ [0, StartBGM, BGM.STAGE6_1], [0, StartMapDrawEnemyBase], # [0, SetMapScroll, 0.0, 0.0], # [1000, SetMapScroll, 0.5, 0.0], # [3160, SetMapScroll, 0.0, 0.0], # [3240, SetMapScroll, 0.0, -0.5], # [3560, SetMapScroll, 0.5, 0.0], # [4180, SetMapScroll, 0.0, 0.0], # [4300, SetMapScroll, 0.0, 0.5], # [4640, SetMapScroll, 0.5, 0.0], # [5840, SetMapScroll, 0.0, 0.0], # [5960, SetMapScroll, 0.0, 0.5], # [6500, SetMapScroll, 0.0, 0.0], # [6620, SetMapScroll, 0.5, 0.0], [8100, StartBGM, BGM.STAGE6_3], # [8100, SetMapScroll, 0.25, 0.0], # [10300, SetMapScroll, 0.5, 0.0], [10300, StartBGM, BGM.BOSS], # [10588, SetMapScroll, 0.0, 0.0], ] def initEventBossRush(self): self.eventTable = [ [0, InitBossRushManager], ] def initStory(self): if self.stage == "1A": self.story = story.Story.getStory1() elif self.stage == "2A": self.story = story.Story.getStory2() elif self.stage == "2B": self.story = story.Story.getStoryCave() elif self.stage == "3A": self.story = story.Story.getStory3() elif self.stage == "3B": self.story = story.Story.getStoryWarehouse() elif self.stage == "3C": self.story = story.Story.getStoryBattileShip() elif self.stage == "4A": self.story = story.Story.getStory4() elif self.stage == "4B": self.story = story.Story.getStoryLabyrinth() elif self.stage == "5A": self.story = story.Story.getStoryFactory() elif self.stage == "5B": self.story = story.Story.getStoryFire() elif self.stage == "6A": self.story = story.Story.getStoryLast() elif self.stage == "6B": self.story = story.Story.getStoryEnemyBase() elif self.stage == "B1": self.story = story.Story.getStoryBossRush()
class EnterPlayerNameScene: allCharsList = ("ABCDEFGHIJKLM", "NOPQRSTUVWXYZ", "0123456789", " .-?!") allChars = allCharsList[0] + allCharsList[1] + allCharsList[ 2] + allCharsList[3] ALPHA_X = 16 ALPHA_Y = 112 def __init__(self): self.bgStarV = gcommon.BGStarV() self.mouseManager = MouseManager() self.markerRects = [] for y, chars in enumerate(__class__.allCharsList): for i in range(len(chars)): rx = __class__.ALPHA_X - 4 + i * 18 ry = __class__.ALPHA_Y - 4 + y * 18 self.markerRects.append(gcommon.Rect.createWH(rx, ry, 16, 16)) self.markerRects.append(gcommon.Rect.createWH(rx + 18, ry, 16, 16)) # Back Space self.backSpaceIndex = len(self.markerRects) - 1 self.markerRects.append(gcommon.Rect.createWH(rx + 18 * 2, ry, 24, 16)) # End self.endIndex = len(self.markerRects) - 1 self.rectIndex = 0 self.cursorPos = 0 self.name = "" def init(self): BGM.playOnce(BGM.RANKING) def update(self): self.bgStarV.update() self.mouseManager.update() if self.mouseManager.visible: n = gcommon.checkMouseMenuPos(self.markerRects) if n != -1: self.rectIndex = n else: if gcommon.checkLeftP(): BGM.sound(gcommon.SOUND_MENUMOVE) self.rectIndex -= 1 if self.rectIndex < 0: self.rectIndex = self.endIndex elif gcommon.checkRightP(): BGM.sound(gcommon.SOUND_MENUMOVE) self.rectIndex += 1 if self.rectIndex > self.endIndex: self.rectIndex = 0 elif gcommon.checkUpP(): BGM.sound(gcommon.SOUND_MENUMOVE) if self.rectIndex < 7: self.rectIndex = 26 + 10 + self.rectIndex elif self.rectIndex >= 7 and self.rectIndex < 13: self.rectIndex = self.endIndex elif self.rectIndex >= 13 and self.rectIndex < ( 26 + 10): # アルファベット+数字 self.rectIndex -= 13 elif self.rectIndex >= (26 + 10) and self.rectIndex < ( 26 + 10 + 7): # 記号+BS+End self.rectIndex -= 10 elif gcommon.checkDownP(): BGM.sound(gcommon.SOUND_MENUMOVE) if self.rectIndex >= 0 and self.rectIndex < 13: # アルファベット1段目 self.rectIndex += 13 elif self.rectIndex >= 13 and self.rectIndex < ( 13 + 10): # アルファベット2段目の途中 self.rectIndex += 13 elif self.rectIndex >= ( 13 + 10) and self.rectIndex < 26: # アルファベット2段目の途中から2段目最後まで self.rectIndex = 26 + 10 - 1 elif self.rectIndex >= 26 and self.rectIndex < (26 + 7): self.rectIndex += 10 elif self.rectIndex >= (26 + 7) and self.rectIndex < (26 + 10): self.rectIndex = 26 + 10 + 7 - 1 else: self.rectIndex -= 26 + 10 if gcommon.checkShotKeyP(): BGM.sound(gcommon.SOUND_MENUMOVE) if self.cursorPos < 3 and self.rectIndex < self.backSpaceIndex: self.name += self.allChars[self.rectIndex] self.cursorPos += 1 elif self.cursorPos > 0 and self.rectIndex == self.backSpaceIndex: self.name = self.name[:-1] self.cursorPos -= 1 elif self.rectIndex == self.endIndex: self.addRecord() gcommon.app.startScoreRanking(0) def addRecord(self): rakingManager = ranking.RankingManager() rakingManager.load() rakingManager.addRecord(GameSession, self.name) rakingManager.save() def setOptionColor(self, index): if index == self.rectIndex: pyxel.pal() else: pyxel.pal(7, 12) def draw(self): pyxel.cls(0) self.bgStarV.draw() ty = 16 Drawing.showTextHCenter(ty, "ENTER YOUR NAME") ty += 16 Drawing.showTextHCenter( ty, "= " + gcommon.difficultyText[GameSession.difficulty] + " =") x0 = 32 x1 = 128 ty += 24 Drawing.showText(x0, ty, "SCORE") Drawing.showText(x1, ty, str(GameSession.score).rjust(8, "0")) ty += 16 Drawing.showText(x0, ty, "STAGE") stage = "" if GameSession.stage == "-1": stage = "CLEAR" else: stage = " " + str(GameSession.stage) Drawing.showText(x1, ty, stage) ty += 16 Drawing.showText(x0, ty, "YOUR NAME") Drawing.showText(x1, ty, self.name) pyxel.rectb(x1 - 4, ty - 4, 8 * 3 + 8, 16, 5) pyxel.pal(7, 12) index = 0 x0 = __class__.ALPHA_X = 16 ty = __class__.ALPHA_Y for chars in __class__.allCharsList: for i, c in enumerate(chars): self.setOptionColor(index) Drawing.showText(x0 + i * 18, ty, str(c)) index += 1 ty += 18 ty -= 18 # BackSpace self.setOptionColor(index) pyxel.blt(x0 + 5 * 18, ty, 0, 208, 136, 8, 8, gcommon.TP_COLOR) index += 1 # End self.setOptionColor(index) pyxel.blt(x0 + 6 * 18, ty, 0, 216, 136, 16, 8, gcommon.TP_COLOR) index += 1 pyxel.pal() rect = self.markerRects[self.rectIndex] Drawing.setBrightness1() pyxel.blt(rect.left, rect.top, 4, rect.left, rect.top, rect.getWidth(), rect.getHeight()) pyxel.pal() self.mouseManager.draw()
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
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])