Advertisement
Guest User

Minigame Template (DistributedCoolGame.py)

a guest
Jun 27th, 2016
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.62 KB | None | 0 0
  1. from toontown.minigame.DistributedMinigame import *
  2. from direct.fsm import ClassicFSM, State
  3.  
  4. # PS: All the toons are kept on a list
  5. # self.avIdList
  6.  
  7. class DistributedCoolGame(DistributedMinigame):
  8.     def __init__(self, cr):
  9.         DistributedMinigame.__init__(self, cr)
  10.         # This is our game FSM, it defines all the states
  11.         # the minigame is going to have, eg. toon dies, toon wins, etc.
  12.         self.gameFSM = ClassicFSM.ClassicFSM(
  13.             'DistributedCoolGame', [
  14.             ]
  15.         )
  16.         self.addChildGameFSM(self.gameFSM)
  17.         # Here goes all your initial variables
  18.         self.myHappyness = 0
  19.        
  20.     def getTitle(self):
  21.         # Title of our minigame
  22.         return "Cool Minigame"
  23.        
  24.     def getInstructions(self):
  25.         # Instructions
  26.         return "Just do it right"
  27.        
  28.     def getMaxDuration(self):
  29.         # Max duration of the minigame in seconds
  30.         return 3 * 60
  31.        
  32.     def load(self):
  33.         # This is where you load all your game resources, such as environment,
  34.         # props, gui, and such.
  35.         self.environment = loader.loadModel("environment.egg")
  36.         self.prop = loader.loadModel("sphere.egg")
  37.        
  38.     def unload(self):
  39.         # You should unload everything you added on load here
  40.         self.environment.removeNode()
  41.         self.prop.removeNode()
  42.        
  43.     def onstage(self):
  44.         # That means the toons are on the instructions screen
  45.         # and the game should start rendering now, also intro movies.
  46.         # (You can start playing a music from here)
  47.         DistributedMinigame.onstage(self) # Keep this.
  48.         self.environment.reparentTo(render)
  49.         self.prop.reparentTo(render)
  50.        
  51.     def offstage(self)
  52.         # The game is preparing to unload, set everything
  53.         # invisible again
  54.         self.environment.reparentTo(hidden)
  55.         self.prop.reparentTo(hidden)
  56.         DistributedMinigame.offstage(self) # keep this.
  57.        
  58.     def setGameReady(self):
  59.         # If you want to do something right when the game is ready
  60.         # to go, do it here
  61.         if DistributedMinigame.setGameReady(self):
  62.             return # avoid duplicates
  63.         self.prop.setPos(0, 0, 5)
  64.        
  65.     def setGameStart(self, ts):
  66.         # The game has started, do all the gameplay
  67.         # stuff here
  68.         DistributedMinigame.setGameStart(self, ts) # keep this
  69.         base.localAvatar.b_setAnimState("Swim")
  70.         # All the game should use States from now on,
  71.         # you can also add timeout handlers by using ToontownTimer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement