Пример #1
0
        public override void Update(GameTime gameTime)
        {
            pShip.Update(gameTime);

            foreach (Ship currentShip in allShips)
            {
                currentShip.Update(gameTime);
                if (tukHelper.determineDistance(currentShip.myPosition, pShip.myPosition) > 1000f) //should we still draw the ship or is it too far away?
                {
                    currentShip.visible = false;
                }
                else //i guess we are close enough so lets set it to true
                {
                    currentShip.visible = true;
                }
                if (!pShip.Equals(currentShip))
                {
                    currentShip.collisionRectangle.X -= 10;
                    if (currentShip.collisionRectangle.Contains(new Point((int)pShip.beamController.singleFireTarget.X, (int)pShip.beamController.singleFireTarget.Y)))
                    {
                        currentShip.shieldsUp         = !currentShip.shieldsUp;
                        currentShip.shieldPercentage -= 30 * gameTime.ElapsedGameTime.Milliseconds * 0.01f;
                    }
                    //still off.
                    if (RectCollision.Check(currentShip.collisionRectangle, pShip.ROTATION_POINT, currentShip.rotationAngle,
                                            pShip.collisionRectangle, pShip.myPosition, pShip.rotationAngle))
                    {
                        currentShip.shieldsUp = !currentShip.shieldsUp;
                    }
                }
            }

            if (curScreen.ReleaseMe == true)
            {
                curScreen = helmScreen;
            }
            curScreen.Update(gameTime); //update our current screen
            HandleInput(gameTime);      //calls our global input hook, which passes any unprocessed input to the currentitleScreen

            //update network
            NetworkManager.Update(gameTime);
        }
Пример #2
0
        /* //////////////////////////////////////////
        *  ///////////// INPUT HANDLING ///////////// */

        public override void HandleInput(GameTime gameTime, KeyboardState kState, MouseState mState)
        {
            //first 2 handle rotation
            //next 2 handle thrust: if impulse engine is in use, time based acceleration
            //                    : if warp engine is in use, check for a keypress to accelerate by 1 warp factor

            if (kState.IsKeyDown(Keys.Left))
            {
                pShip.RotateByValue((float)(gameTime.ElapsedGameTime.Milliseconds * TIME_BASED_KEY_MOD), -1);
            }
            else if (kState.IsKeyDown(Keys.Right))
            {
                pShip.RotateByValue((float)(gameTime.ElapsedGameTime.Milliseconds * TIME_BASED_KEY_MOD), 1);
            }

            if (pShip.engineController.WarpOn())
            {
                if (kState.IsKeyDown(Keys.Up))
                {
                    if (!base.oldKState.IsKeyDown(Keys.Up))
                    {
                        pShip.ThrustByValue(1.0f, 1);
                    }
                }
                else if (kState.IsKeyDown(Keys.Down))
                {
                    if (!base.oldKState.IsKeyDown(Keys.Down))
                    {
                        pShip.ThrustByValue(1.0f, -1);
                    }
                }
            }
            else
            {
                if (kState.IsKeyDown(Keys.Up))
                {
                    pShip.ThrustByValue((float)(gameTime.ElapsedGameTime.Milliseconds * TIME_BASED_KEY_MOD), 1);
                }
                else if (kState.IsKeyDown(Keys.Down))
                {
                    pShip.ThrustByValue((float)(gameTime.ElapsedGameTime.Milliseconds * TIME_BASED_KEY_MOD), -1);
                }
            }

            //Regular keypress checks
            //makes the first ship in allShips move.
            if (kState.IsKeyDown(Keys.I))
            {
                allShips[0].ThrustByValue((float)(gameTime.ElapsedGameTime.Milliseconds * TIME_BASED_KEY_MOD), -1);
            }
            else if (kState.IsKeyDown(Keys.W))
            {
                if (!base.oldKState.IsKeyDown(Keys.W))
                {
                    pShip.engineController.ChangeWarpState();

                    if (pShip.engineController.WarpOn())
                    {
                        warpStatus = warpOn;
                    }
                    else
                    {
                        warpStatus = warpOff;
                    }
                }
            }

            else if (kState.IsKeyDown(Keys.A))
            {
                if (!base.oldKState.IsKeyDown(Keys.A))
                {
                    pShip.engineController.AllStop();
                    warpStatus = warpOff;
                }
            }


            if (mState.ScrollWheelValue != oldMState.ScrollWheelValue && theWorld.curScreen == this)
            {
                cam.Zoom += (float)(mState.ScrollWheelValue - oldMState.ScrollWheelValue) * .001f;
            }

            //being hacked in for testing

            //converting the mousepointer to world space is essential when using a camera.
            Vector2   adjustedMousePos = cam.ToWorldLocation(new Vector2(mState.X, mState.Y));
            Rectangle mousePointer     = new Rectangle((int)adjustedMousePos.X, (int)adjustedMousePos.Y, 1, 1);

            if (mState.LeftButton == ButtonState.Released && oldMState.LeftButton == ButtonState.Pressed)
            {
                //did we click on pShip?
                if (RectCollision.Check(mousePointer, Vector2.Zero, 0f, pShip.collisionRectangle, Vector2.Zero, pShip.rotationAngle))
                {
                    pShip.shieldsUp = !pShip.shieldsUp;
                }
                else
                {
                    //lets check the other ships
                    foreach (Ship aShip in allShips)
                    {
                        if (RectCollision.Check(mousePointer, Vector2.Zero, 0f, aShip.collisionRectangle, Vector2.Zero, aShip.rotationAngle))
                        {
                            targetReticulePosition = aShip.myPosition;
                            break;
                        }
                    }
                }
            }


            base.HandleInput(gameTime, kState, mState);
        }