Example #1
0
 public void ClearList()
 {
     for (int i = NextLevelEntityList.Count - 1; i >= 0; i--)
     {
         NextLevelEntityList[i].Destroy();
     }
     for (int x = ActionEntityList.Count - 1; x >= 0; x--)
     {
         ActionEntityList[x].Destroy();
     }
     for (int z = BulletList.Count - 1; z >= 0; z--)
     {
         BulletList[z].Destroy();
     }
     for (int y = SignEntityList.Count - 1; y >= 0; y--)
     {
         SignEntityList[y].Destroy();
     }
     for (int g = EnemyCornerList.Count - 1; g >= 0; g--)
     {
         EnemyCornerList[g].Destroy();
     }
     for (int h = GroundEnemyList.Count - 1; h >= 0; h--)
     {
         GroundEnemyList[h].Destroy();
     }
     for (int o = EnemyBulletList.Count - 1; o >= 0; o--)
     {
         EnemyBulletList[o].Destroy();
     }
     NextLevelEntityList.Clear();
     ActionEntityList.Clear();
     BulletList.Clear();
     EnemyBulletList.Clear();
     GroundEnemyList.Clear();
     SignEntityList.Clear();
     EnemyCornerList.Clear();
 }
Example #2
0
        private void SetUpTiles()
        {
            const float tileSize = 16;

            string[] splitters = { "_" };

            foreach (MapDrawableBatch layer in TiledMap.MapLayers)
            {
                if (layer.NamedTileOrderedIndexes.ContainsKey("Collision"))
                {
                    List <int> indexes = layer.NamedTileOrderedIndexes["Collision"];
                    foreach (int index in indexes)
                    {
                        float left;
                        float bottom;
                        layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                        float centerX = left + tileSize;
                        float centerY = bottom + tileSize;
                        AddShapes(TileCollisionShapes, tileSize, tileSize, new Vector3(centerX, centerY, 0), false, Color.Green);
                    }
                }
                if (layer.NamedTileOrderedIndexes.ContainsKey("StartPos"))
                {
                    List <int> indexes = layer.NamedTileOrderedIndexes["StartPos"];
                    foreach (int index in indexes)
                    {
                        float left;
                        float bottom;
                        layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                        float centerX = left + tileSize / 2.0f;
                        float centerY = bottom + tileSize / 2.0f;
                        PlayerInstance.Position = new Vector3(centerX, centerY, 10);
                        layer.Visible           = false;
                    }
                }

                foreach (KeyValuePair <string, List <int> > entry in layer.NamedTileOrderedIndexes)
                {
                    if (entry.Key.StartsWith("NextLevel_"))
                    {
                        string[] levelName = entry.Key.Split(splitters, StringSplitOptions.None);

                        List <int> indexes = entry.Value;
                        foreach (int index in indexes)
                        {
                            float left;
                            float bottom;
                            layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                            float centerX = left + tileSize;
                            float centerY = bottom + tileSize;

                            Entities.NextLevelEntity nextLevel = new Entities.NextLevelEntity();
                            nextLevel.Position      = new Vector3(centerX, centerY, 15);
                            nextLevel.nextLevelName = levelName[1];
                            NextLevelEntityList.Add(nextLevel);
                        }
                    }

                    if (entry.Key.StartsWith("Sign_"))
                    {
                        string[] signMessage = entry.Key.Split(splitters, StringSplitOptions.None);

                        List <int> indexes = entry.Value;
                        foreach (int index in indexes)
                        {
                            float left;
                            float bottom;
                            layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                            float centerX = left + tileSize;
                            float centerY = bottom + tileSize;

                            Entities.SignEntity sign = new Entities.SignEntity();
                            sign.Position    = new Vector3(centerX, centerY, 20);
                            sign.signMessage = signMessage[1];
                            SignEntityList.Add(sign);
                        }
                    }

                    if (entry.Key.StartsWith("Action_"))
                    {
                        string[] actionString = entry.Key.Split(splitters, StringSplitOptions.None);

                        List <int> indexes = entry.Value;
                        foreach (int index in indexes)
                        {
                            float left;
                            float bottom;
                            layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                            float centerX = left + tileSize;
                            float centerY = bottom + tileSize;

                            Entities.ActionEntity action = new Entities.ActionEntity();
                            action.Position     = new Vector3(centerX, centerY, 0);
                            action.actionString = actionString[1];
                            ActionEntityList.Add(action);

                            layer.Visible = false;
                        }
                    }

                    if (entry.Key.StartsWith("EnemyCorner_"))
                    {
                        string[] rotationString = entry.Key.Split(splitters, StringSplitOptions.None);

                        List <int> indexes = entry.Value;
                        foreach (int index in indexes)
                        {
                            float left;
                            float bottom;
                            layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                            float centerX = left + tileSize;
                            float centerY = bottom + tileSize;

                            Entities.EnemyCorner enemy = new Entities.EnemyCorner();
                            enemy.Position = new Vector3(centerX, centerY, 10);
                            if (rotationString[1] == "Right")
                            {
                                enemy.rightDirection = true;
                            }
                            else
                            {
                                enemy.rightDirection = false;
                            }
                            EnemyCornerList.Add(enemy);
                            layer.Visible = false;
                        }
                    }

                    if (entry.Key.StartsWith("EnemyGround"))
                    {
                        List <int> indexes = entry.Value;
                        foreach (int index in indexes)
                        {
                            float left;
                            float bottom;
                            layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                            float centerX = left + tileSize;
                            float centerY = bottom + tileSize;

                            Entities.GroundEnemy enemy = new Entities.GroundEnemy();
                            enemy.Position = new Vector3(centerX, centerY, 12);
                            GroundEnemyList.Add(enemy);
                            layer.Visible = false;
                        }
                    }

                    if (entry.Key == "EnemyCollision")
                    {
                        List <int> indexes = entry.Value;
                        foreach (int index in indexes)
                        {
                            float left;
                            float bottom;
                            layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                            float centerX = left + tileSize;
                            float centerY = bottom + tileSize;

                            AddShapes(EntityCollisionShapes, 16, 16, new Vector3(centerX, centerY, 0), true, Color.Red);
                            layer.Visible = false;
                        }
                    }

                    if (entry.Key == "EnemyCollisionGround")
                    {
                        List <int> indexes = entry.Value;
                        foreach (int index in indexes)
                        {
                            float left;
                            float bottom;
                            layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);
                            float centerX = left + tileSize;
                            float centerY = bottom + tileSize;

                            AddShapes(EnemyCollisionGround, 16, 16, new Vector3(centerX, centerY, 0), false, Color.Red);
                            layer.Visible = false;
                        }
                    }
                }
            }
        }