Beispiel #1
0
        /// <summary>
        /// ゲームが自身を描画するためのメソッドです。
        /// </summary>
        /// <param name="gameTime">ゲームの瞬間的なタイミング情報</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.DarkGreen);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            // テキストを描画
            String level_text = "Level: " + level;
            spriteBatch.DrawString(text, level_text, new Vector2(10, 10), Color.White);

            // シーンによって処理を分岐
            if (scene == SCENE.READY)
            {
                // 宝箱を描画
                for (int i = 0; i < box.Length; i++)
                {
                    spriteBatch.Draw(img[(int)box[i].status], new Vector2(box[i].rect.X, box[i].rect.Y), Color.White);
                }

                // テキストを描画
                String message_text = "Start by tapping shuffle";
                spriteBatch.DrawString(text, message_text, new Vector2(((graphics.PreferredBackBufferWidth - text.MeasureString(message_text).X) / 2), graphics.PreferredBackBufferHeight * 4 / 5), Color.White);
            }
            else if (scene == SCENE.SHUFFLE)
            {

                // 宝箱を描画
                for (int i = 0; i < box.Length; i++)
                {
                    if (!animation.isShuffle(box[i]))
                    {
                        spriteBatch.Draw(img[(int)IMG.CLOSE_BOX], new Vector2(box[i].rect.X, box[i].rect.Y), Color.White);
                    }
                }

                // シャッフルアニメーションを描画
                if (animation.Active)
                {
                    animation.Draw(spriteBatch);
                }
                else
                {
                    animation = shuffleAnimations.Dequeue();
                }
            }
            else if (scene == SCENE.SELECT)
            {
                // 宝箱を描画
                for (int i = 0; i < box.Length; i++)
                {
                    spriteBatch.Draw(img[(int)IMG.CLOSE_BOX], new Vector2(box[i].rect.X, box[i].rect.Y), Color.White);
                }

                // テキストを描画
                String message_text = "Tap a box";
                spriteBatch.DrawString(text, message_text, new Vector2(((graphics.PreferredBackBufferWidth - text.MeasureString(message_text).X) / 2), graphics.PreferredBackBufferHeight * 4 / 5), Color.White);
            }
            else if ((scene == SCENE.WIN) || (scene == SCENE.LOSE))
            {
                // 宝箱を描画
                for (int i = 0; i < box.Length; i++)
                {
                    spriteBatch.Draw(img[(int)box[i].status], new Vector2(box[i].rect.X, box[i].rect.Y), Color.White);
                }

                // テキストを描画
                String message_text = "You " + (scene == SCENE.WIN ? "win!" : "lose!");
                spriteBatch.DrawString(text, message_text, new Vector2(((graphics.PreferredBackBufferWidth - text.MeasureString(message_text).X) / 2), graphics.PreferredBackBufferHeight * 4 / 5), Color.White);
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
Beispiel #2
0
        /// <summary>
        /// ゲームが自身を描画するためのメソッドです。
        /// </summary>
        /// <param name="gameTime">ゲームの瞬間的なタイミング情報</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.DarkGreen);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            // テキストを描画
            String level_text = "Level: " + level;

            spriteBatch.DrawString(text, level_text, new Vector2(10, 10), Color.White);

            // シーンによって処理を分岐
            if (scene == SCENE.READY)
            {
                // 宝箱を描画
                for (int i = 0; i < box.Length; i++)
                {
                    spriteBatch.Draw(img[(int)box[i].status], new Vector2(box[i].rect.X, box[i].rect.Y), Color.White);
                }

                // テキストを描画
                String message_text = "Start by tapping shuffle";
                spriteBatch.DrawString(text, message_text, new Vector2(((graphics.PreferredBackBufferWidth - text.MeasureString(message_text).X) / 2), graphics.PreferredBackBufferHeight * 4 / 5), Color.White);
            }
            else if (scene == SCENE.SHUFFLE)
            {
                // 宝箱を描画
                for (int i = 0; i < box.Length; i++)
                {
                    if (!animation.isShuffle(box[i]))
                    {
                        spriteBatch.Draw(img[(int)IMG.CLOSE_BOX], new Vector2(box[i].rect.X, box[i].rect.Y), Color.White);
                    }
                }

                // シャッフルアニメーションを描画
                if (animation.Active)
                {
                    animation.Draw(spriteBatch);
                }
                else
                {
                    animation = shuffleAnimations.Dequeue();
                }
            }
            else if (scene == SCENE.SELECT)
            {
                // 宝箱を描画
                for (int i = 0; i < box.Length; i++)
                {
                    spriteBatch.Draw(img[(int)IMG.CLOSE_BOX], new Vector2(box[i].rect.X, box[i].rect.Y), Color.White);
                }

                // テキストを描画
                String message_text = "Tap a box";
                spriteBatch.DrawString(text, message_text, new Vector2(((graphics.PreferredBackBufferWidth - text.MeasureString(message_text).X) / 2), graphics.PreferredBackBufferHeight * 4 / 5), Color.White);
            }
            else if ((scene == SCENE.WIN) || (scene == SCENE.LOSE))
            {
                // 宝箱を描画
                for (int i = 0; i < box.Length; i++)
                {
                    spriteBatch.Draw(img[(int)box[i].status], new Vector2(box[i].rect.X, box[i].rect.Y), Color.White);
                }

                // テキストを描画
                String message_text = "You " + (scene == SCENE.WIN ? "win!" : "lose!");
                spriteBatch.DrawString(text, message_text, new Vector2(((graphics.PreferredBackBufferWidth - text.MeasureString(message_text).X) / 2), graphics.PreferredBackBufferHeight * 4 / 5), Color.White);
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
Beispiel #3
0
        /// <summary>
        /// ワールドの更新、衝突判定、入力値の取得、オーディオの再生などの
        /// ゲーム ロジックを、実行します。
        /// </summary>
        /// <param name="gameTime">ゲームの瞬間的なタイミング情報</param>
        protected override void Update(GameTime gameTime)
        {
            // ゲームの終了条件をチェックします。
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            if (scene == SCENE.INIT)
            {
                Random rnd = new Random();
                int w = img[(int)IMG.OPEN_BOX].Width;
                int h = img[(int)IMG.OPEN_BOX].Height;
                int y = (graphics.PreferredBackBufferHeight - h) / 2;
                int x = (graphics.PreferredBackBufferWidth - (w * box.Length)) / 2;

                // 状態を初期化
                for (int i = 0; i < box.Length; i++)
                {
                    box[i] = new Box();
                    box[i].status = Box.STATUS.MISS;
                    box[i].rect.Width = w;
                    box[i].rect.Height = h;
                    box[i].rect.X = 60 + ((w + 40) * i);
                    box[i].rect.Y = y;
                }
                box[rnd.Next(0, box.Length - 1)].status = Box.STATUS.HIT;
                shuffleAnimations = new Queue<ShuffleAnimation>();
                scene = SCENE.READY;
            }
            else if (scene == SCENE.READY)
            {
                // タッチを検出
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gs = TouchPanel.ReadGesture();
                    if (gs.GestureType == GestureType.Tap)
                    {
                        // シャッフル
                        int[] shuffle;
                        int frameCount = 120 - ((level - 1) * 30);
                        int times = (3 + level > 8 ? 8 : 3 + level);
                        ShuffleAnimation anim;
                        for (int i = 0; i < times; i++)
                        {
                            anim = new ShuffleAnimation();
                            shuffle = Enumerable.Range(0, box.Length).ToArray().OrderBy(n => Guid.NewGuid()).ToArray();
                            anim.Initialize(img[(int)IMG.CLOSE_BOX], ref box[shuffle[0]], ref box[shuffle[1]], (frameCount < 20 ? 20 : frameCount), Color.White, 1.0f);
                            shuffleAnimations.Enqueue(anim);
                        }
                        animation = shuffleAnimations.Dequeue();
                        scene = SCENE.SHUFFLE;
                    }
                }
            }
            else if (scene == SCENE.SHUFFLE)
            {
                // シャッフルアニメーション処理
                if (animation.Active)
                {
                    animation.Update(gameTime.ElapsedGameTime);
                }
                if (shuffleAnimations.Count <= 0)
                {
                    scene = SCENE.SELECT;
                }
            }
            else if (scene == SCENE.SELECT)
            {
                Rectangle rect;

                // タッチを検出
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gs = TouchPanel.ReadGesture();
                    if (gs.GestureType == GestureType.Tap)
                    {
                        rect = new Rectangle((int)gs.Position.X, (int)gs.Position.Y, 10, 10);
                        for (int i = 0; i < box.Length; i++)
                        {
                            if (rect.Intersects(box[i].rect))
                            {
                                scene = (box[i].status == Box.STATUS.HIT ? SCENE.WIN : SCENE.LOSE);
                            }

                        }
                    }
                }
            }
            else if ((scene == SCENE.WIN) || (scene == SCENE.LOSE))
            {
                // タッチを検出
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gs = TouchPanel.ReadGesture();
                    if (gs.GestureType == GestureType.Tap)
                    {
                        if (scene == SCENE.WIN)
                        {
                            level++;
                        }
                        else
                        {
                            level = 1;
                        }
                        scene = SCENE.INIT;
                    }
                }
            }

            base.Update(gameTime);
        }
