// *************************************************************************** // Konstruktor 3 public GameObject(GameObjectInner goi) { // Sollte kein GO angegeben sein if (goi == null) { LocationBehavior = new MapLocation(new Vector2(0, 0)); LocationBehavior.Rotation = 0; Renderer = LoadedRenderer.Get("NoRenderer"); } else { // UI oder MapLocation if (!goi.isUILocation) { LocationBehavior = new MapLocation(new Vector2(goi.xPos, goi.yPos), new Vector2(goi.width, goi.height)); LocationBehavior.Rotation = goi.rotation; } else { LocationBehavior = new UILocation(new Vector2(goi.xPos, goi.yPos), new Vector2(goi.width, goi.height)); LocationBehavior.Rotation = goi.rotation; } // Kein Renderer = NoRenderer if (goi.renderer != null) Renderer = LoadedRenderer.Get(goi.renderer); else Renderer = LoadedRenderer.Get("NoRenderer"); } GetRect = RectDefault; }
public WayPoint(int xPosition, int yPosition) { // Liste init connectedPoints = new List<WayPoint>(); distances = new Dictionary<int, float>(); // Position bestimmen - jeder wegpunkt ist zur anzeige 32px groß Location = new MapLocation(new Vector2(xPosition, yPosition), new Vector2(32)); }
/// <summary> /// Kosntruktor /// </summary> /// <param name="locationBehavior"> Position des Spielers auf der Map </param> /// <param name="maxHealth"> Maximal Leben </param> /// <param name="health"> Aktuelles Leben </param> /// <param name="speed"> Bewegungsgeschwindigkeit </param> public Player(ILocationBehavior locationBehavior, float maxHealth, float health, float speed) : base(locationBehavior) { Buffs = new Dictionary<EBuffType, Buff>(); Speed = speed; MaxHealth = maxHealth; Health = maxHealth; // Texturen für Renderer laden RendererStanding = LoadedRenderer.GetStatic("S_Player_Standing"); RendererBigWeapon = LoadedRenderer.GetStatic("S_Player_BW"); RendererBigWeaponShot = LoadedRenderer.GetStatic("S_Player_BW_Shot"); RendererSmallWeapon = LoadedRenderer.GetStatic("S_Player_SW"); RendererSmallWeaponShot = LoadedRenderer.GetStatic("S_Player_SW_Shot"); RendererDying = LoadedRenderer.GetAnimation("A_Splatter_01"); RendererDying.PlayOnce(); Texture2D[] textureFootMoving = new[] { Main.ContentManager.Load<Texture2D>("images/character/left_foot"), Main.ContentManager.Load<Texture2D>("images/character/right_foot") }; RendererFootMoving = new AnimationRenderer(textureFootMoving, 4F); _footRenderer = new NoRenderer(); // Location für die Füße _footLocation = new MapLocation(locationBehavior.Position, new Vector2(textureFootMoving[0].Width, textureFootMoving[0].Height)); // Standardmäßig den StandingRenderer zuweisen //Renderer = RendererBigWeapon; // LocationSize anpassen LocationSizing(); LocationBehavior.Size = Renderer.Size; // Sollte LocationSizing machen // InventarListe init Inventar = new Dictionary<int, int>(); Shortcuts = new Dictionary<int, Weapon>(); // Schusstime auf 0 setzten _shotTimer = 0; // Poweruplist init ActivePowerups = new List<Powerup>(); // Liquids auf 0 setzten Liquids = new Vector3(0, 0, 0); // Rect Methode setzten base.GetRect = base.RectPlayer; }
// *************************************************************************** // Läd und erzeugt das eigentliche Spiel public SpawnPoint(MapLocation location, EEnemyType enemyType, float modifier) { Location = location; EnemyType = enemyType; this.modifier = modifier; }
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; }
// *************************************************************************** // Clone public ILocationBehavior Clone() { MapLocation m = new MapLocation(BoundingBox); m.Rotation = Rotation; return m; }
// *************************************************************************** // Läd den ganzen Stuff, den der GameManager benötigt public void Load() { Debug.WriteLine( "Läd das eigentliche Spiel" ); // Update Delegator setzen updateDelegater = UpdateGame; updateGamePlayDelegator = UpdateGamePlay; // Variablen initialisiwerung GameState = new GameState(); // Renderer laden Main.MainObject.MenuManager.LoadingText = "Loading images.."; LoadRenderer(); // Sounds laden Main.MainObject.MenuManager.LoadingText = "Loading sounds.."; Sound.LoadSounds(); // GameState initialisieren Main.MainObject.MenuManager.LoadingText = "Initialize objects.."; GameState.MapSize = new Vector2( 10000, 10000 ); // TODO: Mapgröße hier mitgeben GameState.QuadTreeEnemies = new QuadTree<Enemy>( 0, 0, ( int ) GameState.MapSize.X, ( int ) GameState.MapSize.Y ); GameState.QuadTreeSpawnPoints = new QuadTree<SpawnPoint>( 0, 0, ( int ) GameState.MapSize.X, ( int ) GameState.MapSize.Y ); GameState.QuadTreeStaticObjects = new QuadTree<StaticObject>( 0, 0, ( int ) GameState.MapSize.X, ( int ) GameState.MapSize.Y ); GameState.QuadTreeItems = new QuadTree<Item>( 0, 0, ( int ) GameState.MapSize.X, ( int ) GameState.MapSize.Y ); GameState.ShotListVsEnemies = new List<Shot>(); // Shots als Liste, da diese nur eine kurze Lebenszeit haben GameState.ShotListVsPlayer = new List<Shot>(); // Shots als Liste, da diese nur eine kurze Lebenszeit haben Main.MainObject.MenuManager.LoadingText = "Loading map.."; GameState.Karte = new Karte(); GameState.Karte.LoadMap( GameState, "testmap" ); GameState.GameStatistic = new GameStatistic(); // Werte für Runde GameState.RoundDelay = 1; GameState.GameStatistic.Round = 1; GameState.RoundIsRunning = false; GameState.TimeToRoundStart = GameState.RoundDelay; // Buffs laden Buff.Load(); // Items laden Main.MainObject.MenuManager.LoadingText = "Loading items.."; Item.LoadItems(); // Player MapLocation playerPosition = new MapLocation( GameState.Karte.PlayerStart ); GameState.Player = new Player( playerPosition, 100, 100, 200 ); Weapon w1 = Item.DefaultWeapon[ 8 ].Clone(); w1.Munition = Item.DefaultMunition[ 200 ].Clone(); //GameState.Player.AddItemToInventar(w1); GameState.Player.AddWeaponToShortcutList( 1, w1 ); Weapon w2 = Item.DefaultWeapon[ 15 ].Clone(); w2.Munition = Item.DefaultMunition[ 201 ].Clone(); //GameState.Player.AddItemToInventar(w2); GameState.Player.AddWeaponToShortcutList( 2, w2 ); CalculateMapOffset(); // Keybelegung keyMoveUp = ( Keys ) Enum.Parse( typeof( Keys ), Configuration.Get( "keyMoveUp" ) ); keyMoveDown = ( Keys ) Enum.Parse( typeof( Keys ), Configuration.Get( "keyMoveDown" ) ); keyMoveLeft = ( Keys ) Enum.Parse( typeof( Keys ), Configuration.Get( "keyMoveLeft" ) ); keyMoveRight = ( Keys ) Enum.Parse( typeof( Keys ), Configuration.Get( "keyMoveRight" ) ); // Background laden background = Main.ContentManager.Load<Texture2D>( "images/background" ); PixelWhite = Main.ContentManager.Load<Texture2D>( "images/pixelWhite" ); PixelTransparent = Main.ContentManager.Load<Texture2D>( "images/pixelTransparent" ); // GUI elemente gui_overlay = Main.ContentManager.Load<Texture2D>( "images/gui/gui_overlay" ); health_bar = Main.ContentManager.Load<Texture2D>( "images/gui/health_bar" ); gui_backlayer = Main.ContentManager.Load<Texture2D>( "images/gui/gui_backlayer" ); gameoverTexture = Main.ContentManager.Load<Texture2D>( "images/gameover" ); defaultFont = Main.ContentManager.Load<SpriteFont>( Configuration.Get( "defaultFont" ) ); defaultFontBig = Main.ContentManager.Load<SpriteFont>( Configuration.Get( "defaultFontBig" ) ); defaultFontSmall = Main.ContentManager.Load<SpriteFont>( Configuration.Get( "defaultFontSmall" ) ); // Posi für Gui DrawHelper.AddDimension( "HealthBar_Position", 184, 425 ); DrawHelper.AddDimension( "HealthBar_Size", 33, 153 ); DrawHelper.AddDimension( "Munition_Position", 235, 535 ); DrawHelper.AddDimension( "BuffIcon_Position", 16, 365 ); DrawHelper.AddDimension( "BuffIcon_Size", 32, 32 ); DrawHelper.AddDimension( "Minimap_Size", 181, 170 ); DrawHelper.AddDimension( "Minimap_Position", 0, 407 ); DrawHelper.AddDimension( "IconOnTheFloor_Size", 32, 32 ); // AI Thread starten new Thread( new ThreadStart( AIThread.UpdateAI ) ).Start(); //User Interface erstellen InitGui(); // Enemies laden Enemy.Load(); // Maus auf fadenkreuz setzten MouseCursor.CurrentCursor = MouseCursor.Cross_01; // ################################################################################ // ################################################################################ // ################################################################################ // TEST Item it1 = Item.Get( 100 ); it1.LocationBehavior.Position = new Vector2( 1100, 4150 ); it1.LocationBehavior.Size = DrawHelper.Get( "IconOnTheFloor_Size" ); //it1.LocationSizing(); Item it2 = Item.Get( 200 ); it2.LocationBehavior.Position = new Vector2( 1200, 4150 ); it2.LocationBehavior.Size = DrawHelper.Get( "IconOnTheFloor_Size" ); //it2.LocationSizing(); Item it3 = Item.Get( 300 ); it3.LocationBehavior.Position = new Vector2( 1300, 4150 ); it3.LocationBehavior.Size = DrawHelper.Get( "IconOnTheFloor_Size" ); //it3.LocationSizing(); Item it4 = Item.Get( 400 ); it4.LocationBehavior.Position = new Vector2( 1400, 4150 ); it4.LocationBehavior.Size = DrawHelper.Get( "IconOnTheFloor_Size" ); //it4.LocationSizing(); Item it5 = Item.Get( 700 ); it5.LocationBehavior.Position = new Vector2( 1500, 4150 ); it5.LocationBehavior.Size = DrawHelper.Get( "IconOnTheFloor_Size" ); //it5.LocationSizing(); GameState.QuadTreeItems.Add( it1 ); GameState.QuadTreeItems.Add( it2 ); GameState.QuadTreeItems.Add( it3 ); GameState.QuadTreeItems.Add( it4 ); GameState.QuadTreeItems.Add( it5 ); //peng = Main.ContentManager.Load<SoundEffect>("test/Skorpion-Kibblesbob-1109158827"); headshot = Main.ContentManager.Load<SoundEffect>( "test/headshot2" ); monster3 = Main.ContentManager.Load<Texture2D>( "test/red_monster_angry" ); shot = Main.ContentManager.Load<Texture2D>( "test/shot" ); blood = Main.ContentManager.Load<Texture2D>( "test/blood" ); shot_01 = Main.ContentManager.Load<Texture2D>( "images/shots/shot_01" ); // Testtextur test = Main.ContentManager.Load<Texture2D>( "images/pixelWhite" ); testFont = Main.ContentManager.Load<SpriteFont>( "fonts/arialSmall" ); // TEST-ENDE // ################################################################################ // Wenn ladevorgang fertig => Switch von MenuManager auf GameManager Main.MainObject.CurrentManager = this; MusicPlayer.Stop(); }