Space AI Documentation

Introduction

Space AI is a game for programmers. You control a spaceship by writing JavaScript code in order to complete a specific task. Each level is a challenge with its own objectives, which may include navigating your ship to a set of coordinates, eliminating enemy ships, and evading obstacles like space mines and asteroids, among other things. This documentation contains a list of keyboard shortcuts you can use in the game, a few code examples, a full function reference that describes the functions you can use to control the ship, and a full object reference that describes the types of game objects on which the functions might operate.

Getting Started

To start playing, you should first choose a level – either click "Select Level" or hit the "s" key and the Level Selector window will pop up. Use the "n" and "p" keys to highlight the next and previous levels, respectively, or click one with your mouse. Then hit enter or click the "load" button to load the selected level. If the level has some help text, it will be displayed in a dialog after it has been loaded. As you complete levels, this will be indicated by a green checkmark on the level's thumbnail.

To start writing code, either click the arrow on the left or hit the "i" key to slide out the coding window. Any JavaScript you write in this window will be executed once per frame in the game. To change the editor theme, you can go to View -> Editor Themes. Once you have written some code, to see it in action it you need to click the "Install & Restart", then click the "Run" button. This will install your code and start it executing, respectively. To save code you have written, go to File -> Save, or hit "Ctrl+s". Saved code will persist across browser sessions unless you clear local storage.

To debug your code, log diagnostic information to the console. You can view the console by clicking the arrow on the bottom of the screen or by hitting the "c" key. For more information, take a look at the logging functions.

Table of Contents

  1. Keyboard Shortcuts
  2. Code Examples
    1. Radar Usage
    2. Weapons Usage
    3. Persistent Variables
    4. State Machines
  3. Function Reference
    1. Movement
      1. thrust([power])
      2. turn([power])
    2. Diagnostics
      1. accel()
      2. bounds()
      3. health()
      4. pos()
      5. vel()
    3. Radar
      1. radar([filter])
    4. Weapons
      1. fire(x, y)
      2. equip([weapon])
      3. equipped()
      4. weapons()
    5. Storage
      1. load(key, [defaultValue])
      2. store(key, value)
    6. Logging
      1. console.error(message)
      2. console.log(message)
      3. console.warn(message)
  4. Object Reference
    1. GameObject
      1. Ammo
      2. Asteroid
      3. Bullet
      4. HealthPack
      5. Target
        1. EnemyShip
        2. EnemyTarget
        3. FriendlyTarget
        4. ReachTarget
        5. SpaceMine
    2. Rectangle
    3. Vector
    4. Weapon