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 use the ‘Show Mods Folder’ button in Settings->Advanced if you’ve forgotten where this is. (‘mods folder’ is just another term for the user scripts directory).
import bs # how BombSquad knows we exist def getGames(): return [HelloWorldGame] class HelloWorldGame(bs.TeamGameActivity): @classmethod def getName(cls): return 'Hello World Game' @classmethod def getDescription(cls,sessionType): return 'Just a test game.' def onBegin(self): bs.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._endGameTimer = bs.Timer(5000,bs.WeakCall(self.endGame)) def endGame(self): # game's over - set a score for each team and tell our activity to finish ourResults = bs.TeamGameResults() for team in self.teams: ourResults.setTeamScore(team,0) self.end(results=ourResults)
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.
If you’d like documentation on any of these classes or methods, take a look at the BombSquad Python API Docs.
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)