public GameObject(String id, Point position) { GameObjectData data = Game.Manager.Resources.GameObjectDatas[id]; Graphic = GraphicData.GenerateGraphic(data.GraphicId); Position = new Rectangle(position, data.Size); }
public void LoadLevel(String id) { Player = null; GravityMod = 1f; Platforms.Clear(); Actors.Clear(); BgObjects.Clear(); if (Camera == null) { Camera = new Camera2D(Game.Manager.GraphicsDevice.Viewport); } LevelId = id; try { Data = Game.Manager.Resources.LevelDatas[id]; } catch (KeyNotFoundException e) { Data = Game.Manager.Resources.LevelDatas["Level1"]; Game.Manager.PlayerChoseBouncy = false; Game.Manager.PlayerChoseIcy = false; Game.Manager.PlayerHasDash = false; Game.Manager.PlayerHasDoubleJump = false; Game.Manager.PlayerHasFloat = false; Game.Manager.PlayerHasWallJump = false; ChoiceMade = false; Game.Manager.SorryScreen.Activate(); } Spawn = new Point(Data.PlayerPos.X, Options.RESOLUTION_DEFAULT.Y - Data.PlayerPos.Y); Player = new Player("Player", Spawn); Player.Initialize(this); GravityMod = Data.GravityModifier; if (Data.ChoiceId != null) { ChoiceMade = false; } foreach (InstData obj in Data.Objects) { GameObjectData data = Game.Manager.Resources.GameObjectDatas[obj.Id]; if (data.Type == GameObjectType.Platform) { Platform plat = new Platform { ObjectId = data.Id, Graphic = GraphicData.GenerateGraphic(data.GraphicId), Position = new Rectangle( new Point(obj.Pos.X, Options.RESOLUTION_DEFAULT.Y - data.Size.Y - obj.Pos.Y), data.Size), Type = data.PlatformType, StartingPos = obj.Pos, StartingDir = data.Direction, Moving = data.Moving, MoveRange = data.MoveRange, Direction = data.Direction }; plat.owner = this; Platforms.Add(plat); } if (data.Type == GameObjectType.Actor) { Actor a = new Actor { ObjectId = data.Id, Graphic = GraphicData.GenerateGraphic(data.GraphicId), Position = new Rectangle(obj.Pos, data.Size) }; a.ActualCoords.X = a.Position.X; a.ActualCoords.Y = a.Position.Y - Options.RESOLUTION_DEFAULT.Y; a.LastPosition = a.Position; Actors.Add(a); } } Random rand = new Random(); Int32 hills = rand.Next(6, 8); for (Int32 a = 0; a < hills * 3; a++) { Int32 size = rand.Next(3, 15); BgObjects.Add(new ScrollingBgObject( Game.Manager.Resources.Sprites["cloud" + rand.Next(0, 5)], new Vector2(rand.Next(0, Options.RESOLUTION_DEFAULT.X), rand.Next(-10, Options.RESOLUTION_DEFAULT.Y - 100)), (Single)(rand.NextDouble() * 0.4) + 0.1f, new Point(size, size), 3f + (Single)(rand.NextDouble() * 15f) )); } for (Int32 b = 0; b < hills; b++) { Int32 size = rand.Next(20, 30); BgObjects.Add(new ScrollingBgObject( Game.Manager.Resources.Sprites["hill" + rand.Next(0, 3)], new Vector2(rand.Next(20, Options.RESOLUTION_DEFAULT.X + 20), Options.RESOLUTION_DEFAULT.Y), 0.85f + (Single)(rand.NextDouble() * 0.15), new Point(size, size), 0.2f + (Single)(rand.NextDouble() * 0.8f) )); } NextLevelId = Data.NextLevelId; Game.Manager.ChoiceMaker.Load(Data.ChoiceId); }
public override void Initialize(Stage stage) { base.Initialize(stage); Fill = GraphicData.GenerateGraphic("PlayerGraphicF") as RectangleGraphic; }