예제 #1
0
파일: Level.cs 프로젝트: Diogo45/CargoHell
    public static Vector3 CorrectViewportPosition(EnemyConfig enemy)
    {
        var pos = enemy.viewportPosition;

        if (Mathf.Round(Mathf.Abs(enemy.direction.x)) != 0.0f)
        {
            if (pos.x > 0.5f)
            {
                pos.x += 0.1f;
            }
            else if (pos.x < 0.5f)
            {
                pos.x -= 0.1f;
            }
        }
        else if (Mathf.Round(Mathf.Abs(enemy.direction.y)) != 0.0f)
        {
            if (pos.y > 0.5f)
            {
                pos.y += 0.1f;
            }
            else if (pos.y < 0.5f)
            {
                pos.y -= 0.1f;
            }
        }

        return(pos);
    }
예제 #2
0
    private bool TryPickRandomPositionToSpawn(EnemyConfig enemyConfig, out Vector3 position)
    {
        var triesLeft = 8;

        while (enemyConfig != null && triesLeft-- > 0)
        {
            // This is assuming the player is in the origin.

            var distance = UnityEngine.Random.Range(_activeConfig.minSpawnDistanceFromPlayer, _activeConfig.maxSpawnDistanceFromPlayer);
            var angle    = UnityEngine.Random.Range(0f, 360f) * Mathf.PI / 180f;
            var sin      = Mathf.Sin(angle) * distance;
            var cos      = Mathf.Cos(angle) * distance;

            var centreHeight = enemyConfig.edgeSize / 2f;

            _candidateSpawnPositions[0] = new Vector3(cos, centreHeight, sin);
            _candidateSpawnPositions[1] = new Vector3(sin, centreHeight, -cos);
            _candidateSpawnPositions[2] = new Vector3(-cos, centreHeight, -sin);
            _candidateSpawnPositions[3] = new Vector3(-sin, centreHeight, cos);

            foreach (var candidatePosition in _candidateSpawnPositions)
            {
                if (CanSpawnEnemyAt(enemyConfig, candidatePosition))
                {
                    position = candidatePosition;
                    return(true);
                }
            }
        }

        position = Vector3.zero;

        return(false);
    }
예제 #3
0
        //Our enemy factory machine
        public static EnemyAbstractFactory MakeFactory(EnemyConfig enemy)
        {
            //Make our abstract factory object to return
            EnemyAbstractFactory factory = null;

            //Find out what type of enemy we're dealing with and return the appropriate factory
            switch (enemy.enemyType)
            {
            case EnemyType.EnemyA:
                factory = new EnemyAFactory();
                break;

            case EnemyType.EnemyB:
                factory = new EnemyBFactory();
                break;

            case EnemyType.MidBoss:
                factory = new MidBossFactory();
                break;

            case EnemyType.FinalBoss:
                factory = new FinalBossFactory();
                break;
            }

            return(factory);
        }
예제 #4
0
 // Constructor
 public SpawnEnemyB(BulletManager bulletManager, GameData gameData)
 {
     this.bulletManager  = bulletManager;
     this._reciever      = gameData.EnemyBFact;
     this._myGameData    = gameData;
     this._myEnemyConfig = null;
 }
예제 #5
0
    public LevelConfig()
    {
        WorldScreenHeight = Camera.main.orthographicSize * 2f;
        WorldScreenWidth  = WorldScreenHeight / Screen.height * Screen.width;

        PlayerConfig       = new PlayerConfig();
        PlayerConfig.Scale = WorldScreenWidth * PlayerConfig.Scale;
        PlayerConfig.Speed = WorldScreenWidth * PlayerConfig.Speed;

        LocationConfig        = new LocationConfig();
        LocationConfig.Height = WorldScreenHeight * 2 * LocationConfig.Height;
        LocationConfig.Width  = WorldScreenWidth * 2 * LocationConfig.Width;

        CameraConfig            = new CameraConfig();
        CameraConfig.BorderMove = 1 - 2 * CameraConfig.BorderMove;

        EnemyConfig                = new EnemyConfig();
        EnemyConfig.Scale          = WorldScreenWidth * EnemyConfig.Scale;
        EnemyConfig.Speed          = WorldScreenWidth * EnemyConfig.Speed;
        EnemyConfig.AggroRadius    = WorldScreenWidth * EnemyConfig.AggroRadius;
        EnemyConfig.BounceDistance = WorldScreenWidth * EnemyConfig.BounceDistance;

        ProjectileConfig        = new ProjectileConfig();
        ProjectileConfig.Width  = WorldScreenWidth * ProjectileConfig.Width;
        ProjectileConfig.Height = WorldScreenWidth * ProjectileConfig.Height;
        ProjectileConfig.Speed  = WorldScreenWidth * ProjectileConfig.Speed;
    }
