コード例 #1
0
        public void Update(GameTime gameTime)
        {
            MouseState currentMouse = Mouse.GetState();
            if (gameState.state == State.over) return;
            if (gameState.state == State.menu)
            {
                KeyboardState currentKb=Keyboard.GetState();
                waitTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (currentKb.IsKeyDown(Keys.Enter) && previousKb.IsKeyUp(Keys.Enter) && waitTime > .1f)
                {
                    gameState.state = State.play; waitTime = 0;
                }
                previousKb=currentKb;
            }

            if (gameState.state == State.play)
            {
                if (miss == totalMiss)
                {
                    currentTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (currentTime > 3.0f)
                    {
                        gameState.state = State.over;
                    }
                }
                if (sugarState == SugarAndBeanState.rigid && beanState == SugarAndBeanState.rigid)
                {
                    KeyboardState currentKb = Keyboard.GetState();
                    beansPosition[(int)Keys.Up - (int)Keys.Left] = new Vector2(400, 70);
                    beansPosition[(int)Keys.Left - (int)Keys.Left] = new Vector2(250, 175);
                    beansPosition[(int)Keys.Right - (int)Keys.Left] = new Vector2(550, 175);
                    beansPosition[(int)Keys.Down - (int)Keys.Left] = new Vector2(400, 300);

                    currentTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (currentTime >= maxTime && miss<totalMiss)
                    {
                        while (value == previousValue)
                        {
                            value = random.Next(4);
                        }
                        startSugarCubePosition = sugarCubePosition = beansPosition[value];
                        rotation[value] = (float)random.Next(360) / 180 * (float)Math.PI;
                        currentTime = 0.0f;
                        if (previousScore == score) { miss += 1; }
                        previousScore = score;
                        previousValue = value;
                    }
                    if (currentTime <= maxTime && miss < totalMiss)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (sugarCubePosition == beansPosition[i] && currentKb.IsKeyDown(Keys.Left + i)
                                && previousKb.IsKeyUp(Keys.Left + i))
                            {
                                score += levelUps; sugarCubeCount += 1; currentTime = maxTime;
                                sugarState = SugarAndBeanState.dropping;
                            }
                            if (sugarCubePosition != beansPosition[i] && currentKb.IsKeyDown(Keys.Left + i)
                                && previousKb.IsKeyUp(Keys.Left + i))
                            {
                                wrongBeanPosition = i; currentTime = maxTime; beanCollected += 1;
                                beanState = SugarAndBeanState.dropping;
                            }
                        }
                    }
                    if (sugarCubeCount >= 5)
                    {
                        maxTime = (float)2 / 3 * maxTime;
                        levelUps += 1;
                        sugarCubeCount = 0;
                        maxTime = MathHelper.Clamp(maxTime, 0.4f, 4.0f);
                    }
                    previousKb = currentKb;
                }
                if (beanState == SugarAndBeanState.dropping)
                {
                    if (beansPosition[wrongBeanPosition].Y <= 600)
                        beansPosition[wrongBeanPosition].Y += (float)gameTime.ElapsedGameTime.TotalSeconds * velocity;
                }
                else if(sugarState == SugarAndBeanState.dropping)
                {
                    if (sugarCubePosition.Y <= 600)
                        sugarCubePosition.Y += (float)gameTime.ElapsedGameTime.TotalSeconds * velocity;
                }
                if ((sugarCubePosition.Y >= 500 || beansPosition[wrongBeanPosition].Y >= 500) && splat == false)
                {
                    splat = true;
                    splatValue = random.Next(3);
                    splatPosition = new Vector2(
                        (sugarCubePosition.Y >= 500 ? sugarCubePosition.X : beansPosition[wrongBeanPosition].X) - 50,
                        500 + splatTextures[splatValue].Height);
                    drop.Play();
                }

                if (splat == true)
                {
                    splatPosition.Y += (float)gameTime.ElapsedGameTime.TotalSeconds * velocity * direction;
                    if (splatPosition.Y <= (510 - splatTextures[splatValue].Height)) direction = 1;
                    if (splatPosition.Y > (510 + splatTextures[splatValue].Height))
                    {
                        sugarState = SugarAndBeanState.rigid;
                        beanState = SugarAndBeanState.rigid;
                        direction = -1;
                        splat = false;
                    }
                }
            }
        }
