Ships

You can access the list of ships (players) through the array game.ships

You can also find a ship with a specific id using game.findShip(id), which returns an object representing the matched ship or null (if no ships are matching the provided id)

Accessible fields

You have read access to the ship’s main fields and options:

FieldDescription
idA unique identifier for the ship
gamePoints to the global game object
xX coordinate
yY coordinate
vxVelocity vector X component
vyVelocity vector Y component
rRotation angle of the ship (in radian)
nameplayer’s name
aliveWhether the ship is alive or destroyed
typeShip type code (e.g. 101)
statsShip current stats upgrades, compiled into a single integer. For example: 10012301 means the 8 stats upgrade levels are 1,0,0,1,2,3,0 and 1
idletells if the ship is in idle status or not
teamthe id of the team this ship is in
scoreplayer’s score
shieldcurrent shield value
generatorcurrent generator value
crystalscurrent crystals value
healingwhether the ship’s lasers are in healing mode or not

Configuration

You can set different options on the ships. For example:

> game.ships[0].set({x:0,y:0});
>

Will move the first ship in the list to the center of the map

List of accepted options when using ship.set:

OptionDescriptionServer response error message (if improper)
xX coordinateWrong coordinate
yY coordinateWrong coordinate
vxVelocity vector X componentWrong coordinate
vyVelocity vector Y componentWrong coordinate
invulnerableUse to set the ship invulnerable for X ticks (e.g. 60 for one second invulnerability)Wrong invulnerable time
typechanges the type of ship (use the ship code, e.g. {type:403} )None
anglechanges the direction the ship is facingWrong angle
scoresets player’s scoreWrong score
idleset to true to force the ship to stay idle (and false to revert)None
shieldsets the value of the shieldWrong shield value
generatorsets the value of the generatorWrong generator value
healingsets ship’s lasers mode to healing (true or false)None
crystalssets ship’s crystal amountWrong crystals
statsset the stats upgrades of the shipNone
killSet kill: (any "truthy" value, e.g: true) to destroy the shipNo violation
teamChanges the team this ship belongs to (in range [0-X] where X is teams - 1)None
colliderChange the ship’s collider (the ship can interact with other objects in-game or not), must be true or falseNone
hueSets the colour of the ship (range [0-359])Hue mapNone

Intermission

You can send the ship to intermission (a screen with results, offering to respawn). This screen allows you to display custom results information:

> game.ships[0].intermission({"Best Achievement":"Managed to run the mod","Score":1234});
>

Triggering and Customizing player’s GameOver screen

You can also trigger the gameover screen for any given ship. Here again, you can pass results information to pass on to the player:

> game.ships[0].gameover({"Rating":"Can do better","Score":1234});
>

Instructor

Calling instructor

You can have the flight instructor send instructions to the player. For this find the player’s ship and use:

> ship.instructorSays("Hello!")
>

You can hide the instructor window using:

> ship.hideInstructor()
>

You can later show it again using:

> ship.showInstructor()
>

A second, optional parameter allows you to choose which one of the instructor characters will talk to the player. Example:

> ship.instructorSays("Here is your report, Commander","Maria")
>

Available characters

LucinaKlausMariaKanZoltar
LucinaKlausMariaKanZoltar

Custom UI components

General

The mod can create custom UI components that will show up on the player’s screen. This is done by calling setUIComponent on the ship - passing in a component descriptor.

For example:

> ship.setUIComponent({
    id:"myid",
    position:[0,0,25,25],
    clickable: true,
    shortcut: "X",
    visible: true,
    components: [
      { type:"box",position:[0,0,100,100],fill:"#456",stroke:"#CDE",width:2},
      { type: "text",position: [0,0,100,50],color: "#FFF",value: "My Text"},
      { type: "player",id: 1, position: [0,0,50,50],color: "#FFF"},
    ]
  })
>

Here is the list of UIComponent’s accepted options:

