Exemplo n.º 1
0
 public LevelConfig(float magnifier, int width, int height, List <ObjectStatus> enemies, ObjectStatus player)
 {
     _magnifier = magnifier;
     _width     = width;
     _height    = height;
     _enemies   = enemies;
     _player    = player;
 }
        public override void Execute()
        {
            Retain();
            playerEndAnimationSignal.AddListener(onPlayerAnimationComplete);


            ObjectStatus player = gameModel.currentLevel.player;

            Vector3 pos = gameUtil.positionInWorldSpace(player.x, player.y);

            view.GoTo(pos);
        }
Exemplo n.º 3
0
 public void Reset()
 {
     magnifier = _config.magnifier;
     width     = _config.width;
     height    = _config.height;
     enemies   = new List <ObjectStatus>();
     for (int a = 0, aa = _config.enemies.Count; a < aa; a++)
     {
         enemies.Add(new ObjectStatus(_config.enemies[a].x, _config.enemies[a].y));
     }
     player = new ObjectStatus(_config.player.x, _config.player.y);
 }
        private void moveEnemy()
        {
            ObjectStatus enemy = gameModel.currentLevel.enemies [index];

            if (index < gameModel.currentLevel.enemies.Count)
            {
                Vector3 pos = gameUtil.positionInWorldSpace(enemy.x, enemy.y);


                EnemyView enemyView = enemy.view as EnemyView;
                enemyView.GoTo(pos);
            }
        }
Exemplo n.º 5
0
        public void PostConstruct()
        {
            TextAsset file = Resources.Load("gameConfig") as TextAsset;

            var n = SimpleJSON.JSON.Parse(file.text);

            initLives    = n ["initLives"].AsInt;
            newLifeEvery = n ["newLifeEvery"].AsInt;
            maxLives     = n ["maxLives"].AsInt;


            additionalRocksPerLevel = n ["additionalRocksPerLevel"].AsInt;
            baseRockScore           = n ["baseRockScore"].AsInt;
            rockExplosiveForceMin   = n ["rockExplosiveForceMin"].AsFloat;
            rockExplosiveForceMax   = n ["rockExplosiveForceMax"].AsFloat;

            baseEnemyScore = n ["baseEnemyScore"].AsInt;

            SimpleJSON.JSONArray lvls = n ["levels"].AsArray;

            levels = new ArrayList();

            for (int a = 0; a < lvls.Count; a++)
            {
                float magnifier = lvls[a]["magnifier"].AsFloat;
                int   width     = lvls[a]["dimensions"]["width"].AsInt;
                int   height    = lvls[a]["dimensions"]["height"].AsInt;

                SimpleJSON.JSONArray nms     = lvls[a]["enemies"].AsArray;
                List <ObjectStatus>  enemies = new List <ObjectStatus>();

                for (int b = 0; b < nms.Count; b++)
                {
                    int x = nms[b]["x"].AsInt;
                    int y = nms[b]["y"].AsInt;
                    enemies.Add(new ObjectStatus(x, y));
                }

                int          playerX = lvls[a]["player"]["x"].AsInt;
                int          playerY = lvls[a]["player"]["y"].AsInt;
                ObjectStatus player  = new ObjectStatus(playerX, playerY);



                levels.Add(new LevelConfig(magnifier, width, height, enemies, player));
            }
        }
Exemplo n.º 6
0
        public override void Execute()
        {
            LevelModel level = gameModel.currentLevel;
            int        aa    = level.enemies.Count;

            for (var a = aa - 1; a >= 0; a--)
            {
                ObjectStatus enemy = level.enemies[a];
                if (enemy.destroyed)
                {
                    Debug.Log(enemy.x + ", " + enemy.y + "(" + a + "/" + level.enemies.Count + ")");

                    level.enemies.RemoveAt(a);
                }
            }
            endTurnSignal.Dispatch();
        }
Exemplo n.º 7
0
        public override void Execute()
        {
            Debug.Log("gameModel.level " + gameModel.level);


            LevelModel   level  = gameModel.currentLevel;
            ObjectStatus player = level.player;

            int xDest = player.x;
            int yDest = player.y;

            //Determine destination coords based on direction

            if (direction.IndexOf("N") > -1)
            {
                yDest -= 1;
            }
            else if (direction.IndexOf("S") > -1)
            {
                yDest += 1;
            }
            if (direction.IndexOf("W") > -1)
            {
                xDest -= 1;
            }
            else if (direction.IndexOf("E") > -1)
            {
                xDest += 1;
            }
            //Confirm player can go in the chosen direction
            bool legalMove = true;

            if (xDest < 0 || yDest < 0 || xDest >= level.width || yDest >= level.height)
            {
                legalMove = false;
            }
            int aa = level.enemies.Count;

            for (int a = 0; a < aa; a++)
            {
                if (level.enemies[a].x == xDest && level.enemies[a].y == yDest)
                {
                    legalMove = false;
                    break;
                }
            }

            //If yes...
            if (legalMove)
            {
                //Move player
                player.x = xDest;
                player.y = yDest;

                level.player = player;

                //Move all enemies iteratively, recording kills
                int bb = level.enemies.Count;
                for (int b = 0; b < bb; b++)
                {
                    ObjectStatus enemy = level.enemies[b];

                    if (enemy.destroyed)
                    {
                        continue;
                    }

                    int enemyXPos = enemy.x;
                    int enemyYPos = enemy.y;

                    int xDist = enemy.x - player.x;
                    int yDist = enemy.y - player.y;

                    float theta = Mathf.Atan2((float)yDist, (float)xDist) * Mathf.Rad2Deg;

                    if (theta >= -45 && theta <= 45)
                    {
                        enemyXPos -= 1;
                    }
                    else if (theta >= 135 || theta <= -135)
                    {
                        enemyXPos += 1;
                    }

                    if (theta >= 45 && theta <= 135)
                    {
                        enemyYPos -= 1;
                    }
                    else if (theta <= -45 && theta >= -135)
                    {
                        enemyYPos += 1;
                    }
                    enemy.x          = enemyXPos;
                    enemy.y          = enemyYPos;
                    level.enemies[b] = enemy;


                    //loop to mark collisions
                    for (int c = 0; c < bb; c++)
                    {
                        ObjectStatus other = level.enemies[c];
                        if (b != c && other.x == enemy.x && other.y == enemy.y)
                        {
                            other.destroyed = enemy.destroyed = true;
                        }
                    }
                }



                //Note if player was killed
            }
            //If no...
            else
            {
                //Reject?
            }
        }