Spaceship.codes - A Game for Programmers

Source code (MIT License)

After a few months of development, I'm proud to announce the first release of spaceship.codes! Spaceship.codes is a browser game for programmers, with a built in code editor that the player uses to write JavaScript to control their spaceship. I will illustrate this with a simple example; it might be helpful to open spaceship.codes in a new tab so that you can follow along.

First we need to load a level. We can do this by clicking the "Select Level" button, then clicking the first level (named "Thrust"), and finally clicking the "Load" button. After the level is loaded, you should see something like the following:

If you hover over the blue circle, you should see a tool tip pop up with more information about the object. It has a type of "target" and an objective of "reach" — this means that you need to navigate your spaceship into that blue circle in order to complete the level.

Now we have to write JavaScript code to get the ship into the reach target. Luckily for us, the target is straight ahead! All we need to do is accelerate. The documentation has information in its function reference about the thrust() function — it is a function that takes a single value, the thrust power, in the range from 0 to 1. We want to accelerate at full power, so the only code we need is thrust(1);.

To run this code, we need to open the code editor. There is a button on the left side of the screen that displays and hides the editor. Once it is open, type thrust(1);. This should look similar to the following:

Now you can close the editor. To install the new code, click the "Install & Restart" button. Then, to run the code, click the "Run" button. You should see your spaceship accelerate into the reach target, like the following:

Congratulations! You have completed the first level. The levels that follow quickly increase in difficulty, and force the player to make use of the other available functions, such as turn(), equip(), fire(), etc. Sometimes to complete a level you will simply have to navigate to some target, while other times you may have to destroy enemies or defend targets of your own.

In the future I may write up a tutorial for completing a more complicated level. In the meantime, if you wish to see the completion of a more complicated level in action, copy and paste this code into the editor, then install and run it with the "Obstacle" level loaded. Enjoy!

If you find any bugs or just have questions or comments, you can reach me at robert@fotino.me.