public Checkpoint(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y, 32, 32) { imageFile = "checkpoint.png"; name = obj.Name.ToLower(); activated = false; }
private NpcSpawner LoadNpcSpawner(TmxObjectGroup.TmxObject tmxObject, OrderedDictionary<string, IGameObject> gameObjects, ContentManager content) { OrderedDictionary<string, Npc> _npcs = new OrderedDictionary<string, Npc>(); var xmlDoc = new XmlDocument(); xmlDoc.Load(tmxObject.Properties["SpawnerFile"]); XmlNodeList nodes = xmlDoc.SelectNodes("NPCS/NPC"); var spawningEntities = new List<IEntity>(); for (int i = 0; i < nodes.Count; i++) { // Load the npcs for the spawner. string uniqueID = nodes[i].Attributes["UniqueID"].Value; string npcDataFilePath = nodes[i].Attributes["filepath"].Value; spawningEntities.Add(Npc.Load(npcDataFilePath, uniqueID, content)); } var spawnerPosition = new Vector2(tmxObject.X, tmxObject.Y); var updateInterval = uint.Parse(tmxObject.Properties["UpdateInterval"]); return new NpcSpawner(spawnerPosition, updateInterval, gameObjects, spawningEntities); }
public Checkpoint(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y, 32, 32) { imageFile = "checkpoint.png"; name = obj.Name.ToLower(); activated = false; soundFiles.Add("Sounds/Checkpoint.wav"); }
// Tiled constructor public Block(TmxObjectGroup.TmxObject obj) : this(obj.X, obj.Y, obj.Properties.ContainsKey("left") ? Boolean.Parse(obj.Properties["left"]) : false, obj.Properties.ContainsKey("right") ? Boolean.Parse(obj.Properties["right"]) : false, obj.Properties.ContainsKey("gravity") ? Boolean.Parse(obj.Properties["gravity"]) : false, obj.Properties.ContainsKey("canBreak") ? Boolean.Parse(obj.Properties["canBreak"]) : false, obj.Name) { }
public TmxGroup(XElement xGroup, int width, int height, string tmxDirectory) { Name = (string)xGroup.Attribute("name") ?? String.Empty; Opacity = (double?)xGroup.Attribute("opacity") ?? 1.0; Visible = (bool?)xGroup.Attribute("visible") ?? true; OffsetX = (double?)xGroup.Attribute("offsetx") ?? 0.0; OffsetY = (double?)xGroup.Attribute("offsety") ?? 0.0; Properties = new PropertyDict(xGroup.Element("properties")); Layers = new TmxList <ITmxLayer>(); TileLayers = new TmxList <TmxLayer>(); ObjectGroups = new TmxList <TmxObjectGroup>(); ImageLayers = new TmxList <TmxImageLayer>(); Groups = new TmxList <TmxGroup>(); foreach (var e in xGroup.Elements().Where(x => x.Name == "layer" || x.Name == "objectgroup" || x.Name == "imagelayer" || x.Name == "group")) { ITmxLayer layer; switch (e.Name.LocalName) { case "layer": var tileLayer = new TmxLayer(e, width, height); layer = tileLayer; TileLayers.Add(tileLayer); break; case "objectgroup": var objectgroup = new TmxObjectGroup(e); layer = objectgroup; ObjectGroups.Add(objectgroup); break; case "imagelayer": var imagelayer = new TmxImageLayer(e, tmxDirectory); layer = imagelayer; ImageLayers.Add(imagelayer); break; case "group": var group = new TmxGroup(e, width, height, tmxDirectory); layer = group; Groups.Add(group); break; default: throw new InvalidOperationException(); } Layers.Add(layer); } }
//TODO: add in function passing for individual button actions public Cannon(TmxObjectGroup.TmxObject obj) : base(obj.X + 16, obj.Y, 32, 32) { this.imageFile = "cannon.png"; this.name = obj.Name; isSolid = true; frameWidth = 64; spriteWidth = 64; collisionWidth = 64; faceLeft = false; direction = obj.Properties["direction"]; if (direction == "left") faceLeft = true; }
public Roller(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y, 32, 32) { imageFile = "roller_new.png"; name = obj.Name; faceLeft = obj.Properties.ContainsKey("left") && Boolean.Parse(obj.Properties["left"]); isSolid = true; collisionHeight = 8; spriteY += 12; speed = faceLeft ? -2 : 2; }
//TODO: add in function passing for individual button actions public Geyser(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y - 16, 32, 32) { this.imageFile = "geyser.png"; name = obj.Name; speed = -5; frameHeight = 128; spriteHeight = 128; collisionHeight = 112; Random rnd = new Random(); seed = rnd.Next(64); // For animation }
/// <summary> /// Initializes a new instance of the <see cref="TiledMapObjectLayer" /> class. /// </summary> /// <param name="tmxObjectLayer">The TMX parsed object layer</param> public TiledMapObjectLayer(TmxObjectGroup tmxObjectLayer) { this.ObjectLayerName = tmxObjectLayer.Name; this.Color = new Color(tmxObjectLayer.Color.R, tmxObjectLayer.Color.G, tmxObjectLayer.Color.B); this.Opacity = tmxObjectLayer.Opacity; this.Visible = tmxObjectLayer.Visible; this.Objects = new List<TiledMapObject>(); this.Properties = new Dictionary<string, string>(tmxObjectLayer.Properties); foreach(var tmxObject in tmxObjectLayer.Objects) { var tiledMapObject = new TiledMapObject(tmxObject); this.Objects.Add(tiledMapObject); } }
// TODO: add in function passing for individual button actions public Button(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y, 32, 32) { imageFile = "button.png"; holdButton = obj.Properties.ContainsKey("hold") && Boolean.Parse(obj.Properties["hold"]); displayText = obj.Properties.ContainsKey("text") ? obj.Properties["text"] : ""; displayTextX = -35; displayTextY = -40; spriteColor = holdButton ? Color.CornflowerBlue : Color.OrangeRed; activated = false; pressed = false; creditScreen = false; controlScreen = false; soundFiles.Add("Sounds/button.wav"); soundFiles.Add("Sounds/HoldButtonPress.wav"); soundFiles.Add("Sounds/HoldButtonRel.wav"); name = obj.Name; collisionWidth = 20; collisionHeight = 30; depth = -1; if (obj.Properties["direction"].Equals("left")) { faceLeft = true; spriteX -= 9; } else if (obj.Properties["direction"].Equals("right")) { faceLeft = false; spriteX += 9; } else if (obj.Properties["direction"].Equals("up")) { rotationAngle = MathHelper.PiOver2 * 3; spriteY -= 9; collisionHeight = 24; collisionWidth = 30; } else { rotationAngle = MathHelper.PiOver2; spriteY += 9; collisionHeight = 24; collisionWidth = 30; } }
//TODO: add in function passing for individual button actions public Geyser(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y - 12, 64, 128) { this.imageFile = "geyser.png"; name = obj.Name; // isSolid = true; frameWidth = 64; frameHeight = 128; collisionWidth = 32; collisionHeight = 112; Random rnd = new Random(); seed = rnd.Next(64); // For animation }
public Pipe(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y, 32, 32) { imageFile = "pipe.png"; isSolid = true; name = obj.Name; collisionWidth = 32; collisionHeight = 32; this.direction = obj.Properties.ContainsKey ("direction") ? (obj.Properties ["direction"]) : "up"; this.destination = obj.Properties.ContainsKey("destination") ? obj.Properties["destination"] : ""; displayText = obj.Properties.ContainsKey("text") ? obj.Properties["text"] : ""; displayTextColor = Color.Black; spriteColor = name.Contains("endPipe") ? Color.Gold : Color.White; if (this.direction == "up") { frameIndexX = 0; displayTextX = -5; displayTextY = -5; } else if (this.direction == "left") { frameIndexX = 0; rotationAngle = MathHelper.PiOver2 * 3; displayTextX = 3; displayTextY = -11; } else if (this.direction == "right") { frameIndexX = 0; rotationAngle = MathHelper.PiOver2; displayTextX = -9; displayTextY = -11; } else if (this.direction == "down") { frameIndexX = 32; } }
private ParticleEmitter LoadParticleEmitter(TmxObjectGroup.TmxObject tmxObject, ContentManager content) { ParticleEmitter particleEmitter = null; Texture2D[] particleTextures = ContentManagerUtilities.LoadParticleTextures(tmxObject.Properties["TexturesFile"], content); int particleCount = int.Parse(tmxObject.Properties["ParticleCount"]); Vector2 position = new Vector2(tmxObject.X, tmxObject.Y); // Get the emitter type. switch (tmxObject.Properties["EmitterType"].ToLower()) { case "default": particleEmitter = new ParticleEmitter(particleTextures, particleCount, position); break; case "spread": uint xIntensity = uint.Parse(tmxObject.Properties["XIntensity"]); uint yIntensity = uint.Parse(tmxObject.Properties["YIntensity"]); particleEmitter = new SpreadParticleEmitter(particleTextures, particleCount, position, xIntensity, yIntensity); break; case "directional": bool positiveXVelocity = bool.Parse(tmxObject.Properties["PositiveXVelocity"]); bool positiveYVelocity = bool.Parse(tmxObject.Properties["PositiveYVelocity"]); particleEmitter = new DirectionalParticleEmitter(particleTextures, particleCount, position, positiveXVelocity, positiveYVelocity); break; } particleEmitter.Initialize(); particleEmitter.Emitting = true; return particleEmitter; }
void ParseCollisionLayer(TmxObjectGroup objectGroup) { foreach (TmxObjectGroup.TmxObject obj in objectGroup.Objects) { PhysicsObject pobj; pobj.Position.X = (obj.X + obj.Width / 2) * Scale; // move xy from top left to center of shape pobj.Position.Y = (obj.Y + obj.Height / 2) * Scale; pobj.Width = obj.Width * Scale; pobj.Height = obj.Height * Scale; PhysicsObjects.Add(pobj); } }
public SpikeBall(TmxObjectGroup.TmxObject obj) : this(obj.X, obj.Y) { }
public Face(TmxObjectGroup.TmxObject obj) : this(obj.X, obj.Y) { }
public Bird(TmxObjectGroup.TmxObject obj) : this(obj.X, obj.Y) { }
private void Load(XDocument xDoc) { var xMap = xDoc.Element("map"); Version = (string)xMap.Attribute("version"); TiledVersion = (string)xMap.Attribute("tiledversion"); Width = (int)xMap.Attribute("width"); Height = (int)xMap.Attribute("height"); TileWidth = (int)xMap.Attribute("tilewidth"); TileHeight = (int)xMap.Attribute("tileheight"); HexSideLength = (int?)xMap.Attribute("hexsidelength"); // Map orientation type var orientDict = new Dictionary <string, OrientationType> { { "unknown", OrientationType.Unknown }, { "orthogonal", OrientationType.Orthogonal }, { "isometric", OrientationType.Isometric }, { "staggered", OrientationType.Staggered }, { "hexagonal", OrientationType.Hexagonal }, }; var orientValue = (string)xMap.Attribute("orientation"); if (orientValue != null) { Orientation = orientDict[orientValue]; } // Hexagonal stagger axis var staggerAxisDict = new Dictionary <string, StaggerAxisType> { { "x", StaggerAxisType.X }, { "y", StaggerAxisType.Y }, }; var staggerAxisValue = (string)xMap.Attribute("staggeraxis"); if (staggerAxisValue != null) { StaggerAxis = staggerAxisDict[staggerAxisValue]; } // Hexagonal stagger index var staggerIndexDict = new Dictionary <string, StaggerIndexType> { { "odd", StaggerIndexType.Odd }, { "even", StaggerIndexType.Even }, }; var staggerIndexValue = (string)xMap.Attribute("staggerindex"); if (staggerIndexValue != null) { StaggerIndex = staggerIndexDict[staggerIndexValue]; } // Tile render order var renderDict = new Dictionary <string, RenderOrderType> { { "right-down", RenderOrderType.RightDown }, { "right-up", RenderOrderType.RightUp }, { "left-down", RenderOrderType.LeftDown }, { "left-up", RenderOrderType.LeftUp } }; var renderValue = (string)xMap.Attribute("renderorder"); if (renderValue != null) { RenderOrder = renderDict[renderValue]; } NextObjectID = (int?)xMap.Attribute("nextobjectid"); BackgroundColor = new TmxColor(xMap.Attribute("backgroundcolor")); Properties = new PropertyDict(xMap.Element("properties")); Tilesets = new TmxList <TmxTileset>(); foreach (var e in xMap.Elements("tileset")) { Tilesets.Add(new TmxTileset(e, TmxDirectory, CustomLoader)); } Layers = new TmxList <ITmxLayer>(); TileLayers = new TmxList <TmxLayer>(); ObjectGroups = new TmxList <TmxObjectGroup>(); ImageLayers = new TmxList <TmxImageLayer>(); Groups = new TmxList <TmxGroup>(); foreach (var e in xMap.Elements().Where(x => x.Name == "layer" || x.Name == "objectgroup" || x.Name == "imagelayer" || x.Name == "group")) { ITmxLayer layer; switch (e.Name.LocalName) { case "layer": var tileLayer = new TmxLayer(e, Width, Height); layer = tileLayer; TileLayers.Add(tileLayer); break; case "objectgroup": var objectgroup = new TmxObjectGroup(e); layer = objectgroup; ObjectGroups.Add(objectgroup); break; case "imagelayer": var imagelayer = new TmxImageLayer(e, TmxDirectory); layer = imagelayer; ImageLayers.Add(imagelayer); break; case "group": var group = new TmxGroup(e, Width, Height, TmxDirectory); layer = group; Groups.Add(group); break; default: throw new InvalidOperationException(); } Layers.Add(layer); } }
void ParseParallaxLayer(TmxObjectGroup objectGroup) { foreach (TmxObjectGroup.TmxObject obj in objectGroup.Objects) { ParallaxSprite sprite; sprite.Texture = spriteSheets[idSheet[obj.Tile.Gid]]; sprite.Position.X = (obj.X + sprite.Texture.Size.X / 2) * Scale; // move xy from top left to center of shape sprite.Position.Y = (obj.Y + sprite.Texture.Size.Y / 2) * Scale; sprite.Width = sprite.Texture.Size.X * Scale; sprite.Height = sprite.Texture.Size.Y * Scale; sprite.SubImageRect = subImageRects[obj.Tile.Gid]; float parallaxFactor; if (objectGroup.Properties.ContainsKey("parallax_factor")) { if (float.TryParse(objectGroup.Properties["parallax_factor"], out parallaxFactor)) sprite.ParallaxFactor = parallaxFactor; else sprite.ParallaxFactor = 1.0f; } else sprite.ParallaxFactor = 1.0f; if (objectGroup.Properties.ContainsKey("zindex")) { int zIndex; if (int.TryParse(objectGroup.Properties["zindex"], out zIndex)) sprite.ZIndex = zIndex; else sprite.ZIndex = 0; } else sprite.ZIndex = 0; ParallaxSprites.Add(sprite); } }
public Rat(TmxObjectGroup.TmxObject obj) : this(obj.X, obj.Y) { }
public Pipe(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y, 32, 32) { imageFile = "pipe.png"; isSolid = true; name = obj.Name; collisionWidth = 32; collisionHeight = 32; this.direction = obj.Properties.ContainsKey ("direction") ? (obj.Properties ["direction"]) : "up"; this.destination = obj.Properties.ContainsKey("destination") ? obj.Properties["destination"] : ""; if (this.direction == "up") { frameIndex = 0; } else if (this.direction == "down") { frameIndex = 32; } else if (this.direction == "vertical") { frameIndex = 32*2; } else if (this.direction == "horizontal") { frameIndex = 32*3; } else if (this.direction == "cornerLeft") { frameIndex = 32*4; } else if (this.direction == "cornerLeftR") { frameIndex = 32*5; } else if (this.direction == "cornerRightR") { frameIndex = 32*6; } else if (this.direction == "cornerRight") { frameIndex = 32*7; } else if (obj.Properties["direction"].Equals("end")) { this.direction = "end"; frameIndex = 0; } }
public Hand(TmxObjectGroup.TmxObject obj) : this(obj.X, obj.Y, obj.Properties.ContainsKey("left") ? Boolean.Parse(obj.Properties["left"]) : false) { }
public PowerUp(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y, 32, 32) { imageFile = obj.Name + ".png"; name = obj.Name.ToLower(); }
public NextLevel(TmxObjectGroup.TmxObject obj) : base(obj.X, obj.Y, 32, 32) { imageFile = "NextLevel.png"; levelDestination = obj.Name.ToLower(); }
public Level(string mapFile, GraphicsDeviceManager graphicsManager) { this.isComplete = false; this.bunnydead = false; this.graphics = graphicsManager; this.map = new TmxMap(mapFile); this.Bunny = new Bunny( Single.Parse(map.Properties["bunnySpawnX"]), Single.Parse(map.Properties["bunnySpawnY"])); this.Clyde = new Clyde( Single.Parse(map.Properties["clydeSpawnX"]), Single.Parse(map.Properties["clydeSpawnY"])); this.inventory = new Inventory(0, 0, 55, 55); this.worldSprites = new List<Sprite>(); this.platforms = new List<Sprite>(); this.items = new List<Item>(); this.sounds = new List<SoundEffect>(); this.keys = new List<Item>(); this.ramps = new List<Item>(); this.doors = new List<Item>(); this.buttons = new List<Item>(); this.waters = new List<Item>(); this.goal = new List<Item>(); this.gates = new List<Item>(); this.physics = new Physics(); this.physics.Add(this.Bunny); this.physics.Add(this.Clyde); this.collisions = new CollisionManager(platforms, items, new List<Sprite>()); this.collisions.addMoving(this.Clyde); this.collisions.addMoving(this.Bunny); this.mapObjectsDrawable = map.ObjectGroups["drawable"]; this.mapObjectsNonDrawable = map.ObjectGroups["nondrawable"]; // draw the nondrawable objects as Regions foreach (TmxObjectGroup.TmxObject o in mapObjectsNonDrawable.Objects) { Console.WriteLine("X:" + o.X); Console.WriteLine("Y:" + o.Y); Console.WriteLine("Width:" + o.Width); Console.WriteLine("Height:" + o.Height); Region currentRegion = new Region(o.X, o.Y, o.Width, o.Height); //Sprite currentRegion = new Sprite("ground", o.X, o.Y, o.Width, o.Height); this.worldSprites.Add(currentRegion); this.platforms.Add(currentRegion); } // draw the drawable objects foreach (TmxObjectGroup.TmxObject o in mapObjectsDrawable.Objects) { Item currentObject; Key whiteKey = new Key(Color.AliceBlue, this, 0, 0, 0, 0); if (o.Properties["type"] == "water") { currentObject = new Water(o.X, o.Y, o.Width, o.Height, this); this.waters.Add(currentObject); } else if (o.Properties["type"] == "key") { System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]); Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A); whiteKey = new Key(c, this, o.X, o.Y, o.Width, o.Height); currentObject = whiteKey; this.keys.Add(currentObject); } else if (o.Properties["type"] == "goal_door") { System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]); Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A); currentObject = new Goal(this, c, o.X, o.Y, o.Width, o.Height); this.goal.Add(currentObject); } else if (o.Properties["type"] == "switch_button") { System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]); Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A); currentObject = new Switch(c, this, o.X, o.Y, o.Width, o.Height, false); this.buttons.Add(currentObject); } else if (o.Properties["type"] == "reverse_switch") { System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]); Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A); currentObject = new Switch(c, this, o.X, o.Y, o.Width, o.Height, true); this.buttons.Add(currentObject); } else if (o.Properties["type"] == "switch_gate") { System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]); Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A); currentObject = new Gate(o.Properties["imageName"], c, o.X, o.Y, o.Width, o.Height); this.platforms.Add(currentObject); this.gates.Add(currentObject); } else if (o.Properties["type"] == "door") { System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]); Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A); currentObject = new Door(this, c, o.X, o.Y, o.Width, o.Height); this.platforms.Add(currentObject); this.doors.Add(currentObject); } else if (o.Properties["type"] == "ramp") { Ramp r = new Ramp(o.Properties["imageName"], o.X, o.Y, o.Width, o.Height, this); currentObject = r; this.items.Add(r.leftPushBox); this.worldSprites.Add(r.leftPushBox); this.items.Add(r.rightPushBox); this.worldSprites.Add(r.rightPushBox); this.physics.Add(r); this.platforms.Add(currentObject); this.ramps.Add(currentObject); this.collisions.addMoving(currentObject); } else if (o.Properties["type"] == "cloud") { currentObject = new Cloud(o.Properties["imageName"], o.X, o.Y, o.Width, o.Height); } else { //this shouldn't happen currentObject = new Water(o.X, o.Y, o.Width, o.Height, this); Console.WriteLine(o.Properties["imageName"]); } this.worldSprites.Add(currentObject); this.items.Add(currentObject); } this.PlayerIcon = new PlayerIcon("BunnyCurrentsmall", "ClydeCurrentsmall"); this.background = new Sprite(map.Properties["backgroundImage"], 0, 0, GameGlobals.WINDOW_WIDTH, GameGlobals.WINDOW_HEIGHT); this.worldSprites.Add(this.Bunny); this.worldSprites.Add(this.Clyde); this.worldSprites.Add(this.Clyde.back); this.items.Add(this.Clyde.back); this.platforms.Add(this.Clyde); this.inputManager = new InputManager(worldSprites, this.Bunny, this.Clyde, platforms, sounds, this); this.worldSprites.Add(inventory); this.imshow3 = new imageshow("win", 0, 0, 0, (map.TileHeight * map.Height)); this.worldSprites.Add(imshow3); this.imshow2 = new imageshow("bunnydies", (map.TileWidth * map.Width) / 3, (map.TileHeight * map.Height) / 4, 0, (map.TileHeight * map.Height) / 2); this.worldSprites.Add(imshow2); this.Bunny.die = imshow2; this.Bunny.mapwidth = (map.TileWidth * map.Width) / 3; String logoImage = "mainlogo"; String resetImage = "reset_keyboard.png"; if (GamePad.GetState(PlayerIndex.One).IsConnected) { logoImage = "mainlogo_controller"; resetImage = "reset_controller"; } this.imshow = new imageshow(logoImage, (map.TileWidth * map.Width) / 4, (map.TileHeight * map.Height) / 4, 0, (map.TileHeight * map.Height) / 2); this.imshoww = (map.TileWidth * map.Width) / 2; this.worldSprites.Add(imshow); }