class CogdoMemoGui(DirectFrame): def __init__(self, parent): DirectFrame.__init__(self, parent=parent, relief=None, state=DGG.NORMAL, sortOrder=DGG.BACKGROUND_SORT_INDEX) self._initModel() self.hide() return def destroy(self): ToontownIntervals.cleanup('memocount_pulse') self._countLabel.removeNode() del self._countLabel self._memoIcon.removeNode() del self._memoIcon DirectFrame.destroy(self) def posNextToLaffMeter(self): self.setPos(-0.975, 0, -0.875) def _initModel(self): self._countLabel = DirectLabel(parent=self, relief=None, pos=(0.0625, 0, -0.025), scale=CogdoGameConsts.MemoGuiTextScale, text=str(0), text_fg=CogdoGameConsts.MemoGuiTextColor, text_shadow=(0.2, 0.2, 0.2, 1), text_align=TextNode.ALeft, text_font=ToontownGlobals.getToonFont()) self._memoIcon = CogdoUtil.loadModel('memo_card', game='shared', group='gui') self._memoIcon.reparentTo(self) self._memoIcon.setScale(MEMOICON_SCALE) return def setCount(self, count): self._countLabel['text'] = str(count) self._countLabel.setText() ToontownIntervals.cleanup('memocount_pulse') ToontownIntervals.start(ToontownIntervals.getPulseLargerIval(self._memoIcon, 'memocount_pulse', scale=MEMOICON_SCALE))
class CogdoMemoGui(DirectFrame): def __init__(self, parent): DirectFrame.__init__(self, parent=parent, relief=None, state=DGG.NORMAL, sortOrder=DGG.BACKGROUND_SORT_INDEX) self._initModel() self.hide() return def destroy(self): ToontownIntervals.cleanup('memocount_pulse') self._countLabel.removeNode() del self._countLabel self._memoIcon.removeNode() del self._memoIcon DirectFrame.destroy(self) def posNextToLaffMeter(self): self.setPos(-0.975, 0, -0.875) def _initModel(self): self._countLabel = DirectLabel(parent=self, relief=None, pos=(0.0625, 0, -0.025), scale=CogdoGameConsts.MemoGuiTextScale, text=str(0), text_fg=CogdoGameConsts.MemoGuiTextColor, text_shadow=(0.2, 0.2, 0.2, 1), text_align=TextNode.ALeft, text_font=ToontownGlobals.getToonFont()) self._memoIcon = CogdoUtil.loadModel('memo_card', game='shared', group='gui') self._memoIcon.reparentTo(self) self._memoIcon.setScale(MEMOICON_SCALE) return def setCount(self, count): self._countLabel['text'] = str(count) self._countLabel.setText() ToontownIntervals.cleanup('memocount_pulse') ToontownIntervals.start(ToontownIntervals.getPulseLargerIval(self._memoIcon, 'memocount_pulse', scale=MEMOICON_SCALE))
class RepairNail(NodePath, FSM.FSM): def __init__(self, name, parent, nailModel): self.config = RepairGlobals.Hammering NodePath.__init__(self, name) FSM.FSM.__init__(self, 'Nail_%sFSM' % name) self.reparentTo(parent) self.nailModel = nailModel self._initVars() self._initVisuals() def _initVars(self): self.totalClicks = 0 self.remainingPercent = 1.0 def _initVisuals(self): self.visual = self.attachNewNode('RepairNail.visual') self.nailModel.find('**/nail_collision').setPos(0.0, -35.0, 0.0) self.nailModel.setScale(1.5) self.nailModel.find('**/nail_collision').setCollideMask(NAIL_COLLIDE_MASK) self.nailModel.find('**/nail_collision').setPythonTag('nail', self) self.nailModel.find('**/nail_collision').hide() self.nailModel.reparentTo(self.visual) self.nailModel.find('**/nail_model').setHpr(0.0, 20.0, 0.0) self.nailModel.setDepthTest(True) self.nailModel.setDepthWrite(True) self.shadow = self.nailModel.find('**/shadow') self.shadow.reparentTo(self) self.shadow.setPos(0.0, -0.040000000000000001, 0.02) self.shadow.setDepthTest(True) self.shadow.setDepthWrite(True) self.shadow.setScale(2.0) self.shadow.setTransparency(1) self.shadow.setSa(0.59999999999999998) self.resultLabel = DirectLabel(text = '', relief = None, text_fg = (1.0, 1.0, 1.0, 1.0), text_shadow = (0.0, 0.0, 0.0, 1.0), text_font = PiratesGlobals.getPirateFont(), scale = (0.050000000000000003, 0.050000000000000003, 0.050000000000000003), pos = (0.0, 0.0, -0.089999999999999997), parent = self) def removeNode(self): self.visual.removeNode() del self.visual self.resultLabel.destroy() NodePath.removeNode(self) def setShadow(self, percent): self.shadow.setScale(percent * 1.0 + 1.3999999999999999) self.shadow.setSa(1.0 - percent * 0.20000000000000001 + 0.20000000000000001) def hitNail(self, percentage): self.remainingPercent = max(0.0, self.remainingPercent - percentage) self.totalClicks += 1 self.setShadow(self.remainingPercent) newDepth = (1.0 - self.remainingPercent) * HAMMERED_DEPTH self.visual.setZ(newDepth) if self.remainingPercent <= 0.0: for i in range(len(self.config.rankingThresholds)): if self.totalClicks >= self.config.rankingThresholds[i]: break continue self.request('Hammered', PLocalizer.Minigame_Repair_Hammering_Thresholds[i]) return True return False def enterActive(self): self.visual.setZ(0.0) self.remainingPercent = 1.0 self.totalClicks = 0 self.setShadow(1.0) def exitActive(self): pass def enterHammered(self, successText): self.resultLabel['text'] = successText self.resultLabel.setText() def exitHammered(self): self.resultLabel['text'] = '' self.resultLabel.setText() def enterIdle(self): self.stash() def exitIdle(self): self.unstash()
class CogdoFlyingFuelGui(DirectFrame): def __init__(self, parent): DirectFrame.__init__(self, relief=None, state=DGG.NORMAL, sortOrder=DGG.BACKGROUND_SORT_INDEX) self.reparentTo(parent) self.active = 0 self._initModel() self._initIntervals() return def _initModel(self): self.setPos(Globals.Gui.FuelPos2D[0], 0.0, Globals.Gui.FuelPos2D[1]) self.gui = CogdoUtil.loadFlyingModel('propellerMeter', group='gui') self.gui.reparentTo(self) self.gui.setBin('fixed', 0) self.healthBar = self.gui.find('**/healthBar') self.healthBar.setBin('fixed', 1) self.healthBar.setColor(*Globals.Gui.FuelNormalColor) bottomBarLocator = self.gui.find('**/bottomOfBar_loc') bottomBarPos = bottomBarLocator.getPos(render) topBarLocator = self.gui.find('**/topOfBar_loc') topBarPos = topBarLocator.getPos(render) zDist = topBarPos.getZ() - bottomBarPos.getZ() self.fuelLowIndicator = self.gui.find('**/fuelLowIndicator') self.fuelLowIndicator.setBin('fixed', 2) pos = self.fuelLowIndicator.getPos(render) newPos = pos newPos.setZ(bottomBarPos.getZ() + zDist * Globals.Gameplay.FuelLowAmt) self.fuelLowIndicator.setPos(render, newPos) self.fuelVeryLowIndicator = self.gui.find('**/fuelVeryLowIndicator') self.fuelVeryLowIndicator.setBin('fixed', 2) pos = self.fuelVeryLowIndicator.getPos(render) newPos = pos newPos.setZ(bottomBarPos.getZ() + zDist * Globals.Gameplay.FuelVeryLowAmt) self.fuelVeryLowIndicator.setPos(render, newPos) self.propellerMain = self.gui.find('**/propellers') self.propellerMain.setBin('fixed', 3) self.propellerHead = self.gui.find('**/propellerHead') self.propellerHead.setBin('fixed', 4) self.blades = [] self.activeBlades = [] index = 1 blade = self.propellerMain.find('**/propeller%d' % index) while not blade.isEmpty(): self.blades.append(blade) index += 1 blade = self.propellerMain.find('**/propeller%d' % index) for blade in self.blades: self.activeBlades.append(blade) self.bladeNumberLabel = DirectLabel(parent=self.propellerHead, relief=None, pos=(Globals.Gui.FuelNumBladesPos2D[0], 0, Globals.Gui.FuelNumBladesPos2D[1]), scale=Globals.Gui.FuelNumBladesScale, text=str(len(self.activeBlades)), text_align=TextNode.ACenter, text_fg=(0.0, 0.0, -0.002, 1), text_shadow=(0.75, 0.75, 0.75, 1), text_font=ToontownGlobals.getInterfaceFont()) self.bladeNumberLabel.setBin('fixed', 5) return def _initIntervals(self): self._healthIval = LerpFunctionInterval(self.healthBar.setSz, fromData=0.0, toData=1.0, duration=2.0) self.baseSpinDuration = 2.0 self._spinIval = LerpFunctionInterval(self.propellerMain.setR, fromData=0.0, toData=-360.0, duration=self.baseSpinDuration) def show(self): DirectFrame.show(self) self._spinIval.loop() def hide(self): DirectFrame.hide(self) self._spinIval.pause() def resetBlades(self): self.setBlades(len(self.blades)) def setBlades(self, fuelState): if fuelState not in Globals.Gameplay.FuelStates: return numBlades = fuelState - 1 if len(self.activeBlades) != numBlades: for i in range(len(self.activeBlades)): blade = self.activeBlades.pop() blade.stash() if numBlades > len(self.blades): numBlades = len(self.blades) for i in range(numBlades): blade = self.blades[i] self.activeBlades.append(blade) blade.unstash() self.bladeNumberLabel['text'] = str(len(self.activeBlades)) self.bladeNumberLabel.setText() self.updateHealthBarColor() def bladeLost(self): if len(self.activeBlades) > 0: blade = self.activeBlades.pop() blade.stash() self.bladeNumberLabel['text'] = str(len(self.activeBlades)) self.bladeNumberLabel.setText() self.updateHealthBarColor() def updateHealthBarColor(self): color = Globals.Gui.NumBlades2FuelColor[len(self.activeBlades)] self.healthBar.setColor(*color) def setPropellerSpinRate(self, newRate): self._spinIval.setPlayRate(newRate) def setRefuelLerpFromData(self): startScale = self.healthBar.getSz() self._healthIval.fromData = startScale def setFuel(self, fuel): self.fuel = fuel def update(self): self.healthBar.setSz(self.fuel) def destroy(self): self.bladeNumberLabel.removeNode() self.bladeNumberLabel = None self._healthIval.clearToInitial() del self._healthIval self.healthBar = None self.fuelLowIndicator = None self.fuelVeryLowIndicator = None self.propellerMain = None self.propellerHead = None del self.blades[:] del self.activeBlades[:] self.gui.detachNode() self.gui = None DirectFrame.destroy(self) return
class RepairSawingGame(RepairMincroGame): sawSounds = None boardComplet = None boardDestroyed = None def __init__(self, repairGame): self.config = RepairGlobals.Sawing notify = DirectNotifyGlobal.directNotify.newCategory( 'RepairSawingGame') RepairMincroGame.__init__(self, repairGame, 'sawing', PLocalizer.Minigame_Repair_Sawing_Start) def _initVars(self): RepairMincroGame._initVars(self) self.boardsPool = {} self.currentBoard = None self.currentBoardIndex = 0 self.onDeckBoard = None self.onDeckBoardIndex = 0 self.totalScore = 0.0 self.hitZone1Penalty = False self.hitZone2Penalty = False self.hitBoardPenalty = False self.moveDiffForSound = 0.0 self.startPositions = (Point3(0.0, 0.0, 0.0), ) self.currentStartIndex = 0 self.lastMousePos = None self.board_left = None self.board_right = None self.cut = None self.zone1_right = None self.zone1_left = None self.zone2_right = None self.zone2_left = None self.piece1 = None self.piece2 = None self.lastHitIndex = -1 self.sawWaypoints = [] def _initAudio(self): RepairMincroGame._initAudio(self) if not self.sawSounds: RepairSawingGame.sawSounds = ( loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_INOUT01), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_INOUT02), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_INOUT03), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_INOUT04)) RepairSawingGame.boardComplete = loadSfx( SoundGlobals.SFX_MINIGAME_REPAIR_SAW_COMPLETE) RepairSawingGame.boardDestroyed = loadSfx( SoundGlobals.SFX_MINIGAME_REPAIR_SAW_FAIL) def _initVisuals(self): RepairMincroGame._initVisuals(self) self.setBin('fixed', 36) self.model = loader.loadModel('models/gui/pir_m_gui_srp_sawing_main') sawModel = self.model.find('**/saw') sawModel.setR(193) sawModel.setPos(0.90000000000000002, 0.0, -0.16500000000000001) sawModel.setBin('gui-popup', 0) self.sawButton = RepairSaw( parent=self, clickDownCommand=self.sawAttachedToMouse, clickUpCommand=self.sawRemovedFromMouse, geom=sawModel, text_pos=(0.20000000000000001, -0.29999999999999999), text_fg=(1, 0, 0, 1), scale=(0.29999999999999999, 0.29999999999999999, 0.29999999999999999), relief=None, pressEffect=0, frameSize=(-0.050000000000000003, 1.05, -0.29999999999999999, 0.050000000000000003), rolloverSound=None, clickSound=None) self.sawingLine = RepairSawingLine(self, self.config.sawlineLineThickness, self.config.sawlineColor, self.config.sawlineLinespawnDist) self.progressDescriptionLabel = DirectLabel( text=PLocalizer.Minigame_Repair_Sawing_Description, text_fg=(1.0, 1.0, 1.0, 1.0), text_pos=(0.0, 0.0), text_shadow=(0.0, 0.0, 0.0, 1.0), text_font=PiratesGlobals.getPirateFont(), text_align=TextNode.ARight, relief=None, scale=(0.080000000000000002, 0.080000000000000002, 0.080000000000000002), pos=(-0.20000000000000001, 0.0, 0.5), parent=self) self.progressLabel = DirectLabel( text=PLocalizer.Minigame_Repair_Sawing_Thresholds[3], text_fg=(1.0, 1.0, 1.0, 1.0), text_pos=(0.0, 0.0), text_shadow=(0.0, 0.0, 0.0, 1.0), text_font=PiratesGlobals.getPirateFont(), text_align=TextNode.ALeft, relief=None, scale=(0.080000000000000002, 0.080000000000000002, 0.080000000000000002), pos=(-0.17999999999999999, 0.0, 0.5), parent=self) self.boardDestroyedLabel = DirectLabel( text=PLocalizer.Minigame_Repair_Sawing_Board_Destroyed, text_fg=(1.0, 0.0, 0.0, 1.0), text_pos=(0.0, 0.0), text_font=PiratesGlobals.getPirateFont(), text_shadow=(0.0, 0.0, 0.0, 1.0), relief=None, scale=(0.10000000000000001, 0.10000000000000001, 0.10000000000000001), pos=(0.0, 0.0, 0.10000000000000001), parent=self) self.boardDestroyedLabel.setBin('fixed', 38) self.boardDestroyedLabel.stash() def _initIntervals(self): RepairMincroGame._initIntervals(self) self.newBoardSequence = Sequence( name='RepairSawingGame.newBoardSequence') self.splitBoardSequence = Sequence( name='RepairSawGame.splitBoardSequence') self.dropBoardSequence = Sequence( name='RepairSawGame.dropBoardSequence') def getNewBoard(self, boardIndex): board = self.model.find('**/wood%i' % boardIndex).copyTo( NodePath('board%i' % len(self.boardsPool))) board.reparentTo(self) piece1 = board.find('**/piece_1') piece1.setPythonTag('piece_1', self.piece1) piece1.setY(self.config.boardYDist) piece2 = board.find('**/piece_2') piece2.setPythonTag('piece_2', self.piece2) piece2.setY(self.config.boardYDist) pieceCut = board.find('**/piece_cut') pieceCut.setPythonTag('cut', self.cut) pieceCut.setColor(self.config.cutColor) pieceCut.setY(self.config.boardYDist) board_left = piece1.find('**/board') board_left.setPythonTag('left', self.board_left) board_right = piece2.find('**/board') board_right.setPythonTag('right', self.board_right) zone1_right = piece2.find('**/zone_1') zone1_right.setPythonTag('zone1_right', self.zone1_right) zone1_right.setColor(self.config.zone1Color) zone1_left = piece1.find('**/zone_1') zone1_left.setPythonTag('zone1_left', self.zone1_left) zone1_left.setColor(self.config.zone1Color) zone2_right = piece2.find('**/zone_2') zone2_right.setPythonTag('zone2_right', self.zone2_right) zone2_right.setColor(self.config.zone2Color) zone2_left = piece1.find('**/zone_2') zone2_left.setPythonTag('zone2_left', self.zone2_left) zone2_left.setColor(self.config.zone2Color) board.stash() return board def reset(self): for key in self.boardsPool.keys(): board = self.boardsPool[key] board.removeNode() self.boardsPool.clear() if self.currentBoard: self.currentBoard.removeNode() self.currentBoard = None if self.onDeckBoard: self.onDeckBoard.removeNode() self.onDeckBoard = None for boardIndex in self.currentDifficultySet: boardIndex -= 1 if 'copy1_%s' % boardIndex not in self.boardsPool: board = self.getNewBoard(boardIndex) self.boardsPool['copy1_%s' % boardIndex] = board if 'copy2_%s' % boardIndex not in self.boardsPool: board = self.getNewBoard(boardIndex) self.boardsPool['copy2_%s' % boardIndex] = board continue self.currentBoardIndex = 0 self.currentBoard = None self.moveNewBoardOnDeck() self.onDeckBoard.unstash() self.totalScore = 0 self.startPositions = (Point3(0.0, 0.0, 0.0), ) self.sawButton.stash() self.sawButton.reparentTo(self) self.lastHitIndex = -1 self.moveDiffForSound = 0.0 RepairMincroGame.reset(self) self.repairGame.gui.setTutorial(self.name) self.repairGame.gui.setTitle(self.name) def destroy(self): RepairMincroGame.destroy(self) taskMgr.remove('SawingGame.updateSawTask') self.sawButton.destroy() self.sawButton.removeNode() del self.sawButton if self.currentBoard: self.currentBoard.removeNode() self.currentBoard = None if self.onDeckBoard: self.onDeckBoard.removeNode() self.onDeckBoard = None self.sawingLine = None self.progressDescriptionLabel.destroy() self.progressDescriptionLabel = None self.progressLabel.destroy() self.progressLabel = None self.boardDestroyedLabel.destroy() self.boardDestroyedLabel = None for key in self.boardsPool.keys(): board = self.boardsPool[key] if not board.isEmpty(): board.removeNode() continue self.boardsPool.clear() self.newBoardSequence.clearToInitial() del self.newBoardSequence self.splitBoardSequence.clearToInitial() del self.splitBoardSequence self.dropBoardSequence.clearToInitial() del self.dropBoardSequence def setDifficulty(self, difficulty): RepairMincroGame.setDifficulty(self, difficulty) percent = difficulty / self.repairGame.difficultyMax difIndex = int( math.floor(percent * (len(self.config.difficultySets) - 1))) self.currentDifficultySet = self.config.difficultySets[difIndex] def splitBoard(self): self.sawingLine.reset() board = self.currentBoard boardIndex = self.currentBoardIndex if self.hitZone2Penalty: boardSplitAnim = Parallel( LerpPosInterval(self.board_left, duration=self.config.splitBoardAnimTime, pos=Point3(-2.0, 0.0, 0.0)), LerpPosInterval(self.board_right, duration=self.config.splitBoardAnimTime, pos=Point3(2.0, 0.0, 0.0)), LerpFunc(self.zone2_left.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0), LerpFunc(self.zone2_right.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0), LerpFunc(self.zone1_left.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0), LerpFunc(self.zone1_right.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0), LerpFunc(self.cut.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0)) elif self.hitZone1Penalty: boardSplitAnim = Parallel( LerpPosInterval(self.board_left, duration=self.config.splitBoardAnimTime, pos=Point3(-2.0, 0.0, 0.0)), LerpPosInterval(self.board_right, duration=self.config.splitBoardAnimTime, pos=Point3(2.0, 0.0, 0.0)), LerpPosInterval(self.zone2_left, duration=self.config.splitBoardAnimTime, pos=Point3(-2.0, 0.0, 0.0)), LerpPosInterval(self.zone2_right, duration=self.config.splitBoardAnimTime, pos=Point3(2.0, 0.0, 0.0)), LerpFunc(self.zone1_left.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0), LerpFunc(self.zone1_right.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0), LerpFunc(self.cut.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0)) else: boardSplitAnim = Parallel( LerpPosInterval(self.piece1, duration=self.config.splitBoardAnimTime, pos=Point3(-2.0, self.config.boardYDist, 0.0)), LerpPosInterval(self.piece2, duration=self.config.splitBoardAnimTime, pos=Point3(2.0, self.config.boardYDist, 0.0)), LerpFunc(self.cut.setSa, duration=self.config.splitBoardAnimTime / 2.0, fromData=1.0, toData=0.0)) self.splitBoardSequence = Sequence( Func(self.updateScore), Func(self.boardComplete.play), boardSplitAnim, Func(board.stash), Func(self.piece1.setPos, self.piece1.getPos()), Func(self.piece2.setPos, self.piece2.getPos()), Func(self.board_right.setPos, self.board_right.getPos()), Func(self.board_left.setPos, self.board_left.getPos()), Func(self.zone2_right.setPos, self.zone2_right.getPos()), Func(self.zone2_left.setPos, self.zone2_left.getPos()), Func(self.zone1_right.setPos, self.zone1_right.getPos()), Func(self.zone1_left.setPos, self.zone1_left.getPos()), Func(self.cut.setSa, 1.0), Func(self.zone1_right.setSa, 1.0), Func(self.zone1_left.setSa, 1.0), Func(self.zone2_right.setSa, 1.0), Func(self.zone2_left.setSa, 1.0), Func(self.board_right.setSa, 1.0), Func(self.board_left.setSa, 1.0), Func(self.loadNewBoard), Func(self.addBoardBackToPool, board, boardIndex), name='RepairSawGame.splitBoardSequence') self.splitBoardSequence.start() def dropBoard(self): board = self.currentBoard boardIndex = self.currentBoardIndex self.dropBoardSequence = Sequence( Parallel( Sequence(Func(self.boardDestroyedLabel.unstash), Wait(1.5), Func(self.boardDestroyedLabel.stash)), Sequence( Wait(0.5), Func(self.boardDestroyed.play), Func(self.sawingLine.reset), LerpPosInterval(board, duration=self.config.splitBoardAnimTime, pos=Point3(0.0, 0.0, -2.0)), Func(board.stash), Wait(0.5), Func(self.loadNewBoard), Func(self.addBoardBackToPool, board, boardIndex))), name='RepairSawGame.dropBoardSequence') self.dropBoardSequence.start() def addBoardBackToPool(self, board, boardIndex): if 'copy1_%s' % boardIndex not in self.boardsPool: self.boardsPool['copy1_%s' % boardIndex] = board elif 'copy2_%s' % boardIndex not in self.boardsPool: self.boardsPool['copy2_%s' % boardIndex] = board else: self.notify.error( 'Two copies of board type %i already in the boardsPool!' % boardIndex) def updateScoreText(self): self.progressLabel.unstash() self.progressDescriptionLabel.unstash() if self.hitBoardPenalty: self.progressLabel[ 'text'] = PLocalizer.Minigame_Repair_Sawing_Thresholds[0] self.progressLabel['text_fg'] = Vec4(1.0, 0.0, 0.0, 1.0) self.progressLabel.setText() elif self.hitZone2Penalty: self.progressLabel[ 'text'] = PLocalizer.Minigame_Repair_Sawing_Thresholds[1] self.progressLabel['text_fg'] = Vec4(1.0, 0.5, 0.0, 1.0) self.progressLabel.setText() elif self.hitZone1Penalty: self.progressLabel[ 'text'] = PLocalizer.Minigame_Repair_Sawing_Thresholds[2] self.progressLabel['text_fg'] = Vec4(1.0, 1.0, 0.0, 1.0) self.progressLabel.setText() else: self.progressLabel[ 'text'] = PLocalizer.Minigame_Repair_Sawing_Thresholds[3] self.progressLabel['text_fg'] = Vec4(0.0, 1.0, 0.0, 1.0) self.progressLabel.setText() def moveNewBoardOnDeck(self): boardIndex = random.randint(0, len(self.currentDifficultySet) - 1) boardType = self.currentDifficultySet[boardIndex] boardType -= 1 if 'copy1_%s' % boardType in self.boardsPool: self.onDeckBoard = self.boardsPool['copy1_%s' % boardType] del self.boardsPool['copy1_%s' % boardType] elif 'copy2_%s' % boardType in self.boardsPool: self.onDeckBoard = self.boardsPool['copy2_%s' % boardType] del self.boardsPool['copy2_%s' % boardType] else: self.notify.error('No copies of board type %i in the boardsPool!' % boardType) self.onDeckBoardIndex = boardType self.onDeckBoard.setScale(0.25) self.onDeckBoard.setPos(0.5, -2.0, 0.56000000000000005) self.onDeckBoard.unstash() def loadNewBoard(self): self.progressLabel.stash() self.progressDescriptionLabel.stash() if self.totalScore >= self.config.totalPoints: if self.onDeckBoard: self.onDeckBoard.stash() self.progressDescriptionLabel.stash() taskMgr.remove('SawingGame.updateSawTask') self.request('Outro') return None self.currentBoard = self.onDeckBoard self.currentBoardIndex = self.onDeckBoardIndex self.piece1 = self.currentBoard.find('**/piece_1') self.piece1.setTransparency(1) self.piece2 = self.currentBoard.find('**/piece_2') self.piece2.setTransparency(1) self.cut = self.currentBoard.find('**/piece_cut') self.cut.setColor(self.config.cutColor) self.cut.setTransparency(1) self.board_left = self.piece1.find('**/board') self.board_left.setTransparency(1) self.zone1_left = self.piece1.find('**/zone_1') self.zone1_left.setTransparency(1) self.zone2_left = self.piece1.find('**/zone_2') self.zone2_left.setTransparency(1) self.board_right = self.piece2.find('**/board') self.board_right.setTransparency(1) self.zone1_right = self.piece2.find('**/zone_1') self.zone1_right.setTransparency(1) self.zone2_right = self.piece2.find('**/zone_2') self.zone2_right.setTransparency(1) self.board_left.setCollideMask(SAW_COLLIDE_MASK) self.board_right.setCollideMask(SAW_COLLIDE_MASK) self.cut.setCollideMask(SAW_COLLIDE_MASK) self.zone1_right.setCollideMask(SAW_COLLIDE_MASK) self.zone1_left.setCollideMask(SAW_COLLIDE_MASK) self.zone2_right.setCollideMask(SAW_COLLIDE_MASK) self.zone2_left.setCollideMask(SAW_COLLIDE_MASK) self.startPositions = ( self.currentBoard.find('**/locator_start_0').getPos() + Point3(*self.config.activeBoardPosition), self.currentBoard.find('**/locator_start_1').getPos() + Point3(*self.config.activeBoardPosition)) self.currentStartIndex = 0 for waypoint in self.sawWaypoints: waypoint.removeNode() self.sawWaypoints = [] locator = self.currentBoard.find('**/locator_0') index = 0 while not locator.isEmpty(): self.sawWaypoints.append( SawWaypoint(index, self.currentBoard, locator.getPos())) locator = self.currentBoard.find('**/locator_%i' % (index + 1)) index += 1 self.sawButton.deactivate() self.sawButton.setPos(self.startPositions[self.currentStartIndex]) self.hitBoardPenalty = False self.hitZone1Penalty = False self.hitZone2Penalty = False self.lastMousePos = None self.moveDiffForSound = self.config.playSawingSoundDelta + 0.10000000000000001 self.newBoardSequence = Sequence( Parallel( self.currentBoard.posInterval( self.config.newBoardAnimTime, Point3(*self.config.activeBoardPosition)), self.currentBoard.scaleInterval(self.config.newBoardAnimTime, 1.0)), name='RepairSawingGame.newBoardSequence') if self.state in ['Game']: self.newBoardSequence.append(Func(self.sawButton.activate)) self.newBoardSequence.append(Wait(0.5)) self.newBoardSequence.append(Func(self.moveNewBoardOnDeck)) self.newBoardSequence.start() def updateSawTask(self, task): if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() relative = Point3(mpos.getX(), 0.0, mpos.getY()) relative = self.getRelativePoint(render2d, relative) moveDiff = 0.0 if self.lastMousePos != None: moveDiff = (relative - self.lastMousePos).length() pickedObjects = self.repairGame.mousePicker.getCollisions( self.currentBoard, useIntoNodePaths=True) self.updateWaypoints() if len(pickedObjects) > 0: self.moveDiffForSound += moveDiff if self.moveDiffForSound > self.config.playSawingSoundDelta: sawSoundPlaying = False for sound in self.sawSounds: if sound.status() == 2: sawSoundPlaying = True break continue if sawSoundPlaying == False: sound = random.choice(self.sawSounds) sound.play() self.moveDiffForSound = 0.0 if self.board_right in pickedObjects or self.board_left in pickedObjects: for waypoint in self.sawWaypoints: waypoint.hit = False self.hitBoardPenalty = True self.dropBoard() self.sawButton.deactivate() elif self.cut in pickedObjects: self.updateWaypoints() elif self.zone1_right in pickedObjects or self.zone1_left in pickedObjects: self.updateWaypoints() if self.hitZone1Penalty == False: self.hitZone1Penalty = True elif self.zone2_right in pickedObjects or self.zone2_left in pickedObjects: self.updateWaypoints() if self.hitZone2Penalty == False: self.hitZone2Penalty = True self.updateScoreText() else: boardComplete = True for waypoint in self.sawWaypoints: if not waypoint.hit: boardComplete = False break continue if boardComplete: self.splitBoard() self.sawButton.deactivate() self.lastMousePos = self.sawButton.getPos() return Task.cont def updateScore(self): if not self.hitBoardPenalty: currBoardScore = self.config.pointsPerBoard if not self.hitZone1Penalty: pass currBoardScore -= self.config.pointsLostForZone1 * self.hitZone2Penalty currBoardScore -= self.config.pointsLostForZone2 * self.hitZone2Penalty rating = 4 - 1 * self.hitZone2Penalty - 3 * self.hitZone1Penalty self.totalScore += currBoardScore self.totalScore = min(self.totalScore, self.config.totalPoints) percent = int((self.totalScore / self.config.totalPoints) * 100.0) self.repairGame.d_reportMincroGameProgress(percent, rating) def resetWaypoints(self): for waypoint in self.sawWaypoints: waypoint.hit = False def updateWaypoints(self): waypointList = self.getHitWaypoints() for waypointIndex in waypointList: self.lastHitIndex = waypointIndex self.sawWaypoints[waypointIndex].hit = True if waypointIndex == 0 and not (self.sawWaypoints[-1].hit): self.currentStartIndex = 0 continue if waypointIndex == len( self.sawWaypoints) - 1 and not (self.sawWaypoints[0].hit): self.currentStartIndex = 1 continue def getHitWaypoints(self): waypointsHit = [] testDelta = self.config.testWaypointDelta for i in range(len(self.sawWaypoints)): waypointPos = self.sawWaypoints[i].getPos(self) closestDistance = 9999 if self.lastMousePos != None: currMousePos = self.sawButton.getPos() lastMousePos = self.lastMousePos totalLength = (currMousePos - lastMousePos).length() testLength = testDelta while testLength < totalLength: testPos = (currMousePos - lastMousePos) * ( testLength / totalLength) + lastMousePos self.updateSawLine(testPos) testDistance = (testPos - waypointPos).length() closestDistance = min(testDistance, closestDistance) testLength += testDelta self.updateSawLine(self.sawButton.getPos()) testDistance = (self.sawButton.getPos() - waypointPos).length() closestDistance = min(testDistance, closestDistance) if closestDistance < self.config.waypointRange[ self.currentBoardIndex]: waypointsHit.append(i) continue return waypointsHit def updateSawLine(self, pos): if pos.getX() < -0.63300000000000001 or pos.getX( ) > 0.63300000000000001: self.sawingLine.reset() return None if pos.getZ() < -0.183 or pos.getZ() > 0.375: self.sawingLine.reset() return None self.sawingLine.update(pos) def getClosestPosition(self, positions): closestIndex = -1 if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() relative = Point3(mpos.getX(), 0.0, mpos.getY()) relative = self.getRelativePoint(base.a2dBackground, relative) bestDistance = 99999.0 for i in range(len(positions)): dX = relative.getX() - positions[i].getX() dZ = relative.getZ() - positions[i].getZ() newDistance = dX * dX + dZ * dZ if newDistance < bestDistance: bestDistance = newDistance closestIndex = i continue return closestIndex def sawAttachedToMouse(self): self.lastHitIndex = -1 if not taskMgr.hasTaskNamed('SawingGame.updateSawTask'): taskMgr.add(self.updateSawTask, 'SawingGame.updateSawTask', priority=2) def sawRemovedFromMouse(self): if not self.sawButton.isStashed(): self.sawButton.setPos(self.startPositions[self.currentStartIndex]) self.lastHitIndex = -1 self.resetWaypoints() self.lastMousePos = None self.progressLabel.stash() self.progressDescriptionLabel.stash() self.sawingLine.reset() self.hitBoardPenalty = False self.hitZone1Penalty = False self.hitZone2Penalty = False taskMgr.remove('SawingGame.updateSawTask') def enterIntro(self): RepairMincroGame.enterIntro(self) self.loadNewBoard() def enterGame(self): RepairMincroGame.enterGame(self) self.repairGame.mousePicker.setCollisionMask(SAW_COLLIDE_MASK) self.sawButton.activate() def exitGame(self): RepairMincroGame.exitGame(self) self.sawButton.deactivate() self.repairGame.mousePicker.clearCollisionMask() taskMgr.remove('SawingGame.updateSawTask') self.splitBoardSequence.clearToInitial() self.dropBoardSequence.clearToInitial() localAvatar.guiMgr._showCursor() def enterOutro(self): RepairMincroGame.enterOutro(self) self.repairGame.d_reportMincroGameScore(150)
class RepairMincroGame(DirectFrame, FSM.FSM): readySound = None goSound = None completeSound = None def __init__(self, repairGame, name, startText): DirectFrame.__init__(self, parent = repairGame.gui, relief = None) FSM.FSM.__init__(self, '%sFSM' % name) self.defaultTransitions = { 'Idle': [ 'Intro', 'Final'], 'Intro': [ 'Game', 'Idle', 'Final'], 'Game': [ 'Outro', 'Idle', 'Final'], 'Outro': [ 'Idle', 'Final'], 'Final': [] } self.name = name self.repairGame = repairGame self.startText = startText self._initVars() self._initAudio() self._initVisuals() self._initIntervals() self.request('Idle') def _initVars(self): self.complete = False self.difficulty = 0 def _initAudio(self): if not self.readySound: RepairMincroGame.readySound = loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_READY) RepairMincroGame.goSound = loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_GO) RepairMincroGame.completeSound = loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_GAMECOMPLETE) def _initVisuals(self): self.countDownLabel = DirectLabel(text = self.startText, text_fg = (1.0, 1.0, 1.0, 1.0), text_shadow = (0.0, 0.0, 0.0, 1.0), text_font = PiratesGlobals.getPirateFont(), scale = (0.16, 0.16, 0.16), pos = (0.0, 0.0, 0.14999999999999999), parent = self, relief = None, textMayChange = 1) self.countDownLabel.setBin('fixed', 37) self.winLabel = DirectLabel(text = PLocalizer.Minigame_Repair_Win, text_fg = (1.0, 1.0, 1.0, 1.0), text_font = PiratesGlobals.getPirateFont(), text_shadow = (0.0, 0.0, 0.0, 1.0), scale = (0.16, 0.16, 0.16), pos = RepairGlobals.Common.youWinPos[self.name], relief = None, parent = self) self.winLabel.setBin('fixed', 37) self.winLabel.stash() self.scoreLabel = DirectLabel(text = PLocalizer.Minigame_Repair_Win, text_fg = (1.0, 1.0, 1.0, 1.0), text_font = PiratesGlobals.getPirateFont(), text_shadow = (0.0, 0.0, 0.0, 1.0), scale = (0.10000000000000001, 0.10000000000000001, 0.10000000000000001), pos = RepairGlobals.Common.scorePos[self.name], relief = None, parent = self) self.scoreLabel.setBin('fixed', 37) self.scoreLabel.stash() self.postWinLabel = DirectLabel(text = PLocalizer.Minigame_Repair_Pick_New_Game, text_fg = (1.0, 1.0, 1.0, 1.0), text_font = PiratesGlobals.getPirateFont(), text_shadow = (0.0, 0.0, 0.0, 1.0), scale = (0.14000000000000001, 0.14000000000000001, 0.14000000000000001), pos = RepairGlobals.Common.youWinPos[self.name], relief = None, textMayChange = 1, parent = self.repairGame.gui) self.postWinLabel.setBin('fixed', 37) self.postWinLabel.stash() def _initIntervals(self): normalPos = Vec3(0.0, 0.0, 0.14999999999999999) belowScreenPos = Vec3(normalPos.getX(), normalPos.getY(), normalPos.getZ() - 0.25) aboveScreenPos = Vec3(normalPos.getX(), normalPos.getY(), normalPos.getZ() + 0.25) self.introSequence = Sequence(Func(self.setCountDown, PLocalizer.Minigame_Repair_Countdown_Ready), Parallel(LerpFunc(self.countDownLabel.setPos, fromData = belowScreenPos, toData = normalPos, duration = 0.25), LerpFunc(self.countDownLabel.setAlphaScale, fromData = 0.0, toData = 1.0, duration = 0.25)), Func(self.readySound.play), Wait(0.5), Parallel(LerpFunc(self.countDownLabel.setPos, fromData = normalPos, toData = aboveScreenPos, duration = 0.25), LerpFunc(self.countDownLabel.setAlphaScale, fromData = 1.0, toData = 0.0, duration = 0.25)), Func(self.setCountDown, self.startText), Parallel(LerpFunc(self.countDownLabel.setPos, fromData = belowScreenPos, toData = normalPos, duration = 0.25), LerpFunc(self.countDownLabel.setAlphaScale, fromData = 0.0, toData = 1.0, duration = 0.25)), Func(self.goSound.play), Wait(0.5), Parallel(LerpFunc(self.countDownLabel.setPos, fromData = normalPos, toData = aboveScreenPos, duration = 0.25), LerpFunc(self.countDownLabel.setAlphaScale, fromData = 1.0, toData = 0.0, duration = 0.25)), Func(self.request, 'Game'), name = 'RepairMincroGame.introSequence') normalPos = Vec3(RepairGlobals.Common.youWinPos[self.name]) normalScorePos = Vec3(RepairGlobals.Common.scorePos[self.name]) belowScreenPos = Vec3(normalPos.getX(), normalPos.getY(), normalPos.getZ() - 0.25) aboveScreenPos = Vec3(normalPos.getX(), normalPos.getY(), normalPos.getZ() + 0.25) belowScreenScorePos = Vec3(normalScorePos.getX(), normalScorePos.getY(), normalScorePos.getZ() - 0.25) aboveScreenScorePos = Vec3(normalScorePos.getX(), normalScorePos.getY(), normalScorePos.getZ() + 0.25) self.outroSequence = Sequence(Func(self.winLabel.setAlphaScale, 0), Func(self.scoreLabel.setAlphaScale, 0), Func(self.postWinLabel.setAlphaScale, 0), Func(self.winLabel.setPos, belowScreenPos), Func(self.scoreLabel.setPos, belowScreenScorePos), Func(self.postWinLabel.setPos, belowScreenPos), Func(self.setScoreLabelText), Func(self.winLabel.unstash), Func(self.scoreLabel.unstash), Func(self.postWinLabel.unstash), Parallel(LerpFunc(self.scoreLabel.setPos, fromData = belowScreenScorePos, toData = normalScorePos, duration = 0.25), LerpFunc(self.scoreLabel.setAlphaScale, fromData = 0.0, toData = 1.0, duration = 0.25), LerpFunc(self.winLabel.setPos, fromData = belowScreenPos, toData = normalPos, duration = 0.25), LerpFunc(self.winLabel.setAlphaScale, fromData = 0.0, toData = 1.0, duration = 0.25)), Func(self.completeSound.play), Wait(1.0), Parallel(LerpFunc(self.winLabel.setPos, fromData = normalPos, toData = aboveScreenPos, duration = 0.25), LerpFunc(self.winLabel.setAlphaScale, fromData = 1.0, toData = 0.0, duration = 0.25), LerpFunc(self.scoreLabel.setPos, fromData = normalScorePos, toData = aboveScreenScorePos, duration = 0.25), LerpFunc(self.scoreLabel.setAlphaScale, fromData = 1.0, toData = 0.0, duration = 0.25)), Func(self.winLabel.stash), Func(self.scoreLabel.stash), Func(self.stashPostWinLabelIfCycleComplete), Wait(0.25), Parallel(LerpFunc(self.postWinLabel.setPos, fromData = belowScreenPos, toData = normalPos, duration = 0.25), LerpFunc(self.postWinLabel.setAlphaScale, fromData = 0.0, toData = 1.0, duration = 0.25)), name = 'outroSequence') self.cleanupSequence = Sequence(Parallel(LerpFunc(self.postWinLabel.setPos, fromData = normalPos, toData = aboveScreenPos, duration = 0.5), LerpFunc(self.postWinLabel.setAlphaScale, fromData = 1.0, toData = 0.0, duration = 0.5), LerpFunc(self.scoreLabel.setAlphaScale, fromData = 1.0, toData = 0.0, duration = 0.5)), Func(self.scoreLabel.stash), Func(self.postWinLabel.stash), name = 'cleanupSequence') def updatePostWinLabel(self): if self.repairGame.isThereAnOpenGame(): self.postWinLabel['text'] = PLocalizer.Minigame_Repair_Pick_New_Game else: self.postWinLabel['text'] = PLocalizer.Minigame_Repair_Waiting_For_Players self.postWinLabel.setText() def setScoreLabelText(self): labelSet = False for i in [ 0, 1, 2]: if not labelSet: percent = self.difficulty / self.repairGame.difficultyMax dif = RepairGlobals.Common.speedThresholds[self.name][i][1] - RepairGlobals.Common.speedThresholds[self.name][i][0] goalTime = RepairGlobals.Common.speedThresholds[self.name][i][0] + dif * percent if self.repairGame.repairClock.gameTime < goalTime: labelSet = True self.scoreLabel['text'] = PLocalizer.Minigame_Repair_Speed_Thresholds[i] self.repairGame.repairClock.gameTime < goalTime if not labelSet: self.scoreLabel['text'] = PLocalizer.Minigame_Repair_Speed_Thresholds[3] def stashPostWinLabelIfCycleComplete(self): if self.repairGame.isCycleComplete(): self.postWinLabel.stash() def setDifficulty(self, difficulty): self.difficulty = difficulty def setCountDown(self, text): self.countDownLabel['text'] = text self.countDownLabel.setText() self.countDownLabel.setAlphaScale(0.0) def destroy(self): DirectFrame.destroy(self) self.countDownLabel.destroy() del self.countDownLabel self.winLabel.destroy() del self.winLabel self.introSequence.clearToInitial() del self.introSequence self.outroSequence.clearToInitial() del self.outroSequence self.cleanupSequence.clearToInitial() del self.cleanupSequence del self.repairGame self.cleanup() def reset(self): self.complete = False self.repairGame.repairClock.stop() def enterIdle(self): self.stash() def exitIdle(self): pass def enterIntro(self): self.unstash() self.countDownLabel.unstash() self.introSequence.start() self.reset() self.countDownLabel.reparentTo(self) def exitIntro(self): self.countDownLabel.stash() self.introSequence.clearToInitial() def enterGame(self): self.repairGame.repairClock.restart() def exitGame(self): self.repairGame.repairClock.pause() def enterOutro(self): self.outroSequence.start() self.complete = True def exitOutro(self): self.outroSequence.finish() self.cleanupSequence.start() self.reset() self.repairGame.gui.clearTutorial() self.repairGame.gui.clearTitle() def enterFinal(self): pass
class CogdoFlyingFuelGui(DirectFrame): def __init__(self, parent): DirectFrame.__init__(self, relief=None, state=DGG.NORMAL, sortOrder=DGG.BACKGROUND_SORT_INDEX) self.reparentTo(parent) self.active = 0 self._initModel() self._initIntervals() return def _initModel(self): self.setPos(Globals.Gui.FuelPos2D[0], 0.0, Globals.Gui.FuelPos2D[1]) self.gui = CogdoUtil.loadFlyingModel('propellerMeter', group='gui') self.gui.reparentTo(self) self.gui.setBin('fixed', 0) self.healthBar = self.gui.find('**/healthBar') self.healthBar.setBin('fixed', 1) self.healthBar.setColor(*Globals.Gui.FuelNormalColor) bottomBarLocator = self.gui.find('**/bottomOfBar_loc') bottomBarPos = bottomBarLocator.getPos(render) topBarLocator = self.gui.find('**/topOfBar_loc') topBarPos = topBarLocator.getPos(render) zDist = topBarPos.getZ() - bottomBarPos.getZ() self.fuelLowIndicator = self.gui.find('**/fuelLowIndicator') self.fuelLowIndicator.setBin('fixed', 2) pos = self.fuelLowIndicator.getPos(render) newPos = pos newPos.setZ(bottomBarPos.getZ() + zDist * Globals.Gameplay.FuelLowAmt) self.fuelLowIndicator.setPos(render, newPos) self.fuelVeryLowIndicator = self.gui.find('**/fuelVeryLowIndicator') self.fuelVeryLowIndicator.setBin('fixed', 2) pos = self.fuelVeryLowIndicator.getPos(render) newPos = pos newPos.setZ(bottomBarPos.getZ() + zDist * Globals.Gameplay.FuelVeryLowAmt) self.fuelVeryLowIndicator.setPos(render, newPos) self.propellerMain = self.gui.find('**/propellers') self.propellerMain.setBin('fixed', 3) self.propellerHead = self.gui.find('**/propellerHead') self.propellerHead.setBin('fixed', 4) self.blades = [] self.activeBlades = [] index = 1 blade = self.propellerMain.find('**/propeller%d' % index) while not blade.isEmpty(): self.blades.append(blade) index += 1 blade = self.propellerMain.find('**/propeller%d' % index) for blade in self.blades: self.activeBlades.append(blade) self.bladeNumberLabel = DirectLabel(parent=self.propellerHead, relief=None, pos=(Globals.Gui.FuelNumBladesPos2D[0], 0, Globals.Gui.FuelNumBladesPos2D[1]), scale=Globals.Gui.FuelNumBladesScale, text=str(len(self.activeBlades)), text_align=TextNode.ACenter, text_fg=(0.0, 0.0, -0.002, 1), text_shadow=(0.75, 0.75, 0.75, 1), text_font=ToontownGlobals.getInterfaceFont()) self.bladeNumberLabel.setBin('fixed', 5) return def _initIntervals(self): self._healthIval = LerpFunctionInterval(self.healthBar.setSz, fromData=0.0, toData=1.0, duration=2.0) self.baseSpinDuration = 2.0 self._spinIval = LerpFunctionInterval(self.propellerMain.setR, fromData=0.0, toData=-360.0, duration=self.baseSpinDuration) def show(self): DirectFrame.show(self) self._spinIval.loop() def hide(self): DirectFrame.hide(self) self._spinIval.pause() def resetBlades(self): self.setBlades(len(self.blades)) def setBlades(self, fuelState): if fuelState not in Globals.Gameplay.FuelStates: return numBlades = fuelState - 1 if len(self.activeBlades) != numBlades: for i in range(len(self.activeBlades)): blade = self.activeBlades.pop() blade.stash() if numBlades > len(self.blades): numBlades = len(self.blades) for i in range(numBlades): blade = self.blades[i] self.activeBlades.append(blade) blade.unstash() self.bladeNumberLabel['text'] = str(len(self.activeBlades)) self.bladeNumberLabel.setText() self.updateHealthBarColor() def bladeLost(self): if len(self.activeBlades) > 0: blade = self.activeBlades.pop() blade.stash() self.bladeNumberLabel['text'] = str(len(self.activeBlades)) self.bladeNumberLabel.setText() self.updateHealthBarColor() def updateHealthBarColor(self): color = Globals.Gui.NumBlades2FuelColor[len(self.activeBlades)] self.healthBar.setColor(*color) def setPropellerSpinRate(self, newRate): self._spinIval.setPlayRate(newRate) def setRefuelLerpFromData(self): startScale = self.healthBar.getSz() self._healthIval.fromData = startScale def setFuel(self, fuel): self.fuel = fuel def update(self): self.healthBar.setSz(self.fuel) def destroy(self): self.bladeNumberLabel.removeNode() self.bladeNumberLabel = None self._healthIval.clearToInitial() del self._healthIval self.healthBar = None self.fuelLowIndicator = None self.fuelVeryLowIndicator = None self.propellerMain = None self.propellerHead = None del self.blades[:] del self.activeBlades[:] self.gui.detachNode() self.gui = None DirectFrame.destroy(self) return
class RepairBarnacle(DirectFrame, FSM.FSM): __module__ = __name__ barnacleFallSounds = None def __init__(self, name, barnacleGeom): self.config = RepairGlobals.Careening DirectFrame.__init__(self, parent=None, relief=None) self.barnacleGeom = barnacleGeom FSM.FSM.__init__(self, 'Barnacle_%sFSM' % name) self._initAudio() self._initVars() self._initGUI() return def _initVars(self): self.heat = 0.0 self.hp = 100 self.maxHP = 100 self.currentShake = None self.fallingAnim = None return def _initAudio(self): if not self.barnacleFallSounds: RepairBarnacle.barnacleFallSounds = ( loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE1), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE2), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE3), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE4), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE5)) def _initGUI(self): self.barnacleGeom.reparentTo(self) self.barnacleGeom.setScale(0.6) self.barnacleGeom.setR(random.random() * 360) if self.config.showBarnacleHP: self.hpLabel = DirectLabel(text='', scale=(0.025, 0.025, 0.025), pos=(0.0, 0.0, -0.01), textMayChange=1, parent=self) def destroy(self): if self.currentShake is not None: self.currentShake.clearToInitial() self.currentShake = None del self.currentShake if self.fallingAnim is not None: self.fallingAnim.clearToInitial() self.fallingAnim = None del self.fallingAnim self.cleanup() if self.config.showBarnacleHP: self.hpLabel.destroy() del self.hpLabel DirectFrame.destroy(self) self.barnacleGeom.removeNode() del self.barnacleGeom return def setMaxHP(self, newMaxHP, globalMaxHP): self.maxHP = newMaxHP self.globalMaxHP = globalMaxHP def setHP(self, newHP): self.hp = newHP if self.config.showBarnacleHP: self.hpLabel['text'] = '%i' % self.hp self.hpLabel.setText() if self.hp <= 0.0: self.hp = 0.0 self.request('Falling') self.setScale(self.hp * MAX_SCALE_ADD / self.globalMaxHP + MIN_SCALE) def reduceHP(self, pushDir, powerScale): amount = pushDir.length() pushDir.normalize() self.heat = min(1.0, self.heat + amount) amount *= 50 if amount > MAX_SCRUB_AMT: amount = MAX_SCRUB_AMT amount *= powerScale newHP = self.hp - amount self.setHP(newHP) if self.currentShake is None: self.currentShake = Sequence( LerpPosInterval( self, duration=0.03, pos=(self.getX() - pushDir[0] * (0.01 + amount / 1000.0), self.getY(), self.getZ() - pushDir[1] * (0.01 + amount / 1000.0)), blendType='easeIn'), LerpPosInterval(self, duration=0.06, pos=(self.getX(), self.getY(), self.getZ()), blendType='easeOut'), LerpPosInterval( self, duration=0.04, pos=(self.getX() + pushDir[0] * (0.0075 + amount / 2000.0), self.getY(), self.getZ() + pushDir[1] * (0.005 + amount / 2000.0)), blendType='easeIn'), LerpPosInterval(self, duration=0.08, pos=(self.getX(), self.getY(), self.getZ()), blendType='easeOut'), Func(self.clearCurrentShake)) self.currentShake.start() return def checkCollision(self, mousePosition): sld = Point3(mousePosition.getX(), 0.0, mousePosition.getY()) - self.getPos(render2d) return self.getCurrentOrNextState() == 'Idle' and sld.length( ) < self.config.barnacleRadius * self.getScale().getX() def clearCurrentShake(self): self.currentShake = None return def enterIdle(self): visibleIndex = random.uniform(0, self.barnacleGeom.getNumChildren() - 1) for i in range(self.barnacleGeom.getNumChildren() - 1): self.barnacleGeom.getChild(i).unstash() newHP = self.maxHP self.heat = 0.0 self.setHP(newHP) self.unstash() def exitIdle(self): pass def enterFalling(self): if self.currentShake is not None: self.currentShake.finish() sound = random.choice(self.barnacleFallSounds) sound.play() self.fallingAnim = Sequence( LerpPosInterval(self, duration=2.0, pos=(self.getX(), self.getY(), self.getZ() - 2.0), blendType='easeIn'), Func(self.request, 'Clean')) self.fallingAnim.start() return def exitFalling(self): self.stash() def enterClean(self): pass def exitClean(self): pass
class RepairNail(NodePath, FSM.FSM): def __init__(self, name, parent, nailModel): self.config = RepairGlobals.Hammering NodePath.__init__(self, name) FSM.FSM.__init__(self, 'Nail_%sFSM' % name) self.reparentTo(parent) self.nailModel = nailModel self._initVars() self._initVisuals() def _initVars(self): self.totalClicks = 0 self.remainingPercent = 1.0 def _initVisuals(self): self.visual = self.attachNewNode('RepairNail.visual') self.nailModel.find('**/nail_collision').setPos(0.0, -35.0, 0.0) self.nailModel.setScale(1.5) self.nailModel.find('**/nail_collision').setCollideMask(NAIL_COLLIDE_MASK) self.nailModel.find('**/nail_collision').setPythonTag('nail', self) self.nailModel.find('**/nail_collision').hide() self.nailModel.reparentTo(self.visual) self.nailModel.find('**/nail_model').setHpr(0.0, 20.0, 0.0) self.nailModel.setDepthTest(True) self.nailModel.setDepthWrite(True) self.shadow = self.nailModel.find('**/shadow') self.shadow.reparentTo(self) self.shadow.setPos(0.0, -0.040000000000000001, 0.02) self.shadow.setDepthTest(True) self.shadow.setDepthWrite(True) self.shadow.setScale(2.0) self.shadow.setTransparency(1) self.shadow.setSa(0.59999999999999998) self.resultLabel = DirectLabel(text = '', relief = None, text_fg = (1.0, 1.0, 1.0, 1.0), text_shadow = (0.0, 0.0, 0.0, 1.0), text_font = PiratesGlobals.getPirateFont(), scale = (0.050000000000000003, 0.050000000000000003, 0.050000000000000003), pos = (0.0, 0.0, -0.089999999999999997), parent = self) def removeNode(self): self.visual.removeNode() del self.visual self.resultLabel.destroy() NodePath.removeNode(self) def setShadow(self, percent): self.shadow.setScale(percent * 1.0 + 1.3999999999999999) self.shadow.setSa(1.0 - percent * 0.20000000000000001 + 0.20000000000000001) def hitNail(self, percentage): self.remainingPercent = max(0.0, self.remainingPercent - percentage) self.totalClicks += 1 self.setShadow(self.remainingPercent) newDepth = (1.0 - self.remainingPercent) * HAMMERED_DEPTH self.visual.setZ(newDepth) if self.remainingPercent <= 0.0: for i in range(len(self.config.rankingThresholds)): if self.totalClicks >= self.config.rankingThresholds[i]: break continue self.request('Hammered', PLocalizer.Minigame_Repair_Hammering_Thresholds[i]) return True return False def enterActive(self): self.visual.setZ(0.0) self.remainingPercent = 1.0 self.totalClicks = 0 self.setShadow(1.0) def exitActive(self): pass def enterHammered(self, successText): self.resultLabel['text'] = successText self.resultLabel.setText() def exitHammered(self): self.resultLabel['text'] = '' self.resultLabel.setText() def enterIdle(self): self.stash() def exitIdle(self): self.unstash()
class DirectTooltip(): def __init__(self): self.tooltipText = DirectLabel( text = "Tooltip", text_fg = (1,1,1,1), text_scale = 0.05, text_align = TextNode.ALeft, frameColor = (0, 0, 0, 0.75), borderWidth = (0.1, 0.1)) self.tooltipText.setTransparency(True) self.textXShift = 0.05 self.textYShift = -0.08 self.mousePos = None # this will determine when the tooltip should be moved in the # respective direction, whereby # 1 : display edge # <1 : margin inside the window # >1 : margin outside the window self.xEdgeStartShift = 0.99 self.yEdgeStartShift = 0.99 self.tooltipText.hide() def show(self, text=None, args=None): if text is not None: self.tooltipText.setText(text) self.tooltipText.resetFrameSize() self.tooltipText.show() # add the tooltips update task so it will be updated every frame base.taskMgr.add(self.updateTooltipPos, "task_updateTooltipPos") def delete(self, args=None): self.tooltipText.removeNode() # remove the tooltips update task base.taskMgr.remove("task_updateTooltipPos") def updateTooltipPos(self, task): # calculate new aspec tratio wp = base.win.getProperties() aspX = 1.0 aspY = 1.0 wpXSize = wp.getXSize() wpYSize = wp.getYSize() if wpXSize > wpYSize: aspX = wpXSize / float(wpYSize) else: aspY = wpYSize / float(wpXSize) # variables to store the mouses current x and y position x = 0.0 y = 0.0 if base.mouseWatcherNode.hasMouse(): self.tooltipText.show() # get the mouse position x = base.mouseWatcherNode.getMouseX() y = base.mouseWatcherNode.getMouseY() # Move the tooltip to the mouse # set the text to the current mouse position self.tooltipText.setPos( (x*aspX) + self.textXShift, 0, (y*aspY)+self.textYShift) bounds = self.tooltipText.getBounds() # bounds = left, right, bottom, top # calculate the texts bounds respecting its current position xLeft = self.tooltipText.getX() + bounds[0]*self.tooltipText.getScale()[0] xRight = self.tooltipText.getX() + bounds[1]*self.tooltipText.getScale()[0] yUp = self.tooltipText.getZ() + bounds[3]*self.tooltipText.getScale()[1] yDown = self.tooltipText.getZ() + bounds[2]*self.tooltipText.getScale()[1] # these will be used to shift the text in the desired direction xShift = 0.0 yShift = 0.0 if xRight/aspX > self.xEdgeStartShift: # shift to the left xShift = self.xEdgeStartShift - xRight/aspX elif xLeft/aspX < -self.xEdgeStartShift: # shift to the right xShift = -(self.xEdgeStartShift + xLeft/aspX) if yUp/aspY > self.yEdgeStartShift: # shift down yShift = self.yEdgeStartShift - yUp/aspY elif yDown/aspY < -self.yEdgeStartShift: # shift up yShift = -(self.yEdgeStartShift + yDown/aspY) # some aspect ratio calculation xShift *= aspX yShift *= aspY # move the tooltip to the new position self.tooltipText.setX(self.tooltipText.getX() + xShift) self.tooltipText.setZ(self.tooltipText.getZ() + yShift) else: self.tooltipText.delete() # continue the task until it got manually stopped return task.cont
class Player(GameObject, ArmedObject): def __init__(self, shipSpec): GameObject.__init__(self, Vec3(0, 0, 0), None, None, shipSpec.maxShields, shipSpec.maxSpeed, "player", MASK_INTO_PLAYER, 2) ArmedObject.__init__(self) self.acceleration = shipSpec.acceleration self.turnRate = shipSpec.turnRate self.numGuns = len(shipSpec.gunPositions) self.numMissiles = shipSpec.numMissiles self.maxEnergy = shipSpec.maxEnergy self.energyRechargeRate = shipSpec.energyRechargeRate self.shieldRechargeRate = shipSpec.shieldRechargeRate self.energy = shipSpec.maxEnergy for gunPos in shipSpec.gunPositions: np = self.actor.attachNewNode(PandaNode("gun node")) np.setPos(gunPos) gun = BlasterWeapon() self.addWeapon(gun, 0, np) missileSetCounter = 1 for missilePos in shipSpec.missilePositions: np = self.actor.attachNewNode(PandaNode("missile node")) np.setPos(missilePos) gun = RocketWeapon() self.addWeapon(gun, missileSetCounter, np) missileSetCounter += 1 self.numMissileSets = missileSetCounter - 1 self.missileSetIndex = 0 light = PointLight("basic light") light.setColor(Vec4(1, 1, 1, 1)) light.setAttenuation((1, 0.01, 0.001)) self.lightNP = self.root.attachNewNode(light) self.lightNP.setZ(1) Common.framework.showBase.render.setLight(self.lightNP) self.colliderNP.node().setFromCollideMask(MASK_WALLS | MASK_FROM_PLAYER) Common.framework.pusher.addCollider(self.colliderNP, self.root) Common.framework.traverser.addCollider(self.colliderNP, Common.framework.pusher) Common.framework.showBase.camera.reparentTo(self.actor) Common.framework.showBase.camera.setPos(0, 0, 0) Common.framework.showBase.camera.setHpr(0, 0, 0) lens = Common.framework.showBase.camLens lens.setNear(0.03) ratio = lens.getAspectRatio() lens.setFov(75 * ratio) self.lastMousePos = Vec2(0, 0) self.mouseSpeedHori = 50.0 self.mouseSpeedVert = 30.0 self.mouseSensitivity = 1.0 self.targetingRay = CollisionSegment(0, 0, 0, 0, 100, 0) self.targetingRayNode = CollisionNode("lock ray") self.targetingRayNode.addSolid(self.targetingRay) self.targetingRayNode.setFromCollideMask(MASK_ENEMY_LOCK_SPHERE) self.targetingRayNode.setIntoCollideMask(0) self.targetingRayNP = self.actor.attachNewNode(self.targetingRayNode) self.targetingQueue = CollisionHandlerQueue() self.prospectiveLockTarget = None self.lockTargetTimer = 0 self.lockDuration = 1 Common.framework.traverser.addCollider(self.targetingRayNP, self.targetingQueue) #rayNodePath.show() self.uiRoot = aspect2d.attachNewNode(PandaNode("player UI")) cardMaker = CardMaker("UI maker") cardMaker.setFrame(-1, 1, -1, 1) self.centreSpot = self.uiRoot.attachNewNode(cardMaker.generate()) self.centreSpot.setTexture( Common.framework.showBase.loader.loadTexture( "../Section2SpaceflightDocking/UI/spot.png")) self.centreSpot.setTransparency(True) self.centreSpot.setPos(0, 0, 0) self.centreSpot.setScale(0.01) self.centreSpot.setAlphaScale(0.5) self.directionIndicator = self.uiRoot.attachNewNode( cardMaker.generate()) self.directionIndicator.setTexture( Common.framework.showBase.loader.loadTexture( "../Section2SpaceflightDocking/UI/directionIndicator.png")) self.directionIndicator.setTransparency(True) self.directionIndicator.setScale(0.05) self.directionIndicator.hide() self.lockMarkerRoot = self.uiRoot.attachNewNode( PandaNode("lock marker root")) for i in range(4): markerRotationNP = self.lockMarkerRoot.attachNewNode( PandaNode("lock marker rotation")) marker = markerRotationNP.attachNewNode(cardMaker.generate()) marker.setTexture( Common.framework.showBase.loader.loadTexture( "../Section2SpaceflightDocking/UI/lockMarker.png")) marker.setTransparency(True) markerRotationNP.setScale(0.04) markerRotationNP.setR(i * 90) self.lockMarkerRoot.hide() self.lockBar = Common.framework.showBase.loader.loadModel( "../Section2SpaceflightDocking/UI/uiLockBar") self.lockBar.reparentTo(self.uiRoot) self.lockBar.setScale(0.15) #self.lockBar.hide() cardMaker.setFrame(-1, 1, 0, 1) self.cockpit = Common.framework.showBase.loader.loadModel( "../Section2SpaceflightDocking/Models/{0}".format( shipSpec.cockpitModelFile)) self.cockpit.reparentTo(self.actor) healthBarRoot = self.cockpit.find("**/healthBar") if healthBarRoot is None or healthBarRoot.isEmpty(): healthBarRoot = self.uiRoot.attachNewNode( PandaNode("health bar root")) print("No health bar root found!") energyBarRoot = self.cockpit.find("**/energyBar") if energyBarRoot is None or energyBarRoot.isEmpty(): energyBarRoot = self.uiRoot.attachNewNode( PandaNode("energy bar root")) print("No energy bar root found!") missileCounterRoot = self.cockpit.find("**/missileCounter") if missileCounterRoot is None or missileCounterRoot.isEmpty(): missileCounterRoot = self.uiRoot.attachNewNode( PandaNode("missile counter root")) print("No missile counter root found!") radarRoot = self.cockpit.find("**/radar") if radarRoot is None or radarRoot.isEmpty(): radarRoot = self.uiRoot.attachNewNode(PandaNode("radar root")) print("No radar root found!") speedometerRoot = self.cockpit.find("**/speedometer") if speedometerRoot is None or speedometerRoot.isEmpty(): speedometerRoot = self.uiRoot.attachNewNode( PandaNode("speedometer root")) print("No speedometer root found!") self.radarDrawer = MeshDrawer() self.radarDrawer.setBudget(4096) self.radarDrawerNP = self.radarDrawer.getRoot() self.radarDrawerNP.reparentTo(radarRoot) self.radarDrawerNP.setTwoSided(True) self.radarDrawerNP.setLightOff() self.radarDrawerNP.setDepthWrite(False) self.radarDrawerNP.setTransparency(True) self.healthBar = healthBarRoot.attachNewNode(cardMaker.generate()) self.healthBar.setSx(0.05) self.energyBar = energyBarRoot.attachNewNode(cardMaker.generate()) self.energyBar.setSx(0.05) self.healthBarScalar = 0.00175 self.energyBarScalar = 0.00175 self.missileCounter = DirectLabel(text="", text_mayChange=True, scale=0.09, relief=None, parent=missileCounterRoot) self.maxRadarRange = 700 self.radarSize = 0.3 self.speedometer = DirectLabel(text="", text_mayChange=True, scale=0.09, relief=None, parent=speedometerRoot) self.updateHealthUI() self.updateEnergyUI() self.updateMissileUI() self.updateRadar() self.updateSpeedometer() self.updatingEffects = [] def update(self, keys, dt): GameObject.update(self, dt) self.updateSpeedometer() self.walking = False quat = self.root.getQuat(Common.framework.showBase.render) forward = quat.getForward() right = quat.getRight() up = quat.getUp() if keys["up"]: self.walking = True self.velocity += forward * self.acceleration * dt if keys["down"]: self.walking = True self.velocity -= forward * self.acceleration * dt if keys["left"]: self.walking = True self.velocity -= right * self.acceleration * dt if keys["right"]: self.walking = True self.velocity += right * self.acceleration * dt if self.walking: self.inControl = True mouseWatcher = base.mouseWatcherNode if mouseWatcher.hasMouse(): xSize = base.win.getXSize() ySize = base.win.getYSize() xPix = float(xSize % 2) / xSize yPix = float(ySize % 2) / ySize mousePos = Vec2(base.mouseWatcherNode.getMouse()) mousePos.addX(-xPix) mousePos.addY(-yPix) if abs(mousePos.x) < xPix: mousePos.x = 0 if abs(mousePos.y) < yPix: mousePos.y = 0 else: mousePos = self.lastMousePos if mousePos.length() > 0.01: axis = right * (mousePos.y) + up * (-mousePos.x) axis.normalize() angle = mousePos.length() * self.turnRate * dt rotQuat = Quat() rotQuat.setFromAxisAngle(angle, axis) self.root.setQuat(quat * rotQuat) if not self.weaponSets[0][0].active: self.alterEnergy( math.sin(1.071 * self.energy / self.maxEnergy + 0.5) * self.energyRechargeRate * dt) self.updateEnergyUI() self.updateHealthUI() self.updateRadar() #self.root.setH(self.root.getH() - mousePos.x*self.mouseSpeedHori*self.mouseSensitivity) #self.actor.setP(self.actor.getP() + mousePos.y*self.mouseSpeedVert*self.mouseSensitivity) if keys["shoot"]: self.startFiringSet(0) else: self.ceaseFiringSet(0) if keys["shootSecondary"]: self.startFiringSet(self.missileSetIndex + 1) else: for i in range(self.numMissileSets): self.ceaseFiringSet(i + 1) [effect.update(self, dt) for effect in self.updatingEffects] [ effect.cleanup() for effect in self.updatingEffects if not effect.active ] self.updatingEffects = [ effect for effect in self.updatingEffects if effect.active ] if self.targetingQueue.getNumEntries() > 0: self.targetingQueue.sortEntries() entry = self.targetingQueue.getEntry(0) intoNP = entry.getIntoNodePath() if intoNP.hasPythonTag(TAG_OWNER): other = intoNP.getPythonTag(TAG_OWNER) if other is self.prospectiveLockTarget and other is not self.lockedTarget: self.lockTargetTimer += dt if self.lockTargetTimer >= self.lockDuration: self.lockedTarget = other else: self.lockTargetTimer = 0 self.prospectiveLockTarget = other else: self.lockTargetTimer = 0 else: self.lockTargetTimer = 0 perc = self.lockTargetTimer / self.lockDuration self.lockBar.setTexOffset(TextureStage.getDefault(), 0, -perc * 1.1) if self.lockedTarget is not None: if self.lockedTarget.health <= 0: self.lockedTarget = None else: relPos = self.lockedTarget.root.getPos(self.root) planarVec = relPos.getXz() relDist = relPos.length() if relDist == 0: angle = 0 else: angle = math.acos(relPos.y / relDist) if relDist > 200 or angle > 1.7453: self.lockedTarget = None else: if self.lockMarkerRoot.isHidden(): self.lockMarkerRoot.show() camPt = Point2() convertedPt = Common.framework.showBase.cam.getRelativePoint( Common.framework.showBase.render, self.lockedTarget.root.getPos( Common.framework.showBase.render)) if Common.framework.showBase.camLens.project( convertedPt, camPt): self.lockMarkerRoot.setPos( Common.framework.showBase.render2d, camPt.x, 0, camPt.y) if self.lockMarkerRoot.isHidden(): self.lockMarkerRoot.show() for child in self.lockMarkerRoot.getChildren(): child.getChild(0).setZ( (1.0 - min(1, relDist / 100)) * 5 + 0.2) elif not self.lockMarkerRoot.isHidden(): self.lockMarkerRoot.hide() if relPos.y < 0 or angle > 0.6: planarVec.normalize() self.directionIndicator.setPos(planarVec.x * 0.4, 0, planarVec.y * 0.4) angle = math.degrees( math.atan2(planarVec.x, planarVec.y)) self.directionIndicator.setR(angle) if self.directionIndicator.isHidden(): self.directionIndicator.show() elif not self.directionIndicator.isHidden(): self.directionIndicator.hide() else: if not self.directionIndicator.isHidden(): self.directionIndicator.hide() if not self.lockMarkerRoot.isHidden(): self.lockMarkerRoot.hide() def weaponReset(self, weapon): ArmedObject.weaponFired(self, weapon) if isinstance(weapon, RocketWeapon): self.ceaseFiringSet(self.missileSetIndex + 1) self.missileSetIndex += 1 if self.missileSetIndex >= self.numMissileSets: self.missileSetIndex = 0 def attackPerformed(self, weapon): ArmedObject.attackPerformed(self, weapon) def postTraversalUpdate(self, dt): ArmedObject.update(self, dt) def alterHealth(self, dHealth, incomingImpulse, knockback, flinchValue, overcharge=False): GameObject.alterHealth(self, dHealth, incomingImpulse, knockback, flinchValue, overcharge) self.updateHealthUI() #self.hurtSound.play() def alterEnergy(self, dEnergy): self.energy += dEnergy if self.energy < 0: self.energy = 0 elif self.energy > self.maxEnergy: self.energy = self.maxEnergy def alterMissileCount(self, dMissiles): self.numMissiles += dMissiles if self.numMissiles < 0: self.numMissiles = 0 self.updateMissileUI() def updateHealthUI(self): perc = self.health / self.maxHealth newVal = max(0.01, self.health * self.healthBarScalar) self.healthBar.setSz(newVal) self.healthBar.setColorScale(1.0 - (perc - 0.5) / 0.5, min(1, perc / 0.5), 0, 1) #self.healthCounter.setText("{0:-.0f}".format(self.health)) #self.healthCounter.setColorScale(1.0 - (perc - 0.5)/0.5, min(1, perc/0.5), 0, 1) def updateEnergyUI(self): perc = self.energy / self.maxEnergy newVal = max(0.01, self.energy * self.energyBarScalar) self.energyBar.setSz(newVal) self.energyBar.setColorScale(1.0 - (perc - 0.5) / 0.5, min(1, perc / 0.5), 0, 1) def updateMissileUI(self): self.missileCounter["text"] = "Missiles:\n{0}".format(self.numMissiles) self.missileCounter.setText() self.missileCounter.resetFrameSize() def updateSpeedometer(self): self.speedometer["text"] = "Speed:\n{0:0=2.0f}m/s".format( self.velocity.length() * 2) self.speedometer.setText() self.speedometer.resetFrameSize() def updateRadar(self): if Common.framework.currentLevel is not None: self.radarDrawer.begin(Common.framework.showBase.cam, Common.framework.showBase.render) uvs = Vec2(0, 0) spotSize = 0.015 self.radarDrawer.tri(Vec3(-spotSize, 0, -spotSize), Vec4(0, 1, 0, 1), uvs, Vec3(spotSize, 0, -spotSize), Vec4(0, 1, 0, 1), uvs, Vec3(-spotSize, 0, spotSize), Vec4(0, 1, 0, 1), uvs) self.radarDrawer.tri(Vec3(-spotSize, 0, spotSize), Vec4(0, 1, 0, 1), uvs, Vec3(spotSize, 0, -spotSize), Vec4(0, 1, 0, 1), uvs, Vec3(spotSize, 0, spotSize), Vec4(0, 1, 0, 1), uvs) selfForward = Vec3(0, 1, 0) for enemy in Common.framework.currentLevel.enemies: enemyPos = enemy.root.getPos(self.root) dist = enemyPos.length() if dist < self.maxRadarRange: distPerc = dist / self.maxRadarRange enemyPos.normalize() anglePerc = selfForward.angleDeg(enemyPos) / 180 enemyPos.setY(0) enemyPos.normalize() enemyPos *= anglePerc * self.radarSize colour = Vec4(1, 0, 0, math.sin(max(0, 1 - distPerc) * 1.571)) self.radarDrawer.tri( Vec3(-spotSize, 0, 0) + enemyPos, colour, uvs, Vec3(spotSize, 0, 0) + enemyPos, colour, uvs, Vec3(0, 0, spotSize) + enemyPos, colour, uvs) self.radarDrawer.tri( Vec3(spotSize, 0, 0) + enemyPos, colour, uvs, Vec3(-spotSize, 0, 0) + enemyPos, colour, uvs, Vec3(0, 0, -spotSize) + enemyPos, colour, uvs) self.radarDrawer.end() def addUpdatingEffect(self, effect): self.updatingEffects.append(effect) effect.start(self) def cleanup(self): if self.uiRoot is not None: self.uiRoot.removeNode() self.uiRoot = None self.healthBar = None if self.lightNP is not None: Common.framework.showBase.render.clearLight(self.lightNP) self.lightNP.removeNode() self.lightNP = None for effect in self.updatingEffects: effect.cleanup() self.updatingEffects = [] ArmedObject.cleanup(self) GameObject.cleanup(self)
class CogdoFlyingGuiManager: def __init__(self, player): self.player = player self.root = NodePath("CogdoFlyingGui") self.root.reparentTo(aspect2d) self.fuelMeter = NodePath("scrubMeter") self.fuelMeter.reparentTo(self.root) self.fuelMeter.setPos(1.1, 0.0, -0.7) self.fuelMeter.setSz(2.0) cm = CardMaker('card') cm.setFrame(-0.07, 0.07, 0.0, 0.75) self.fuelMeterBar = self.fuelMeter.attachNewNode(cm.generate()) self.fuelMeterBar.setColor(0.95, 0.95, 0.0, 1.0) self.fuelLabel = DirectLabel( parent=self.root, relief=None, pos=(1.1, 0, -0.8), scale=0.075, text="Fuel", text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_font=ToontownGlobals.getInterfaceFont(), ) self.messageLabel = DirectLabel( parent=self.root, relief=None, pos=(0.0, 0.0, -0.9), scale=0.1, text=" ", text_align=TextNode.ACenter, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_font=ToontownGlobals.getInterfaceFont(), textMayChange=1, ) self.messageLabel.stash() self.winLabel = DirectLabel( parent=self.root, relief=None, pos=(0.0, 0.0, 0.0), scale=0.25, text="You win!", text_align=TextNode.ACenter, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_font=ToontownGlobals.getInterfaceFont(), ) self.winLabel.stash() self.refuelLerp = LerpFunctionInterval(self.fuelMeterBar.setSz, fromData=0.0, toData=1.0, duration=2.0) def setRefuelLerpFromData(self): startScale = self.fuelMeterBar.getSz() self.refuelLerp.fromData = startScale def setMessageLabelText(self, text): self.messageLabel["text"] = text self.messageLabel.setText() def update(self): self.fuelMeterBar.setSz(self.player.fuel) def destroy(self): # print "Destroying GUI" self.fuelMeterBar.detachNode() self.fuelMeterBar = None self.fuelLabel.detachNode() self.fuelLabel = None self.fuelMeter.detachNode() self.fuelMeter = None self.winLabel.detachNode() self.winLabel = None self.root.detachNode() self.root = None self.player = None
class RepairSawingGame(RepairMincroGame): sawSounds = None boardComplet = None boardDestroyed = None def __init__(self, repairGame): self.config = RepairGlobals.Sawing notify = DirectNotifyGlobal.directNotify.newCategory('RepairSawingGame') RepairMincroGame.__init__(self, repairGame, 'sawing', PLocalizer.Minigame_Repair_Sawing_Start) def _initVars(self): RepairMincroGame._initVars(self) self.boardsPool = { } self.currentBoard = None self.currentBoardIndex = 0 self.onDeckBoard = None self.onDeckBoardIndex = 0 self.totalScore = 0.0 self.hitZone1Penalty = False self.hitZone2Penalty = False self.hitBoardPenalty = False self.moveDiffForSound = 0.0 self.startPositions = (Point3(0.0, 0.0, 0.0),) self.currentStartIndex = 0 self.lastMousePos = None self.board_left = None self.board_right = None self.cut = None self.zone1_right = None self.zone1_left = None self.zone2_right = None self.zone2_left = None self.piece1 = None self.piece2 = None self.lastHitIndex = -1 self.sawWaypoints = [] def _initAudio(self): RepairMincroGame._initAudio(self) if not self.sawSounds: RepairSawingGame.sawSounds = (loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_INOUT01), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_INOUT02), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_INOUT03), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_INOUT04)) RepairSawingGame.boardComplete = loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_COMPLETE) RepairSawingGame.boardDestroyed = loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_SAW_FAIL) def _initVisuals(self): RepairMincroGame._initVisuals(self) self.setBin('fixed', 36) self.model = loader.loadModel('models/gui/pir_m_gui_srp_sawing_main') sawModel = self.model.find('**/saw') sawModel.setR(193) sawModel.setPos(0.90000000000000002, 0.0, -0.16500000000000001) sawModel.setBin('gui-popup', 0) self.sawButton = RepairSaw(parent = self, clickDownCommand = self.sawAttachedToMouse, clickUpCommand = self.sawRemovedFromMouse, geom = sawModel, text_pos = (0.20000000000000001, -0.29999999999999999), text_fg = (1, 0, 0, 1), scale = (0.29999999999999999, 0.29999999999999999, 0.29999999999999999), relief = None, pressEffect = 0, frameSize = (-0.050000000000000003, 1.05, -0.29999999999999999, 0.050000000000000003), rolloverSound = None, clickSound = None) self.sawingLine = RepairSawingLine(self, self.config.sawlineLineThickness, self.config.sawlineColor, self.config.sawlineLinespawnDist) self.progressDescriptionLabel = DirectLabel(text = PLocalizer.Minigame_Repair_Sawing_Description, text_fg = (1.0, 1.0, 1.0, 1.0), text_pos = (0.0, 0.0), text_shadow = (0.0, 0.0, 0.0, 1.0), text_font = PiratesGlobals.getPirateFont(), text_align = TextNode.ARight, relief = None, scale = (0.080000000000000002, 0.080000000000000002, 0.080000000000000002), pos = (-0.20000000000000001, 0.0, 0.5), parent = self) self.progressLabel = DirectLabel(text = PLocalizer.Minigame_Repair_Sawing_Thresholds[3], text_fg = (1.0, 1.0, 1.0, 1.0), text_pos = (0.0, 0.0), text_shadow = (0.0, 0.0, 0.0, 1.0), text_font = PiratesGlobals.getPirateFont(), text_align = TextNode.ALeft, relief = None, scale = (0.080000000000000002, 0.080000000000000002, 0.080000000000000002), pos = (-0.17999999999999999, 0.0, 0.5), parent = self) self.boardDestroyedLabel = DirectLabel(text = PLocalizer.Minigame_Repair_Sawing_Board_Destroyed, text_fg = (1.0, 0.0, 0.0, 1.0), text_pos = (0.0, 0.0), text_font = PiratesGlobals.getPirateFont(), text_shadow = (0.0, 0.0, 0.0, 1.0), relief = None, scale = (0.10000000000000001, 0.10000000000000001, 0.10000000000000001), pos = (0.0, 0.0, 0.10000000000000001), parent = self) self.boardDestroyedLabel.setBin('fixed', 38) self.boardDestroyedLabel.stash() def _initIntervals(self): RepairMincroGame._initIntervals(self) self.newBoardSequence = Sequence(name = 'RepairSawingGame.newBoardSequence') self.splitBoardSequence = Sequence(name = 'RepairSawGame.splitBoardSequence') self.dropBoardSequence = Sequence(name = 'RepairSawGame.dropBoardSequence') def getNewBoard(self, boardIndex): board = self.model.find('**/wood%i' % boardIndex).copyTo(NodePath('board%i' % len(self.boardsPool))) board.reparentTo(self) piece1 = board.find('**/piece_1') piece1.setPythonTag('piece_1', self.piece1) piece1.setY(self.config.boardYDist) piece2 = board.find('**/piece_2') piece2.setPythonTag('piece_2', self.piece2) piece2.setY(self.config.boardYDist) pieceCut = board.find('**/piece_cut') pieceCut.setPythonTag('cut', self.cut) pieceCut.setColor(self.config.cutColor) pieceCut.setY(self.config.boardYDist) board_left = piece1.find('**/board') board_left.setPythonTag('left', self.board_left) board_right = piece2.find('**/board') board_right.setPythonTag('right', self.board_right) zone1_right = piece2.find('**/zone_1') zone1_right.setPythonTag('zone1_right', self.zone1_right) zone1_right.setColor(self.config.zone1Color) zone1_left = piece1.find('**/zone_1') zone1_left.setPythonTag('zone1_left', self.zone1_left) zone1_left.setColor(self.config.zone1Color) zone2_right = piece2.find('**/zone_2') zone2_right.setPythonTag('zone2_right', self.zone2_right) zone2_right.setColor(self.config.zone2Color) zone2_left = piece1.find('**/zone_2') zone2_left.setPythonTag('zone2_left', self.zone2_left) zone2_left.setColor(self.config.zone2Color) board.stash() return board def reset(self): for key in self.boardsPool.keys(): board = self.boardsPool[key] board.removeNode() self.boardsPool.clear() if self.currentBoard: self.currentBoard.removeNode() self.currentBoard = None if self.onDeckBoard: self.onDeckBoard.removeNode() self.onDeckBoard = None for boardIndex in self.currentDifficultySet: boardIndex -= 1 if 'copy1_%s' % boardIndex not in self.boardsPool: board = self.getNewBoard(boardIndex) self.boardsPool['copy1_%s' % boardIndex] = board if 'copy2_%s' % boardIndex not in self.boardsPool: board = self.getNewBoard(boardIndex) self.boardsPool['copy2_%s' % boardIndex] = board continue self.currentBoardIndex = 0 self.currentBoard = None self.moveNewBoardOnDeck() self.onDeckBoard.unstash() self.totalScore = 0 self.startPositions = (Point3(0.0, 0.0, 0.0),) self.sawButton.stash() self.sawButton.reparentTo(self) self.lastHitIndex = -1 self.moveDiffForSound = 0.0 RepairMincroGame.reset(self) self.repairGame.gui.setTutorial(self.name) self.repairGame.gui.setTitle(self.name) def destroy(self): RepairMincroGame.destroy(self) taskMgr.remove('SawingGame.updateSawTask') self.sawButton.destroy() self.sawButton.removeNode() del self.sawButton if self.currentBoard: self.currentBoard.removeNode() self.currentBoard = None if self.onDeckBoard: self.onDeckBoard.removeNode() self.onDeckBoard = None self.sawingLine = None self.progressDescriptionLabel.destroy() self.progressDescriptionLabel = None self.progressLabel.destroy() self.progressLabel = None self.boardDestroyedLabel.destroy() self.boardDestroyedLabel = None for key in self.boardsPool.keys(): board = self.boardsPool[key] if not board.isEmpty(): board.removeNode() continue self.boardsPool.clear() self.newBoardSequence.clearToInitial() del self.newBoardSequence self.splitBoardSequence.clearToInitial() del self.splitBoardSequence self.dropBoardSequence.clearToInitial() del self.dropBoardSequence def setDifficulty(self, difficulty): RepairMincroGame.setDifficulty(self, difficulty) percent = difficulty / self.repairGame.difficultyMax difIndex = int(math.floor(percent * (len(self.config.difficultySets) - 1))) self.currentDifficultySet = self.config.difficultySets[difIndex] def splitBoard(self): self.sawingLine.reset() board = self.currentBoard boardIndex = self.currentBoardIndex if self.hitZone2Penalty: boardSplitAnim = Parallel(LerpPosInterval(self.board_left, duration = self.config.splitBoardAnimTime, pos = Point3(-2.0, 0.0, 0.0)), LerpPosInterval(self.board_right, duration = self.config.splitBoardAnimTime, pos = Point3(2.0, 0.0, 0.0)), LerpFunc(self.zone2_left.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0), LerpFunc(self.zone2_right.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0), LerpFunc(self.zone1_left.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0), LerpFunc(self.zone1_right.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0), LerpFunc(self.cut.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0)) elif self.hitZone1Penalty: boardSplitAnim = Parallel(LerpPosInterval(self.board_left, duration = self.config.splitBoardAnimTime, pos = Point3(-2.0, 0.0, 0.0)), LerpPosInterval(self.board_right, duration = self.config.splitBoardAnimTime, pos = Point3(2.0, 0.0, 0.0)), LerpPosInterval(self.zone2_left, duration = self.config.splitBoardAnimTime, pos = Point3(-2.0, 0.0, 0.0)), LerpPosInterval(self.zone2_right, duration = self.config.splitBoardAnimTime, pos = Point3(2.0, 0.0, 0.0)), LerpFunc(self.zone1_left.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0), LerpFunc(self.zone1_right.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0), LerpFunc(self.cut.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0)) else: boardSplitAnim = Parallel(LerpPosInterval(self.piece1, duration = self.config.splitBoardAnimTime, pos = Point3(-2.0, self.config.boardYDist, 0.0)), LerpPosInterval(self.piece2, duration = self.config.splitBoardAnimTime, pos = Point3(2.0, self.config.boardYDist, 0.0)), LerpFunc(self.cut.setSa, duration = self.config.splitBoardAnimTime / 2.0, fromData = 1.0, toData = 0.0)) self.splitBoardSequence = Sequence(Func(self.updateScore), Func(self.boardComplete.play), boardSplitAnim, Func(board.stash), Func(self.piece1.setPos, self.piece1.getPos()), Func(self.piece2.setPos, self.piece2.getPos()), Func(self.board_right.setPos, self.board_right.getPos()), Func(self.board_left.setPos, self.board_left.getPos()), Func(self.zone2_right.setPos, self.zone2_right.getPos()), Func(self.zone2_left.setPos, self.zone2_left.getPos()), Func(self.zone1_right.setPos, self.zone1_right.getPos()), Func(self.zone1_left.setPos, self.zone1_left.getPos()), Func(self.cut.setSa, 1.0), Func(self.zone1_right.setSa, 1.0), Func(self.zone1_left.setSa, 1.0), Func(self.zone2_right.setSa, 1.0), Func(self.zone2_left.setSa, 1.0), Func(self.board_right.setSa, 1.0), Func(self.board_left.setSa, 1.0), Func(self.loadNewBoard), Func(self.addBoardBackToPool, board, boardIndex), name = 'RepairSawGame.splitBoardSequence') self.splitBoardSequence.start() def dropBoard(self): board = self.currentBoard boardIndex = self.currentBoardIndex self.dropBoardSequence = Sequence(Parallel(Sequence(Func(self.boardDestroyedLabel.unstash), Wait(1.5), Func(self.boardDestroyedLabel.stash)), Sequence(Wait(0.5), Func(self.boardDestroyed.play), Func(self.sawingLine.reset), LerpPosInterval(board, duration = self.config.splitBoardAnimTime, pos = Point3(0.0, 0.0, -2.0)), Func(board.stash), Wait(0.5), Func(self.loadNewBoard), Func(self.addBoardBackToPool, board, boardIndex))), name = 'RepairSawGame.dropBoardSequence') self.dropBoardSequence.start() def addBoardBackToPool(self, board, boardIndex): if 'copy1_%s' % boardIndex not in self.boardsPool: self.boardsPool['copy1_%s' % boardIndex] = board elif 'copy2_%s' % boardIndex not in self.boardsPool: self.boardsPool['copy2_%s' % boardIndex] = board else: self.notify.error('Two copies of board type %i already in the boardsPool!' % boardIndex) def updateScoreText(self): self.progressLabel.unstash() self.progressDescriptionLabel.unstash() if self.hitBoardPenalty: self.progressLabel['text'] = PLocalizer.Minigame_Repair_Sawing_Thresholds[0] self.progressLabel['text_fg'] = Vec4(1.0, 0.0, 0.0, 1.0) self.progressLabel.setText() elif self.hitZone2Penalty: self.progressLabel['text'] = PLocalizer.Minigame_Repair_Sawing_Thresholds[1] self.progressLabel['text_fg'] = Vec4(1.0, 0.5, 0.0, 1.0) self.progressLabel.setText() elif self.hitZone1Penalty: self.progressLabel['text'] = PLocalizer.Minigame_Repair_Sawing_Thresholds[2] self.progressLabel['text_fg'] = Vec4(1.0, 1.0, 0.0, 1.0) self.progressLabel.setText() else: self.progressLabel['text'] = PLocalizer.Minigame_Repair_Sawing_Thresholds[3] self.progressLabel['text_fg'] = Vec4(0.0, 1.0, 0.0, 1.0) self.progressLabel.setText() def moveNewBoardOnDeck(self): boardIndex = random.randint(0, len(self.currentDifficultySet) - 1) boardType = self.currentDifficultySet[boardIndex] boardType -= 1 if 'copy1_%s' % boardType in self.boardsPool: self.onDeckBoard = self.boardsPool['copy1_%s' % boardType] del self.boardsPool['copy1_%s' % boardType] elif 'copy2_%s' % boardType in self.boardsPool: self.onDeckBoard = self.boardsPool['copy2_%s' % boardType] del self.boardsPool['copy2_%s' % boardType] else: self.notify.error('No copies of board type %i in the boardsPool!' % boardType) self.onDeckBoardIndex = boardType self.onDeckBoard.setScale(0.25) self.onDeckBoard.setPos(0.5, -2.0, 0.56000000000000005) self.onDeckBoard.unstash() def loadNewBoard(self): self.progressLabel.stash() self.progressDescriptionLabel.stash() if self.totalScore >= self.config.totalPoints: if self.onDeckBoard: self.onDeckBoard.stash() self.progressDescriptionLabel.stash() taskMgr.remove('SawingGame.updateSawTask') self.request('Outro') return None self.currentBoard = self.onDeckBoard self.currentBoardIndex = self.onDeckBoardIndex self.piece1 = self.currentBoard.find('**/piece_1') self.piece1.setTransparency(1) self.piece2 = self.currentBoard.find('**/piece_2') self.piece2.setTransparency(1) self.cut = self.currentBoard.find('**/piece_cut') self.cut.setColor(self.config.cutColor) self.cut.setTransparency(1) self.board_left = self.piece1.find('**/board') self.board_left.setTransparency(1) self.zone1_left = self.piece1.find('**/zone_1') self.zone1_left.setTransparency(1) self.zone2_left = self.piece1.find('**/zone_2') self.zone2_left.setTransparency(1) self.board_right = self.piece2.find('**/board') self.board_right.setTransparency(1) self.zone1_right = self.piece2.find('**/zone_1') self.zone1_right.setTransparency(1) self.zone2_right = self.piece2.find('**/zone_2') self.zone2_right.setTransparency(1) self.board_left.setCollideMask(SAW_COLLIDE_MASK) self.board_right.setCollideMask(SAW_COLLIDE_MASK) self.cut.setCollideMask(SAW_COLLIDE_MASK) self.zone1_right.setCollideMask(SAW_COLLIDE_MASK) self.zone1_left.setCollideMask(SAW_COLLIDE_MASK) self.zone2_right.setCollideMask(SAW_COLLIDE_MASK) self.zone2_left.setCollideMask(SAW_COLLIDE_MASK) self.startPositions = (self.currentBoard.find('**/locator_start_0').getPos() + Point3(*self.config.activeBoardPosition), self.currentBoard.find('**/locator_start_1').getPos() + Point3(*self.config.activeBoardPosition)) self.currentStartIndex = 0 for waypoint in self.sawWaypoints: waypoint.removeNode() self.sawWaypoints = [] locator = self.currentBoard.find('**/locator_0') index = 0 while not locator.isEmpty(): self.sawWaypoints.append(SawWaypoint(index, self.currentBoard, locator.getPos())) locator = self.currentBoard.find('**/locator_%i' % (index + 1)) index += 1 self.sawButton.deactivate() self.sawButton.setPos(self.startPositions[self.currentStartIndex]) self.hitBoardPenalty = False self.hitZone1Penalty = False self.hitZone2Penalty = False self.lastMousePos = None self.moveDiffForSound = self.config.playSawingSoundDelta + 0.10000000000000001 self.newBoardSequence = Sequence(Parallel(self.currentBoard.posInterval(self.config.newBoardAnimTime, Point3(*self.config.activeBoardPosition)), self.currentBoard.scaleInterval(self.config.newBoardAnimTime, 1.0)), name = 'RepairSawingGame.newBoardSequence') if self.state in [ 'Game']: self.newBoardSequence.append(Func(self.sawButton.activate)) self.newBoardSequence.append(Wait(0.5)) self.newBoardSequence.append(Func(self.moveNewBoardOnDeck)) self.newBoardSequence.start() def updateSawTask(self, task): if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() relative = Point3(mpos.getX(), 0.0, mpos.getY()) relative = self.getRelativePoint(render2d, relative) moveDiff = 0.0 if self.lastMousePos != None: moveDiff = (relative - self.lastMousePos).length() pickedObjects = self.repairGame.mousePicker.getCollisions(self.currentBoard, useIntoNodePaths = True) self.updateWaypoints() if len(pickedObjects) > 0: self.moveDiffForSound += moveDiff if self.moveDiffForSound > self.config.playSawingSoundDelta: sawSoundPlaying = False for sound in self.sawSounds: if sound.status() == 2: sawSoundPlaying = True break continue if sawSoundPlaying == False: sound = random.choice(self.sawSounds) sound.play() self.moveDiffForSound = 0.0 if self.board_right in pickedObjects or self.board_left in pickedObjects: for waypoint in self.sawWaypoints: waypoint.hit = False self.hitBoardPenalty = True self.dropBoard() self.sawButton.deactivate() elif self.cut in pickedObjects: self.updateWaypoints() elif self.zone1_right in pickedObjects or self.zone1_left in pickedObjects: self.updateWaypoints() if self.hitZone1Penalty == False: self.hitZone1Penalty = True elif self.zone2_right in pickedObjects or self.zone2_left in pickedObjects: self.updateWaypoints() if self.hitZone2Penalty == False: self.hitZone2Penalty = True self.updateScoreText() else: boardComplete = True for waypoint in self.sawWaypoints: if not waypoint.hit: boardComplete = False break continue if boardComplete: self.splitBoard() self.sawButton.deactivate() self.lastMousePos = self.sawButton.getPos() return Task.cont def updateScore(self): if not self.hitBoardPenalty: currBoardScore = self.config.pointsPerBoard if not self.hitZone1Penalty: pass currBoardScore -= self.config.pointsLostForZone1 * self.hitZone2Penalty currBoardScore -= self.config.pointsLostForZone2 * self.hitZone2Penalty rating = 4 - 1 * self.hitZone2Penalty - 3 * self.hitZone1Penalty self.totalScore += currBoardScore self.totalScore = min(self.totalScore, self.config.totalPoints) percent = int((self.totalScore / self.config.totalPoints) * 100.0) self.repairGame.d_reportMincroGameProgress(percent, rating) def resetWaypoints(self): for waypoint in self.sawWaypoints: waypoint.hit = False def updateWaypoints(self): waypointList = self.getHitWaypoints() for waypointIndex in waypointList: self.lastHitIndex = waypointIndex self.sawWaypoints[waypointIndex].hit = True if waypointIndex == 0 and not (self.sawWaypoints[-1].hit): self.currentStartIndex = 0 continue if waypointIndex == len(self.sawWaypoints) - 1 and not (self.sawWaypoints[0].hit): self.currentStartIndex = 1 continue def getHitWaypoints(self): waypointsHit = [] testDelta = self.config.testWaypointDelta for i in range(len(self.sawWaypoints)): waypointPos = self.sawWaypoints[i].getPos(self) closestDistance = 9999 if self.lastMousePos != None: currMousePos = self.sawButton.getPos() lastMousePos = self.lastMousePos totalLength = (currMousePos - lastMousePos).length() testLength = testDelta while testLength < totalLength: testPos = (currMousePos - lastMousePos) * (testLength / totalLength) + lastMousePos self.updateSawLine(testPos) testDistance = (testPos - waypointPos).length() closestDistance = min(testDistance, closestDistance) testLength += testDelta self.updateSawLine(self.sawButton.getPos()) testDistance = (self.sawButton.getPos() - waypointPos).length() closestDistance = min(testDistance, closestDistance) if closestDistance < self.config.waypointRange[self.currentBoardIndex]: waypointsHit.append(i) continue return waypointsHit def updateSawLine(self, pos): if pos.getX() < -0.63300000000000001 or pos.getX() > 0.63300000000000001: self.sawingLine.reset() return None if pos.getZ() < -0.183 or pos.getZ() > 0.375: self.sawingLine.reset() return None self.sawingLine.update(pos) def getClosestPosition(self, positions): closestIndex = -1 if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() relative = Point3(mpos.getX(), 0.0, mpos.getY()) relative = self.getRelativePoint(base.a2dBackground, relative) bestDistance = 99999.0 for i in range(len(positions)): dX = relative.getX() - positions[i].getX() dZ = relative.getZ() - positions[i].getZ() newDistance = dX * dX + dZ * dZ if newDistance < bestDistance: bestDistance = newDistance closestIndex = i continue return closestIndex def sawAttachedToMouse(self): self.lastHitIndex = -1 if not taskMgr.hasTaskNamed('SawingGame.updateSawTask'): taskMgr.add(self.updateSawTask, 'SawingGame.updateSawTask', priority = 2) def sawRemovedFromMouse(self): if not self.sawButton.isStashed(): self.sawButton.setPos(self.startPositions[self.currentStartIndex]) self.lastHitIndex = -1 self.resetWaypoints() self.lastMousePos = None self.progressLabel.stash() self.progressDescriptionLabel.stash() self.sawingLine.reset() self.hitBoardPenalty = False self.hitZone1Penalty = False self.hitZone2Penalty = False taskMgr.remove('SawingGame.updateSawTask') def enterIntro(self): RepairMincroGame.enterIntro(self) self.loadNewBoard() def enterGame(self): RepairMincroGame.enterGame(self) self.repairGame.mousePicker.setCollisionMask(SAW_COLLIDE_MASK) self.sawButton.activate() def exitGame(self): RepairMincroGame.exitGame(self) self.sawButton.deactivate() self.repairGame.mousePicker.clearCollisionMask() taskMgr.remove('SawingGame.updateSawTask') self.splitBoardSequence.clearToInitial() self.dropBoardSequence.clearToInitial() localAvatar.guiMgr._showCursor() def enterOutro(self): RepairMincroGame.enterOutro(self) self.repairGame.d_reportMincroGameScore(150)
class DeathScreen(Menu): '''Screen shown on player's death''' def __init__(self, restart_command, exit_level_command, exit_game_command): name = "death screen" parent = base.aspect2d super().__init__(name, parent) #not setting text, coz it will be overwritten anyway #TODO: set align to be on left. Maybe replae death_message's DirectLabel #with OnscreenText and draw frame on background? self.death_message = DirectLabel( pos=(0, 0, 0.3), scale=0.1, frameTexture=base.assets.sprite['frame'], frameSize=(-4.5, 4.5, -2.5, 1), parent=self.frame) self.restart_button = DirectButton(text="Restart", command=restart_command, pos=(0, 0, -0.1), scale=0.1, frameTexture=self.button_textures, frameSize=(-3, 3, -0.5, 1), clickSound=self.select_sfx, rolloverSound=self.hover_sfx, parent=self.frame) self.exit_level_button = DirectButton( text="Back to Menu", command=exit_level_command, pos=(0, 0, -0.3), scale=0.1, frameTexture=self.button_textures, frameSize=(-3, 3, -0.5, 1), clickSound=self.select_sfx, rolloverSound=self.hover_sfx, parent=self.frame) self.exit_button = DirectButton(text="Exit", command=exit_game_command, pos=(0, 0, -0.5), scale=0.1, frameTexture=self.button_textures, frameSize=(-3, 3, -0.5, 1), clickSound=self.select_sfx, rolloverSound=self.hover_sfx, parent=self.frame) #idk if this should be there either. But will do for now self.dn_duration = 2 #notice how its parent is different self.death_notification = Popup(text="Death", scale=0.5, parent=base.aspect2d, duration=self.dn_duration) def update_death_message(self, score: int, wave: int, killed: int): '''Change dispayed self.high_score to provided value''' self.death_message.setText(f"Score: {score}\n" f"Last Wave: {wave}\n" f"Enemies Killed: {killed}") def show(self): #Overriding default "show" function, to first show death message and #only then display the highscores/restart menu #I need to specify it there, coz super cant handle calling for functions #of parent class from multi-layered function sup = super().show def show_frame(event): sup() return self.death_notification.show() base.task_mgr.do_method_later(self.dn_duration, show_frame, "show death screen")
class RepairBarnacle(DirectFrame, FSM.FSM): barnacleFallSounds = None def __init__(self, name, barnacleGeom): self.config = RepairGlobals.Careening DirectFrame.__init__(self, parent = None, relief = None) self.barnacleGeom = barnacleGeom FSM.FSM.__init__(self, 'Barnacle_%sFSM' % name) self._initAudio() self._initVars() self._initGUI() def _initVars(self): self.heat = 0.0 self.hp = 100 self.maxHP = 100 self.currentShake = None self.fallingAnim = None def _initAudio(self): if not self.barnacleFallSounds: RepairBarnacle.barnacleFallSounds = (loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE1), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE2), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE3), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE4), loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_CAREEN_COMPLETE5)) def _initGUI(self): self.barnacleGeom.reparentTo(self) self.barnacleGeom.setScale(0.59999999999999998) self.barnacleGeom.setR(random.random() * 360) if self.config.showBarnacleHP: self.hpLabel = DirectLabel(text = '', scale = (0.025000000000000001, 0.025000000000000001, 0.025000000000000001), pos = (0.0, 0.0, -0.01), textMayChange = 1, parent = self) def destroy(self): if self.currentShake is not None: self.currentShake.clearToInitial() self.currentShake = None del self.currentShake if self.fallingAnim is not None: self.fallingAnim.clearToInitial() self.fallingAnim = None del self.fallingAnim self.cleanup() if self.config.showBarnacleHP: self.hpLabel.destroy() del self.hpLabel DirectFrame.destroy(self) self.barnacleGeom.removeNode() del self.barnacleGeom def setMaxHP(self, newMaxHP, globalMaxHP): self.maxHP = newMaxHP self.globalMaxHP = globalMaxHP def setHP(self, newHP): self.hp = newHP if self.config.showBarnacleHP: self.hpLabel['text'] = '%i' % self.hp self.hpLabel.setText() if self.hp <= 0.0: self.hp = 0.0 self.request('Falling') self.setScale(self.hp * MAX_SCALE_ADD / self.globalMaxHP + MIN_SCALE) def reduceHP(self, pushDir, powerScale): amount = pushDir.length() pushDir.normalize() self.heat = min(1.0, self.heat + amount) amount *= 50 if amount > MAX_SCRUB_AMT: amount = MAX_SCRUB_AMT amount *= powerScale newHP = self.hp - amount self.setHP(newHP) if self.currentShake is None: self.currentShake = Sequence(LerpPosInterval(self, duration = 0.029999999999999999, pos = (self.getX() - pushDir[0] * (0.01 + amount / 1000.0), self.getY(), self.getZ() - pushDir[1] * (0.01 + amount / 1000.0)), blendType = 'easeIn'), LerpPosInterval(self, duration = 0.059999999999999998, pos = (self.getX(), self.getY(), self.getZ()), blendType = 'easeOut'), LerpPosInterval(self, duration = 0.040000000000000001, pos = (self.getX() + pushDir[0] * (0.0074999999999999997 + amount / 2000.0), self.getY(), self.getZ() + pushDir[1] * (0.0050000000000000001 + amount / 2000.0)), blendType = 'easeIn'), LerpPosInterval(self, duration = 0.080000000000000002, pos = (self.getX(), self.getY(), self.getZ()), blendType = 'easeOut'), Func(self.clearCurrentShake)) self.currentShake.start() def checkCollision(self, mousePosition): sld = Point3(mousePosition.getX(), 0.0, mousePosition.getY()) - self.getPos(render2d) if self.getCurrentOrNextState() == 'Idle': pass return sld.length() < self.config.barnacleRadius * self.getScale().getX() def clearCurrentShake(self): self.currentShake = None def enterIdle(self): visibleIndex = random.uniform(0, self.barnacleGeom.getNumChildren() - 1) for i in range(self.barnacleGeom.getNumChildren() - 1): self.barnacleGeom.getChild(i).unstash() newHP = self.maxHP self.heat = 0.0 self.setHP(newHP) self.unstash() def exitIdle(self): pass def enterFalling(self): if self.currentShake is not None: self.currentShake.finish() sound = random.choice(self.barnacleFallSounds) sound.play() self.fallingAnim = Sequence(LerpPosInterval(self, duration = 2.0, pos = (self.getX(), self.getY(), self.getZ() - 2.0), blendType = 'easeIn'), Func(self.request, 'Clean')) self.fallingAnim.start() def exitFalling(self): self.stash() def enterClean(self): pass def exitClean(self): pass