Beispiel #1
0
 private void InitializeTripas()
 {
     Tripa tripa;
     Tripa tripaPair;
     for (int i = 0; i < 7; i++) {
         tripa = new Tripa(i.ToString(), ScreenManager.GraphicsDevice, ScreenManager.SpriteBatch);
         tripaPair = new Tripa(i.ToString(), ScreenManager.GraphicsDevice, ScreenManager.SpriteBatch);
         CheckRelocateTripaPosition(tripa);
         _tripas.Add(tripa);
         CheckRelocateTripaPosition(tripaPair);
         _tripas.Add(tripaPair);
         tripa.MatchingPair = tripaPair;
         tripaPair.MatchingPair = tripa;
     }
     tripa = null;
     tripaPair = null;
 }
Beispiel #2
0
        public void ResetGameScreen(bool resetScore)
        {
            _touchId = 0;
            _activeTripa = null;
            _touchedTripa = false;
            _tripas.Clear();
            _donePairs.Clear();
            _touchedPositions.Clear();
            _actualTouchedPositions.Clear();
            _vertices = _loneVertex;
            _indices = _loneIndex;
            if (resetScore)
            {
                Score = 0;
            }

            InitializeTripas();

            foreach (Tripa tripa in _tripas) {
                tripa.SetMarqueeTexture(_marquee);
                tripa.SetFont(_gameFont);
                tripa.SetSpriteBatch(ScreenManager.SpriteBatch);
                tripa.SetGraphicsDevice(ScreenManager.GraphicsDevice);
                tripa.LoadContent();
            }

            IsCoverable = false;
        }
Beispiel #3
0
 private void CheckRelocateTripaPosition(Tripa tripa)
 {
     bool reassign = true;
     while (reassign) {
         reassign = false;
         foreach (Tripa previousTripa in _tripas) {
             while (previousTripa.Area.Contains(tripa.Area) == ContainmentType.Intersects) {
                 tripa.Position = new Vector2(RandomGenerator.GetRandomNumber(95, 770), RandomGenerator.GetRandomNumber(95, 440));
                 tripa.Area = new BoundingSphere(new Vector3(tripa.Position, 0), 25.0f);
                 reassign = true;
             }
         }
     }
 }
