示例#1
0
        public TurretPlaceholder(Vector2 worldPosition, TurretDirection direction, IPlayer builder)
        {
            OriginalBuilder = builder;
            Team            = builder.GetTeam();
            Direction       = direction;
            IsRemoved       = false;

            var dir = (direction == TurretDirection.Left) ? -1 : 1;

            var ux = Vector2.UnitX * -dir;
            var uy = Vector2.UnitY;

            // worldPosition works best when get from player.GetWorldPosition()
            Position = worldPosition - ux * 10 + uy * 9;
            m_placeholderBgPosition = Position - Vector2.UnitX * (Direction > 0 ? 5 : 3) - uy * 1;
            var legLeft1Position   = Position - ux * 3 + uy * 1;
            var legLeft2Position   = Position - ux * 6 - uy * 5;
            var legRight1Position  = Position + ux * 1 - uy * 5;
            var legRight2Position  = Position + ux * 5 - uy * 13;
            var legMiddle1Position = Position - ux * 1.8f - uy * 3;
            var legMiddle2Position = Position - ux * 1.8f - uy * 6;

            var placeholderBg = Game.CreateObject("BgFrame00B", m_placeholderBgPosition);
            var legMiddle1    = (IObjectActivateTrigger)Game.CreateObject("Lever01", legMiddle1Position, -dir * 0.41f);
            var legMiddle2    = (IObjectActivateTrigger)Game.CreateObject("Lever01", legMiddle2Position, -dir * 0.41f);
            var legLeft1      = (IObjectActivateTrigger)Game.CreateObject("Lever01", legLeft1Position);
            var legLeft2      = (IObjectActivateTrigger)Game.CreateObject("Lever01", legLeft2Position);
            var legRight1     = (IObjectActivateTrigger)Game.CreateObject("Lever01", legRight1Position, MathHelper.PI);
            var legRight2     = (IObjectActivateTrigger)Game.CreateObject("Lever01", legRight2Position, MathHelper.PI);

            m_ground = Turret.GetGround(Position);

            legMiddle1.SetEnabled(false);
            legMiddle2.SetEnabled(false);
            legLeft1.SetEnabled(false);
            legLeft2.SetEnabled(false);
            legRight1.SetEnabled(false);
            legRight2.SetEnabled(false);

            legLeft1.SetFaceDirection(-dir);
            legLeft2.SetFaceDirection(-dir);
            legRight1.SetFaceDirection(dir);
            legRight2.SetFaceDirection(dir);
            legMiddle1.SetFaceDirection(-dir);
            legMiddle2.SetFaceDirection(-dir);

            placeholderBg.SetSizeFactor(new Point(2, 2));

            m_components.Add(placeholderBg); legMiddle1.CustomID = "PlaceholderBg";
            m_components.Add(legMiddle1); legMiddle1.CustomID    = "LegMiddle1";
            m_components.Add(legMiddle2); legMiddle2.CustomID    = "LegMiddle2";
            m_components.Add(legLeft1); legLeft1.CustomID        = "LegLeft1";
            m_components.Add(legLeft2); legLeft2.CustomID        = "LegLeft2";
            m_components.Add(legRight1); legRight1.CustomID      = "LegRight1";
            m_components.Add(legRight2); legRight2.CustomID      = "LegRight2";
        }
示例#2
0
        public static TurretPlaceholder CreateTurretPlaceholder(IPlayer player, TurretDirection direction)
        {
            var placeholder = new TurretPlaceholder(player.GetWorldPosition(), direction, player);

            m_turretPlaceholders.Add(placeholder.UniqueID, new TurretPlaceholderInfo()
            {
                Builder     = player,
                Placeholder = placeholder,
            });
            return(placeholder);
        }
        private void StartBuildingTurret(TurretDirection direction)
        {
            Player.SetInputEnabled(false);
            if (Player.CurrentWeaponDrawn != WeaponItemType.Melee)
            {
                Player.AddCommand(new PlayerCommand(PlayerCommandType.DrawMelee));
            }
            Player.AddCommand(new PlayerCommand(PlayerCommandType.Walk, direction == TurretDirection.Left ?
                                                PlayerCommandFaceDirection.Left : PlayerCommandFaceDirection.Right, 10));

            m_state = EngineerState.PreBuilding;
        }
