コード例 #1
0
ファイル: InputObject.cs プロジェクト: WasimN/ShipHunter
        public void UpdateInput(KeyboardState t_keyState, GameTime t_time, Viewport t_viewPort, int t_switchFrame,
            Background backGround, GameMouse mouse, Camera camera)
        {
            ProccessInput(t_keyState, t_time, t_viewPort, mouse, camera);
            //CalculatePosition(t_viewPort, backGround);
            //ApplyConstraints();
            //RegisterHitBox();
            this.Update(t_time, t_viewPort, t_switchFrame, backGround);

            //if the object needs to animate on a timer do not pass 0 to t_switchFrame
            if (t_switchFrame != 0)
                AnimateSprite(t_time, t_switchFrame);

            Rotation = Force.X;
        }
コード例 #2
0
ファイル: Object.cs プロジェクト: WasimN/ShipHunter
        //recalculate the position, add two physics vectors together, only used in Update()
        protected void CalculatePosition(Viewport t_viewPort, Background backGround)
        {
            //Positional values conatining polar (x, y);
            Vector2 t_start, t_end;
            double pos_x, pos_y;

            //Save the starting location
            t_start = Position;

            //Apply force to the existing trajectory
            pos_x = (Math.Cos(force.X) * force.Y) + (Math.Cos(strafe.X) * strafe.Y) + Position.X;
            pos_y = (Math.Sin(force.X) * force.Y) + (Math.Sin(strafe.X) * strafe.Y) + Position.Y;

            //if the ship is moving
            if (trajectory.Y != 0)
            {
                //Continue to add velocety to the tragectory
                pos_x += (Math.Cos(trajectory.X) * trajectory.Y);
                pos_y += (Math.Sin(trajectory.X) * trajectory.Y);
            }

            //Update the position at which to draw the sprite
            Position = new Vector2((float)pos_x, (float)pos_y);

            //subtract the starting position form the ending position so that the result
            //can be used to calculate the new angle of tragectory
            t_end = Position - t_start;

            //When calculating pythageruims therum the result is always positive therefor
            //the values must be check prior to the calculation to determine if the object
            //is moving in a positive direction or negative and the +/- signs get manually
            //applyed to the tragectory.

            //Check that the velocety is positive
            if (t_end.X == Math.Abs(t_end.X))
                //since the direction of travel is positive leave pythageriums positive
                trajectory.Y = (float)Math.Sqrt(Math.Pow(t_end.X, 2) + Math.Pow(t_end.Y, 2));
            //if for negative velocety
            else if (t_end.X == -Math.Abs(t_end.X))
                //since the direction of travel is negative manualy apply a negative to pythageriums
                trajectory.Y = -(float)Math.Sqrt(Math.Pow(t_end.X, 2) + Math.Pow(t_end.Y, 2));
            //finally calculate the new angle of travel using the tangent of the differance of
            //the starting position and the ending position
            trajectory.X = (float)Math.Atan(t_end.Y / t_end.X);

            //This section is used to loop the object on the screen if said object
            //is to leave the screen redraw it on the opposite side that it left from

            //Bottom of the screen
            if (Position.Y > backGround.Texture.Height * 10)
                Position = new Vector2(Position.X, -backGround.Texture.Height * 10);
            //Top of the screen
            else if (Position.Y < -backGround.Texture.Height * 10)
                Position = new Vector2(Position.X, backGround.Texture.Height * 10);
            //Right side of the screen
            else if (Position.X > backGround.Texture.Width * 15)
                Position = new Vector2(-backGround.Texture.Width * 15, Position.Y);
            //Left side of the screen
            else if (Position.X < -backGround.Texture.Width * 15)
                Position = new Vector2(backGround.Texture.Width * 15, Position.Y);
        }
コード例 #3
0
ファイル: Object.cs プロジェクト: WasimN/ShipHunter
        //central processing for the entire class, pass 0 to t_switchFrame if Object does not animate
        public void Update(GameTime t_time, Viewport t_viewPort, int t_switchFrame, Background backGround)
        {
            CalculatePosition(t_viewPort, backGround);
            ApplyConstraints();
            RegisterHitBox();
            CalculateMatrix();

            //if the object needs to animate on a timer do not pass 0 to t_switchFrame
            if (t_switchFrame != 0)
                AnimateSprite(t_time, t_switchFrame);

            Rotation = force.X;
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: WasimN/ShipHunter
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: Add your initialization logic here
            mouse = new GameMouse(Content, "Art/mice", new Vector2(3,1));
            camera = new Camera();
            debug = new Debug(Content, spriteBatch, 0, 0);
            ship = new InputObject(Content, "Art/spaceShip", new Vector2(0, 0), new Vector2(0, 0), 6.0f, 30);
            backGround = new Background(Content, graphics, "Art/space");
            asteroid = new List<Asteroid>();

            blasters = new List<Blasters>();

            base.Initialize();
        }