Game Development Reference
In-Depth Information
public class PlayerCharacter : Entity
{
double _speed ¼ 512; // pixels per second
public void Move(Vector amount)
{
amount *= _speed;
_sprite.SetPosition(_sprite.GetPosition() þ amount);
}
public PlayerCharacter(TextureManager textureManager)
{
_sprite.Texture ¼ textureManager.Get("player_ship");
_sprite.SetScale(0.5, 0.5); // spaceship is quite big, scale it down.
}
public void Render(Renderer renderer)
{
Render_Debug();
renderer.DrawSprite(_sprite);
}
}
Run the code again, and now both the enemy and player will have appropriate
bounding boxes.
For now, the rule will be that if the PlayerCharacter hits an enemy, the
game ends. This can be refined later by giving the player some health. To get a
game working as fast as possible, it will for now be instant death.
The first change is in the InnerGameState ; it needs to recognize when the
player has died and therefore failed to complete the current level.
public void Update(double elapsedTime)
{
_level.Update(elapsedTime);
_gameTime -= elapsedTime;
if (_gameTime < =0)
{
OnGameStart();
_gameData.JustWon ¼ true;
Search WWH ::




Custom Search