示例#4
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        Debug.DrawLine(_outputTest[0], _outputTest[1], Color.red);

        var mainJobChain = new CameraEndpoint
        {
            CollisionWorld = World.DefaultGameObjectInjectionWorld
                             .GetExistingSystem <BuildPhysicsWorld>().PhysicsWorld.CollisionWorld,
            CameraLocation  = _mainCamTransform.position,
            CameraDirection = _mainCamTransform.forward,
            Endpoint        = _cameraEndpoint
        }.Schedule(inputDeps);

        mainJobChain = new TurretDirection
        {
            Endpoint   = _cameraEndpoint,
            DeltaTime  = Time.DeltaTime,
            OutputTest = _outputTest
        }.ScheduleSingle(_turrets, mainJobChain);

        return(mainJobChain);
    }
示例#5
0
        public void Draw(SpriteBatch sb)
        {
            //Add draw Methods for each enemy here
            if (EnemyType == "Tank")
            {
                sb.Draw(Bottom, new Vector2(ScreenPos.X, ScreenPos.Y), null, Color.White, Direction.ToAngle(), new Vector2(Art.TankBottom.Width / 2, Art.TankBottom.Height / 2), 1f, SpriteEffects.None, 0);
                sb.Draw(Top, new Vector2(ScreenPos.X, ScreenPos.Y), null, Color.White, TurretDirection.ToAngle(), new Vector2(Art.TankTop.Width / 5, Art.TankTop.Height / 2), 1f, SpriteEffects.None, 0);
            }

            else if (EnemyType == "Transport")
            {
                sb.Draw(Bottom, new Vector2(ScreenPos.X, ScreenPos.Y), null, Color.White, Direction.ToAngle(), new Vector2(Art.Transport.Width / 2, Art.Transport.Height / 2), 1f, SpriteEffects.None, 0);
            }

            else if (EnemyType == "Jeep")
            {
                sb.Draw(Bottom, new Vector2(ScreenPos.X, ScreenPos.Y), null, Color.White, Direction.ToAngle(), new Vector2(Art.JeepBottom.Width / 2, Art.JeepBottom.Height / 2), 1f, SpriteEffects.None, 0);
                sb.Draw(Top, new Vector2(ScreenPos.X - Direction.X * Art.JeepBottom.Width / 3, ScreenPos.Y - Direction.Y * Art.JeepBottom.Width / 3), null, Color.White, TurretDirection.ToAngle(), new Vector2(Art.JeepTop.Width / 4, Art.JeepTop.Height / 2), 1f, SpriteEffects.None, 0);
            }

            else if (EnemyType == "Soldier")
            {
                sb.Draw(Bottom, new Vector2(ScreenPos.X, ScreenPos.Y), SourceRect, Color.White, Direction.ToAngle(), new Vector2(SourceRect.Width / 2, SourceRect.Height / 2), 1f, SpriteEffects.None, 0);
            }

            else if (EnemyType == "Helicopter")
            {
                sb.Draw(Bottom, new Vector2(ScreenPos.X, ScreenPos.Y), SourceRect, Color.White, Direction.ToAngle(), new Vector2(SourceRect.Width / 2, SourceRect.Height / 2), 1f, SpriteEffects.None, 0);
            }
        }
示例#6
0
 public static void SpawnTurret(IPlayer owner, Vector2 position, TurretDirection direction)
 {
     m_weapons.Add(new Turret(position, direction, owner));
 }
