Example #1
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager (this);

            Content.RootDirectory = "Assets";

            graphics.IsFullScreen = true;

            gameObjects = new GameObjects ();
            gameObjects.ScreenSize = new Rectangle (
                0, 0,
                GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width,
                GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height
            );

            randomGenerator = new Random ();
            asteroidCount = 12;
            score = 0;
        }
Example #2
0
        public void Update(GameObjects gameObjects)
        {
            // Update Shuttle

            KeyboardState currentState = Keyboard.GetState();

            if(Active)
            {
                AngularVelocity = currentState.IsKeyDown( Keys.A ) ? -turnSpeed
                : currentState.IsKeyDown( Keys.D ) ? turnSpeed
                : 0f;

                Angle += AngularVelocity;

                Vector2 modelVelocityAdd = Vector2.Zero;

                modelVelocityAdd.X = (float) Math.Sin( Angle );
                modelVelocityAdd.Y = -(float) Math.Cos( Angle );

                modelVelocityAdd *= currentState.IsKeyDown( Keys.W ) ? thrust : 0f;

                Velocity += modelVelocityAdd;

                Location += Velocity;

                if (EdgeWrap)
                    WrapEdgeLocation( gameObjects.ScreenSize );
            }

            // Update Engine

            EnginePosition = new Vector2 (
                Location.X - (float)Math.Cos(Angle - Math.PI/2) * Height / 2 * Scale.X,
                Location.Y - (float)Math.Sin(Angle - Math.PI/2) * Height / 2 * Scale.Y
            );

            particleEngine.EmitterLocation = EnginePosition;
            particleEngine.Update();

            // Update Lasers

            GunPosition = new Vector2 (
                Location.X + (float)Math.Cos(Angle - Math.PI/2) * Height / 2 * Scale.X,
                Location.Y + (float)Math.Sin(Angle - Math.PI/2) * Height / 2 * Scale.Y
            );

            TimeToFire--;
            TimeToFire = MathHelper.Clamp( TimeToFire, 0, 30 );

            if (Active && currentState.IsKeyDown( Keys.Space ) && TimeToFire == 0)
            {
                var newLaser = new Laser (laserTexture);
                newLaser.Location = GunPosition;
                newLaser.Angle = Angle;
                newLaser.Velocity = new Vector2((float)Math.Cos(Angle - Math.PI/2),(float)Math.Sin(Angle - Math.PI/2)) * 30f;
                newLaser.Scale = Scale;

                gameObjects.Lasers.Add( newLaser );
                TimeToFire = 20;
                LaserFire.Play();
            }
        }
Example #3
0
 public void Update(GameObjects gameObjects)
 {
     base.Update(gameObjects.ScreenSize);
 }