Beispiel #4
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                ScreenManager.AddScreen(new GameplayPause("Pause!"), ControllingPlayer);
            }

            bool screenDone = false;
            foreach (Tripa tripa in _tripas)
            {
                screenDone = tripa.Done;
                if (!screenDone)
                {
                    break;
                }
            }

            if (screenDone)
            {
                IsCoverable = true;
                ScreenManager.AddScreen(new GameplaySuccess("Success!"), ControllingPlayer);
                return;
            }

            TouchCollection touchState = input.TouchState;

            if (touchState.Count == 0)
            {
                return;
            }

            foreach (TouchLocation touch in touchState)
            {
                if (touch.Position.X > 100.0f && touch.Position.Y > 100.0f)
                {
                    _touchId = touch.Id;
                }
            }

            touchState.FindById(_touchId, out touchLocation);

            if (touchLocation.State == TouchLocationState.Released)
            {
                _activeTripa = null;
                _touchedTripa = false;
                _touchId = 0;
                _touchedPositions.Clear();
                _actualTouchedPositions.Clear();
                _vertices = _loneVertex;
                _indices = _loneIndex;
                return;
            }

            if (touchLocation.State == TouchLocationState.Pressed)
            {
                foreach (Tripa tripa in _tripas)
                {
                    if (tripa.Area.Contains(new Vector3(touchLocation.Position, 0)) == ContainmentType.Contains)
                    {
                        if (tripa.Done)
                        {
                            break; // GAME OVER!!!
                        }

                        _activeTripa = tripa;
                        _touchedTripa = true;
                        _touchedPositions.Add(touchLocation.Position);
                        _actualTouchedPositions.Add(touchLocation.Position);
                        break;
                    }
                }
            }

            if (touchLocation.State == TouchLocationState.Moved)
            {
                if (!_touchedPositions.Contains(touchLocation.Position) &&
                    _touchedTripa)
                {
                    if (_activeTripa.Done)
                    {
                        return;
                    }

                    Vector2 point1 = _touchedPositions[_touchedPositions.Count - 1];
                    Vector2 point2 = touchLocation.Position;

                    Vector2 delta = point2 - point1;
                    float distance = delta.LengthSquared();
                    Vector2 direction = delta / distance;
                    Vector2 newPoint = new Vector2();

                    for (float i = 0.05f; i < 1.0f; i = i + 0.05f)
                    {
                        newPoint = point1 + direction * (distance * i);
                        _touchedPositions.Add(newPoint);
                    }

                    foreach (KeyValuePair<string, Path> pair in _donePairs)
                    {
                        Path path = pair.Value;
                        for (int i = 1; i < path.Vertices.Length; i++)
                        {
                            if (_actualTouchedPositions.Count > 1)
                            {
                                if (
                                    Helpers.LineIntersect(
                                        new Line(new Vector2(path.Vertices[i - 1].Position.X, path.Vertices[i - 1].Position.Y), new Vector2(path.Vertices[i].Position.X, path.Vertices[i].Position.Y)),
                                        new Line(_actualTouchedPositions[_actualTouchedPositions.Count - 1], touchLocation.Position)))
                                {
                                    IsCoverable = true;
                                    ScreenManager.AddScreen(new GameplayGameOver("Fail!"), ControllingPlayer);
                                    return;
                                }
                            }
                        }
                    }

                    for (int i = 1; i < _actualTouchedPositions.Count - 1; i++)
                    {
                        if (Helpers.LineIntersect(
                            new Line(_actualTouchedPositions[i - 1], _actualTouchedPositions[i]),
                            new Line(_actualTouchedPositions[_actualTouchedPositions.Count - 1], touchLocation.Position)))
                        {
                            IsCoverable = true;
                            ScreenManager.AddScreen(new GameplayGameOver("Fail!"), ControllingPlayer);
                            return;
                        }
                    }

                    foreach (Tripa otherTripa in _tripas)
                    {
                        if (otherTripa == _activeTripa ||
                            otherTripa == _activeTripa.MatchingPair)
                        {
                            continue;
                        }

                        if (otherTripa.Area.Contains(new Vector3(touchLocation.Position, 0)) == ContainmentType.Contains)
                        {
                            IsCoverable = true;
                            ScreenManager.AddScreen(new GameplayGameOver("Fail!"), ControllingPlayer);
                            return;
                        }

                    }

                    _touchedPositions.Add(touchLocation.Position);
                    _actualTouchedPositions.Add(touchLocation.Position);

                    if (_activeTripa.MatchingPair.TouchedPair(touchLocation.Position))
                    {
                        if (_donePairs.ContainsKey(_activeTripa.ScreenValue)) return;
                        _donePairs.Add(_activeTripa.ScreenValue, new Path(_actualTouchedPositions));
                        Score++;
                        /*foreach (IGameComponent component in ScreenManager.Game.Components) {
                            if (component is DuckieParticleManager) {
                                DuckieParticleManager particleManager = component as DuckieParticleManager;
                                DuckieParticleCluster particleCluster = new DuckieParticleCluster();
                                particleManager.AddParticleCluster(particleCluster);
                                particleManager.AddTexture("particle");
                                particleCluster.AddParticles(10);
                                particleCluster.OnClusterUpdate += new DuckieParticleCluster.DuckieParticleClusterUpdate(ParticleUpdate);
                            }
                        }*/
                    }
                }
            }

            _vertices = new VertexPositionColor[_actualTouchedPositions.Count];
            _indices = new short[_actualTouchedPositions.Count];

            for (int i = 0; i < _actualTouchedPositions.Count; i++)
            {
                _vertices[i] = new VertexPositionColor(new Vector3(_actualTouchedPositions[i], 0), Color.Black);
                _indices[i] = (short)i;
            }
        }