Example #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            foreach (Bullet bullet in bullets.Objects)
            {
                foreach (Rock rock in rocks.Objects)
                {
                    if (bullet.CollidesWith(rock))
                    {
                        bullet.Visible    = false;
                        score.ScoreValue += 10;

                        if (rock.assetname == "spr_rock3")
                        {
                            rock.Visible = false;
                            this.rocks.Add(new Rock(rock.Position, rock.Velocity, "spr_rock2"));
                            break;
                        }
                        else if (rock.assetname == "spr_rock2")
                        {
                            rock.Visible = false;
                            this.rocks.Add(new Rock(rock.Position, rock.Velocity, "spr_rock1"));
                            break;
                        }
                        else if (rock.assetname == "spr_rock1")
                        {
                            rock.Visible = false;
                            break;
                        }
                    }
                }
            }

            foreach (Rock rock in rocks.Objects)
            {
                if (ship.CollidesWith(rock))
                {
                    Asteroids.GameStateManager.SwitchTo("GameOverState");
                }
            }
        }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            foreach (Bullet bullet in Bullets.Objects)
            {
                if (!bullet.Visible)
                {
                    bullets.Remove(bullet);
                    break;
                }
            }

            foreach (Rock rock in rocks.Objects)
            {
                if (spaceShip.CollidesWith(rock))
                {
                    Asteroids.GameStateManager.SwitchTo(Asteroids.gameoverState);
                }
            }
        }