Beispiel #1
0
        public override bool OnCollision(Fixture f1, Fixture f2, Contact contact)
        {
            CollidingSprite other = SyncedGameCollection.GetCollisionComponent(f2);

            if (other.Tag == TagCategories.CRYSTAL)
            {
                if (Item == null)
                {
                    Crystal crystal = other as Crystal;
                    Item = crystal.PickUp(this, _teamColor);
                }
                return(false);
            }
            else if (other.Tag == TagCategories.UNIT)
            {
                return(false);
            }
            else if (other.Tag == TagCategories.COMPACTZONE)
            {
                if (Item == null)
                {
                    CompactZone compactzone = other as CompactZone;
                    Item = compactzone.PickUp(this, _teamColor);
                }
            }
            else if (other.Tag == TagCategories.BARRIER)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public override void Update(GameTime gameTime)
        {
            if (Enabled)
            {
                #region Input

                Left.Direction  = InputManager.LeftStickDirection(_playerIndex);
                Right.Direction = InputManager.RightStickDirection(_playerIndex);

                // Switch unit positions
                if (InputManager.IsButtonPressed(Buttons.LeftStick, _playerIndex) && InputManager.IsButtonPressed(Buttons.RightStick, _playerIndex) && !_haveSwitched)
                {
                    _haveSwitched = true;
                    Vector2 tmp = Left.Position;
                    Left.Position  = Right.Position;
                    Right.Position = tmp;
                }
                else if (!InputManager.IsButtonPressed(Buttons.LeftStick, _playerIndex) && !InputManager.IsButtonPressed(Buttons.RightStick, _playerIndex))
                {
                    _haveSwitched = false;
                }

                if (InputManager.IsButtonPressed(Buttons.LeftShoulder, _playerIndex))
                {
                    DetonateZones();
                    Left.Shoot();
                }

                if (InputManager.IsButtonPressed(Buttons.RightShoulder, _playerIndex))
                {
                    DetonateZones();
                    Right.Shoot();
                }

                if (InputManager.RightTriggerValue(_playerIndex) != 0.0f)
                {
                    Right.TrailParticleLifetime += (1.5f * InputManager.RightTriggerValue(_playerIndex));
                }
                if (InputManager.LeftTriggerValue(_playerIndex) != 0.0f)
                {
                    Left.TrailParticleLifetime += (1.5f * InputManager.LeftTriggerValue(_playerIndex));
                }
                _areTrailsActive = false;
                if ((InputManager.RightTriggerValue(_playerIndex) > 0.0f) && (InputManager.LeftTriggerValue(_playerIndex) > 0.0f))
                {
                    _areTrailsActive = true;
                }
                #endregion

                #region SpeedUp
                Left.Acceleration        = 40.0f;
                Right.Acceleration       = 40.0f;
                Left.UseEffectParticles  = false;
                Right.UseEffectParticles = false;
                if (AreTrailsActive && ConvertUnits.ToSimUnits(GetDistanceBetweenUnits()) < 2.0f)
                {
                    Left.Acceleration        = 70.0f;
                    Right.Acceleration       = 70.0f;
                    Left.UseEffectParticles  = true;
                    Right.UseEffectParticles = true;
                }
                //if (AreTrailsActive)
                //{
                //    if (ConvertUnits.ToSimUnits(GetDistanceBetweenUnits()) < 2.0f)
                //    {
                //        Left.Acceleration = 70.0f;
                //        Right.Acceleration = 70.0f;
                //        Left.UseEffectParticles = true;
                //        Right.UseEffectParticles = true;
                //    }
                //    else
                //    {
                //        Left.Acceleration = 40.0f;
                //        Right.Acceleration = 40.0f;
                //        Left.UseEffectParticles = false;
                //        Right.UseEffectParticles = false;
                //    }
                //}
                //else
                //{
                //    Left.Acceleration = 40.0f;
                //    Right.Acceleration = 40.0f;
                //    Left.UseEffectParticles = false;
                //    Right.UseEffectParticles = false;
                //}
                #endregion

                #region Barrier
                if (!isBarrierActive)
                {
                    if (CheckBarrierActivationCondition())
                    {
                        _barrier.Activated();
                        isBarrierActive = true;
                    }
                }
                else
                {
                    if (CheckBarrierDeactivationCondition())
                    {
                        _barrier.Deactivated();
                        isBarrierActive = false;
                    }
                }
                #endregion

                #region Zones
                if (InputManager.IsButtonPressed(Buttons.B, _playerIndex) && _canCreateZone) // TODO: Remove. This is for testing
                {
                    Vector2 spawnPosition = new Vector2((Left.RigidBody.Position.X + Right.RigidBody.Position.X) / 2.0f, (Left.RigidBody.Position.Y + Right.RigidBody.Position.Y) / 2.0f);
                    _compactZone = new CompactZone(Library.Zone.CompactTexture[shape], ConvertUnits.ToDisplayUnits(spawnPosition), DrawingHelper.DrawingLevel.Medium, Game, _world, Library.Colors.getColor[Tuple.Create(_teamColor, Library.Colors.ColorVariation.Other)], shape);
                    SyncedGameCollection.ComponentCollection.Add(_compactZone);
                    _compactZones.Add(_compactZone);
                    _canCreateZone = false;
                    Library.Audio.PlaySoundEffect(Library.Audio.SoundEffects.ZoneSpawn);
                }

                for (int i = 0; i < _compactZones.Count; i++)
                {
                    if (_compactZones[i].UpdateCompactZone())
                    {
                        CreateZone(_compactZones[i].Shape, _compactZones[i].SimPosition, _compactZones[i].Rotation, _compactZones[i].Color);
                        _compactZones[i].Detonate();
                        _compactZones.RemoveAt(i);
                        i--;
                    }
                }
                #endregion

                _zoneCreationCooldown -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (_zoneCreationCooldown <= 0)
                {
                    Left.TrailEngine.ParticleColor  = Library.Colors.getColor[Tuple.Create(_teamColor, Library.Colors.ColorVariation.Left)];
                    Right.TrailEngine.ParticleColor = Library.Colors.getColor[Tuple.Create(_teamColor, Library.Colors.ColorVariation.Right)];
                    _canCreateZone        = true;
                    _zoneCreationCooldown = 10.0f;
                }
            }
        }