Sunday, April 22, 2012

StarWright - The Sandbox

Wow, it's been over two months since I last posted about StarWright! But I have been working on the game. In fact, I've been working on a very important change that should make the game much more accessible, understandable, and fun.

A few months ago I watched a talk by Bret Victor called "Inventing on Principle". In it, he talks about and demonstrates a few of his software programs he's created. A common principle of all the programs he shows is that they provide immediate feedback. For example, he demonstrates a scripting program in which he has created a prototype for a platform game. The left side of the screen contains a running game simulation, and the right side of the screen contains the game's programming code. Unlike most old-school programming languages (in which the author writes the code, compiles the code, and tests the code as three separate steps), as Bret modifies the scripting code, his changes immediately effect the game running on the left, so that as he modifies, for example, the gravity in his game world, he instantly sees the character fall faster or slower (or even upwards!) as he adjusts the gravity value.


Bret Victor - Inventing on Principle from CUSEC on Vimeo.

The key here is that all his changes have an immediate effect on how the game is played. This greatly speeds the design process, because every time you change a value, you can immediately see the result. And just as importantly, it makes, in his case, the scripting process much more intuitive, because our human brains are much better at connecting a cause with its effect if the effect happens immediately after the cause, instead of, say, a few minutes later.

I found his talk very inspirational because it made me realize that the "ship designer" user interface that I had created was born from an "old-school programmer" mindset. In the previous version of the ship designer, the player first "designed" a ship, then saved the ship, and then tested it in a separate simulation environment. The problem was, of course, that you couldn't tell what effect a design modification would have until you manually switch to the testing environment. The solution, I believe, is to combine the design interface with the testing environment, so that the player designs their ships directly in the testing environment and can see the immediate impact of, for example, adding that extra thruster.

Merging these two environments together was certainly not trivial. Allowing ships to be updated instantly in a live environment was a challenge, and keeping the nice U.I. features of the designer, such as undo/redo, was a bigger one.

I've dubbed this new merged design/testing environment "The Sandbox". Here are a couple screenshots of what it looks like currently:




Upon first glance, the top screenshot does look quite similar to the old designer interface, which has a similar menu bar at the top and a similar "parts toolbox" (albeit with more parts) on the left. But there are a lot of very nice additions to the old interface:

  • The "Build" and "Play" buttons underneath the menu bar allow you to toggle between the build/design mode (which allows you to modify any ship in the sandbox) and the play/control mode (which allows you to control any ship in the sandbox as if you were playing a real game).
  • There can be any number of ships in the sandbox, and every ship is a live simulation. Added a couple thrusters to your ship and want to see how it flies? Just switch to Play mode and fly it around! Not quite happy with the result? Switch back to Build mode and add another couple thrusters.
  • Any previously-saved ship design can be added into the sandbox by loading it from the Ship menu.
  • To create a new ship design, you plop down a new "grid" anywhere you want, in which you can start placing parts for your ship.
  • To modify an existing ship, simply go into Build mode, select the part you want, mouse over the existing ship, and click where you want the part to go.
  • You can pause or resume the game simulation at any time using the control in the upper right. It's often easier to modify ships while paused. Unpause and the simulation will instantly resume with your new edits.
It's not perfect -- for example, I'm not thrilled with the hard separation between Build and Play modes -- but it's a huge step forward, and the technology behind this could allow me one day to expand the sandbox into a full-blown live level editor.

Saturday, February 4, 2012

StarWright - Ship Combat

Combat is of course a major part of StarWright, and I've just finished the major ship-versus-ship combat systems. The mechanics of combat work essentially the same as in the original prototype. Weapon turrets automatically track and fire upon nearby enemy ships. Damaged is handled on a part-by-part or room-by-room basis, where individual parts or rooms can be individually destroyed. Additionally, if the only parts joining two sections of the ship are destroyed, then the ship will be split in two and become effectively two distinct ships.

As in the original prototype, cannons are able to penetrate deeply inside enemy ships, damaging critical systems deep within the ship. The current defense against cannons is to add parts with a high "penetration resistance" such as armor tiles or cannons themselves. While there currently aren't many systems inside ships worth protecting, I plan in the future to have many such systems, such as ammo supplies, power generators, shield generators, engineering bays, etc...

Here's a screenshot showing two "Enterprise"-like starships attempting to assault a heavily-armed space station:


Friday, January 13, 2012

StarWright - In-Game Ship Controls

The original Starship Builder prototype suffered from some terrible user interface choices. It's not that they were stupid, but that they were a product of tacking on lots of features and not being sure about how I wanted the game to play. Now that I have a better sense of what the game will be, I can greatly improve the user interface.

This past week I've been working on the in-game controls for commanding ships. Since I see no need to reinvent the wheel, I've modeled the controls after typical real-time strategy games like StarCraft and, especially, Company of Heroes. Like most RTS games, you can left-click on a ship you own to select it, or drag a box around several ships to select all of them. When you have ships selected, you can right-click somewhere in empty space to order your ships to move there. I've stolen a feature from Company of Heroes, whereby if you right-click and drag you can easily reorient which way your ships are pointing.

The green circle in this screenshot indicates that the starship is selected. The green "ghost" indicates the destination to which the ship has been commanded. The thick green line indicates the path from the ship to its destination.



As in the original prototype, once you have commanded a ship to move to a location, an algorithm will determine the optimal "activation level" for each thruster on your ship. This algorithm I was able to lift virtually unchanged from the original prototype.

Friday, January 6, 2012

StarWright - Steganography

