public void Initialize(Texture2D texture, ref Box leftBox, ref Box rightBox, int frameCount, Color color, float scale) { this.color = color; this.scale = scale; this.LeftBox = leftBox; this.RightBox = rightBox; this.frameCount = frameCount; spriteStrip = texture; Active = true; currentFrame = 0; left = new Vector2(leftBox.rect.X, leftBox.rect.Y); right = new Vector2(rightBox.rect.X, rightBox.rect.Y); step = (right.X - left.X) / frameCount; }
public Boolean isShuffle(Box target) { return (LeftBox.Equals(target) || RightBox.Equals(target)); }
/// <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); }