04. Main Ship Entity

Introduction

So far we’ve done a lot of work on our project, but nothing is showing up at runtime yet. This tutorial will begin work on the MainShip entity – the Entity which will be controlled by the players of our game.

How much to define?

Before we begin to define our MainShip, it is important to note that there is not a set way to define Entities. If you are extremely familiar with the genre you that you are creating a game for, or if you have very detailed plans about what you are creating, then you may be able to define your Entities very thoroughly the very first time you work with them. However, if you still have some questions in your head about how the game will play or how objects will behave (this is very common, so don’t feel bad if you do) then you may implement only a portion of your Entity before you play the game and possibly move on to a different area of the game.

This tutorial will take an iterative approach to defining Entities, as this is more common in real game development. This means we will define some of the MainShip Entity now, and we’ll return to refine and add additional logic and content in later tutorials.

The art

As mentioned in the introduction to this set of tutorials, this game will be built using art from Tyrian as provided by Dan Cook. For simplicity these tutorials will provide a subset of the Tyrian art. Modifications have been made only to remove unused parts of various images, to add transparency, and to separate images into separate files for convenience. Otherwise all art is in its original state. If you finish this tutorial and would like to continue developing this game, visit http://www.lostgarden.com/2007/04/free-game-graphics-tyrian-ships-and.html for the full set of Tyrian art.

For the ship, save the following four files to any location on your computer – just remember where you save them as you will need to be able to find them:

MainShip1.png

MainShip2.png

MainShip3.png

MainShip4.png

We will use four files to support up to four players at the same time.

Adding existing files to Glue

Next we will add these four ship files to Glue. To do this:

  1. Expand the “MainShip” Entity in Glue
  2. Right-click on the Files item under MainShip
  3. Select “Add File”->”Existing File”
  4. Navigate to where you saved the MainShip images
  5. If you saved all four in the same location, then you can select all four images and click OK on the file window.
  6. You should now see the files as part of your MainShip Entity

Alternatively, you can also navigate to a location where the files are located in an explorer window, then drag+drop the file from the explorer window to your Entity’s Files item.
MainShipFiles.PNG

Where are my files located? If you saved the .png files in the same folder as the .contentproj file (which will probably be called RockBlasterContent) then Glue will reference the .png files from their current location. If you saved the files outside of this folder, then Glue will copy them into a folder specific to the MainShip Entity.

If you ever need to find the files, you can right-click on the files in Glue and select “View In explorer”

Adding a Sprite to your Entity

Now that we have four images in our game, we need a Sprite to display them. To add a Sprite to your MainShip Entity:

  1. Right-click on the Objects item under MainShip
  2. Select “Add Object”
  3. Select the “FlatRedBall Type” option
  4. Select the “Sprite” option
  5. Enter the name “Sprite” and click OK
  6. Scroll the PropertyGrid up and verify the TextureScale is 1.0 (this makes our Sprite sized according to the source texture)
    Note: You may need to set a value of 1,0 instead of 1.0 depending on the language settings of your computer.
  7. Use the Texture dropdown (under the “Variable” category”) to select “MainShip1”

If you run GlueView, you should see your MainShip Entity in GlueView.

Adding a MainShip instance to GameScreen

Now that our MainShip has a Sprite, we can see it in game – or at least we will be able to once we add a MainShip object to our MainShipList object in GameScreen. To do this:

  1. Expand GameScreen
  2. Expand Objects
  3. Right-click on MainShipList
  4. Select “Add Object”
  5. Enter the name “Player1Ship”

PlayerShipInList.PNG

Notice that Glue automatically selected “Entity” for SourceType and “Entities\MainShip” for SourceClassType. It knew this is what we intended since we were adding instances to a list of MainShips.

Running the Game

You can now run the game in Visual Studio (which you can get to by selecting “Project”->”View in Visual Studio” in Glue). You should see a MainShip in the middle of the screen.

Is2DSetToTrue.PNG

Conclusion

At this point our GameScreen contains a MainShip Entity. The MainShip is using a Sprite defined in Glue. However, nothing is happening in our game so far. The next tutorial will add some simple behavior to our MainShip Entity.

<- 03. Game Skeleton05. Main Ship Behavior ->