Example #1
0
        public static void SpawnShot(ShotSpawnData data)
        {
            var settings = TwoStickBootstrap.Settings;
            var prefab   = data.Faction.Value == Faction.Type.Player
                ? settings.PlayerShotPrefab
                : settings.EnemyShotPrefab;
            var newShot = Object.Instantiate(prefab);

            var shotPos = newShot.GetComponent <Position2D>();

            shotPos.Value = data.Position;
            var shotHeading = newShot.GetComponent <Heading2D>();

            shotHeading.Value = data.Heading;

            var shotFaction = newShot.GetComponent <Faction>();

            shotFaction.Value = data.Faction.Value;
        }
        protected override void OnUpdate()
        {
            if (m_Data.Length == 0)
            {
                return;
            }

            var settings = TwoStickBootstrap.Settings;

            float dt            = Time.deltaTime;
            var   firingPlayers = new List <GameObject>();

            for (int index = 0; index < m_Data.Length; ++index)
            {
                var position = m_Data.Position[index];
                var heading  = m_Data.Heading[index];

                var playerInput = m_Data.Input[index];

                position.Value += dt * playerInput.Move * settings.playerMoveSpeed;

                if (playerInput.Fire)
                {
                    heading.Value            = math.normalize(playerInput.Shoot);
                    playerInput.FireCooldown = settings.playerFireCoolDown;

                    firingPlayers.Add(m_Data.GameObject[index]);
                }
            }

            foreach (var player in firingPlayers)
            {
                var newShotData = new ShotSpawnData()
                {
                    Position = player.GetComponent <Position2D>().Value,
                    Heading  = player.GetComponent <Heading2D>().Value,
                    Faction  = player.GetComponent <Faction>()
                };

                ShotSpawnSystem.SpawnShot(newShotData);
            }
        }
Example #3
0
        protected override void OnUpdate()
        {
            if (m_Player.Length == 0)
            {
                return;
            }

            var playerPos = m_Player.Position[0].Value;

            var shotSpawnData = new List <ShotSpawnData>();

            float dt        = Time.deltaTime;
            float shootRate = TwoStickBootstrap.Settings.enemyShootRate;

            for (int i = 0; i < m_Data.Length; ++i)
            {
                var state = m_Data.ShootState[i];

                state.Cooldown -= dt;
                if (state.Cooldown <= 0.0)
                {
                    state.Cooldown = shootRate;
                    var position = m_Data.Position[i].Value;

                    ShotSpawnData spawn = new ShotSpawnData()
                    {
                        Position = position,
                        Heading  = math.normalize(playerPos - position),
                        Faction  = TwoStickBootstrap.Settings.EnemyFaction
                    };
                    shotSpawnData.Add(spawn);
                }
            }

            foreach (var spawn in shotSpawnData)
            {
                ShotSpawnSystem.SpawnShot(spawn);
            }
        }