Beispiel #4
0
        /// <summary>
        /// ワールドの更新、衝突判定、入力値の取得、オーディオの再生などの
        /// ゲーム ロジックを、実行します。
        /// </summary>
        /// <param name="gameTime">ゲームの瞬間的なタイミング情報</param>
        protected override void Update(GameTime gameTime)
        {
            // ゲームの終了条件をチェックします。
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            if (scene == SCENE.INIT)
            {
                Random rnd = new Random();
                int    w   = img[(int)IMG.OPEN_BOX].Width;
                int    h   = img[(int)IMG.OPEN_BOX].Height;
                int    y   = (graphics.PreferredBackBufferHeight - h) / 2;
                int    x   = (graphics.PreferredBackBufferWidth - (w * box.Length)) / 2;

                // 状態を初期化
                for (int i = 0; i < box.Length; i++)
                {
                    box[i]             = new Box();
                    box[i].status      = Box.STATUS.MISS;
                    box[i].rect.Width  = w;
                    box[i].rect.Height = h;
                    box[i].rect.X      = 60 + ((w + 40) * i);
                    box[i].rect.Y      = y;
                }
                box[rnd.Next(0, box.Length - 1)].status = Box.STATUS.HIT;
                shuffleAnimations = new Queue <ShuffleAnimation>();
                scene             = SCENE.READY;
            }
            else if (scene == SCENE.READY)
            {
                // タッチを検出
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gs = TouchPanel.ReadGesture();
                    if (gs.GestureType == GestureType.Tap)
                    {
                        // シャッフル
                        int[]            shuffle;
                        int              frameCount = 120 - ((level - 1) * 30);
                        int              times      = (3 + level > 8 ? 8 : 3 + level);
                        ShuffleAnimation anim;
                        for (int i = 0; i < times; i++)
                        {
                            anim    = new ShuffleAnimation();
                            shuffle = Enumerable.Range(0, box.Length).ToArray().OrderBy(n => Guid.NewGuid()).ToArray();
                            anim.Initialize(img[(int)IMG.CLOSE_BOX], ref box[shuffle[0]], ref box[shuffle[1]], (frameCount < 20 ? 20 : frameCount), Color.White, 1.0f);
                            shuffleAnimations.Enqueue(anim);
                        }
                        animation = shuffleAnimations.Dequeue();
                        scene     = SCENE.SHUFFLE;
                    }
                }
            }
            else if (scene == SCENE.SHUFFLE)
            {
                // シャッフルアニメーション処理
                if (animation.Active)
                {
                    animation.Update(gameTime.ElapsedGameTime);
                }
                if (shuffleAnimations.Count <= 0)
                {
                    scene = SCENE.SELECT;
                }
            }
            else if (scene == SCENE.SELECT)
            {
                Rectangle rect;

                // タッチを検出
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gs = TouchPanel.ReadGesture();
                    if (gs.GestureType == GestureType.Tap)
                    {
                        rect = new Rectangle((int)gs.Position.X, (int)gs.Position.Y, 10, 10);
                        for (int i = 0; i < box.Length; i++)
                        {
                            if (rect.Intersects(box[i].rect))
                            {
                                scene = (box[i].status == Box.STATUS.HIT ? SCENE.WIN : SCENE.LOSE);
                            }
                        }
                    }
                }
            }
            else if ((scene == SCENE.WIN) || (scene == SCENE.LOSE))
            {
                // タッチを検出
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gs = TouchPanel.ReadGesture();
                    if (gs.GestureType == GestureType.Tap)
                    {
                        if (scene == SCENE.WIN)
                        {
                            level++;
                        }
                        else
                        {
                            level = 1;
                        }
                        scene = SCENE.INIT;
                    }
                }
            }

            base.Update(gameTime);
        }