public object Clone() { FrameAnimation anim = new FrameAnimation(); anim.frameLength = frameLength; anim.frames = frames; return anim; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); //needs to be after base.Initialize because that creates sprite FrameAnimation up = new FrameAnimation(2, 32, 32, 0, 0); up.FramesPerSecond = 4; sprite.Animations.Add("Up", up); FrameAnimation down = new FrameAnimation(2, 32, 32, 64, 0); down.FramesPerSecond = 4; sprite.Animations.Add("Down", down); FrameAnimation left = new FrameAnimation(2, 32, 32, 128, 0); left.FramesPerSecond = 4; sprite.Animations.Add("Left", left); FrameAnimation right = new FrameAnimation(2, 32, 32, 192, 0); right.FramesPerSecond = 4; sprite.Animations.Add("Right", right); Random rand = new Random(); foreach (AnimatedSprite s in npcs) { s.Animations.Add("Up", (FrameAnimation)up.Clone()); s.Animations.Add("Down", (FrameAnimation)down.Clone()); s.Animations.Add("Left", (FrameAnimation)left.Clone()); s.Animations.Add("Right", (FrameAnimation)right.Clone()); int animation = rand.Next(3); switch(animation) { case 0: s.CurrentAnimationName = "Up"; break; case 1: s.CurrentAnimationName = "Down"; break; case 2: s.CurrentAnimationName = "Left"; break; case 3: s.CurrentAnimationName = "Right"; break; } //position of NPCs s.Position = new Vector2( //use tileMap.GetWidthInPixel() - 32 to set size to full map rand.Next(600), rand.Next(400)); } sprite.CurrentAnimationName = "Down"; }
protected override void Initialize() { dialog = new Dialog(this, Content); Components.Add(dialog); dialog.Enabled = false; dialog.Visible = false; base.Initialize(); FrameAnimation up = new FrameAnimation(2, 32, 32, 0, 0); up.FramesPerSecond = 6; sprite.Animations.Add("Up", up); FrameAnimation down = new FrameAnimation(2, 32, 32, 32 * 2, 0); down.FramesPerSecond = 6; sprite.Animations.Add("Down", down); FrameAnimation left = new FrameAnimation(2, 32, 32, 32 * 4, 0); left.FramesPerSecond = 6; sprite.Animations.Add("Left", left); FrameAnimation right = new FrameAnimation(2, 32, 32, 32 * 6, 0); right.FramesPerSecond = 6; sprite.Animations.Add("Right", right); Random rand = new Random(); foreach (AnimatedSprite s in npcs) { s.OriginOffset = new Vector2(16, 30); s.Animations.Add("Up", new FrameAnimation(2, 32, 32, 0, 0)); s.Animations.Add("Down", new FrameAnimation(2, 32, 32, 32*2, 0)); s.Animations.Add("Left", new FrameAnimation(2, 32, 32, 32*4, 0)); s.Animations.Add("Right", new FrameAnimation(2, 32, 32, 32*6, 0)); // used once all sprites are loaded the same //s.Animations.Add("Up", (FrameAnimation)up.Clone()); //s.Animations.Add("Down", (FrameAnimation)down.Clone()); //s.Animations.Add("Left", (FrameAnimation)left.Clone()); //s.Animations.Add("Right", (FrameAnimation)right.Clone()); int animation = rand.Next(3); switch (animation) { case 0: s.CurrentAnimationName = "Up"; break; case 1: s.CurrentAnimationName = "Down"; break; case 2: s.CurrentAnimationName = "Left"; break; case 3: s.CurrentAnimationName = "Right"; break; } s.Postition = new Vector2(rand.Next(600), rand.Next(400)); renderList.Add(s); } sprite.CurrentAnimationName = "Down"; renderList.Add(sprite); }
public void AddDoor(Vector2 position) { Door door = new Door(); door.Animations.Add("Closed", new FrameAnimation(1, 96, 64, 0, 0)); FrameAnimation Opening = new FrameAnimation(4, 96, 64, 0, 0); Opening.FramesPerSecond = 5; door.Animations.Add("Opening", Opening); door.Animations.Add("Open", new FrameAnimation(1, 96, 64, 0, 192)); door.CurrentAnimationName = "Closed"; door.Postition = position; doors.Add(door); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { dialog = new Dialog(this, Content); Components.Add(dialog); dialog.Visible = false; base.Initialize(); // TODO: Move into content loader // <Player> // <Texture Name="blah" /> // <FrameHeight>32></FrameHeight> // <FrameWidth>32</FrameWidth> // <FrameAnimations> // <FrameAnimation Key="Down" FrameCount="3" FrameCount OffsetX="0" OffsetY="0" /> // <FrameAnimation Key="Left" FrameCount="3" FrameCount OffsetX="96" OffsetY="0" /> // <FrameAnimation Key="Down" FrameCount="3" FrameCount OffsetX="192" OffsetY="0" /> // <FrameAnimation Key="Down" FrameCount="3" FrameCount OffsetX="288" OffsetY="0" /> // </FrameAnimations> // </Animation> FrameAnimation down = new FrameAnimation(3, 32, 32, 0, 0); down.FramesPerSecond = 10; playerSprite.Animations.Add("Down", down); FrameAnimation left = new FrameAnimation(3, 32, 32, 96, 0); left.FramesPerSecond = 10; playerSprite.Animations.Add("Left", left); FrameAnimation right = new FrameAnimation(3, 32, 32, 192, 0); right.FramesPerSecond = 10; playerSprite.Animations.Add("Right", right); FrameAnimation up = new FrameAnimation(3, 32, 32, 288, 0); up.FramesPerSecond = 10; playerSprite.Animations.Add("Up", up); Random rand = new Random(); foreach (NPC s in npcs.Values) { s.Animations.Add("Down", (FrameAnimation)down.Clone()); s.Animations.Add("Up", (FrameAnimation)up.Clone()); s.Animations.Add("Left", (FrameAnimation)left.Clone()); s.Animations.Add("Right", (FrameAnimation)right.Clone()); int animation = rand.Next(0, 3); switch (animation) { case 0: s.CurrentAnimationName = "Up"; break; case 1: s.CurrentAnimationName = "Down"; break; case 2: s.CurrentAnimationName = "Left"; break; case 3: s.CurrentAnimationName = "Right"; break; } s.Position = new Vector2( rand.Next(400), rand.Next(400)); } playerSprite.CurrentAnimationName = "Down"; renderList.Add(playerSprite); renderList.AddRange(npcs.Values); // TODO: add triggers to a resource // <NPC> // <blah></blah> // <more></more> // <blah></blah> // <Triggers> // <Trigger Type="DialogTrigger"> // <CreationParameters>Quest1</CreationParameters> // <Regions> // <Region Type="Circular" /> <!-- default radius is collisionradius * 2, specify a different one if desired // </Regions> // </Trigger> // </Triggers> // Trigger dialogTrigger = new DialogTrigger(npc, "Quest1"); dialogTrigger.AddTriggerRegion(new ProximityRegion(npc, npc.CollisionRadius * 2)); //CircularTriggerRegion(npc.Position, npc.CollisionRadius * 2)); npcTriggers.AddTrigger(dialogTrigger); npc.Target = playerSprite; EventService.Subscribe( EventNames.RemoveConversation, new EventHandler<GlobalEventEventArgs>( (sender, e) => { RemoveConversation(e.Message); } )); EventService.Subscribe( EventNames.EndConversationEvent, new EventHandler<GlobalEventEventArgs>( (sender, e) => { dialog.Visible = false; } )); EventService.Subscribe( EventNames.StartConversationEvent, new EventHandler<GlobalEventEventArgs>( (sender, e) => { StartConversation(e.Message); } ) ); }