public Game_Screen(World _world, GameCamera _camera, PenumbraComponent _lighting, Particle_World _particle_world, Physics_Engine _physics_engine, Lua _lua, GraphicsDevice _device, string _id) : base(_id) { world = _world; camera = _camera; lighting = _lighting; particle_world = _particle_world; physics_engine = _physics_engine; lua = _lua; device = _device; }
public Boss_Room_1( World _world, GameCamera _camera, PenumbraComponent _lighting, Particle_World _particle_world, Physics_Engine _physics_engine, ContentManager _content, Lua _lua, GraphicsDevice _device) : base(_world, _camera, _lighting, _particle_world, _physics_engine, _lua, _device, "Boss Room 1") { this.content = _content; }
public static Entity Create(Lua lua, World world, Particle_World particle_world, Vector2 position) { var entity = world.Create_Entity(); Texture2D texture = Assets.It.Get <Texture2D>("Boss_Texture"); if (texture == null) { Console.WriteLine("ERROR::BOSS::1 requires a texture with the id Boss_Texture!"); } entity.Add(new Body(position, new Vector2(24, 24))); entity.Add(new Physics(Vector2.Zero, Physics.PType.DYNAMIC)); // main container for the head var graphics = new Multipart_Animation(); // the base sprite var base_head = new Animated_Sprite(texture, "head"); base_head.Animations.Add("head", new Animation( new List <Animation_Frame> { new Animation_Frame(new Vector2(0, 0), new Vector2(47, 52)) } , "head")); base_head.Offset = new Vector2(0, -17); base_head.Layer_Offset = 0.2f; var eyes = new Animated_Sprite(texture, "eye-close"); eyes.Animations.Add("eye-close", new Animation( new List <Animation_Frame> { new Animation_Frame(new Vector2(95, 0), new Vector2(33, 5)), new Animation_Frame(new Vector2(95, 5), new Vector2(33, 5)), new Animation_Frame(new Vector2(95, 10), new Vector2(33, 5)), new Animation_Frame(new Vector2(95, 15), new Vector2(33, 5)), }, "eye-close")); eyes.Layer_Offset = 0.25f; eyes.Offset = new Vector2(0, -32 + 5); var mouth = new Animated_Sprite(texture, "mouth-open"); mouth.Animations.Add("mouth-open", new Animation( new List <Animation_Frame> { new Animation_Frame(new Vector2(0, 52), new Vector2(47, 17)) { Offset = Vector2.Zero }, new Animation_Frame(new Vector2(0, 52 + 17), new Vector2(47, 17)), new Animation_Frame(new Vector2(0, 52 + 17 * 2), new Vector2(47, 17)), new Animation_Frame(new Vector2(0, 52 + 17 * 3), new Vector2(47, 17)), new Animation_Frame(new Vector2(48, 0), new Vector2(47, 18)) { Offset = new Vector2(0, 1) }, new Animation_Frame(new Vector2(48, 18), new Vector2(47, 23)) { Offset = new Vector2(0, 6) }, new Animation_Frame(new Vector2(48, 41), new Vector2(47, 23)) { Offset = new Vector2(0, 6) }, new Animation_Frame(new Vector2(48, 64), new Vector2(47, 23)) { Offset = new Vector2(1, 6) }, }, "mouth-open")); mouth.Layer_Offset = 0.25f; mouth.Offset = new Vector2(0, 0); graphics.Animation_Components.Add("mouth", mouth); graphics.Animation_Components.Add("eyes", eyes); graphics.Animation_Components.Add("head", base_head); entity.Add(graphics); entity.Add(new Entity_Particle_Emitter( new Boss_1_Emitter(position, false), particle_world, false ) { Offset = new Vector2(0, 4) }); entity.Add(new Health(BOSS_HEALTH)); entity.Add(new Lua_Function(lua.DoFile("Content/Lua/Boss_1_Ai.lua")[0] as LuaFunction, "Content/Lua/Boss_1_Ai.lua")); return(entity); }
public Player_Controller_System(GameCamera _camera, Particle_World particle_world, Screen_Manager screen) : base(Types.Body, Types.Player, Types.Physics) { this.screen_manager = screen; this.camera = _camera; this.particle_world = particle_world; }
public Tiled_Map(string name, GameCamera _camera, World world, Screen level, Particle_World particle_world, Lua lua, GraphicsDevice device, PenumbraComponent lighting = null, bool create_astar_collision_map = false) { this.device = device; this.camera = _camera; this.lighting = lighting; var current = Directory.GetCurrentDirectory(); if (!File.Exists(current + "/Content/Maps/" + name + ".tmx")) { var files = Directory.GetFiles(current + "/Content/Maps/"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR:: no map named {0} in directory, did you mean one of these?", name); foreach (var file in files) { var toks = file.Split('\\', '/'); Console.WriteLine(toks.Last()); } Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } map = new TmxMap(Directory.GetCurrentDirectory() + "/Content/Maps/" + name + ".tmx"); quads = Assets.It.Get_Quads("quads"); // load a texture var tileset_name = Path.GetFileName(map.Tilesets[0].Image.Source).Split('.').First(); if (Assets.It.Has(tileset_name, typeof(Texture2D))) { texture = Assets.It.Get <Texture2D>(map.Tilesets[0].Name); } else { texture = Assets.It.Load_Texture(tileset_name, tileset_name); } billboards = new List <Billboard>(); if (map.Properties.ContainsKey("Sky")) { Has_Sky = map.Properties["Sky"] == "true"; } if (map.Properties.ContainsKey("Ambiant")) { string color_string = map.Properties["Ambiant"]; var tokens = color_string.Split(' '); var color = new Color( byte.Parse(tokens[0]), byte.Parse(tokens[1]), byte.Parse(tokens[2]) ); lighting.AmbientColor = color; } Map_Height_In_Pixels = map.Height * map.TileHeight; foreach (var layer in map.Layers) { layer_render_targets.Add(new RenderTarget2D( device, map.Width * map.TileWidth, map.Height * map.TileHeight, false, device.PresentationParameters.BackBufferFormat, DepthFormat.Depth24 )); } for (int i = map.Layers.Count - 1; i >= 0; i--) { var layer = map.Layers[i]; if (layer.Properties.ContainsKey("ignore") == true) { map.Layers.RemoveAt(i); } } var solids = new List <RectangleF>(); foreach (var layer in map.ObjectGroups) { foreach (var obj in layer.Objects) { if (obj.Type == "") { // Create a solid // check if its a polygon! var physics_engine = (Physics_Engine)world.Get_System <Physics_Engine>(); if (physics_engine != null) { if (obj.Points == null) { var rect = new RectangleF((float)obj.X, (float)obj.Y, (float)obj.Width, (float)obj.Height); var solid = physics_engine.Add_Solid(rect); solids.Add(rect); } else { List <Vector2> points = new List <Vector2>(); foreach (var p in obj.Points) { points.Add(new Vector2((float)p.X, (float)p.Y)); } var polygon = new Polygon { Points = points, Position = new Vector2((float)obj.X, (float)obj.Y) }; var poly = physics_engine.Add_Polygon(polygon); } } } else if (obj.Type == "hull") { var points = new Vector2[obj.Points.Count]; int ptr = 0; foreach (var pnt in obj.Points) { points[ptr++] = new Vector2((float)(obj.X + pnt.X), (float)(obj.Y + pnt.Y)); } lighting.Hulls.Add(new Hull(points)); } else if (obj.Type == "Particle") { Debug.Assert(obj.Properties.ContainsKey("Type"), "ERROR:: Particle object requires a Type property!"); var type = obj.Properties["Type"]; switch (type) { case "Fire_Fly": particle_world.Add(new Fire_Fly_Emitter(new Vector2(0, 0))); break; case "Fire": Console.WriteLine("Hey"); particle_world.Add(new Fire_Emitter(new Vector2((float)obj.X, (float)obj.Y))); break; default: Console.WriteLine("WARNING:: unknown particle type: " + type); Console.WriteLine("Did you mean one of these?"); Console.Write("1) Fire_Fly\n2) Fire\n3) Blue_Fire"); break; } } else if (obj.Type == "Boss") { var boss = Boss_1.Create(lua, world, particle_world, new Vector2((float)obj.X, (float)obj.Y)); } else if (obj.Type == "Billboard") { Debug.Assert(obj.Properties.ContainsKey("Region"), "Billboard object requires the property: Region, for example: x y width height"); var str = obj.Properties["Region"]; var toks = str.Split(' '); var billboard = new Billboard() { Position = new Vector2((float)obj.X, (float)obj.Y), Region = new Rectangle(int.Parse(toks[0]), int.Parse(toks[1]), int.Parse(toks[2]), int.Parse(toks[3])) }; billboards.Add(billboard); } else if (obj.Type == "Door") { Debug.Assert(obj.Properties.ContainsKey("Door"), "Door object requires the property: Door, for example: Door 100 563"); var str = obj.Properties["Door"]; var is_sensor = false; if (obj.Properties.ContainsKey("is_sensor")) { is_sensor = bool.Parse(obj.Properties["is_sensor"]); } var toks = str.Split(' '); var door = world.Create_Entity(); door.Add(new Body(new Vector2((float)obj.X, (float)obj.Y), new Vector2((float)obj.Width, (float)obj.Height))); door.Add(new Physics(Vector2.Zero, Physics.PType.WORLD_INTERACTION)); var wi = (World_Interaction)door.Add(new World_Interaction( (self, other) => { var _wi = (World_Interaction)self.Get(Component.Types.World_Interaction); if (other.Has(Component.Types.Player)) { if (!_wi.Is_Sensor && Input.It.Is_Key_Pressed(Keys.Z) || GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed) { Change_Scene_Callback?.Invoke(_wi.ID, _wi.X, _wi.Y); // Check if the door just requires the player to walk into the zone } else if (_wi.Is_Sensor) { Change_Scene_Callback?.Invoke(_wi.ID, _wi.X, _wi.Y); } } return(true); })); wi.Is_Sensor = is_sensor; wi.ID = toks[0]; wi.X = float.Parse(toks[1]); wi.Y = float.Parse(toks[2]); } else if (obj.Type == "PointLight") { // light var scale = 200f; if (obj.Properties.ContainsKey("Scale")) { scale = float.Parse(obj.Properties["Scale"]); } var color = Color.White; if (obj.Properties.ContainsKey("Color")) { string color_string = obj.Properties["Color"]; var tokens = color_string.Split(' '); color = new Color( byte.Parse(tokens[0]), byte.Parse(tokens[1]), byte.Parse(tokens[2]) ); } lighting.Lights.Add(new PointLight() { Position = new Vector2((float)(obj.X + obj.Width / 2), (float)(obj.Y + obj.Height / 2)), Scale = new Vector2(scale), Color = color, Intensity = 1f }); } else if (obj.Type.ToLower() == "player") { if (world.Get_All_With_Component(Component.Types.Player).Count == 0) { world.Create_Entity( Assets.It.Get <LuaTable>(obj.Type), (float)obj.X, (float)obj.Y ); } } else { world.Create_Entity( Assets.It.Get <LuaTable>(obj.Type), (float)obj.X, (float)obj.Y ); } } } // creating the ai map if (create_astar_collision_map) { astar_collision_map = new bool[map.Height, map.Width]; foreach (var obj in solids) { int x = (int)Math.Floor(obj.X / map.TileWidth); int y = (int)Math.Floor(obj.Y / map.TileHeight); int w = (int)Math.Floor(obj.Width / map.TileWidth); int h = (int)Math.Floor(obj.Height / map.TileHeight); for (int yy = y; yy < y + h; yy++) { for (int xx = x; xx < x + w; xx++) { if (xx < 0 || xx > map.Width - 1) { continue; } if (yy < 0 || yy > map.Height - 1) { continue; } astar_collision_map[yy, xx] = true; } } } } }
public Level_1_Screen(Screen_Manager screen_manager, World _world, GameCamera _camera, PenumbraComponent _lighting, Particle_World _particle_world, Physics_Engine _physics_engine, Lua lua, GraphicsDevice device) : base(_world, _camera, _lighting, _particle_world, _physics_engine, lua, device, "Level 1") { //sky = new Sky_Renderer(Assets.It.Get<Texture2D>("sky_1"), false); world = _world; pause_menu = new Pause_Menu(screen_manager, camera); }