Game Development Reference
In-Depth Information
_gameTime ¼ _gameData.CurrentLevel.Time;
}
// Code omitted
public void Update(double elapsedTime)
{
_level.Update(elapsedTime);
// Code omitted
public void Render()
{
Gl.glClearColor(1, 0, 1, 0);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
_level.Render(_renderer);
Run the code and start the game. The spaceship will flash, giving a brief glance
of this new player sprite and then suddenly the game will end. To test the
InnerGameState thoroughly, the level length must be increased. The level
length is set in the form.cs file in the InitializeGameData function. Find
the code and make the length longer; 30 seconds is probably fine.
The spaceship movement is going to be very simple, with no acceleration or
physics modeling. The control stick and arrow keys map directly to the move-
ment of the ship. The PlayerCharacter class needs a new method
called Move .
double _speed ¼ 512; // pixels per second
public void Move(Vector amount)
{
amount *= _speed;
_spaceship.SetPosition(_spaceship.GetPosition() þ amount);
}
The Move method takes in a vector that gives the direction and amount to move
the spaceship. The vector is then multiplied by the speed value to increase
the movement length. The new vector is then added to the current position
of the ship to create a new position in space, and the sprite is moved there. This is
how all basic movement is done in arcade-style games. The movement can be
given a different feel by modeling more physical systems such as acceleration and
friction, but we will stick with the basic movement code.
 
Search WWH ::




Custom Search