Example #1
0
        private bool ReadMapFile(string mapFile)
        {
            Debug.WriteLine("Lade Map " + mapFile + "..");

            // prüfen ob config.ini existiert
            if (!File.Exists(Configuration.Get("mapDir") + mapFile))
            {
                Debug.WriteLine("MapFile " + mapFile + " nicht vorhanden");
                return false;
            }

            // Map File öffnen
            TextReader tr = new StreamReader(Configuration.Get("mapDir") + mapFile);

            // Debug
            int rectCount = 0;

            // Alle lines einlesen, bei ',' trennen und diese bei [0]=R in Rechtecke einteilen
            string input;
            while ((input = tr.ReadLine()) != null)
            {
                // falls erstes zeichen eine # ist, dann ist die zeile ein kommenatar
                if (input.Length < 1 || input.Substring(0, 1).Equals("#"))
                {
                    continue;
                }

                string[] split = input.Split(new char[] { ',' });

                // Map Rechteck
                if (split[0].Equals("R") && split.Length == 5)
                {
                    rectCount++;

                    // Variablen parsen
                    int x = int.Parse(split[1]);
                    int y = int.Parse(split[2]);
                    int w = int.Parse(split[3]);
                    int h = int.Parse(split[4]);

                    // SO erstellen
                    StaticObject so = new StaticObject(new MapLocation(new Rectangle(x, y, w, h)), new SimpleRenderer(Color.White), false);

                    // SO dem QT zufügen
                    QuadTreeWalkable.Add(so);
                }

                // Playerstart
                if (split[0].Equals("X") && split.Length == 3)
                {
                    // Variablen parsen
                    int x = int.Parse(split[1]);
                    int y = int.Parse(split[2]);

                    // SO erstellen
                    PlayerStart = new Vector2(x, y);

                    Debug.WriteLine("Playerstart: " + x + "/" + +y);
                }

                // SpawnPoints
                if (split[0].Equals("S") && split.Length == 3)
                {
                    // Variablen parsen
                    int x = int.Parse(split[1]);
                    int y = int.Parse(split[2]);

                    // SP erstellen
                    SpawnPoint sp = new SpawnPoint(new MapLocation(new Vector2(x, y)), EEnemyType.E3, 1);

                    // SP adden
                    Main.MainObject.GameManager.GameState.QuadTreeSpawnPoints.Add(sp);
                }

                // Objekte etc
                if (split[0].Equals("M") && split.Length == 6)
                {
                    // Variablen parsen
                    string img = split[1];
                    int x = int.Parse(split[2]);
                    int y = int.Parse(split[3]);
                    int faktor = int.Parse(split[4]);
                    int winkel = int.Parse(split[5]);

                    // Vars für SO
                    string renderer = "S_Map_" + img;

                    float rotation = (float)((Math.PI * 2) / 360 * winkel);

                    // SP erstellen
                    MapLocation m = new MapLocation(new Vector2(x, y));
                    m.Rotation = rotation;
                    IRenderBehavior r = LoadedRenderer.Get(renderer);
                    StaticObject so = new StaticObject(m, r);
                    so.LocationSizing();

                    // SP adden
                    Main.MainObject.GameManager.GameState.QuadTreeStaticObjects.Add(so);
                }

                // Wegpunkte W,48,1700,4538
                if (split[0].Equals("W") && split.Length == 4)
                {
                    // Variablen parsen
                    int id = int.Parse(split[1]);
                    int x = int.Parse(split[2]);
                    int y = int.Parse(split[3]);

                    // WP
                    WayPoint w = new WayPoint(x, y);
                    w.ID = id;

                    // WP adden
                    Main.MainObject.GameManager.GameState.Karte.WayPoints.Add(id, w);
                    Main.MainObject.GameManager.GameState.Karte.QuadTreeWayPoints.Add(w);
                }

                // Wegpunkte C,11,10
                if (split[0].Equals("C") && split.Length == 3)
                {
                    // Variablen parsen
                    int srcId = int.Parse(split[1]);
                    int desId = int.Parse(split[2]);

                    // Connection in BEIDE richtung
                    WayPoints[srcId].AddConnection(WayPoints[desId]);
                    WayPoints[desId].AddConnection(WayPoints[srcId]);
                }
            }

            // File schließen
            tr.Close();

            //Debug
            Debug.WriteLine(rectCount + " Rects geladen");

            return true;
        }
Example #2
0
        // ***************************************************************************
        // Prüfe ob Player an neue Position laufen darf
        public void KillEnemie( Enemy e )
        {
            // Killcounter erhöhen
            GameState.GameStatistic.KilledMonsters[ e.TypOfEnemy ]++;

            //Test new StaticRenderer(blood)
            AnimationRenderer a = LoadedRenderer.GetAnimation( "A_Splatter_01" );
            a.PlayOnce();

            // Splatter erstellen und in quadtree einfügen
            StaticObject splatter = new StaticObject( new MapLocation( e.LocationBehavior.Position ), a );
            GameState.QuadTreeStaticObjects.Add( splatter );

            // KillsToEndRound - 1
            GameState.KillsToEndRound--;

            // Liquid droppen
            ELiquid droppedLiquidType = ELiquid.Green;
            switch ( e.TypOfEnemy )
            {
                //case EEnemyType.E1:
                //case EEnemyType.E2:
                //    droppedLiquidType = ELiquid.Green;
                //    break;
                case EEnemyType.E3:
                case EEnemyType.E4:
                    droppedLiquidType = ELiquid.Blue;
                    break;
                case EEnemyType.E5:
                case EEnemyType.E6:
                    droppedLiquidType = ELiquid.Red;
                    break;
            }

            Random r = new Random();
            Liquid droppedLiquid = Liquid.Get( droppedLiquidType, r.Next( 1, 5 ) );
            droppedLiquid.LocationBehavior = new MapLocation( e.LocationBehavior.Position );
            droppedLiquid.LocationSizing();

            // Liquid den items hinzufügen
            GameState.QuadTreeItems.Add( droppedLiquid );

            // Remove enemie
            if ( !GameState.QuadTreeEnemies.Remove( e ) )
            {
                Debug.WriteLine( "Fehler beim löschen eines Gegners" );
            }
        }