-1

わかりましたので、私は自分が作ったプロトタイプ ゲームを再検討しています。これを説明するのは難しいですが、基本的には画面上に「食べる」ことができるゲーム オブジェクトがあり、基本的には新しいポイント値とテクスチャで再スポーンします。

次の段階のメソッドは、ゲーム オブジェクトが「食べられた」ときに、テクスチャが画面上の口と交差するときに呼び出されます。

スポイラーを隠す

コード:

void NextPhase(int food)
    {

        switch (foodNumber)
        {
                //Detects what food object has been eaten
            case 1:
                {
                    food1Phase++;
                    break;
                }
            case 2:
                {
                    food2Phase++
                    break;
                }
            case 3:
                {
                    food3Phase++;
                    break;
                }
                //
        }
        switch (foodNumber)
        {
            case 1:
                {

                    switch (food1Phase)
                    {
                    //Each phase is a new set of Textures, Points Values and specific spawn delay.
                    //Multiplier sotrage tells another method
                    //what food has been eaten and decides whether to increase the score mulitplier
                    //the position properties reset it to a location off screen and then it flies on screen
                    //for the player to collect
                    //delayCompleted false activates another method that starts timing the spawn
                    //delay
                case 1:
                    {


                        multiplierStorage("Gay Bacon");
                        food1Position.X = -200;
                        food1Position.Y = 60;
                        food1 = contentManager.Load<Texture2D>("Food2Img");
                                food1Height = food1.Bounds.Height + 20;
                                food1Width = food1.Bounds.Width + 30;
                                food1Speed.X = 0;
                                food1Speed.Y = 0;
                        delayCompleted = false;
                        if (gameOverallTimer < 30.0)
                        {

                            timeWanted = gameOverallTimer + 4.0;
                        }
                        break;
                    }
                case 2:
                    {
                        food1 = contentManager.Load<Texture2D>("Food6");
                        food1Height = food1.Bounds.Height + 20;
                        food1Width = food1.Bounds.Width + 30;
                        food1Position.X = -100;
                        food1Position.Y = 60;
                        food1Speed.X = 0;
                        food1Speed.Y = 0;
                        multiplierStorage("Bacon");




                        break;
                    }
                case 3:
                    {
                        food1 = contentManager.Load<Texture2D>("Food1Img");
                        food1Height = food1.Bounds.Height + 20;
                        food1Width = food1.Bounds.Width + 30;
                        food1Position.X = -100;
                        food1Position.Y = 60;
                        food1Speed.X = 0;
                        food1Speed.Y = 0;
                        vegetableEatenMultiplier();
                        lives = lives - 1;
                        UpdateLives();
                        food1Phase = 0;
                        break;
                    }
                }
            }
        }

            case 2:
                {

                    switch (food2Phase)
                    {
                        food2 = contentManager.Load<Texture2D>("Food4");
                        food2Height = food2.Bounds.Height + 30;
                        food2Width = food2.Bounds.Width + 30;
                        food2Position.X = 850;
                        food2Position.Y = 200;
                        food2Speed.X = 0;
                        food2Speed.Y = 0;

                        multiplierStorage("Bacon");
                        break;
                    }
                case 2:
                    {


                        food2 = contentManager.Load<Texture2D>("Food5");
                        food2Height = food2.Bounds.Height + 30;
                        food2Width = food2.Bounds.Width + 30;
                        food2Position.X = 850;
                        food2Position.Y = 200;
                        food2Speed.X = 0;
                        food2Speed.Y = 0;
                        vegetableEatenMultiplier();
                        lives = lives - 1;
                        UpdateLives();
                        break;
                    }
                case 3:
                    {
                        food2 = contentManager.Load<Texture2D>("Food2Img");
                        food2Height = food2.Bounds.Height + 30;
                        food2Width = food2.Bounds.Width + 30;
                        food2Position.X = 850;
                        food2Position.Y = 200;
                        food2Speed.X = 0;
                        food2Speed.Y = 0;
                        food2Phase = 0;
                        multiplierStorage("Steak");
                        break;
                    }
                }
            }



            case 3:
                {

                    switch (food3Phase)
                    {

                        food3Position.X = 600;
                        food3Position.Y = -100;
                        food3Speed.X = 0;
                        food3Speed.Y = 0;
                        food3Phase = 0;
                        multiplierStorage("Gay Bacon");
                        break;
                    }
                }
            }
        }

    }      

問題は、これは私にはあまり効率的ではないようです。はい、テクスチャと位置などのプロパティを持つ新しいクラスを作成することを考えました。その後、そのクラスの新しいオブジェクトを作成し、その方法で改善しますが、それでもそのクラスでこのフェーズ コードを使用します。コードのみの代替が必要です。

4

1 に答える 1