예제 #6
0
        //Load enemy based on JSON using a configuration
        protected void Load(Enemy enemy, EnemyConfig enemyConfiguration, Vector2 origin)
        {
            //Set enemy starting position
            //Enemy is randomly spawned
            if (enemyConfiguration.randomSpawn == 1)
            {
                enemy.Position = enemy.GetRandomSpawnPosition(enemyConfiguration.spawnInterval);
            }
            else
            {
                enemy.Position = new Vector2((float)origin.X, (float)origin.Y);
            }

            //Load enemy attributes
            enemy.MaxHealth       = enemyConfiguration.health;
            enemy.FireRate        = enemyConfiguration.fireRate;
            enemy.Velocity        = enemyConfiguration.velocity;
            enemy.Health          = enemyConfiguration.health;
            enemy.MovementPattern = enemyConfiguration.movementPattern;

            //Set movement
            if (enemy.MovementPattern != MovementPattern.None)
            {
                this.factory = MovementFactory.MakeFactory(enemy.MovementPattern);
                Movement movement = this.factory.Create(enemy.Position, new Vector2((float)enemyConfiguration.direction.X, (float)enemyConfiguration.direction.Y), (float)enemy.Velocity);
                enemy.Movement = movement;
            }
        }
예제 #7
0
    private void OnGUI()
    {
        enemyScriptable = (EnemyConfig)EditorGUILayout.ObjectField(enemyScriptable, typeof(EnemyConfig), false);


        if (GUI.Button(new Rect(30, 30, 50, 30), "Load"))
        {
            EnemyEditorWindow enemyEditorWindow = (EnemyEditorWindow)GetWindow(typeof(EnemyEditorWindow));

            if (enemyScriptable != null)
            {
                enemyEditorWindow.enemyName  = enemyScriptable.enemyName;
                enemyEditorWindow.health     = enemyScriptable.health;
                enemyEditorWindow.damage     = enemyScriptable.damage;
                enemyEditorWindow.speed      = enemyScriptable.speed;
                enemyEditorWindow.melee      = enemyScriptable.melee;
                enemyEditorWindow.flyMonster = enemyScriptable.flyMonster;
                enemyEditorWindow.head       = enemyScriptable.head;
                enemyEditorWindow.body       = enemyScriptable.body;
                enemyEditorWindow.leftArm    = enemyScriptable.leftArm;
                enemyEditorWindow.rightArm   = enemyScriptable.rightArm;
            }

            enemyEditorWindow.Show();
            Close();
        }
    }
예제 #8
0
    private void SpawnAndSetupComposingCubes(EnemyConfig config)
    {
        var unitCubeLength     = config.edgeSize / config.sectionCount;
        var halfUnitCubeLength = unitCubeLength / 2f;

        var delta  = (config.sectionCount - 1) * halfUnitCubeLength;
        var startP = -CachedTransform.forward * delta - CachedTransform.right * delta - CachedTransform.up * delta;

        var right = CachedTransform.right * unitCubeLength;
        var back  = CachedTransform.forward * unitCubeLength;
        var up    = CachedTransform.up * unitCubeLength;

        var partScale = new Vector3(unitCubeLength, unitCubeLength, unitCubeLength);

        for (int i = 0; i < config.sectionCount; ++i)
        {
            for (int j = 0; j < config.sectionCount; ++j)
            {
                for (int k = 0; k < config.sectionCount; ++k)
                {
                    var v    = startP + right * k + up * j + back * i;
                    var cube = Instantiate <EnemyComposingPart>(bodyPartPrototype, CachedTransform.position + v,
                                                                CachedTransform.rotation, CachedTransform);

                    cube.CachedTransform.localScale = partScale;
                    SetupComposingPart(cube, config);
                }
            }
        }
    }
예제 #9
0
 private void SetupDamageOnImpact(EnemyConfig config)
 {
     if (dealDamageOnImpact != null)
     {
         dealDamageOnImpact.damage = config.damageOnImpact;
     }
 }