OptionDescriptionDefault value (if omitted)
ida unique identifier for this component, mandatoryNone (component won’t be set)
positionexpressed in percentage of the main screen, the position of the component [x,y,width,height]. Example: [45,45,10,10] creates a component in the center of the screen, in which width and height are 10% of the screen width and height.Client-based positions ("radar_background" and "scoreboard" id, see this section) [0,0,100,100] (others)
visibleWhether the component is visible or not. Resend the same data with visible set to false to hide the componenttrue
clickableWhether this component can be clicked or notfalse
shortcutWhen the component is clickable, a keyboard shortcut allowing to trigger the click eventNone (no shortcuts)
componentsgives a list (array) of graphical features to render within the component, which will be described belowEmpty array ([])

Subcomponents’ accepted options

OptionDescriptionDefault value (if omitted)
typetype of the subcomponent currently supported: “round”, “text”, “box” or “player”None (subcomponent won’t be rendered)
id (“player” type only)id of the player associated with the subcomponent, which will be disapleyd as their name and badge (if exists) in the rendered subcomponentNone (blank player info)
positionpositions of the subcomponent, formatted as [x,y,width,height] that subcomponent are meant within the main component coordinatesNone (subcomponent won’t be rendered)
value (“text” type only)value of the text subcomponent, e.g value:"Sample text"Empty string ("")
colortext color of the subcomponent, this can be a string with any color formats (hex, hsla, rgb, etc.), e.g "#fff"Black (with opacity 1)
fillbackground color of the subcomponent, same format as the color propertyBlack (with opacity 0)
widthwidth of the subcomponent’s border One unit of this value equals (1 / (End user screen’s pixel density)) CSS pixels (px)0
strokeborder color of the subcomponent, same format as the color propertyBlack (with opacity 0)
alignalignment of the texts inside the subcomponent “left”, “right” or “center” only"center"

Combining with events

The example below creates a warp button for every player, which can be clicked and results in the ship warping to another random location, adding 3 seconds invulnerability to it:

Full example: https://github.com/pmgl/starblast-modding/blob/master/examples/warp_button.js

var warp_button = {
  id: "warp",
  position: [2,50,8,14],
  clickable: true,
  shortcut: "W",
  visible: true,
  components: [
    { type:"round",position:[0,0,100,100],fill:"#456",stroke:"#CDE",width:2},
    { type: "text",position:[10,35,80,30],value:"WARP",color:"#CDE"},
    { type: "text",position:[20,70,60,20],value:"[W]",color:"#CDE"}
    ]
};
 
var warpShip = function(ship) {
  x = (Math.random()-.5) * ship.game.options.map_size*10 ;
  y = (Math.random()-.5) * ship.game.options.map_size*10 ;
  ship.set({x:x,y:y,vx:0,vy:0,invulnerable:180}) ;
} ;
 
this.tick = function(game) {
  if (game.step%60==0) // ensure this is done only once per second
  {
    for (var i=0;i<game.ships.length;i++)
    {
      var ship = game.ships[i] ;
      if (!ship.custom.warp_button_installed)
      {
        ship.custom.warp_button_installed = true;
        ship.setUIComponent(warp_button);
      }
    }
  }
} ;
 
this.event = function(event,game) {
  switch (event.name)
  {
    case "ui_component_clicked":
      var ship = event.ship ;
      var component = event.id ;
      if (component == "warp") // check that this is our component "warp"
      {
        warpShip(ship);
      }
      break ;
  }
} ;

Customizing the scoreboard or radar

The built-in scoreboard or radar can be replaced by your own custom scoreboard/radar component. As soon as an UI component with id "scoreboard" or "radar_background" is created, you will be responsible for updating the scoreboard/radar. Your custom scoreboard/radar component does not have to include a position because it will automatically fill the area already reserved for the perspective UI Component.

Global UI

You can use game.setUIComponent({ options }) to set the UI to all current players in the game

Other methods and instances

Remove all ship’s secondary slots

Syntax: ship.emptyWeapons()