public void LoadContent(MainPlayScreen screen) { this.screen = screen; var animationSpriteSheet = CONTENT_MANAGER.Sprites["animation"]; font = MainPlayScreen.font; var frames = JsonConvert.DeserializeObject <List <KeyValuePair <string, Rectangle> > >(File.ReadAllText(@"Content/sprite/animation.json")); var anims = new List <Animation>(); var animnames = Enum.GetNames(typeof(AnimationName)); foreach (var an in animnames) { anims.Add(LoadAnimation(an, frames)); } animatedEntity = new AnimatedEntity(IsoPos, VT2.Zero, Color.White, 0.4f, Constant.SCALE); animatedEntity.LoadContent(animationSpriteSheet); animatedEntity.AddAnimation(anims); animatedEntity.PlayAnimation(AnimationName.idle_right.ToString()); walksfx = CONTENT_MANAGER.Sounds["footstep"].CreateInstance(); walksfx.Volume = 0f; leversfx = CONTENT_MANAGER.Sounds["lever"].CreateInstance(); floorswitchpressedsfx = CONTENT_MANAGER.Sounds["switch_pressed"].CreateInstance(); floorswitchreleasedsfx = CONTENT_MANAGER.Sounds["switch_released"].CreateInstance(); timer = new Timer(); }
public static Unit Create(UnitType unittype, Owner owner, int hp = 10, AnimationName startingAnimation = AnimationName.idle, Guid guid = default(Guid)) { AnimatedEntity animEntity = new AnimatedEntity(Vector2.Zero, Vector2.Zero, Color.White, LayerDepth.Unit); animEntity.LoadContent(CONTENT_MANAGER.animationSheets[unittype.GetSpriteSheetUnit(owner)]); #region declare animation frame Animation idle; Animation right; Animation up; Animation down; Animation done; switch (unittype) { case UnitType.TransportCopter: case UnitType.BattleCopter: animEntity.Origin = new Vector2(8, 16); idle = new Animation("idle", true, 3, string.Empty); for (int i = 0; i < 3; i++) { idle.AddKeyFrame(i * 64, 0, 64, 64); } right = new Animation("right", true, 4, string.Empty); for (int i = 0; i < 4; i++) { right.AddKeyFrame(i * 64, 64, 64, 64); } up = new Animation("up", true, 4, string.Empty); for (int i = 0; i < 4; i++) { up.AddKeyFrame(i * 64, 128, 64, 64); } down = new Animation("down", true, 4, string.Empty); for (int i = 0; i < 4; i++) { down.AddKeyFrame(i * 64, 192, 64, 64); } done = new Animation("done", true, 1, string.Empty); done.AddKeyFrame(0, 256, 64, 64); break; case UnitType.Fighter: case UnitType.Bomber: animEntity.Origin = new Vector2(8, 16); idle = new Animation("idle", true, 4, string.Empty); for (int i = 0; i < 4; i++) { idle.AddKeyFrame(i * 64, 0, 64, 64); } right = new Animation("right", true, 4, string.Empty); for (int i = 0; i < 4; i++) { right.AddKeyFrame(i * 64, 64, 64, 64); } up = new Animation("up", true, 4, string.Empty); for (int i = 0; i < 4; i++) { up.AddKeyFrame(i * 64, 128, 64, 64); } down = new Animation("down", true, 4, string.Empty); for (int i = 0; i < 4; i++) { down.AddKeyFrame(i * 64, 192, 64, 64); } done = new Animation("done", true, 1, string.Empty); done.AddKeyFrame(0, 256, 64, 64); break; default: idle = new Animation("idle", true, 4, string.Empty); for (int i = 0; i < 4; i++) { idle.AddKeyFrame(i * 48, 0, 48, 48); } right = new Animation("right", true, 4, string.Empty); for (int i = 0; i < 4; i++) { right.AddKeyFrame(i * 48, 48, 48, 48); } up = new Animation("up", true, 4, string.Empty); for (int i = 0; i < 4; i++) { up.AddKeyFrame(i * 48, 96, 48, 48); } down = new Animation("down", true, 4, string.Empty); for (int i = 0; i < 4; i++) { down.AddKeyFrame(i * 48, 144, 48, 48); } done = new Animation("done", true, 1, string.Empty); done.AddKeyFrame(0, 192, 48, 48); break; } #endregion animEntity.AddAnimation(idle, right, up, down, done); Unit result; if (guid == default(Guid)) { result = new Unit(unittype, animEntity, owner, hp); } else { result = new Unit(unittype, animEntity, owner, guid, hp); } result.Animation.PlayAnimation(startingAnimation.ToString()); return(result); }
public void LoadContent(Texture2D spritesheet) { AnimatedEntity.LoadContent(spritesheet); }
private static void LoadAnimationContent() { //string delimit = "Yellow"; CONTENT_MANAGER.animationEntities = new Dictionary <SpriteSheetUnit, AnimatedEntity>(); CONTENT_MANAGER.animationSheets = new Dictionary <SpriteSheetUnit, Texture2D>(); CONTENT_MANAGER.animationTypes = new List <Animation>(); //list of unit type var UnitTypes = new List <SpriteSheetUnit>((IEnumerable <SpriteSheetUnit>)Enum.GetValues(typeof(SpriteSheetUnit))); //Artillery //load animation sprite sheet for each unit type foreach (SpriteSheetUnit unittype in UnitTypes) { var paths = unittype.ToString().Split('_'); //if (paths[0].CompareTo(delimit) == 0) { // break; } CONTENT_MANAGER.animationSheets.Add(unittype, CONTENT_MANAGER.Content.Load <Texture2D>("sprite//Animation//" + paths[0] + "//" + paths[1])); } //declare animation frame //animation frame for "normal" unit Animation idle = new Animation("idle", true, 4, string.Empty); for (int i = 0; i < 4; i++) { idle.AddKeyFrame(i * 48, 0, 48, 48); } Animation right = new Animation("right", true, 4, string.Empty); for (int i = 0; i < 4; i++) { right.AddKeyFrame(i * 48, 48, 48, 48); } Animation up = new Animation("up", true, 4, string.Empty); for (int i = 0; i < 4; i++) { up.AddKeyFrame(i * 48, 96, 48, 48); } Animation down = new Animation("down", true, 4, string.Empty); for (int i = 0; i < 4; i++) { down.AddKeyFrame(i * 48, 144, 48, 48); } Animation done = new Animation("done", true, 1, string.Empty); done.AddKeyFrame(0, 192, 48, 48); //animation frame for "HIGH" unit Animation idleAir = new Animation("idle", true, 4, string.Empty); for (int i = 0; i < 4; i++) { idleAir.AddKeyFrame(i * 64, 0, 64, 64); } Animation rightAir = new Animation("right", true, 4, string.Empty); for (int i = 0; i < 4; i++) { rightAir.AddKeyFrame(i * 64, 64, 64, 64); } Animation upAir = new Animation("up", true, 4, string.Empty); for (int i = 0; i < 4; i++) { upAir.AddKeyFrame(i * 64, 128, 64, 64); } Animation downAir = new Animation("down", true, 4, string.Empty); for (int i = 0; i < 4; i++) { downAir.AddKeyFrame(i * 64, 192, 64, 64); } Animation doneAir = new Animation("done", true, 1, string.Empty); doneAir.AddKeyFrame(0, 256, 64, 64); //animation frame for copter unit Animation idleCopter = new Animation("idle", true, 3, string.Empty); for (int i = 0; i < 3; i++) { idleCopter.AddKeyFrame(i * 64, 0, 64, 64); } CONTENT_MANAGER.animationTypes.Add(idle); CONTENT_MANAGER.animationTypes.Add(right); CONTENT_MANAGER.animationTypes.Add(up); CONTENT_MANAGER.animationTypes.Add(down); CONTENT_MANAGER.animationTypes.Add(done); foreach (SpriteSheetUnit unittype in UnitTypes) { string unittypestring = unittype.ToString(); AnimatedEntity temp = new AnimatedEntity(Vector2.Zero, Vector2.Zero, Color.White, LayerDepth.Unit); //if (unittypestring.Contains(delimit)) { //break; } temp.LoadContent(CONTENT_MANAGER.animationSheets[unittype]); if (unittypestring.Contains("TransportCopter") || unittypestring.Contains("BattleCopter") || unittypestring.Contains("Fighter") || unittypestring.Contains("Bomber")) { //we enter "HIGH" mode //first we set the origin to "HIGH" //because we are drawing from topleft and the sprite size is 64x64 temp.Origin = new Vector2(8, 16); //then we load the "HIGH" animation in if (unittypestring.Contains("Copter")) { temp.AddAnimation(idleCopter, rightAir, upAir, downAir, doneAir); } else { temp.AddAnimation(idleAir, rightAir, upAir, downAir, doneAir); } } else { //we enter "normal" mode temp.AddAnimation(idle, right, up, down, done); } temp.PlayAnimation("idle"); CONTENT_MANAGER.animationEntities.Add(unittype, temp); } }