Tutorial 3 was pretty long-winded, so if you made it through that it’s time for something simpler. Today we’re gonna write our very first mini-game.
This mini-game we’ll be making doesn’t actually do anything; it just ends after 5 seconds and gives all teams a score of 0, so the game comes out a Draw. That’s ok though; the point is to show what a bare-bones mini-game looks like; we’ll make it fancier in a later tutorial.
When BombSquad gathers its list of mini-games, it simply scans through all modules in its user and system scripts directories looking for ones that define a ‘getGames()’ function.. so to add a game we simply have to write a module that provides that function.
Create a file named HelloWorldGame.py (or whatever you want to call it), paste the following code in, and drop it into BombSquad’s user-scripts directory. You can run bsUtils.showUserScripts() to show you where this is if you’ve forgotten.
import bs import bsTeamGame # how BombSquad knows we exist def getGames(): return [HelloWorldGame] class HelloWorldGame(bsTeamGame.TeamGameActivity): @classmethod def getName(c): return 'Hello World Game' @classmethod def getDescription(c,sessionType): return 'Just a test game.' def onBegin(self): bsTeamGame.TeamGameActivity.onBegin(self) # game's starting - let's just set a timer to end it in 5 seconds bs.screenMessage("Hello World! Ending in 5 seconds...") self._endTimer = bs.Timer(5000,bs.WeakCall(self._endGame)) def _endGame(self): # game's over - set a score for each team and tell the game to end results = bsTeamGame.Results() for t in self.teams.values(): results.setTeamScore(t,0) self.end(results=results)
Now, to try out your shiny new mini-game, launch BombSquad, create a new game list, and add a game to it. You should see ‘Hello World Game’ in the list of available game types. When you run the game you should just see it print its message and end.
Well, that’s it for this tutorial.. next time we’ll start to add logic to our game to make it actually worth playing… stay tuned. (or if you’re impatient, you can look through BombSquad’s system scripts directory at all the built-in mini-games as reference)