protected override Scene CreateScene() { var scene = new Scene("MainScene"); scene.Add(new ColorLayer("Background", Color.CornflowerBlue)); var spriteSheet = this.CreateSpriteSheet(); this.entityLayer = new SpriteLayer("EntityMap"); scene.Add(this.entityLayer); this.playerShipEntity = new PlayerShipEntity(this.entityLayer, spriteSheet); this.playerShipEntity.BindController(this.InputConfiguration); scene.Add(this.playerShipEntity); var yellowSprite = new Sprite(spriteSheet, "YellowEnemy") { Position = new Vector(250, 100) }; var redSprite = new Sprite(spriteSheet, "RedEnemy") { Position = new Vector(300, 100) }; var blueSprite = new Sprite(spriteSheet, "BlueEnemy") { Position = new Vector(350, 100) }; this.entityLayer.AddSprite(yellowSprite); this.entityLayer.AddSprite(redSprite); this.entityLayer.AddSprite(blueSprite); return scene; }
private BulletEntity(SpriteLayer entityLayer, SpriteSheet shipSheet, Vector position, Vector velocity) { this.entityLayer = entityLayer; this.shipSheet = shipSheet; this.position = position; this.velocity = velocity; this.isActive = true; this.SpriteReference = new SpriteReference { Position = this.position, SpriteName = "Bullet", Sprite = new Sprite(this.shipSheet, "YellowShot") }; this.entityLayer.AddSprite(this.SpriteReference); }
public static SpriteLayer SpriteLayerFromXml(GameResourceManager gameResourceManager, XElement layerElement) { var layerName = layerElement.Attribute("name").Value; var layer = new SpriteLayer(layerName); XmlRepository.BaseFromXml(layer, layerElement); foreach (var element in layerElement.Element("Sprites").Elements()) { var sheetName = element.Attribute("sheetName").Value; var name = element.Attribute("name").Value; var position = element.Attribute("position").Value; var sprite = new Sprite(gameResourceManager.GetSpriteSheet(sheetName), name) { Position = MathUtil.ParseVector(position) }; layer.AddSprite(sprite); } return layer; }
public static XElement ToXml(SpriteLayer spriteLayer) { return new XElement("SpriteLayer", XmlRepository.LayerBaseToXml(spriteLayer), new XElement("Sprites", spriteLayer.Sprites.OfType<Sprite>().Select(GetXml))); }
public PlayerShipEntity(SpriteLayer entityLayer, SpriteSheet shipSheet) { this.entityLayer = entityLayer; this.shipSheet = shipSheet; this.SpriteReference = new SpriteReference { Position = new Vector(300, 400), SpriteName = "Player Ship", Sprite = new Sprite(this.shipSheet, "Ship") }; this.entityLayer.AddSprite(this.SpriteReference); this.bullets = new List<BulletEntity>(); }
public static BulletEntity Create(SpriteLayer entityLayer, SpriteSheet shipSheet, Vector position, Vector velocity) { return new BulletEntity(entityLayer, shipSheet, position, velocity); }
private SpriteLayer CreateSpriteLayer() { var texture = this.ResourceManager.GetTexture(@"Sandbox\LinkSheet"); var sheet = new SpriteSheet(texture, "Link"); sheet.AddSpriteDefinition("Link01", new RectangleInt(3, 3, 16, 22), new Vector(8, 11)); sheet.AddSpriteDefinition("Sleep01", new RectangleInt(45, 219, 32, 40)); var la1 = sheet.AddSpriteDefinition("LinkAnim01", new RectangleInt(187, 270, 28, 28), new Vector(07, 25)); var la2 = sheet.AddSpriteDefinition("LinkAnim02", new RectangleInt(225, 273, 31, 22), new Vector(07, 19)); var la3 = sheet.AddSpriteDefinition("LinkAnim03", new RectangleInt(268, 270, 26, 28), new Vector(06, 19)); var la4 = sheet.AddSpriteDefinition("LinkAnim04", new RectangleInt(303, 266, 17, 35), new Vector(06, 19)); var la5 = sheet.AddSpriteDefinition("LinkAnim05", new RectangleInt(328, 269, 26, 30), new Vector(17, 19)); var la6 = sheet.AddSpriteDefinition("LinkAnim06", new RectangleInt(355, 273, 32, 22), new Vector(23, 19)); var la7 = sheet.AddSpriteDefinition("LinkAnim07", new RectangleInt(389, 271, 24, 25), new Vector(16, 22)); var la8 = sheet.AddSpriteDefinition("LinkAnim08", new RectangleInt(423, 268, 16, 31), new Vector(08, 28)); //var linkAnimTemplate = new SpriteAnimationTemplate("LinkAnim") var linkAnimTemplate = sheet.AddSpriteAnimationTemplate("LinkAnim") .AddFrame(la1, 0.1f) .AddFrame(la2, 0.1f) .AddFrame(la3, 0.1f) .AddFrame(la4, 0.1f) .AddFrame(la5, 0.1f) .AddFrame(la6, 0.1f) .AddFrame(la7, 0.1f) .AddFrame(la8, 0.1f); var crystal = sheet.AddSpriteDefinition("Crystal", new RectangleInt(336, 221, 10, 14), new Vector(4, 6)); //this.linkCompositeTemplate = new SpriteCompositeTemplate("CompositeLink") this.linkCompositeTemplate = sheet.AddSpriteCompositeTemplate("CompositeLink") .AddTemplate(linkAnimTemplate) .AddTemplate(crystal, new SpriteTransform(translation: new Vector(20, 0))); //sheet.Save(@"C:\Users\Pascal\Dev\DotNet\GitHub\XNAGameEngine2D\Link SpriteSheet.xml"); var link01 = new Sprite(sheet, "Link01") { Position = this.player, Color = Color.Blue, Scale = 2, ShouldDrawPixelPrecision = true }; this.sleep01 = new Sprite(sheet, "Sleep01") { Position = new Vector(125, 25), FlipVertically = true }; this.ResourceManager.AddSpriteSheet(sheet); var spriteLayer = new SpriteLayer("Sprites"); spriteLayer.AddSprite(link01); spriteLayer.AddSprite(this.sleep01); spriteLayer.ParallaxScrollingVector = new Vector(4.0f, 8.0f); spriteLayer.Offset = new Vector(50, 50); return spriteLayer; }
private ILayer CreateMouseFollow() { var layer = new SpriteLayer("MouseFollow"); layer.CameraMode = CameraMode.Fix; this.linkMouseFollow = this.linkCompositeTemplate.CreateInstance(); layer.AddSprite(this.linkMouseFollow); return layer; }