예제 #10
0
 private void SetupBody(EnemyConfig config)
 {
     body.Setup(config);
     body.OnHitPointsChanged          += HandleHpChanged;
     body.dealDamageOnImpact.OnImpact += HandleImpact;
     body.SetVisible(false);
 }
예제 #11
0
 public EnemyController(EnemyMaster enemyAIMaster, EnemyConfig aIConfig, EnemyData aIData)
 {
     this.enemyAIMaster = enemyAIMaster;
     this.aIConfig      = aIConfig;
     this.aIData        = aIData;
     Initialize();
 }
예제 #12
0
    void SetRandomColor(EnemyConfig config)
    {
        int randomColorIndex = Random.Range(0, config.numberOfColors);

        enemyData.colorIndex      = randomColorIndex;
        enemySpriteRenderer.color = config.availableColors[randomColorIndex];
    }
예제 #13
0
 public void setSpawnSequence(
     int index, float aguarde, int qtd, EnemyFactory factory, EnemyConfig enemy
     )
 {
     spawnSequences[index] = new EnemySpawnSequenceCompiler(
         aguarde, qtd, factory, enemy
         );
 }
예제 #14
0
 private void OnEnemyKilled(EnemyConfig config)
 {
     enemiesKilled++;
     if (config.Equals(level.titanConfig))
     {
         StartCoroutine(WaitAndWin());
     }
 }
예제 #15
0
 public Enemy Get(EnemyType type)
 {
     EnemyConfig config = GetConfig(type);
     Enemy instance = CreateGameObjectInstance(config.prefab);
     instance.OriginFactory = this;
     instance.Initialize(config.scale.RandomValueInRange, config.speed.RandomValueInRange, config.pathOffset.RandomValueInRange, config.health.RandomValueInRange);
     return instance;
 }
예제 #16
0
    public EnemyConfig Clone()
    {
        EnemyConfig conf = new EnemyConfig();

        conf.ammount = ammount;
        conf.enemy   = enemy;
        return(conf);
    }
예제 #17
0
        public EnemyData(EnemyConfig config)
        {
            Config = config;
            Hp     = new ReactiveProperty <int>(config.lifeAmount);
            var hpProperty = Hp.Select(x => x <= 0);

            IsDead = hpProperty.ToReactiveProperty();
        }
예제 #18
0
    public void SetData(EnemyConfig config, Vector2Int index)
    {
        enemyData             = new EnemyData();
        enemyData.lives       = config.lives;
        enemyData.bulletSpeed = config.bulletSpeed;
        enemyData.indexPos    = index;

        SetRandomColor(config);
    }
예제 #19
0
    public Enemy Get(EnemyType type = EnemyType.Medium)
    {
        EnemyConfig config   = GetConfig(type);
        Enemy       instance = CreateGameObjectInstance(config.prefab);

        instance.OriginFactory = this;
        instance.Initialize(config.health, config.gold);
        Enemy.instanceCount += 1;
        return(instance);
    }
예제 #20
0
    public void Setup(EnemyConfig config)
    {
        SpawnAndSetupComposingCubes(config);

        dealDamageOnImpact.BoxCollider.size = new Vector3(config.edgeSize, config.edgeSize, config.edgeSize);
        dealDamageOnImpact.damage           = config.damageOnImpact;

        _hp    = config.hitPointsPerPart * config.composingPartCount;
        _maxHP = _hp;
    }
예제 #21
0
        public void Init(EnemyConfig config, Damagable targetBase)
        {
            _damagable.CurrentHP   = config.hp;
            _damager.CurrentDamage = config.damage;
            _goldForKill           = config.goldForKill;

            _goldForKill = config.goldForKill;

            _damager.CurrentDamagable = targetBase;
        }
 public EnemySpawnSequenceCompiler(
     float aguarde, int qtd, EnemyFactory factory,
     EnemyConfig enemy
     )
 {
     this.enemy    = enemy;
     this.cooldown = aguarde * 2f;
     this.amount   = qtd;
     this.factory  = factory;
 }
예제 #23
0
    public void Initialize(Action <Collision2D> onCollisionEnter, EnemyConfig config)
    {
        _onCollisionEnter = onCollisionEnter;

        float ratioScale = config.Size / GetComponent <SpriteRenderer>().sprite.bounds.size.x;

        transform.localScale    = new Vector3(ratioScale, ratioScale, 1);
        transform.localPosition = Vector3.zero;
        BodyBounds = GetComponent <Collider2D>().bounds;
    }