示例#7
0
        public Turret(Vector2 worldPosition, TurretDirection direction, IPlayer owner = null)
        {
            Direction   = (direction == TurretDirection.Left) ? -1 : 1;
            Owner       = owner;
            Team        = owner.GetTeam();
            IsDestroyed = false;

            var ux = Vector2.UnitX * -Direction;
            var uy = Vector2.UnitY;

            // worldPosition works best when get from TurretPlaceholder.Position
            RotationCenter = worldPosition;
            var legLeft1Position      = RotationCenter - ux * 4 + uy * 1;
            var legLeft2Position      = RotationCenter - ux * 7 - uy * 5;
            var legRight1Position     = RotationCenter + ux * 0 - uy * 5;
            var legRight2Position     = RotationCenter + ux * 4 - uy * 13;
            var legMiddle1Position    = RotationCenter - ux * 2.8f - uy * 3;
            var legMiddle2Position    = RotationCenter - ux * 2.8f - uy * 6;
            var ammoPosition          = RotationCenter + ux * 2 - uy * 2;
            var comp1Position         = RotationCenter - ux * 5 + uy * 2;
            var controllerPosition    = RotationCenter + ux * 0 + uy * 1;
            var sensorPosition        = RotationCenter + ux * 5 + uy * 2;
            var rotorPosition         = RotationCenter + ux * 0 - uy * 1;
            var barrelSolid1Position  = RotationCenter - ux * 8 - uy * 2;
            var barrelSolid2Position  = RotationCenter - ux * 16 - uy * 2;
            var barrelPosition        = RotationCenter - ux * 6 + uy * 2;
            var tipPosition           = RotationCenter - ux * 24 + uy * 0;
            var teamIndicatorPosition = RotationCenter - ux * 11f - uy * 1;

            // Object creation order is important. It will determine the z-layer the object will be located to
            var teamIndicator = Game.CreateObject("BgBottle00D", teamIndicatorPosition, -Direction * MathHelper.PIOver2);

            teamIndicator.SetColor1(GetColor(owner.GetTeam()));

            var legMiddle1 = (IObjectActivateTrigger)Game.CreateObject("Lever01", legMiddle1Position, -Direction * 0.41f);
            var legMiddle2 = (IObjectActivateTrigger)Game.CreateObject("Lever01", legMiddle2Position, -Direction * 0.41f);
            var legLeft1   = (IObjectActivateTrigger)Game.CreateObject("Lever01", legLeft1Position);
            var legLeft2   = (IObjectActivateTrigger)Game.CreateObject("Lever01", legLeft2Position);
            var legRight1  = (IObjectActivateTrigger)Game.CreateObject("Lever01", legRight1Position, MathHelper.PI);
            var legRight2  = (IObjectActivateTrigger)Game.CreateObject("Lever01", legRight2Position, MathHelper.PI);
            var ammo       = (IObjectActivateTrigger)Game.CreateObject("AmmoStash00", ammoPosition);

            var comp1 = Game.CreateObject("ItemDebrisDark00", comp1Position);

            m_controller = new Component("ItemDebrisShiny00", controllerPosition);
            m_sensor     = new Component("ItemDebrisDark00", sensorPosition);
            m_rotor      = new Component("MetalDebris00A", rotorPosition);

            var barrel1 = Game.CreateObject("MetalPlat01A", barrelSolid1Position);
            var barrel2 = Game.CreateObject("MetalPlat01B", barrelSolid2Position);

            m_barrel = new Component("JusticeStatue00Scales", barrelPosition);
            m_tip    = Game.CreateObject("LedgeGrab", tipPosition);
            m_ground = GetGround(RotationCenter);

            legMiddle1.SetEnabled(false);
            legMiddle2.SetEnabled(false);
            legLeft1.SetEnabled(false);
            legLeft2.SetEnabled(false);
            legRight1.SetEnabled(false);
            legRight2.SetEnabled(false);
            ammo.SetEnabled(false);

            legLeft1.SetFaceDirection(-Direction);
            legLeft2.SetFaceDirection(-Direction);
            legRight1.SetFaceDirection(Direction);
            legRight2.SetFaceDirection(Direction);
            legMiddle1.SetFaceDirection(-Direction);
            legMiddle2.SetFaceDirection(-Direction);

            ammo.SetFaceDirection(-Direction);
            barrel1.SetFaceDirection(-Direction);
            barrel2.SetFaceDirection(-Direction);
            m_barrel.Object.SetFaceDirection(-Direction);
            m_tip.SetFaceDirection(-Direction);
            comp1.SetFaceDirection(-Direction);
            m_controller.Object.SetFaceDirection(-Direction);
            m_sensor.Object.SetFaceDirection(-Direction);
            m_rotor.Object.SetFaceDirection(-Direction);
            teamIndicator.SetFaceDirection(-Direction);

            m_bodyJoint          = (IObjectWeldJoint)Game.CreateObject("WeldJoint");
            m_alterCollisionTile = (IObjectAlterCollisionTile)Game.CreateObject("AlterCollisionTile");

            legMiddle1.CustomID    = "TurretLegMiddle1";
            legMiddle2.CustomID    = "TurretLegMiddle2";
            legLeft1.CustomID      = "TurretLegLeft1";
            legLeft2.CustomID      = "TurretLegLeft2";
            legRight1.CustomID     = "TurretLegRight1";
            legRight2.CustomID     = "TurretLegRight2";
            ammo.CustomID          = "TurretAmmo";
            barrel1.CustomID       = "TurretBarrel1";
            barrel2.CustomID       = "TurretBarrel2";
            m_barrel.CustomID      = "TurretBarrel3";
            m_tip.CustomID         = "TurretTip";
            teamIndicator.CustomID = "TurretTeamIndicator";
            comp1.CustomID         = "TurretComp1";
            m_controller.CustomID  = "TurretController";
            m_sensor.CustomID      = "TurretSensor";
            m_rotor.CustomID       = "TurretRotor";

            m_components.Add(legMiddle1.CustomID, legMiddle1);
            m_components.Add(legMiddle2.CustomID, legMiddle2);
            m_components.Add(legLeft1.CustomID, legLeft1);
            m_components.Add(legLeft2.CustomID, legLeft2);
            m_components.Add(legRight1.CustomID, legRight1);
            m_components.Add(legRight2.CustomID, legRight2);
            m_components.Add(ammo.CustomID, ammo);
            m_components.Add(barrel1.CustomID, barrel1);
            m_components.Add(barrel2.CustomID, barrel2);
            m_components.Add(m_barrel.CustomID, m_barrel.Object);
            m_components.Add(m_tip.CustomID, m_tip);
            m_components.Add(teamIndicator.CustomID, teamIndicator);
            m_components.Add(comp1.CustomID, comp1);
            m_components.Add(m_controller.CustomID, m_controller.Object);
            m_components.Add(m_sensor.CustomID, m_sensor.Object);
            m_components.Add(m_rotor.CustomID, m_rotor.Object);

            // The reason I randomize health for each part is because bullets will likely shoot
            // through all the parts at once, so part with lowest hp will be destroyed first,
            // which is predictable, which is bad
            var healths = RandomHelper.Shuffle(new List <float>()
            {
                50, 100, 125, 150
            });

            m_barrel.MaxHealth     = healths[0];
            m_rotor.MaxHealth      = healths[1];
            m_sensor.MaxHealth     = healths[2];
            m_controller.MaxHealth = healths[3];

            m_damageableComponents.Add(m_barrel);
            m_damageableComponents.Add(m_rotor);
            m_damageableComponents.Add(m_sensor);
            m_damageableComponents.Add(m_controller);

            foreach (var dc in m_damageableComponents)
            {
                dc.RemoveWhenDestroyed = false;
            }

            foreach (var component in m_components.Values)
            {
                RegisterComponent(component);
            }

            m_alterCollisionTile.SetDisableCollisionTargetObjects(true);
            RotateTo(Direction > 0 ? 0 : MathHelper.PI);
        }