Probably only programmers will appreciate this, but I did something I think is pretty neat today...

For StarWright, my super-awesome spaceship building game I'm making, I added more awesome to how spaceship designs are saved to files. Take a look at this PNG image:



If you download the file to your computer -- and of course have the latest version of StarWright -- you can simply load that PNG straight into the game and it will be fully playable and customizable. I'm hoping this will make ships easier and more fun to share, and it has the added bonus that I don't need to generate an in-game preview of the ship.

There's no fancy image-analysis going on. I'm simply embedding the ship data into the least significant bit of each of the red, green, and blue color channels of each pixel in the PNG (which is 32bpp ARGB). That's 3 bits per pixel, which means a 512x512 image can store about 98KB of data, which is more than enough for the largest ship I currently allow. Since only 1 very-insignificant bit is used per color channel, it's very difficult to see any visual difference. This is a kind of "Steganography" (hiding one message inside another), and Spore and the upcoming game Monaco use the same technique for creatures and custom levels.

The basic process in StarWright works like this:

  1. Save the ship layout to a proprietary data format.
  2. Compress the data using GZIP. Since the data is highly repetitive, I get about a 20:1 compression ratio.
  3. Take a 512x512 screenshot of the ship at 32bpp.
  4. Embed the compressed data into the least significant red, green, and blue bit of each pixel in the screenshot. I could use the alpha channel as well but that'd probably be more visually noticeable.
  5. Save as PNG! Done!

There are some drawbacks to this method, but nothing really major:

  • Save files are much larger than plain compressed text files. But the largest ship I have is still only 116KB on disk.
  • Any alterations to the PNG file will almost certainly corrupt the embedded data.
  • Theoretically the ship data may not fit in the image, but I can always increase the image size or use more bits per pixel. At first I was using 1024x1024 at 6bpp which was way more than I needed.
  • Supposedly embedding already-compressed data inside a PNG will reduce the PNG compression, but I've seen virtually no file size increase vs screenshots without embedded data.

Okay, I'm done nerding out now. ;-)

Thursday, January 5, 2012

StarWright - A New Beginning

Well, I'm starting over from scratch.

For a while now I've been working on a game prototype called Starship Builder. In short, it's a "build-your-own starship simulator" in which players design their own starships by placing rooms and parts onto a grid. Players can challenge other players in multiplayer matches to see who can design the best starship. Eventually, players will be able to explore galaxies with the starships that they create. You can read more about the game on my website.

I think that the existing prototype shows a lot of promise (usually when I show it to fellow gamers, the response I get is, "When can I buy this?"). But as high as its cool-factor is, the prototype as it exists right now is deeply flawed, both in terms of design (the user interface is very confusing and too detail-oriented) and programming (the game is being held back by choice of game engine).

So I'm starting over. For now, I'm calling this new version StarWright.

Beginning again from the ground will help me hit reset on the game's design. I will take what I learned from the prototype (the premise is fun and interesting, but the U.I. is terrible, micromanagement is tedious, and player-control of multiple ships is desirable) and build a much more fun game that is much easier to play.

But probably more importantly, starting over afresh will let me correct some major technical issues with the current prototype, most of which stem from the use of the Unity3D game engine. While Unity was I think a good choice for proving out the basic concepts of the game, it has proven to be unable to scale up to the complexity that the game demands. Unity requires that ever piece of code be attached to a game object, and it does not provide control over the main game loop or the precise order in which objects are updated or rendered. Working around those limitations was cumbersome, inefficient, and a lot of work. By switching to my own game engine (dubbed Halfling, it was originally created to power my games Tetrik and Tanky-Tank), I now have full control over the game's code, which will allow me to make a more sophisticated and much more optimized game.

I'm just getting started, but here's a sneak peak at the new ship designer interface:


There's not much to the game yet -- only three parts you can use, and no way to test your ship, fly around, or fight other ships. But I have high hopes for this new version. Throwing off the shackles of the old design and game engine already feels like breathing in a cool breeze atop a mountain. It's liberating.

Now that I'm taking the project more seriously and hope to sell a finished game one day, I probably won't be posting regular playable builds of the game -- just screenshots and maybe an occasional video. That will also save me the hassle of having to make a new build for every blog post I make!

Monday, September 19, 2011

Starship Builder - New Art (again)

My previous attempt at creating a new art style for Starship Builder was such a failure that I figured I'd try again! I'm not thrilled with the result, but I do think it's better than the original, and much better than that previous attempt.

Here's what it looks like:


Future Walt thinks that those sickly green people are really ugly.

Download this latest version for PC and Mac.

Thursday, September 15, 2011

Starship Builder - Multi-Ship!

The past few days I've been working on a big new feature that I've been wanting to add for quite a while: multiple ships! That is, each player can now control up to four ships. I think supporting multiple ships per player is important because 1-vs-1 ship combat, while fun to watch, can be a bit dull and non-interactive to actually play. By allowing multiple ships, I'm opening up more tactical possibilities, such as flanking and maximizing the strengths and weaknesses of different ship designs.

Once in the simulator, you can add a friendly or enemy ship by pressing either the "Spawn Friendly" or "Spawn Enemy" buttons. Once you have more than one ship, simply click on a ship to select and control that ship. The rest of the game works just the same.


Download for PC and Mac.

Here's a full list of the latest changes:

  • Added support for up to 4 ships per player.
  • Ships are now more intelligent about how they fly to a location: they will fly directly to the location at the maximum speed and then will rotate into final position once arrived.
  • Bullets now fly through space twice as fast.
  • Big performance improvement to physics calculations.