예제 #24
0
 public EnemyConfig(EnemyConfig ec, string hval)      // clumsy but fast fix for the lesson that structs are immutable...
 {
     movementType    = ec.movementType;
     shootType       = ec.shootType;
     position        = ec.position;
     shotDelay       = ec.shotDelay;
     shipSpeedMult   = ec.shipSpeedMult;
     bulletSpeedMult = ec.bulletSpeedMult;
     heldValue       = hval;
     bulletCount     = ec.bulletCount;
 }
예제 #25
0
    // Update is called once per frame
    void Update()
    {
        if (this.tmpMsg == null)
        {
            return;
        }
        ServerMsg data = JsonUtility.FromJson <ServerMsg> (this.tmpMsg);

        this.tmpMsg = null;
        switch ((Exec)data.exec)
        {
        case Exec.Enter:
        {
            this.strPlayerID = data.uid;
        }
        break;

        case Exec.Ready:
        {
            int start = data.start;
            int end   = data.end;

//				GameManager.Instance.setupConfig (start, end);

            EnemyConfig enA = new EnemyConfig();
            enA.name   = "A";
            enA.speed  = 14;
            enA.health = 100;

            EnemyConfig enB = new EnemyConfig();
            enB.name   = "B";
            enB.speed  = 6;
            enB.health = 200;

            EnemyConfig[] enemyCon = { enA, enB };

//				GameManager.Instance.setupEnemyInfo (data.team, enemyCon);
        }
        break;

        case Exec.UpdatePath:
        {
            string userID = data.userID;
            if (userID != this.strPlayerID)
            {
//					GameManager.Instance.recieveBuildingInfo (data.tileIdx, data.tower);
            }
        }
        break;

        default:
            break;
        }
    }
예제 #26
0
        public static Enemy Create(BulletManager bulletManager, EnemyConfig enemy, GameData gameData, Vector2 origin)
        {
            //Make a factory for the corresponding type of enemy
            EnemyAbstractFactory factory = MakeFactory(enemy);

            if (factory != null)
            {
                return(factory.Create(bulletManager, enemy, gameData, origin));
            }
            return(null);
        }
예제 #27
0
    public void MakeEnemy(EnemyConfig enemy)
    {
        GameObject NewEnemy    = Instantiate(genericEnemy, spawnPoint.transform.position, spawnPoint.transform.rotation);
        var        enemyConfig = NewEnemy.GetComponent <EnemyPrefabConfig> ();

        NewEnemy.transform.SetParent(enemyManager.transform);
        enemyConfig.enemyScriptableObject = enemy;
        enemyConfig.owningPlayer          = owningPlayer;
        enemyConfig.waypointManager       = wayPoints;
        enemyConfig.Initialize();
    }
예제 #28
0
        public override Enemy Create(BulletManager bulletManager, EnemyConfig enemy, GameData gameData, Vector2 origin)
        {
            this.bulletManager = bulletManager;

            FinalBoss newEnemy = new FinalBoss(bulletManager, gameData);

            //Load - sets position of enemy as well
            Load(newEnemy, enemy, origin);

            return(newEnemy);
        }
예제 #29
0
 public void LoadMovements(EnemyConfig config)
 {
     speed = config.speed;
     secondaryMovementFrequency = config.secondaryMovementFrequency;
     mainMovement       = config.mainMovement.CreateMovement(gameObject);
     secondaryMovements = new List <EnemyMovementLogic>();
     foreach (EnemyMovementType movementType in config.secondayMovements)
     {
         secondaryMovements.Add(movementType.CreateMovement(gameObject));
     }
 }
예제 #30
0
파일: Level.cs 프로젝트: z3nk0/VLTest
        public Enemy SpawnEnemy(EnemyConfig enemyConfig, Vector3 position, Quaternion rotation)
        {
            Vector3 finalPosition = position;

            finalPosition.y -= 0.5f - (enemyConfig.size * 0.5f);
            Enemy enemy = enemyPool.Spawn(finalPosition, rotation).GetComponent <Enemy>();

            enemy.LoadConfig(enemyConfig);
            enemy.MoveTowards();
            return(enemy);
        }
예제 #31
0
	public LevelConfig(EnemyConfig enemy)
	{
		Enemy = enemy;
	}
예제 #32
0
	public LevelState(LevelConfig config)
	{
		MaxTime = config.Enemy.InitialTime;
		TimeLeft = config.Enemy.InitialTime;
		Enemy = config.Enemy;
	}