class MenuScene(Scene): def Enter(self): # Set background colour self.GetSceneManager().setBackgroundColor(0.25, 0.5, 1.0, 1) self.startButton = DirectButton(text="Start", scale=0.1, command=self.HandleClick, extraArgs=[1], pos=(0, 0, 0.3)) self.exitButton = DirectButton(text="Exit", scale=0.1, command=self.HandleClick, extraArgs=[2], pos=(0, 0, 0.1)) self.menuTitle = DirectLabel(text="Angry Pacman", frameColor=(0.25, 0.5, 1.0, 1), scale=0.25, pos=(0, 0, 0.5)) def HandleClick(self, n): # If the Start button is clicked if (n == 1): # Change the active scene to the GameScene from GameScene import GameScene scene = GameScene() self.GetSceneManager().ChangeScene(scene) # If the Exit button is clicked else: # We exit sys.exit(1) def Update(self): # Nothing to update pass def Leave(self): # Clean up self.startButton.remove() self.exitButton.remove() self.menuTitle.remove()
class NamePicker: def __init__(self): self.instructions = OnscreenText(text='Type your name', scale=0.1, fg=(1, 1, 1, 1), pos=(0, 0.8, 0.8), shadow=(0, 0, 0, 1)) self.nameEntry = DirectEntry(focus=1, initialText='Toon', width=10, scale=0.1, pos=(-0.5, 0.3, 0.3), command=self.confirmNameAndContinue) self.confirmBtn = DirectButton(text='Confirm', scale=0.1, pos=(0, 0.1, 0.1), command=self.confirmNameAndContinue, extraArgs=[self.nameEntry.get()]) def confirmNameAndContinue(self, textEntered): try: self.badName_lbl.remove() del self.badName_lbl except: pass if self.nameEntry.get().isspace() or len(self.nameEntry.get()) <= 0: self.badName_lbl = OnscreenText(text=CIGlobals.InvalidName, scale=0.09, fg=(1, 0, 0, 1), pos=(0, -0.1, -0.1), shadow=(0, 0, 0, 1)) return self.instructions.remove() self.nameEntry.remove() self.confirmBtn.remove() try: self.badName_lbl.remove() except: pass messenger.send('nameConfirmed', [self.nameEntry.get()])
class MenuScene(Scene): def Enter(self): # Set background colour self.GetSceneManager().setBackgroundColor(0.25,0.5,1.0,1) self.startButton = DirectButton(text="Start",scale=0.1,command=self.HandleClick, extraArgs=[1],pos=(0,0,0.3)) self.exitButton = DirectButton(text="Exit",scale=0.1,command=self.HandleClick, extraArgs=[2],pos=(0,0,0.1)) self.menuTitle = DirectLabel(text="Angry Pacman",frameColor=(0.25,0.5,1.0,1),scale=0.25,pos=(0,0,0.5)) def HandleClick(self,n): # If the Start button is clicked if (n==1): # Change the active scene to the GameScene from GameScene import GameScene scene = GameScene() self.GetSceneManager().ChangeScene(scene) # If the Exit button is clicked else: # We exit sys.exit(1) def Update(self): # Nothing to update pass def Leave(self): # Clean up self.startButton.remove() self.exitButton.remove() self.menuTitle.remove()