コード例 #2
0
        public void Update(GameTime gameTime, InputState inputSate)
        {
            MouseState currentMouse = Mouse.GetState();

            if (gameState.state == State.over)
            {
                return;
            }
            if (gameState.state == State.menu)
            {
                KeyboardState currentKb = Keyboard.GetState();
                waitTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (inputSate.IsMouseLeftButtonClick() && waitTime > .1f)
                {
                    gameState.state = State.play; waitTime = 0;
                }
                previousKb = currentKb;
            }

            if (gameState.state == State.play)
            {
                if (miss == totalMiss)
                {
                    currentTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (currentTime > 3.0f)
                    {
                        gameState.state = State.over;
                    }
                }
                if (sugarState == SugarAndBeanState.rigid && beanState == SugarAndBeanState.rigid)
                {
                    KeyboardState currentKb = Keyboard.GetState();
                    beansPosition[(int)Keys.Up - (int)Keys.Left]    = new Vector2(240, 180);
                    beansPosition[(int)Keys.Left - (int)Keys.Left]  = new Vector2(360, 300);
                    beansPosition[(int)Keys.Right - (int)Keys.Left] = new Vector2(120, 300);
                    beansPosition[(int)Keys.Down - (int)Keys.Left]  = new Vector2(240, 420);

                    currentTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (currentTime >= maxTime && miss < totalMiss)
                    {
                        while (value == previousValue)
                        {
                            value = random.Next(4);
                        }
                        startSugarCubePosition = sugarCubePosition = beansPosition[value];
                        rotation[value]        = (float)random.Next(360) / 180 * (float)Math.PI;
                        currentTime            = 0.0f;
                        if (previousScore == score)
                        {
                            miss += 1;
                        }
                        previousScore = score;
                        previousValue = value;
                    }
                    if (currentTime <= maxTime && miss < totalMiss && inputSate.IsMouseLeftButtonClick())
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (sugarCubePosition == beansPosition[i] &&
                                Vector2.Distance(beansPosition[i], new Vector2(inputSate.CurrentMouseState.X,
                                                                               inputSate.CurrentMouseState.Y)) < 75)
                            {
                                score     += levelUps; sugarCubeCount += 1; currentTime = maxTime;
                                sugarState = SugarAndBeanState.dropping; break;
                            }
                            if (sugarCubePosition != beansPosition[i] &&
                                Vector2.Distance(beansPosition[i], new Vector2(inputSate.CurrentMouseState.X,
                                                                               inputSate.CurrentMouseState.Y)) < 75)
                            {
                                wrongBeanPosition = i; currentTime = maxTime; beanCollected += 1;
                                beanState         = SugarAndBeanState.dropping; break;
                            }
                        }
                    }
                    if (sugarCubeCount >= 5)
                    {
                        maxTime        = 0.9f * maxTime;
                        levelUps      += 1;
                        sugarCubeCount = 0;
                        maxTime        = MathHelper.Clamp(maxTime, 1.0f, 4.0f);
                    }
                    previousKb = currentKb;
                }

                int cupTop = 670, screenHeight = 800;

                if (beanState == SugarAndBeanState.dropping)
                {
                    if (beansPosition[wrongBeanPosition].Y <= screenHeight)
                    {
                        beansPosition[wrongBeanPosition].Y += (float)gameTime.ElapsedGameTime.TotalSeconds * velocity;
                    }
                }
                else if (sugarState == SugarAndBeanState.dropping)
                {
                    if (sugarCubePosition.Y <= screenHeight)
                    {
                        sugarCubePosition.Y += (float)gameTime.ElapsedGameTime.TotalSeconds * velocity;
                    }
                }
                if ((sugarCubePosition.Y >= cupTop || beansPosition[wrongBeanPosition].Y >= cupTop) && splat == false)
                {
                    splat         = true;
                    splatValue    = random.Next(3);
                    splatPosition = new Vector2(
                        (sugarCubePosition.Y >= cupTop ? sugarCubePosition.X : beansPosition[wrongBeanPosition].X) - 50,
                        cupTop + splatTextures[splatValue].Height);
                    drop.Play();
                }

                if (splat == true)
                {
                    splatPosition.Y += (float)gameTime.ElapsedGameTime.TotalSeconds * velocity * direction;
                    if (splatPosition.Y <= (cupTop + 10 - splatTextures[splatValue].Height))
                    {
                        direction = 1;
                    }
                    if (splatPosition.Y > (cupTop + 10 + splatTextures[splatValue].Height))
                    {
                        sugarState = SugarAndBeanState.rigid;
                        beanState  = SugarAndBeanState.rigid;
                        direction  = -1;
                        splat      = false;
                    }
                }
            }
        }