private static void handleInteractive(Game1 game, JObject layer, Dictionary<int,TileInfo> tileinfo, List<Block> list) { JArray objects = (JArray)layer["objects"]; foreach (JObject obj in objects) { int x = (int) obj["x"]; int y = (int) obj["y"]; var kind = (string)obj["type"]; var name = (string)obj["name"]; Block createdBlock = null; if (obj["gid"] != null) { createdBlock = handleInteractiveTile(game, tileinfo, obj, name, kind, x, y); } else { createdBlock = handleInteractiveEntity(game, tileinfo, obj, name, kind, x, y); } if (createdBlock == null) { Console.WriteLine("bad block x={0} y={1} name={2}", x, y, name); } else { list.Add(createdBlock); } } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (Game1 game = new Game1()) { game.Run(); } }
public Hud(Game1 game, Player player) { this.screenBox = new Rectangle(0, 0, game.mapWidth, game.mapHeight); this.player = player; this.thermoFrame = game.ConditionalLoadSprite("thermoframe", "sprites/thermo_frame-01"); this.thermoFill = game.ConditionalLoadSprite("thermofill", "sprites/thermo_fill-01"); this.warningCool = game.ConditionalLoadSprite("tiles/warning_cool-01"); this.warningHot = game.ConditionalLoadSprite("tiles/warning_heat-01"); }
public Player(int x, int y, Sprite sprite, Game1 g, ViewArea viewArea) : base(x, y, sprite) { startPosition = new Vector2(x, y); Position = new Vector2(x, y); game = g; heat = 30; velocity = Vector2.Zero; acceleration = Vector2.Zero; this.viewArea = viewArea; this.punchSprite = new Sprite(g.ConditionalLoadSprite("punch", "sprites/fireball")); this.SetupAnimationSprites(); }
public static void ReadInMapData(Game1 game, String mapName) { string basepath = @"..\..\..\..\IndieSpeedRunContent\maps\"; if (Directory.Exists("maps")) { basepath = @"maps\"; } String filePath = basepath + mapName + ".json"; JObject root = getMapRoot(filePath); var tileinfo = parseTileSets((JArray)root["tilesets"]); JArray layers = (JArray)root["layers"]; if (layers.Count >= 3) { for (int i = 0; i < layers.Count; i++) { JObject layer = (JObject)layers[i]; List<Block> destination = null; switch ((String) layer["name"]) { case "Background": destination = game.currentMap.BottomLayer; break; case "Gameplay": destination = game.currentMap.Blocks; break; case "Interactive": handleInteractive(game, layer, tileinfo, game.currentMap.Interactables); destination = null; break; case "Foreground": destination = game.currentMap.TopLayer; break; default: throw new Exception("Unknown layer type"); } if (destination != null) handleLayer(game, layer, tileinfo, destination); } } else { handleLayer(game, (JObject)layers[0], tileinfo, game.currentMap.Blocks); } game.currentMap.ReduceCollisionBlocks(); }
public Parallax(Game1 game) { this.backLayer = game.ConditionalLoadSprite("tiles/scene-01"); this.frontLayer = game.ConditionalLoadSprite("tiles/scene2-01"); this.destRect = new Rectangle(0, 0, game.mapWidth, game.mapHeight); }
private static void handleLayer(Game1 game, JObject layer, Dictionary<int, TileInfo> tileinfo, List<Block> blocks) { game.currentMap.Height = (int)layer["height"]; int width = game.currentMap.Width = (int)layer["width"]; JArray blockData = (JArray)layer["data"]; for (int y = 0; y < game.currentMap.Height; y++) { for (int x = 0; x < width; x++) { int pos = y * width + x; int curItem = (int)blockData[pos]; if (curItem == 0) continue; TileInfo ti = tileinfo[curItem]; Sprite sprite = new Sprite(game.ConditionalLoadSprite(ti.Loc, ti.Path), ti.Origin); blocks.Add(new Block(x * Game1.TILE_SIZE, y * Game1.TILE_SIZE, sprite)); } } game.currentMap.ReduceCollisionBlocks(); }
private static Block handleInteractiveTile(Game1 game, Dictionary<int, TileInfo> tileinfo, JObject obj, string name, string kind, int x, int y) { int gid = (int)obj["gid"]; var ti = tileinfo[gid]; Sprite sprite = new Sprite(game.ConditionalLoadSprite(ti.Loc, ti.Path), ti.Origin); y = y - 32; switch (kind) { case "door": return new SwitchBlock(x, y, sprite); // FIXME case "switch": return new SwitchBlock(x, y, sprite); case "breakable": var b = new BreakableBlock(x, y, sprite, game.currentMap); return b; case "lantern": var lb = new LanternBlock(x, y, sprite, name); game.currentMap.AddSpawn(x, y, name); return lb; } return null; }
private static Block handleInteractiveEntity(Game1 game, Dictionary<int, TileInfo> tileinfo, JObject obj, string name, string kind, int x, int y) { int width = (int)obj["width"]; int height = (int)obj["height"]; switch (kind) { case "spawn": game.currentMap.AddSpawn(x, y, name); return null; case "thermal": int amount = int.Parse((string)obj["properties"]["value"]); return new HeatBlock(x, y, width, height, amount); case "exit": string destination = (string) obj["properties"]["destination"]; game.currentMap.AddExit(new Rectangle(x, y, width, height), destination); break; } return null; }