示例#8
0
        public override void Move(CVGameTime gameTime)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            TimeSinceLastMove += elapsedTime;

            // do nothing
            Player nearestPlayer = (Player)TargetingLogic.FindNearest(this.WorldPosition, CurrentStage.Players);

            AngleBetweenTurretAndPlayer = TargetingLogic.FindClockPosition(this.WorldPosition, nearestPlayer.BoundingBox().Center.ToVector());

            if (AngleBetweenTurretAndPlayer != _currentPosition)
            {
                if (TimeSinceLastMove > TurretMoveDelay)
                {
                    //TimeSinceLastMove -= TurretMoveDelay;
                    TimeSinceLastMove = 0;

                    //float currentTurretAngle = iCurrentPosition * 30;
                    int iCounterDistance = 0;
                    if (_currentPosition < AngleBetweenTurretAndPlayer)
                    {
                        iCounterDistance = 12 - (int)AngleBetweenTurretAndPlayer + _currentPosition;
                    }
                    else
                    {
                        iCounterDistance = _currentPosition - (int)AngleBetweenTurretAndPlayer;
                    }

                    if (iCounterDistance < 6)
                    {
                        TurretTurnDirection = TurretDirection.CounterClockWise;
                    }
                    else
                    {
                        TurretTurnDirection = TurretDirection.Clockwise;
                    }

                    _currentPosition += (int)TurretTurnDirection;
                    if (_currentPosition == 12)
                    {
                        _currentPosition = 0;
                    }
                    else if (_currentPosition == -1)
                    {
                        _currentPosition = 11;
                    }
                }
            }
            else
            {
                TurretTurnDirection = TurretDirection.TargetFound;
                TimeTargetLocked   += elapsedTime;
                if (TimeTargetLocked > TurretFireDelay)
                {
                    TimeTargetLocked = 0.0f;
                    _gun.AddProjectile(this.CurrentStage, GunBarrelLocation(), _currentPosition * 30, 2f);
                }
            }

            //float f = AngleBetweenTurretAndPlayer - currentTurretAngle;

            //currentTurretDirection = (TurretDirection) Math.Sign(-f % 360 - f % 360);
        }