protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); var zombieAnimations = Content.Load <SpriteSheetAnimationFactory>("Animations/zombie-animations"); _zombie = new Zombie(zombieAnimations) { Position = new Vector2(100, 100) }; var fireballTexture = Content.Load <Texture2D>("Animations/fireball"); var fireballAtlas = TextureAtlas.Create("Animations/fireball-atlas", fireballTexture, 130, 50); _animation = new SpriteSheetAnimation("fireballAnimation", fireballAtlas.Regions.ToArray()) { FrameDuration = 0.2f }; _fireballSprite = new Sprite(_animation.CurrentFrame);// { Position = new Vector2(-150, 100) }; var motwTexture = Content.Load <Texture2D>("Animations/motw"); var motwAtlas = TextureAtlas.Create("Animations/fireball-atlas", motwTexture, 52, 72); var motwAnimationFactory = new SpriteSheetAnimationFactory(motwAtlas); motwAnimationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0 })); motwAnimationFactory.Add("walkSouth", new SpriteSheetAnimationData(new[] { 0, 1, 2, 1 }, isLooping: false)); motwAnimationFactory.Add("walkWest", new SpriteSheetAnimationData(new[] { 12, 13, 14, 13 }, isLooping: false)); motwAnimationFactory.Add("walkEast", new SpriteSheetAnimationData(new[] { 24, 25, 26, 25 }, isLooping: false)); motwAnimationFactory.Add("walkNorth", new SpriteSheetAnimationData(new[] { 36, 37, 38, 37 }, isLooping: false)); _motwSprite = new AnimatedSprite(motwAnimationFactory);// { Position = new Vector2(20, 20) }; _motwSprite.Play("walkSouth").IsLooping = true; }
protected void UpdateAnimation() { string toPlay; switch (this.Direction) { case 0: toPlay = "Up"; break; case 1: toPlay = "Right"; break; case 2: toPlay = "Down"; break; default: toPlay = "Left"; break; } if (!(this is Player) || Math.Abs(this.Velocity.X) < 0.1 && Math.Abs(this.Velocity.Y) < 0.1) { var diff = this.Position - this.LastPosition; if (Math.Abs(diff.X) < 0.1 && Math.Abs(diff.Y) < 0.1) { toPlay = "Standing" + toPlay; } } if (this.CurrentAnimation.Name != toPlay) { this.CurrentAnimation = this.AnimationFactory.Create(toPlay); } }
void Grenade(Vector2 Target) { foreach (Vector3 v in NavTestStatic.CalculateExplosion_DistributorNoBacksiesTileSplit( Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x), Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y), 200 )) { GameObject blastAnim = new GameObject(); blastAnim.transform.position = new Vector3(v.x, v.y, -5); blastAnim.AddComponent <SpriteRenderer>(); SpriteSheetAnimation banim = blastAnim.AddComponent <SpriteSheetAnimation>(); banim.Sprites = Resources.LoadAll <Sprite>("Fx/Explosion"); banim.LifeSpanInSeconds = 0.5f; banim.Mode = SpriteSheetAnimation.Modes.Destroy; blastAnim.GetComponent <SpriteRenderer>().color = new Color(1, v.z / 30, 0); blastAnim.name = v.z.ToString(); GameObject ActualBlast = new GameObject(); ActualBlast.transform.position = new Vector3(v.x, v.y, -5); ActualBlast.AddComponent <DamagerInflicter>().ini(Entity.team.Neutral, (int)v.z, true, true, 0, 0, false, DamagerInflicter.WeaponTypes.Explosion); ActualBlast.AddComponent <CircleCollider2D>().isTrigger = true; ActualBlast.GetComponent <CircleCollider2D>().radius = 0.6f; ActualBlast.AddComponent <Rigidbody2D>().isKinematic = true; ActualBlast.AddComponent <DieIn>().Frames = 0; } }
private Material CreateDefaultMaterial2D() { var imageData = new ImageCreationData(new Size(8.0f, 8.0f)); imageData.DisableLinearFiltering = true; var image = ContentLoader.Create <Image>(imageData); var colors = new Color[8 * 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if ((i + j) % 2 == 0) { colors[i * 8 + j] = Color.LightGray; } else { colors[i * 8 + j] = Color.DarkGray; } } } image.Fill(colors); spriteSheetAnimation = new SpriteSheetAnimation(new SpriteSheetAnimationCreationData(image, 1, new Size(2, 2))); return(new Material(ShaderFlags.Position2DTextured, "") { SpriteSheet = spriteSheetAnimation }); }
public Handgun(AbstractScene scene, Hero hero) : base(scene, hero) { LeftFacingOffset = new Vector2(-3, -17); RightFacingOffset = new Vector2(3, -17); if (hero.CurrentFaceDirection == Direction.EAST) { Transform.Position = RightFacingOffset; } else { Transform.Position = LeftFacingOffset; } ClipSize = 7; AmmoInClip = ClipSize; AllAmmo = 0; Animations.Offset = Offset; SpriteSheetAnimation animLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Gun"), 40); animLeft.StartFrame = 1; animLeft.EndFrame = 2; SpriteSheetAnimation animRight = animLeft.CopyFlipped(); animLeft = animLeft.CopyFlipped(); animLeft.FlipVertical(); Animations.RegisterAnimation("GunLeft", animLeft, () => CurrentFaceDirection == Direction.WEST); Animations.RegisterAnimation("GunRight", animRight, () => CurrentFaceDirection == Direction.EAST); //AddComponent(Texture); //DEBUG_SHOW_PIVOT = true; }
public Machinegun(AbstractScene scene, Hero hero) : base(scene, hero) { Animations = new AnimationStateMachine(); RemoveComponent <AnimationStateMachine>(); AddComponent(Animations); AllAmmo = 0; //LeftFacingOffset = new Vector2(50, 0); //RightFacingOffset = new Vector2(-50, 0); if (hero.CurrentFaceDirection == Direction.EAST) { Transform.Position = RightFacingOffset; } else { Transform.Position = LeftFacingOffset; } /*SpriteSheetAnimation machineGunLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Machinegun"), 1); * Animations.RegisterAnimation("MachineGunLeft", machineGunLeft, () => CurrentFaceDirection == Direction.WEST); * * SpriteSheetAnimation machineGunRight = machineGunLeft.CopyFlipped(); * machineGunLeft.FlipVertical(); * Animations.RegisterAnimation("MachineGunRight", machineGunRight, () => CurrentFaceDirection == Direction.EAST);*/ SpriteSheetAnimation animLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Machinegun"), 32, 32, 1); SpriteSheetAnimation animRight = animLeft.CopyFlipped(); animLeft = animLeft.CopyFlipped(); animLeft.FlipVertical(); Animations.RegisterAnimation("MachineGunLeft", animLeft, () => CurrentFaceDirection == Direction.WEST); Animations.RegisterAnimation("MachineGunRight", animRight, () => CurrentFaceDirection == Direction.EAST); }
void Start() { spriteRenderer = GetComponent <SpriteRenderer>(); spriteSheetAnimation = GetComponent <SpriteSheetAnimation>(); Debug.Assert(spriteRenderer != null, "sprite renderer not set", this); Debug.Assert(spriteSheetAnimation != null, "sprite sheet animation not set", this); }
public ImpactEffect(Transform transform, SpriteSheet effectSheet, float effectLength) { m_impactSprite = new Sprite(Globals.TheGame, effectSheet, transform); m_impactSprite.Origin = new Microsoft.Xna.Framework.Vector2(0.1f, 0.9f); m_impactSprite.Alpha = 0.3f; m_spriteAnimation = new SpriteSheetAnimation(m_impactSprite, 0, effectSheet.AmountOfFrames - 1, effectLength, 1); m_spriteAnimation.Start(); }
public MiniFire(Transform parent, Vector2 position) { m_transform = new Transform(parent, true); m_transform.Position = position; float scale = (float)Globals.Random.NextDouble() * 0.5f + 0.5f; m_transform.Scale = new Vector2(scale, scale); m_sprite = new Sprite(Globals.TheGame, MiniFireTexture, m_transform); m_animation = new SpriteSheetAnimation(m_sprite, 0, 3, 0.1f, -1); }
public void PlayAnimation(string name, Action onCompleteAction = null) { if (_currentAnimation != null && _currentAnimation.Name == name) { return; } _currentAnimation = _animations[name]; _frameIndex = 0; _onCompleteAction = onCompleteAction; }
public Shuriken() : base() { m_attack = new AttackComponent(1.0f, 0.1f); m_sprite = new Sprite(Globals.TheGame, TextureLibrary.GetSpriteSheet("atk_shuriken", 1, 5), m_transform); m_sprite.Origin = new Vector2(0.5f, 0.0f); m_transform.Scale = new Vector2(3.0f, 3.0f); m_animation = new SpriteSheetAnimation(m_sprite, 0, 4, 0.1f, 1); m_pointCollider = new PointCollider(m_attack, Transform); World.UL_Global.Add(this, 0); World.DL_Foreground.Add(this, 0); }
public ContentMetaData CreateMetaDataFromSpriteSheetAnimation(string animationName, SpriteSheetAnimation spriteSheetAnimation) { var contentMetaData = new ContentMetaData(); SetDefaultValues(contentMetaData, animationName); contentMetaData.Type = ContentType.SpriteSheetAnimation; contentMetaData.Values.Add("DefaultDuration", spriteSheetAnimation.DefaultDuration.ToString(CultureInfo.InvariantCulture)); contentMetaData.Values.Add("SubImageSize", spriteSheetAnimation.SubImageSize.ToString()); contentMetaData.Values.Add("ImageName", spriteSheetAnimation.Image.Name); return(contentMetaData); }
public EnemyTest(AbstractScene scene, Vector2 position, Direction direction) : base(scene, position, direction) { AddCollisionAgainst("Spikes"); CurrentFaceDirection = Direction.EAST; AnimationStateMachine animations = new AnimationStateMachine(); animations.Offset = offset; AddComponent(animations); SpriteSheetAnimation runLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyRun"), 32, 32, 40); animations.RegisterAnimation("RunLeft", runLeft, () => Velocity.X != 0 && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation runRight = runLeft.CopyFlipped(); animations.RegisterAnimation("RunRight", runRight, () => Velocity.X != 0 && CurrentFaceDirection == Direction.EAST); animations.AddFrameTransition("RunLeft", "RunRight"); SpriteSheetAnimation idleLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyIdle"), 32, 32, 1); animations.RegisterAnimation("IdleLeft", idleLeft, () => Velocity.X == 0 && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation idleRight = idleLeft.CopyFlipped(); animations.RegisterAnimation("IdleRight", idleRight, () => Velocity.X == 0 && CurrentFaceDirection == Direction.EAST); SpriteSheetAnimation jumpLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyRun"), 1); jumpLeft.StartFrame = 6; jumpLeft.EndFrame = 7; animations.RegisterAnimation("JumpLeft", jumpLeft, () => !IsOnGround && CurrentFaceDirection == Direction.WEST, 1); SpriteSheetAnimation jumpRight = jumpLeft.CopyFlipped(); animations.RegisterAnimation("JumpRight", jumpRight, () => !IsOnGround && CurrentFaceDirection == Direction.EAST, 1); CollisionOffsetBottom = 1; //AddComponent(new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30))); if (!Tutorial) { AddComponent(new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30))); } else { AddComponent(new BoxCollisionComponent(this, 22, 30, new Vector2(-8, -30))); } //DEBUG_SHOW_COLLIDER = true; }
public Title() : base() { m_sprite = new Sprite(Program.TheGame, TextureLibrary.GetSpriteSheet("titre_anime", 4, 1), m_transform); m_animation = new SpriteSheetAnimation(m_sprite, 0, 3, 1.0f, -1); m_animation.Start(); m_physics = new PhysicsComponent(Program.TheGame, m_transform); m_physics.GroundLevel = (int)TitleY; m_physics.Mass = 4; m_moveTo = new MoveToStaticAction(Program.TheGame, m_transform, new Vector2(TitleX, -100), 1); m_moveTo.Interpolator = new PSmoothstepInterpolation(); m_moveTo.Timer.Interval = 0.4f; m_transform.Position = new Vector2(TitleX, -100); }
public void CreateSpriteSheetAnimationWithNewTexture() { var data = new ImageCreationData(new Size(8, 8)) { BlendMode = BlendMode.Opaque }; var image = ContentLoader.Create <Image>(data); FillImage(image); var animationData = new SpriteSheetAnimationCreationData(image, 2, new Size(2, 2)); var texturedShader = ContentLoader.Create <Shader>( new ShaderCreationData(ShaderFlags.Position2DTextured)); var newMaterial = new SpriteSheetAnimation(animationData).CreateMaterial(texturedShader); new Sprite(newMaterial, Rectangle.HalfCentered); }
static void InitialiseMovingOutAnimation() { #region Backpacker 0 Sequence waveAnimation_0 = new Sequence(); MoveToStaticAction walkMove_0 = new MoveToStaticAction(Globals.TheGame, Backpackers[0].Transform, new Vector2(MeetingPoint, 0), 1); walkMove_0.Timer.Interval = 0.5f; SpriteSheetAnimation walkAnim_0 = new SpriteSheetAnimation(Backpackers[0].Sprite, 0, 1, 0.1f, 5); waveAnimation_0.AddAction(new Concurrent(new PastaGameLibrary.Action[] { walkMove_0, walkAnim_0 })); waveAnimation_0.AddAction(new SpriteSheetAnimation(Backpackers[0].Sprite, 0, 0, 0.5f, 1)); waveAnimation_0.AddAction(new SpriteSheetAnimation(Backpackers[0].Sprite, 2, 3, 0.2f, 4)); waveAnimation_0.AddAction(new SpriteSheetAnimation(Backpackers[0].Sprite, 0, 0, 0.1f, 1)); #endregion #region Backpacker 1 Sequence waveAnimation_1 = new Sequence(); MoveToStaticAction walkMove_1 = new MoveToStaticAction(Globals.TheGame, Backpackers[1].Transform, new Vector2(MeetingPoint - 40, 0), 1); walkMove_1.Timer.Interval = 0.5f; SpriteSheetAnimation walkAnim_1 = new SpriteSheetAnimation(Backpackers[1].Sprite, 0, 1, 0.1f, 5); waveAnimation_1.AddAction(new DelayAction(Globals.TheGame, 0.2f)); waveAnimation_1.AddAction(new Concurrent(new PastaGameLibrary.Action[] { walkMove_1, walkAnim_1 })); waveAnimation_1.AddAction(new SpriteSheetAnimation(Backpackers[1].Sprite, 0, 0, 0.5f, 1)); waveAnimation_1.AddAction(new SpriteSheetAnimation(Backpackers[1].Sprite, 2, 3, 0.1f, 5)); waveAnimation_1.AddAction(new SpriteSheetAnimation(Backpackers[1].Sprite, 0, 0, 0.1f, 1)); #endregion #region Backpacker 2 Sequence waveAnimation_2 = new Sequence(); MoveToStaticAction walkMove_2 = new MoveToStaticAction(Globals.TheGame, Backpackers[2].Transform, new Vector2(MeetingPoint - 80, 0), 1); walkMove_2.Timer.Interval = 0.5f; SpriteSheetAnimation walkAnim_2 = new SpriteSheetAnimation(Backpackers[2].Sprite, 0, 1, 0.1f, 5); waveAnimation_2.AddAction(new DelayAction(Globals.TheGame, 0.4f)); waveAnimation_2.AddAction(new Concurrent(new PastaGameLibrary.Action[] { walkMove_2, walkAnim_2 })); waveAnimation_2.AddAction(new SpriteSheetAnimation(Backpackers[2].Sprite, 2, 3, 0.2f, 3)); waveAnimation_2.AddAction(new SpriteSheetAnimation(Backpackers[2].Sprite, 0, 0, 0.1f, 1)); #endregion s_movingOutAnimation = new Concurrent(new PastaGameLibrary.Action[] { waveAnimation_0, waveAnimation_1, waveAnimation_2 }); }
protected void UpdateAnimation() { var toPlay = this.Direction.Name; var limit = this.WalkSpeed / 2; if (!(this is Player) || Math.Abs(this.Velocity.X) < limit && Math.Abs(this.Velocity.Y) < limit) { var diff = this.Position - this.LastPosition; if (Math.Abs(diff.X) < limit && Math.Abs(diff.Y) < limit) { toPlay = "Standing" + toPlay; } } if (this.CurrentAnimation.Name != toPlay) { this.CurrentAnimation = this.AnimationFactory.Create(toPlay); } }
public Monster() : base() { m_spriteSheetNomNom = TextureLibrary.GetSpriteSheet("anim_monstre_miam", 8, 1); m_spriteSheetIdle = TextureLibrary.GetSpriteSheet("anim_monstre_neutre", 5, 1); m_sprite = new Sprite(Program.TheGame, m_spriteSheetIdle, m_transform); m_sprite.PixelCorrection = true; m_idle = new SpriteSheetAnimation(m_sprite, 0, 4, 3.0f, -1); m_openMouth = new SpriteSheetAnimation(m_sprite, 4, 6, 0.5f, 1); m_closeMouth = new Sequence(1); m_closeMouth.AddAction(new SpriteSheetAnimation(m_sprite, 6, 7, 0.45f, 1)); m_closeMouth.AddAction(new MethodAction(Idle)); m_actionManager = new SingleActionManager(); m_transform.Position = new Vector2(MonsterPosX, MonsterPosY); m_breathing = new MoveToStaticAction(Program.TheGame, m_transform, m_transform.Position + new Vector2(0, 3), -1); m_breathing.Interpolator = new PSineInterpolation(); m_breathing.Timer.Interval = 4.0f; m_breathing.Start(); }
public void ShowSpritesheetAnimation() { var image = ContentLoader.Load <Image>(ImageList[0]); if (SubImageSize.Width == 0 || SubImageSize.Height == 0) { subImageSize = image.PixelSize; RaisePropertyChanged("SubImageSize"); } spriteSheetAnimation = new SpriteSheetAnimation(new SpriteSheetAnimationCreationData(image, Duration, SubImageSize)); var material = new Material(ShaderFlags.Position2DTextured, "") { SpriteSheet = spriteSheetAnimation }; renderExample = new Sprite(material, Rectangle.FromCenter(0.5f, 0.5f, 0.5f * SubImageSize.AspectRatio, 0.5f)); }
public Character(string name, Map map, Vector2 position) : base(map, position) { this.RenderBounds = new RectangleF(-0.5F, -1.5F, 1, 2); this.CollisionBounds = new RectangleF(-0.4F, 0, 0.8F, 0.35F); this.AnimationFactory = new SpriteSheetAnimationFactory(new TextureAtlas( name, GameImpl.LoadContent <Texture2D>("Characters/" + name), GameImpl.LoadContent <Dictionary <string, Rectangle> >("Characters/Animation"))); this.AnimationFactory.Add("StandingDown", new SpriteSheetAnimationData(new[] { 0 })); this.AnimationFactory.Add("Down", new SpriteSheetAnimationData(new[] { 1, 2, 3 }, isPingPong: true)); this.AnimationFactory.Add("StandingUp", new SpriteSheetAnimationData(new[] { 4 })); this.AnimationFactory.Add("Up", new SpriteSheetAnimationData(new[] { 5, 6, 7 }, isPingPong: true)); this.AnimationFactory.Add("StandingLeft", new SpriteSheetAnimationData(new[] { 8 })); this.AnimationFactory.Add("Left", new SpriteSheetAnimationData(new[] { 9, 10, 11 }, isPingPong: true)); this.AnimationFactory.Add("StandingRight", new SpriteSheetAnimationData(new[] { 12 })); this.AnimationFactory.Add("Right", new SpriteSheetAnimationData(new[] { 13, 14, 15 }, isPingPong: true)); this.CurrentAnimation = this.AnimationFactory.Create("StandingDown"); }
public NewLevelButton() : base(new Sprite(Globals.TheGame, TextureLibrary.GetSpriteSheet("btn_newlevel", 1, 4), new Transform())) { m_animation = new SpriteSheetAnimation(m_buttonSprite, 0, 3, 0.5f, -1); m_popAction = new SingleActionManager(); //m_in = new MoveToStaticAction(Globals.TheGame, m_transform, new Vector2(150, 300), false); //m_out = new MoveToStaticAction(Globals.TheGame, m_transform, new Vector2(150, 0), false); m_transform.Position = new Vector2(150, 300); _generation = new Counter(2, TextureLibrary.GetSpriteSheet("levelscore_vertical", 20, 1)); _generation.Transform.ParentTransform = m_transform; _section = new Counter(1, TextureLibrary.GetSpriteSheet("levelscore_vertical", 20, 1)); _section.Transform.ParentTransform = m_transform; _generation.Alpha = _section.Alpha = 1.0f; _generation.ScrollSpeed = _section.ScrollSpeed = 50; }
protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); Content.Load <BitmapFont>("Fonts/courier-new-32"); _map = Content.Load <TiledMap>("Tilesets/level01"); _world = new CollisionWorld(new Vector2(0, 900)); //_world.CreateGrid(_tiledMap.GetLayer<TiledTileLayer>("Tile Layer 1")); var zombieAnimations = Content.Load <SpriteSheetAnimationFactory>("Sprites/zombie-animations"); _zombie = new Zombie(zombieAnimations); var zombieActor = _world.CreateActor(_zombie); zombieActor.Position = new Vector2(462.5f, 896f); var fireballTexture = Content.Load <Texture2D>("Sprites/fireball"); var fireballAtlas = TextureAtlas.Create("Sprites/fireball-atlas", fireballTexture, 130, 50); _animation = new SpriteSheetAnimation("fireballAnimation", fireballAtlas.Regions.ToArray()) { FrameDuration = 0.2f }; _fireballSprite = new Sprite(_animation.CurrentFrame) { Position = _zombie.Position }; var motwTexture = Content.Load <Texture2D>("Sprites/motw"); var motwAtlas = TextureAtlas.Create("Sprites/fireball-atlas", motwTexture, 52, 72); var motwAnimationFactory = new SpriteSheetAnimationFactory(motwAtlas); motwAnimationFactory.Add("idle", new SpriteSheetAnimationData(new[] { 0 })); motwAnimationFactory.Add("walkSouth", new SpriteSheetAnimationData(new[] { 0, 1, 2, 1 }, isLooping: false)); motwAnimationFactory.Add("walkWest", new SpriteSheetAnimationData(new[] { 12, 13, 14, 13 }, isLooping: false)); motwAnimationFactory.Add("walkEast", new SpriteSheetAnimationData(new[] { 24, 25, 26, 25 }, isLooping: false)); motwAnimationFactory.Add("walkNorth", new SpriteSheetAnimationData(new[] { 36, 37, 38, 37 }, isLooping: false)); _motwSprite = new AnimatedSprite(motwAnimationFactory); _motwSprite.Position = new Vector2(350, 800); _motwSprite.Play("walkSouth").IsLooping = true; }
public Coin(COIN_TYPE type) : base() { _type = type; m_sprite = new Sprite(Globals.TheGame, CoinTextures[(int)type], Transform); m_sprite.Origin = new Vector2(0.5f, 1.0f); m_physics = new PhysicsComponent(Globals.TheGame, Transform); m_animation = new SpriteSheetAnimation(m_sprite, 0, 5, 0.1f, -1); m_animation.Start(); m_physics.Throw((float)Globals.Random.NextDouble() * 25, Globals.Random.Next(-30, -10), 0); m_physics.Mass = 1.3f; m_physics.Restitution = 0.75f; //m_physics.GroundLevel = Globals.Random.Next(-8, 3); m_physics.GroundLevel = 0; m_circleCollider = new CircleCollider(this); World.UL_Global.Add(this, 0); World.DL_ItemDrops.Add(this, 1); //ADDTHISLATER //Backpacker.HitPlayerColliders.Add(m_circleCollider, PickUp); }
public Character(string name, Map map, Vector2 position) : base(map, position) { this.Size = new Size2(0.75F, 0.95F) * this.Map.Scale; this.InteractionArea = new RectangleF(new Vector2(0, -0.5F) * this.Map.Scale, new Size2(0.75F, 1.95F) * this.Map.Scale); this.AnimationFactory = new SpriteSheetAnimationFactory(new TextureAtlas( name, GameImpl.LoadContent <Texture2D>("Objects/" + name), GameImpl.LoadContent <Dictionary <string, Rectangle> >("Objects/CharacterAnimation"))); this.AnimationFactory.Add("StandingDown", new SpriteSheetAnimationData(new[] { 0 })); this.AnimationFactory.Add("Down", new SpriteSheetAnimationData(new[] { 1, 2, 3 }, isPingPong: true)); this.AnimationFactory.Add("StandingUp", new SpriteSheetAnimationData(new[] { 4 })); this.AnimationFactory.Add("Up", new SpriteSheetAnimationData(new[] { 5, 6, 7 }, isPingPong: true)); this.AnimationFactory.Add("StandingLeft", new SpriteSheetAnimationData(new[] { 8 })); this.AnimationFactory.Add("Left", new SpriteSheetAnimationData(new[] { 9, 10, 11 }, isPingPong: true)); this.AnimationFactory.Add("StandingRight", new SpriteSheetAnimationData(new[] { 12 })); this.AnimationFactory.Add("Right", new SpriteSheetAnimationData(new[] { 13, 14, 15 }, isPingPong: true)); this.CurrentAnimation = this.AnimationFactory.Create("StandingDown"); }
private MyVisual() { //animation using a single SpriteSheet explosion = new SpriteSheetAnimation(new SpriteSheet(TextureLoader.FromBitmap(Resourcen.explosion), 5), 0, 24, 1f); //art from https://github.com/sparklinlabs/superpowers-asset-packs var spriteSheetGirl = new SpriteSheet(TextureLoader.FromBitmap(Resourcen.girl_2), 6, 7); girlIdleRun = new SpriteSheetAnimation(spriteSheetGirl, 0, 10, 1f); girlJumpBall = new SpriteSheetAnimation(spriteSheetGirl, 11, 20, 1f); girlFight = new SpriteSheetAnimation(spriteSheetGirl, 21, 25, 1f); girlDie = new SpriteSheetAnimation(spriteSheetGirl, 25, 32, 1f); girlBack = new SpriteSheetAnimation(spriteSheetGirl, 33, 36, 1f); //animation using a bitmap for each frame alienShip = new AnimationTextures(.5f); //art from http://millionthvector.blogspot.de/p/free-sprites.html alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10001)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10002)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10003)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10004)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10005)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10006)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10007)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10008)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10009)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10010)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10011)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10012)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10013)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10014)); alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10015)); //for transparency in textures GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); timeSource.Start(); //start game time }
public DogBehaviour(KhvGame game, Animal owner) : base(game, owner) { random = new Random(); Texture2D texture = game.Content.Load <Texture2D>(Path.Combine("Entities", owner.Dataset.AssetName)); effect = game.Content.Load <SoundEffect>(Path.Combine("Sounds", "woof")); animation = new SpriteSheetAnimation(texture); animation.AddSets(new SpriteAnimationSet[] { new SpriteAnimationSet("idle", new Size(32, 32), 2, 0) { FrameTime = 100 * 3 } }); animation.ChangeSet("idle"); owner.Collider.OnCollision += new CollisionEventHandler(Collider_OnCollision); brain.PushState(Walking); }
private MyVisual(IRenderState renderState, IContentLoader contentLoader) { //animation using a single SpriteSheet explosion = new SpriteSheetAnimation(new SpriteSheet(contentLoader.Load <ITexture2D>("explosion"), 5, 5), 0, 24, 1f); //art from https://github.com/sparklinlabs/superpowers-asset-packs var spriteSheetGirl = new SpriteSheet(contentLoader.Load <ITexture2D>("girl-2"), 6, 7); girlIdleRun = new SpriteSheetAnimation(spriteSheetGirl, 0, 10, 1f); girlJumpBall = new SpriteSheetAnimation(spriteSheetGirl, 11, 20, 1f); girlFight = new SpriteSheetAnimation(spriteSheetGirl, 21, 25, 1f); girlDie = new SpriteSheetAnimation(spriteSheetGirl, 25, 32, 1f); girlBack = new SpriteSheetAnimation(spriteSheetGirl, 33, 36, 1f); //animation using a bitmap for each frame alienShip = new AnimationTextures(.5f); //art from http://millionthvector.blogspot.de/p/free-sprites.html alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10001")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10002")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10003")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10004")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10005")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10006")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10007")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10008")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10009")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10010")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10011")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10012")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10013")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10014")); alienShip.AddFrame(contentLoader.Load <ITexture2D>("alien10015")); //for transparency in textures renderState.Set(BlendStates.AlphaBlend); GL.Enable(EnableCap.Texture2D); //TODO: remove if shader is used }
static bool NextWillReachEnd(SpriteSheetAnimation anim, SpriteIndex sprite) { return(sprite.Value + 1 >= anim.maxSprites); }
public void AddAnimation(string name, int[] frameIndices) { var animation = new SpriteSheetAnimation(name, frameIndices); _animations.Add(name, animation); }
public void SetAnimation(string name) { _currentAnimation = _animations[name]; }
public Hero(AbstractScene scene, Vector2 position) : base(scene.LayerManager.EntityLayer, null, position) { //DEBUG_SHOW_PIVOT = true; AddTag("Hero"); AddCollisionAgainst("Enemy"); AddCollisionAgainst("Spikes"); AddCollisionAgainst("Trap"); CanFireTriggers = true; DrawPriority = 10; AddCollisionAgainst("Pickup"); AddCollisionAgainst("Door", false); AddCollisionAgainst("Key"); AddCollisionAgainst("MountedGunBullet"); SetupController(); CollisionOffsetBottom = 1; CollisionOffsetLeft = 0.5f; CollisionOffsetRight = 0.5f; CollisionOffsetTop = 1; CurrentFaceDirection = Direction.EAST; collisionComponent = new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30)); AddComponent(collisionComponent); //DEBUG_SHOW_COLLIDER = true; AnimationStateMachine animations = new AnimationStateMachine(); animations.Offset = offset; AddComponent(animations); SpriteSheetAnimation idleLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroIdle"), 24); /*idleLeft.AnimationSwitchCallback = () => { if (CurrentWeapon != null) CurrentWeapon.SetAnimationBreathingOffset(Vector2.Zero); }; * idleLeft.EveryFrameAction = (frame) => * { * if (CurrentWeapon == null) return; * float unit = 0.5f; * float offsetY = 0; * if (frame == 2 || frame == 3 || frame == 4) * { * offsetY += unit; * } * else if (frame == 6 || frame == 7) * { * offsetY -= unit; * } * CurrentWeapon.SetAnimationBreathingOffset(new Vector2(0, offsetY)); * };*/ idleLeft.StartedCallback = () => { if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } }; animations.RegisterAnimation("IdleLeft", idleLeft, () => previousPosition == Transform.Position && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation idleRight = idleLeft.CopyFlipped(); animations.RegisterAnimation("IdleRight", idleRight, () => previousPosition == Transform.Position && CurrentFaceDirection == Direction.EAST); SpriteSheetAnimation runLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRun"), 40); runLeft.StartedCallback = () => { if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17)); } }; animations.RegisterAnimation("RunLeft", runLeft, () => Velocity.X < 0 && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation runRight = runLeft.CopyFlipped(); animations.RegisterAnimation("RunRight", runRight, () => Velocity.X > 0 && CurrentFaceDirection == Direction.EAST); SpriteSheetAnimation runBackwardsLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRunBackwards"), 40); runBackwardsLeft.StartedCallback = () => { if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17)); } }; animations.RegisterAnimation("RunBackwardsLeft", runBackwardsLeft, () => Velocity.X > 0 && CurrentFaceDirection == Direction.WEST); SpriteSheetAnimation runRighrunBackwardsRight = runBackwardsLeft.CopyFlipped(); animations.RegisterAnimation("RunBackwardsRight", runRighrunBackwardsRight, () => Velocity.X < 0 && CurrentFaceDirection == Direction.EAST); SpriteSheetAnimation jumpLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRun"), 1); jumpLeft.StartFrame = 6; jumpLeft.EndFrame = 7; animations.RegisterAnimation("JumpLeft", jumpLeft, () => !IsOnGround && CurrentFaceDirection == Direction.WEST, 1); SpriteSheetAnimation jumpRight = jumpLeft.CopyFlipped(); animations.RegisterAnimation("JumpRight", jumpRight, () => !IsOnGround && CurrentFaceDirection == Direction.EAST, 1); SpriteSheetAnimation jetpackLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Jetpacking"), 40); animations.RegisterAnimation("JetpackLeft", jetpackLeft, () => flying && CurrentFaceDirection == Direction.WEST, 2); SpriteSheetAnimation jetpackRight = jetpackLeft.CopyFlipped(); animations.RegisterAnimation("JetpackRight", jetpackRight, () => flying && CurrentFaceDirection == Direction.EAST, 2); SpriteSheetAnimation kickLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Kick"), 40); kickLeft.Looping = false; kickLeft.AddFrameAction(5, (frame) => { AudioEngine.Play("Kick"); IsKicking = true; if (THIS_IS_SPARTAAAAA && collidingWith.Count > 0) { THIS_IS_SPARTAAAAA = false; Vector2 canSpawnPos = collidingWith[0].Transform.Position; FuelCan can = new FuelCan(scene, canSpawnPos + new Vector2(0, -20), TankCapacity); can.Velocity += new Vector2(-3, -1); can.CollisionsEnabled = false; Ammo ammo = new Ammo(scene, canSpawnPos + new Vector2(0, -20), 20, typeof(Handgun)); ammo.Velocity += new Vector2(-4f, -1.5f); ammo.CollisionsEnabled = false; Timer.TriggerAfter(2000, () => { can.CollisionsEnabled = true; ammo.CollisionsEnabled = true; new TextPopup(Scene, Assets.GetTexture("FuelAmmoText"), Transform.Position + new Vector2(-20, -80), 0.3f, 3000); }); } }); kickLeft.AddFrameAction(6, (frame) => { IsKicking = false; }); kickLeft.StartedCallback = () => { if (THIS_IS_SPARTAAAAA && collidingWith.Count > 0) { THIS_IS_SPARTA(); Globals.FixedUpdateMultiplier = 0.1f; Timer.TriggerAfter(3000, () => { Globals.FixedUpdateMultiplier = 0.5f; Timer.Repeat(1000, (elapsedTime) => { Scene.Camera.Zoom -= 0.002f * elapsedTime; }); }); } //IsKicking = true; if (IsOnGround) { MovementSpeed = 0; } if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17)); } }; kickLeft.AnimationSwitchCallback = () => { IsKicking = false; MovementSpeed = Config.CHARACTER_SPEED; foreach (AbstractEnemy enemy in collidingWith) { enemy.IsKicked = false; } }; animations.RegisterAnimation("KickLeft", kickLeft, () => false); SpriteSheetAnimation kickRight = kickLeft.CopyFlipped(); animations.RegisterAnimation("KickRight", kickRight, () => false); SpriteSheetAnimation kickJetpackLeft = new SpriteSheetAnimation(this, Assets.GetTexture("KickJetpacking"), 40); kickJetpackLeft.Looping = false; kickJetpackLeft.AddFrameAction(5, (frame) => { AudioEngine.Play("Kick"); IsKicking = true; }); kickJetpackLeft.AddFrameAction(6, (frame) => { IsKicking = false; }); kickJetpackLeft.StartedCallback = () => { //IsKicking = true; if (CurrentWeapon == null) { return; } if (CurrentWeapon is Shotgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Machinegun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17)); } else if (CurrentWeapon is Handgun) { (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17)); (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17)); } }; kickJetpackLeft.AnimationSwitchCallback = () => { IsKicking = false; }; animations.RegisterAnimation("KickJetpackLeft", kickJetpackLeft, () => false); SpriteSheetAnimation kickJetpackRight = kickJetpackLeft.CopyFlipped(); animations.RegisterAnimation("KickJetpackRight", kickJetpackRight, () => false); animations.AddFrameTransition("RunLeft", "RunBackwardsLeft"); animations.AddFrameTransition("RunRight", "RunBackwardsRight"); animations.AddFrameTransition("RunLeft", "RunRight"); animations.AddFrameTransition("RunBackwardsLeft", "RunBackwardsRight"); animations.AddFrameTransition("JetpackLeft", "JetpackRight"); Visible = true; Active = true; /*DebugFunction = () => * { * return "Fuel: " + (int)(((float)(Fuel / TankCapacity)) * 100) + " %"; * };*/ CurrentWeapon = new Handgun(scene, this); weapons.Add(CurrentWeapon); Machinegun mg = new Machinegun(scene, this); mg.Visible = false; Shotgun sg = new Shotgun(scene, this); sg.Visible = false; weapons.Add(mg); weapons.Add(sg); }
public void PlayAnimation(string name, Action onCompleteAction = null) { if(_currentAnimation != null && _currentAnimation.Name == name && IsPlaying) return; _currentAnimation = _animationGroup.GetAnimation(name); _frameIndex = 0; _onCompleteAction = onCompleteAction; IsPlaying = true; }
//public IEnumerable<TextureRegion2D> Frames //{ // get { return _frames; } //} //public IEnumerable<string> Animations //{ // get { return _animations.Keys.OrderBy(i => i); } //} //public int AddFrame(TextureRegion2D textureRegion) //{ // var index = _frames.Count; // _frames.Add(textureRegion); // if (Sprite != null && Sprite.TextureRegion == null) // Sprite.TextureRegion = textureRegion; // return index; //} //public bool RemoveFrame(TextureRegion2D textureRegion) //{ // return _frames.Remove(textureRegion); //} //public bool RemoveFrame(string name) //{ // var frame = GetFrame(name); // return RemoveFrame(frame); //} //public void RemoveFrameAt(int frameIndex) //{ // _frames.RemoveAt(frameIndex); //} //public TextureRegion2D GetFrameAt(int index) //{ // return _frames[index]; //} //public TextureRegion2D GetFrame(string name) //{ // return _frames.FirstOrDefault(f => f.Name == name); //} //public SpriteSheetAnimation AddAnimation(string name, int framesPerSecond, int[] frameIndices) //{ // if (_animations.ContainsKey(name)) // throw new InvalidOperationException(string.Format("Animator already contrains an animation called {0}", name)); // var animation = new SpriteSheetAnimation(name, framesPerSecond, frameIndices); // _animations.Add(name, animation); // return animation; //} //public SpriteSheetAnimation AddAnimation(string name, int framesPerSecond, int firstFrameIndex, int lastFrameIndex) //{ // var frameIndices = new int[lastFrameIndex - firstFrameIndex + 1]; // for (var i = 0; i < frameIndices.Length; i++) // frameIndices[i] = firstFrameIndex + i; // return AddAnimation(name, framesPerSecond, frameIndices); //} //public bool RemoveAnimation(string name) //{ // SpriteSheetAnimation animation; // if (!_animations.TryGetValue(name, out animation)) // return false; // if (_currentAnimation == animation) // _currentAnimation = null; // _animations.Remove(name); // return true; //} public void PlayAnimation(SpriteSheetAnimation animation, Action onCompleteAction = null) { if (!_animationGroup.Contains(animation)) throw new InvalidOperationException("Animation does not belong to this animator"); PlayAnimation(animation.Name); }
public void Convert(Entity entity, EntityManager eManager, GameObjectConversionSystem conversionSystem) { var archetype = eManager.CreateArchetype( typeof(Position2D), typeof(Rotation2D), typeof(Scale), //typeof(Bound2D), typeof(SpriteSheet), typeof(SpriteSheetAnimation), typeof(SpriteSheetMaterial), typeof(UvBuffer), typeof(SpriteSheetColor), typeof(RenderData) ); NativeArray <Entity> entities = new NativeArray <Entity>(spriteCount, Allocator.Temp); eManager.CreateEntity(archetype, entities); KeyValuePair <Material, float4[]> atlasData = SpriteSheetCache.BakeSprites(sprites); int cellCount = atlasData.Value.Length; Random rand = new Random((uint)UnityEngine.Random.Range(0, int.MaxValue)); Rect area = GetSpawnArea(); SpriteSheetMaterial material = new SpriteSheetMaterial { material = atlasData.Key }; for (int i = 0; i < entities.Length; i++) { Entity e = entities[i]; SpriteSheet sheet = new SpriteSheet { spriteIndex = rand.NextInt(0, cellCount), maxSprites = cellCount }; Scale scale = new Scale { Value = rand.NextFloat(minScale, maxScale) }; Position2D pos = new Position2D { Value = rand.NextFloat2(area.min, area.max) }; SpriteSheetAnimation anim = new SpriteSheetAnimation { play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10 }; var color = UnityEngine.Random.ColorHSV(.15f, .75f); SpriteSheetColor col = new SpriteSheetColor { value = new float4(color.r, color.g, color.b, color.a) }; eManager.SetComponentData(e, sheet); eManager.SetComponentData(e, scale); eManager.SetComponentData(e, pos); eManager.SetComponentData(e, anim); eManager.SetComponentData(e, col); eManager.SetSharedComponentData(e, material); // Fill uv buffer var buffer = eManager.GetBuffer <UvBuffer>(entities[i]); for (int j = 0; j < atlasData.Value.Length; j++) { buffer.Add(atlasData.Value[j]); } } }