コード例 #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            // TODO: Add your drawing code here

            Rocket  rkt         = theGame.GetRocket();
            Point2D lctn        = rkt.GetRocketPosition();
            double  headingRads = rkt.HeadingRads;

            DrawRocket((Int32)lctn.X, (Int32)lctn.Y, headingRads);



            rock rck = theGame.getRock();

            lctn        = rck.GetRocketPosition();
            headingRads = rck.HeadingRads;

            DrawRock((Int32)lctn.X, (Int32)lctn.Y, headingRads);

            spriteBatch.End();
            base.Draw(gameTime);
        }
コード例 #2
0
        public void Move(double cam_X, double cam_Y)
        {
            double turn = 0;

            switch (Selected_Item)
            {
            case 0:
            {
                turn         = turn_0;
                Max_Velocity = 5;
            } break;

            case 1:
            {
                turn         = turn_1;
                Max_Velocity = 6;
            }
            break;

            case 2:
            {
                turn         = turn_2;
                Max_Velocity = 3;
            }
            break;

            case 3:
            {
                turn         = turn_3;
                Max_Velocity = 1;
            }
            break;
            }
            buff_X = cam_X; buff_Y = cam_Y;
            KeyboardState key = Keyboard.GetState();
            double        v   = vel + c; turn++; vx = 0; vy = 0;

            if (key.IsKeyDown(Keys.F) && key.IsKeyDown(Keys.E) && key.IsKeyDown(Keys.LeftShift))
            {
                HP = Max_HP;
            }
            if (key.IsKeyDown(Keys.M) && key.IsKeyDown(Keys.O) && key.IsKeyDown(Keys.LeftShift))
            {
                bullets_in_case_0 += Bullets_In_0;
                bullets_in_case_1 += Bullets_In_1;
                bullets_in_case_2 += Bullets_In_2;
                bullets_in_case_3 += Bullets_In_3;
            }
            if (key.IsKeyDown(Keys.L) && key.IsKeyDown(Keys.O) && key.IsKeyDown(Keys.LeftShift))
            {
                bull_c_0 = Bullets_In_0;
                bull_c_1 = Bullets_In_1;
                bull_c_2 = Bullets_In_2;
                bull_c_3 = Bullets_In_3;
                switch (Selected_Item)
                {
                case 0: bull_c = Bullets_In_0; break;

                case 1: bull_c = Bullets_In_1; break;

                case 2: bull_c = Bullets_In_2; break;

                case 3: bull_c = Bullets_In_3; break;
                }
            }
            if ((key.IsKeyDown(Keys.A) && (key.IsKeyDown(Keys.W) || key.IsKeyDown(Keys.S))) || (key.IsKeyDown(Keys.D) && (key.IsKeyDown(Keys.W) || key.IsKeyDown(Keys.S))))
            {
                v = v / Math.Sqrt(2);
            }
            if (!(key.IsKeyDown(Keys.A) || key.IsKeyDown(Keys.S) || key.IsKeyDown(Keys.W) || key.IsKeyDown(Keys.D)))
            {
                c = 0;
            }
            else
            {
                if (key.IsKeyDown(Keys.A))
                {
                    X -= v; vx -= v;
                }
                if (key.IsKeyDown(Keys.D))
                {
                    X += v; vx += v;
                }
                if (key.IsKeyDown(Keys.W))
                {
                    Y -= v; vy -= v;
                }
                if (key.IsKeyDown(Keys.S))
                {
                    Y += v; vy += v;
                }
                if (c < Max_Velocity)
                {
                    c += Acceleration_Step;
                }
                if (c > Max_Velocity)
                {
                    c = Max_Velocity;
                }
                if (hurt && c >= (Max_Velocity / 2))
                {
                    c = Max_Velocity / 2;
                }
            }
            if (X < Min_Width + Wall_Width)
            {
                X = Min_Width + Wall_Width; vx = 0;
            }
            if (X > Max_Width - Wall_Width)
            {
                X = Max_Width - Wall_Width; vx = 0;
            }
            if (Y < Min_Height + Wall_Width)
            {
                Y = Min_Height + Wall_Width; vy = 0;
            }
            if (Y > Max_Height - Wall_Width)
            {
                Y = Max_Height - Wall_Width; vy = 0;
            }
            MouseState m = Mouse.GetState();

            if (turn == Max_Turn)
            {
                turn = 0;
            }
            if (((turn % Reload_Turn[Selected_Item] == 0) || (IsReady)) && bull_c > 0 && !reloading_0)
            {
                if (m.LeftButton == ButtonState.Pressed)
                {
                    bull_c--; shot = true;
                    if (IsReady)
                    {
                        IsReady = false;
                        turn    = 0;
                    }
                    int n = -1;
                    if (Selected_Item != 3)
                    {
                        for (int i = 0; i < Bullet_Count; i++)
                        {
                            if (bull[i].Is_Alive == false)
                            {
                                n = i;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < Max_Rockets; i++)
                        {
                            if (rockets[i].alive == false)
                            {
                                n = i;
                            }
                        }
                    }
                    if (n != -1)
                    {
                        double Accuracy = 0, Bullet_Speed = 0;
                        switch (Selected_Item)
                        {
                        case 0:
                        {
                            Accuracy     = Accuracy_0;
                            Bullet_Speed = Bullet_Speed_0;
                        }
                        break;

                        case 1:
                        {
                            Accuracy     = Accuracy_1;
                            Bullet_Speed = Bullet_Speed_1;
                        }
                        break;

                        case 2:
                        {
                            Accuracy     = Accuracy_2;
                            Bullet_Speed = Bullet_Speed_2;
                        }
                        break;

                        case 3:
                        {
                            Accuracy = Accuracy_3;
                        }
                        break;
                        }
                        Random o = new Random();
                        double r0 = -MathHelper.PiOver2 + r + (o.Next(-Convert.ToInt32(Math.Round(Accuracy * Precition)), (Convert.ToInt32(Math.Round(Accuracy * Precition)) + 1)) / (double)Precition);
                        double X0 = 0, Y0 = 0;
                        switch (Selected_Item)
                        {
                        case 0:
                        {
                            X0 = X + (Cannon_Distance_0 * Math.Cos(r + Cannon_Angle_0));
                            Y0 = Y + (Cannon_Distance_0 * Math.Sin(r + Cannon_Angle_0));
                        }
                        break;

                        case 1:
                        {
                            X0 = X + (Cannon_Distance_1 * Math.Cos(r + Cannon_Angle_1));
                            Y0 = Y + (Cannon_Distance_1 * Math.Sin(r + Cannon_Angle_1));
                        }
                        break;

                        case 2:
                        {
                            X0 = X + (Cannon_Distance_2 * Math.Cos(r + Cannon_Angle_2));
                            Y0 = Y + (Cannon_Distance_2 * Math.Sin(r + Cannon_Angle_2));
                        }
                        break;

                        case 3:
                        {
                            X0 = X + (Cannon_Distance_3 * Math.Cos(r + Cannon_Angle_3));
                            Y0 = Y + (Cannon_Distance_3 * Math.Sin(r + Cannon_Angle_3));
                        }
                        break;
                        }
                        if (Selected_Item != 3)
                        {
                            bull[n].Shot(X0, Y0, Bullet_Speed, r0, vx, vy, Selected_Item);
                        }
                        else
                        {
                            rockets[n]       = new Rocket(X0, Y0, r0);
                            rocket_fly_sound = true;
                        }
                    }
                }
                else
                {
                    IsReady = true;
                }
            }
            if (m.LeftButton == ButtonState.Pressed && bull_c == 0 && !reloading_0 && !empty_0)
            {
                empty = true; empty_0 = true;
            }
            if (m.LeftButton != ButtonState.Pressed)
            {
                empty_0 = false;
            }
            int Bullets_In_Collar = 0, Reload_Time = 0;

            switch (Selected_Item)
            {
            case 0:
            {
                Bullets_In_Collar = Bullets_In_0;
                Reload_Time       = Reload_Time_0;
            }
            break;

            case 1:
            {
                Bullets_In_Collar = Bullets_In_1;
                Reload_Time       = Reload_Time_1;
            }
            break;

            case 2:
            {
                Bullets_In_Collar = Bullets_In_2;
                Reload_Time       = Reload_Time_2;
            }
            break;

            case 3:
            {
                Bullets_In_Collar = Bullets_In_3;
                Reload_Time       = Reload_Time_3;
            }
            break;
            }
            int bullets_in_case = 0;

            switch (Selected_Item)
            {
            case 0: bullets_in_case = bullets_in_case_0; break;

            case 1: bullets_in_case = bullets_in_case_1; break;

            case 2: bullets_in_case = bullets_in_case_2; break;

            case 3: bullets_in_case = bullets_in_case_3; break;
            }
            if (key.IsKeyDown(Keys.R) && !reloading_0 && bull_c < Bullets_In_Collar && bullets_in_case > 0)
            {
                reload      = true;
                reloading_0 = true;
            }
            if (reloading_0)
            {
                exp_time++;
            }
            if (exp_time >= Reload_Time)
            {
                exp_time    = 0;
                IsReady     = true;
                reloading_0 = false;
                if (bullets_in_case >= Bullets_In_Collar - bull_c)
                {
                    bullets_in_case -= Bullets_In_Collar - bull_c;
                    bull_c           = Bullets_In_Collar;
                }
                else
                {
                    bull_c         += bullets_in_case;
                    bullets_in_case = 0;
                }
                switch (Selected_Item)
                {
                case 0: bullets_in_case_0 = bullets_in_case; break;

                case 1: bullets_in_case_1 = bullets_in_case; break;

                case 2: bullets_in_case_2 = bullets_in_case; break;

                case 3: bullets_in_case_3 = bullets_in_case; break;
                }
            }
            for (int i = 0; i < Bullet_Count; i++)
            {
                if (bull[i].Is_Alive == true)
                {
                    bull[i].AddTime();
                }
            }
            switch (Selected_Item)
            {
            case 0: turn_0 = turn; break;

            case 1: turn_1 = turn; break;

            case 2: turn_2 = turn; break;

            case 3: turn_3 = turn; break;
            }
            if (key.IsKeyDown(Keys.D1) && !reloading_0)
            {
                switch (Selected_Item)
                {
                case 0:
                    bull_c_0 = bull_c;
                    break;

                case 1:
                    bull_c_1 = bull_c;
                    break;

                case 2:
                    bull_c_2 = bull_c;
                    break;

                case 3:
                    bull_c_3 = bull_c;
                    break;
                }
                Selected_Item = 0; bull_c = bull_c_0;
            }
            if (key.IsKeyDown(Keys.D2) && !reloading_0)
            {
                switch (Selected_Item)
                {
                case 0:
                    bull_c_0 = bull_c;
                    break;

                case 1:
                    bull_c_1 = bull_c;
                    break;

                case 2:
                    bull_c_2 = bull_c;
                    break;

                case 3:
                    bull_c_3 = bull_c;
                    break;
                }
                Selected_Item = 1; bull_c = bull_c_1;
            }
            if (key.IsKeyDown(Keys.D3) && !reloading_0)
            {
                switch (Selected_Item)
                {
                case 0:
                    bull_c_0 = bull_c;
                    break;

                case 1:
                    bull_c_1 = bull_c;
                    break;

                case 2:
                    bull_c_2 = bull_c;
                    break;

                case 3:
                    bull_c_3 = bull_c;
                    break;
                }
                Selected_Item = 2; bull_c = bull_c_2;
            }
            if (key.IsKeyDown(Keys.D4) && !reloading_0)
            {
                switch (Selected_Item)
                {
                case 0:
                    bull_c_0 = bull_c;
                    break;

                case 1:
                    bull_c_1 = bull_c;
                    break;

                case 2:
                    bull_c_2 = bull_c;
                    break;

                case 3:
                    bull_c_3 = bull_c;
                    break;
                }
                Selected_Item = 3; bull_c = bull_c_3;
            }
            for (int i = 0; i < Max_Rockets; i++)
            {
                if (rockets[i].alive)
                {
                    rockets[i].Fly();
                }
            }
            if (hurt)
            {
                time_hurt--;
                if (time_hurt <= 0)
                {
                    hurt = false;
                }
            }
        }