Beispiel #1
0
        private void CreateBackground()
        {
            var background = new Entity("Background")
                             .AddComponent(new Sprite("Content/BG.wpk"))
                             .AddComponent(new SpriteRenderer(DefaultLayers.Opaque))
                             .AddComponent(new Transform2D {
                DrawOrder = 1
            });

            this.EntityManager.Add(background);

            var countdownAnimation = new Entity("Countdown")
                                     .AddComponent(new Transform2D()
            {
                X      = WaveServices.ViewportManager.VirtualWidth - 20,
                Y      = 20,
                Origin = Vector2.UnitX
            })
                                     .AddComponent(new Sprite("Content/Countdown.wpk"))
                                     .AddComponent(Animation2D.Create <TexturePackerGenericXml>("Content/Countdown.xml")
                                                   .Add("Default", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 5, FramesPerSecond = 1
            }))
                                     .AddComponent(new AnimatedSpriteRenderer());

            this.EntityManager.Add(countdownAnimation);

            this.countdownAnimationComponent = countdownAnimation.FindComponent <Animation2D>();
        }
Beispiel #2
0
        /// <summary>
        /// Create Yurei, the main character
        /// </summary>
        private void CreateYurei()
        {
            Entity startDust = new Entity("dust")
            {
                Enabled = false
            }
            .AddComponent(new Transform2D()
            {
                Position  = new Vector2(0, WaveServices.ViewportManager.BottomEdge - 27),
                DrawOrder = 140,
                Origin    = new Vector2(0.75f, 1)
            })
            .AddComponent(new Sprite("Content/Dust/Dust"))
            .AddComponent(Animation2D.Create <TexturePackerGenericXml>("Content/Dust/Dust.xml")
                          .Add("start", new SpriteSheetAnimationSequence()
            {
                First = 0, Length = 13, FramesPerSecond = 30
            }))
            .AddComponent(new AnimatedSpriteRenderer(typeof(ForegroundLayer)));

            EntityManager.Add(startDust);

            this.yurei = new YureiDecorator(
                "yurei",
                new Vector3(
                    500,
                    WaveServices.ViewportManager.BottomEdge - 82,
                    150),
                Vector3.One * 0.85f,
                startDust,
                typeof(ForegroundLayer));

            EntityManager.Add(yurei);
        }
Beispiel #3
0
        /// <summary>
        /// Add coins
        /// </summary>
        private void AddCoins()
        {
            var         cratesLayer = this.tiledMap.ObjectLayers["Coins"];
            Animation2D anim;

            int i = 0;

            foreach (var obj in cratesLayer.Objects)
            {
                Entity crateEntity = new Entity("coin_" + (i++))
                {
                    Tag = "coin"
                }
                .AddComponent(new Transform2D()
                {
                    LocalPosition = new Vector2(obj.X, obj.Y), Origin = Vector2.Center, DrawOrder = -9
                })
                .AddComponent(new Sprite("Content/coin.png")
                {
                    SourceRectangle = new Rectangle(0, 128, 16, 16)
                })
                .AddComponent(anim = Animation2D.Create <TexturePackerGenericXml>("Content/coin.xml").Add("flip", new SpriteSheetAnimationSequence()
                {
                    First = 1, Length = 8, FramesPerSecond = 12
                }))
                .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha, AddressMode.PointWrap))
                .AddComponent(new CircleCollider())
                ;

                this.EntityManager.Add(crateEntity);

                anim.CurrentAnimation = "flip";
                anim.Play(true);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Kite" /> class.
        /// </summary>
        public Kite()
        {
            this.Transform = new Transform2D()
            {
                X      = WaveServices.ViewportManager.VirtualWidth / 4,
                Y      = WaveServices.ViewportManager.VirtualHeight / 2,
                Origin = Vector2.Center
            };

            this.entity = new Entity("kite")
                          .AddComponent(this.Transform)
                          .AddComponent(new Sprite(Textures.KITE_ANIMS))
                          .AddComponent(Animation2D.Create <TexturePackerGenericXml>(Textures.KITE_ANIMS_XML)
                                        .Add(this.kiteAnimations[0], new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 9, FramesPerSecond = 27
            })
                                        .Add(this.kiteAnimations[1], new SpriteSheetAnimationSequence()
            {
                First = 10, Length = 9, FramesPerSecond = 27
            })
                                        .Add(this.kiteAnimations[2], new SpriteSheetAnimationSequence()
            {
                First = 19, Length = 9, FramesPerSecond = 27
            }))
                          .AddComponent(new AnimatedSpriteRenderer(typeof(ObstaclesLayer)))
                          .AddComponent(new PerPixelCollider(Textures.KITE_COLLID, 0.5f))
                          .AddComponent(new KiteBehavior());
        }
Beispiel #5
0
        private void CreatePlayers()
        {
            var playerObjects = this.tiledMap.ObjectLayers["players"].Objects;

            for (int i = 0; i < Game.PLAYER_COUNT; i++)
            {
                var eye = CreateEye(i);

                var player = new Entity("player" + i)
                             .AddComponent(new Transform2D()
                {
                    Position = new Vector2(playerObjects[i].X + Game.FIELD_SIZE / 2, playerObjects[i].Y),
                    Origin   = new Vector2(0.5f, 1)
                })
                             .AddComponent(new Sprite("Content/Animations/body.wpk"))
                             .AddComponent(Animation2D.Create <TexturePackerGenericXml>("Content/Animations/body.xml")
                                           .Add(Game.PLAYER_SMALL_WALKING, new SpriteSheetAnimationSequence()
                {
                    First           = 1, // + i * Game.EYE_ANIMATION_COUNT,
                    Length          = 10,
                    FramesPerSecond = 30
                })
                                           .Add(Game.PLAYER_GROWING, new SpriteSheetAnimationSequence()
                {
                    First           = 11, // + index * Game.EYE_ANIMATION_COUNT,
                    Length          = 8,
                    FramesPerSecond = 30
                })
                                           .Add(Game.PLAYER_BIG_WALKING, new SpriteSheetAnimationSequence()
                {
                    First           = 19, //+ index * Game.EYE_ANIMATION_COUNT,
                    Length          = 12,
                    FramesPerSecond = 30
                })
                                           .Add(Game.PLAYER_SHRINKING, new SpriteSheetAnimationSequence()
                {
                    First           = 31, // + index * Game.EYE_ANIMATION_COUNT,
                    Length          = 8,
                    FramesPerSecond = 30
                })
                                           )
                             .AddComponent(new AnimatedSpriteRenderer())
                             .AddComponent(new RectangleCollider())
                             .AddComponent(new RigidBody2D()
                {
                    FixedRotation = true,
                    Mass          = Game.BODY_MASS,
                    Friction      = Game.BODY_FRICTION,
                    Restitution   = Game.BODY_RESTITUTION
                })
                             .AddComponent(new PlayerController(i));

                EntityManager.Add(player);
                player.FindComponent <PlayerController>().AttachEye(eye);
            }
        }
Beispiel #6
0
        public Insect(int type, float speed, int score, string spriteName)
        {
            m_Type       = type;
            m_Speed      = speed;
            m_Score      = score;
            m_SpriteName = spriteName;

            int    x          = WaveServices.Random.Next(0, 768);
            string spritePath = m_SpriteName + ".wpkk";
            string spriteMap  = m_SpriteName + ".xml";

            m_Entity = new Entity()
                       .AddComponent(
                new Transform2D()
            {
                Origin = Vector2.Center,
                X      = x,
                Y      = 0,
            })
                       .AddComponent(new Sprite(spritePath))
                       .AddComponent(Animation2D.Create <TexturePackerGenericXml> (spriteMap)
                                     .Add("Run", new SpriteSheetAnimationSequence()
            {
                First           = 2,
                Length          = 2,
                FramesPerSecond = 10
            })
                                     .Add("Die", new SpriteSheetAnimationSequence()
            {
                First           = 1,
                Length          = 1,
                FramesPerSecond = 5
            })
                                     )
                       .AddComponent(new AnimationUI())
                       .AddComponent(new TouchGestures()
            {
                EnabledGestures = SupportedGesture.Translation
            })
                       .AddComponent(new RectangleCollider())
                       .AddComponent(new InsectBehavior())
                       .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Debug));

            var         move      = new SingleAnimation(0f, WaveServices.Platform.ScreenHeight, 1f / m_Speed, EasingFunctions.Cubic);
            AnimationUI animation = m_Entity.FindComponent <AnimationUI>();

            animation.BeginAnimation(Transform2D.YProperty, move);

            var anim2D = m_Entity.FindComponent <Animation2D>();

            anim2D.Play(true);

            var insectBehavior = m_Entity.FindComponent <InsectBehavior> ();

            insectBehavior.SetState(InsectBehavior.AnimState.Run);
        }
Beispiel #7
0
        public Mob_Base(int start_grid_x, int start_grid_y, int [,] map, int i)
        {
            HP           = 100;
            Alive        = true;
            Lives_value  = 1;
            Monster_gold = 20;
            Alive        = true;

            Last_Grid_X = Last_Grid_Y = -1;

            this.anim2D  = null;//new Animation2D();
            this.trans2D = null;

            this.Grid_x = start_grid_x;
            this.Grid_y = start_grid_y;


            var Ast = Static.Functions.Astar(Grid_x, Grid_y, Last_Grid_X, Last_Grid_Y, map);

            this.F_Grid_x = Ast.Item2;
            this.F_Grid_y = Ast.Item1;
            get_direction();


            Mob = new Entity("Enemy " + i)
                  .AddComponent(trans2D = new Transform2D()
            {
                X = (start_grid_x * Const.BITMAP_SIZE) + Const.OFFSET,
                Y = (start_grid_y * Const.BITMAP_SIZE) + Const.OFFSET,

                Origin = new Vector2(0.5f, 0.5f)
            })
                  .AddComponent(new Sprite("Content/Monsters/Monster_Beta/Mob.wpk"))
                  .AddComponent(Animation2D.Create <TexturePackerGenericXml>("Content/Monsters/Monster_Beta/Mob.xml")
                                .Add("Idle", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 1, FramesPerSecond = 30
            })
                                .Add("Running", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 4, FramesPerSecond = 5
            }))
                  .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha));


            anim2D = Mob.FindComponent <Animation2D>();
            anim2D.CurrentAnimation = "Running";
            anim2D.Play(true);
        }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Squid" /> class.
        /// </summary>
        /// <param name="positionY">The position Y.</param>
        public Squid(float positionY)
        {
            this.initialPosY  = positionY;
            this.gamePlayPosY = WaveServices.ViewportManager.BottomEdge + 50;

            this.entity = new Entity("SquidEntity")
                          .AddComponent(new Transform2D()
            {
                Origin    = new Vector2(0.5f, 0f),
                X         = WaveServices.ViewportManager.VirtualWidth / 2,
                Y         = this.gamePlayPosY,
                DrawOrder = 0.3f,
            })
                          .AddComponent(new AnimationUI())
                          .AddComponent(new SquidBehavior())
                          .AddComponent(new Sprite(Directories.TexturePath + "squidSpriteSheet.wpk"))
                          .AddComponent(Animation2D.Create <TexturePackerGenericXml>(Directories.TexturePath + "squidSpriteSheet.xml")
                                        .Add("swim", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 30, FramesPerSecond = 30
            }))
                          .AddComponent(new PerPixelCollider(Directories.TexturePath + "squidCollider.wpk", 0.5f))
                          .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha));

            // Cached
            this.transform   = this.entity.FindComponent <Transform2D>();
            this.animation2D = this.entity.FindComponent <Animation2D>();
            this.direction   = -Vector2.UnitY;
            this.animation   = this.entity.FindComponent <AnimationUI>();

            // Bubble
            this.entity.AddChild(new Entity("bubblesParticle")
                                 .AddComponent(new Transform2D()
            {
                LocalY = 210,
            })
                                 .AddComponent(ParticleFactory.CreateBubbleParticles())
                                 .AddComponent(
                                     new Material2D(new BasicMaterial2D(Directories.TexturePath + "waterParticle.wpk",
                                                                        DefaultLayers.Additive)))
                                 .AddComponent(new ParticleSystemRenderer2D("bubblesParticle")));

            // Cached
            this.particleSystem = this.entity.FindChild("bubblesParticle").FindComponent <ParticleSystem2D>();

            // Animations
            this.appearAnim = new SingleAnimation(gamePlayPosY, this.initialPosY, TimeSpan.FromSeconds(1.5f), EasingFunctions.Cubic);
        }
Beispiel #9
0
        private Entity CreateEye(int index)
        {
            var eye = new Entity("eye" + index)
            {
                Tag = Game.TAG_EYE
            }
            .AddComponent(new Transform2D()
            {
                Origin = Vector2.Center
            })
            .AddComponent(new Sprite("Content/Animations/eye.wpk"))
            .AddComponent(Animation2D.Create <TexturePackerGenericXml>("Content/Animations/eye.xml")
                          .Add(Game.ANIMATION_RIGHT, new SpriteSheetAnimationSequence()
            {
                First  = 1 + index * Game.EYE_ANIMATION_COUNT,
                Length = 1
            })
                          .Add(Game.ANIMATION_TURNING, new SpriteSheetAnimationSequence()
            {
                First           = 1 + index * Game.EYE_ANIMATION_COUNT,
                Length          = 11,
                FramesPerSecond = 50
            })
                          .Add(Game.ANIMATION_LEFT, new SpriteSheetAnimationSequence()
            {
                First  = 11 + index * Game.EYE_ANIMATION_COUNT,
                Length = 1
            })
                          .Add(Game.ANIMATION_HOT, new SpriteSheetAnimationSequence()
            {
                First  = 12 + index * Game.EYE_ANIMATION_COUNT,
                Length = 1
            })
                          )
            .AddComponent(new AnimatedSpriteRenderer())
            .AddComponent(new CircleCollider())
            .AddComponent(new RigidBody2D()
            {
                Restitution = Game.EYE_RESTITUTION
            })
            .AddComponent(new JointMap2D())
            .AddComponent(new EyeController());

            EntityManager.Add(eye);

            return(eye);
        }
Beispiel #10
0
        private void CreateExplosion()
        {
            this.explosion = new Entity("boom")
                             .AddComponent(new Transform2D()
            {
                XScale = 3, YScale = 2.5f, Origin = new Vector2(0.5f)
            })
                             .AddComponent(new Sprite(TEXTUREEXPLOSION))
                             .AddComponent(Animation2D.Create <TexturePackerGenericXml>(EXPLOSIONSPRITESHEET)
                                           .Add("Explosion", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 16, FramesPerSecond = 16
            }))
                             .AddComponent(new AnimatedSpriteRenderer());
            this.explosion.Enabled = false;

            this.EntityManager.Add(this.explosion);
        }
        private Entity CreateExplosion()
        {
            var explode = new Entity()
                          .AddComponent(new Transform2D()
            {
                Origin = Vector2.Center, XScale = 2, YScale = 2
            })
                          .AddComponent(new Sprite("Content/explodeSprite.wpk"))
                          .AddComponent(Animation2D.Create <TexturePackerGenericXml>("Content/explodeSprite.xml")
                                        .Add("explosion", new SpriteSheetAnimationSequence()
            {
                First = 0, Length = 10, FramesPerSecond = 60
            }))

                          .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Additive));

            explode.Enabled = false;

            var anim2D = explode.FindComponent <Animation2D>();

            this.Scene.EntityManager.Add(explode);

            return(explode);
        }
Beispiel #12
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.CornflowerBlue;

            var credits = new TextBlock()
            {
                Text = "Braid's art copyright from their original owners\n" +
                       "Sprites from Cyrus Annihilator, background from David Hellman's web\n" +
                       "We just love this game and wanted to make a small tribute within this sample :-)",
                Margin     = new Thickness(10, 10, 0, 0),
                Foreground = Color.Black
            };

            var sky = new Entity("Sky")
                      .AddComponent(new Sprite("Content/Sky.wpk"))
                      .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                      .AddComponent(new Transform2D()
            {
                Origin = new Vector2(0.5f, 1),
                X      = WaveServices.Platform.ScreenWidth / 2,
                Y      = WaveServices.Platform.ScreenHeight
            });
            var floor = new Entity("Floor")
                        .AddComponent(new Sprite("Content/Floor.wpk"))
                        .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                        .AddComponent(new Transform2D()
            {
                Origin = new Vector2(0.5f, 1),
                X      = WaveServices.Platform.ScreenWidth / 2,
                Y      = WaveServices.Platform.ScreenHeight
            });

            // Tim
            var tim = new Entity("Tim")
                      .AddComponent(new Transform2D()
            {
                X      = WaveServices.Platform.ScreenWidth / 2,
                Y      = WaveServices.Platform.ScreenHeight - 46,
                Origin = new Vector2(0.5f, 1)
            })
                      .AddComponent(new Sprite("Content/TimSpriteSheet.wpk"))
                      .AddComponent(Animation2D.Create <TexturePackerGenericXml>("Content/TimSpriteSheet.xml")
                                    .Add("Idle", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 22, FramesPerSecond = 11
            })
                                    .Add("Running", new SpriteSheetAnimationSequence()
            {
                First = 23, Length = 27, FramesPerSecond = 27
            }))
                      .AddComponent(new AnimatedSpriteRenderer())
                      .AddComponent(new TimBehavior());

            // We add the floor the first so the rocks are on top of Tim
            EntityManager.Add(credits.Entity);
            EntityManager.Add(floor);
            EntityManager.Add(tim);
            EntityManager.Add(sky);

            var anim2D = tim.FindComponent <Animation2D>();

            anim2D.Play(true);
        }
Beispiel #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rock" /> class.
        /// </summary>
        /// <param name="rockType">Type of the rock.</param>
        public Rock(RockType rockType, Vector2 position)
        {
            this.entity = new Entity()
                          .AddComponent(new Transform2D()
            {
                X         = position.X,
                Y         = position.Y,
                DrawOrder = 0.2f,
            })
                          .AddComponent(new SpriteRenderer(DefaultLayers.Alpha));

            string  textureName;
            Vector2 rockOrigin, seaweedsPosition;

            switch (rockType)
            {
            case RockType.Center:
                textureName      = "centralRock";
                rockOrigin       = Vector2.Center;
                seaweedsPosition = Vector2.Zero;
                break;

            case RockType.Left:
                textureName      = "leftRock";
                rockOrigin       = Vector2.Zero;
                seaweedsPosition = new Vector2(225, 135);
                break;

            case RockType.Right:
                textureName      = "rightRock";
                rockOrigin       = Vector2.UnitX;
                seaweedsPosition = new Vector2(-170, 100);
                break;

            default:
                textureName      = "centralRock";
                rockOrigin       = Vector2.Zero;
                seaweedsPosition = Vector2.Zero;
                break;
            }
            this.entity.AddComponent(new Sprite(Directories.TexturePath + string.Format("{0}.wpk", textureName))
            {
                IsGlobalAsset = true
            });
            this.entity.AddComponent(new PerPixelCollider(Directories.TexturePath + string.Format("{0}Collider.wpk", textureName), 0.5f)
            {
                IsGlobalAsset = true
            });
            this.entity.FindComponent <Transform2D>().Origin = rockOrigin;

            // Seaweeds
            Entity seaweeds = new Entity()
                              .AddComponent(new Transform2D()
            {
                Origin    = new Vector2(0.5f, 1),
                X         = seaweedsPosition.X,
                Y         = seaweedsPosition.Y,
                DrawOrder = 0.1f,
            })
                              .AddComponent(new Sprite(Directories.TexturePath + "seaweedsSpriteSheet.wpk")
            {
                IsGlobalAsset = true
            })
                              .AddComponent(Animation2D.Create <TexturePackerGenericXml>(Directories.TexturePath + "seaweedsSpriteSheet.xml")
                                            .Add("wave", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 80, FramesPerSecond = 20
            }))
                              .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha));

            this.entity.AddChild(seaweeds);

            seaweeds.FindComponent <Animation2D>().Play(true);

            this.Collider = this.entity.FindComponent <Collider2D>(false);
        }
Beispiel #14
0
        public JellyFish(JellyFishType type, Vector2 position, bool rightAnimation = true)
        {
            this.entity = new Entity()
                          .AddComponent(new Transform2D()
            {
                Origin    = Vector2.Center,
                X         = position.X,
                Y         = position.Y,
                DrawOrder = 0.3f,
            })
                          .AddComponent(new AnimationUI());

            // Cached
            this.animation = this.entity.FindComponent <AnimationUI>();


            string textureName, colliderName;

            switch (type)
            {
            case JellyFishType.Big:
                textureName  = "jellyFishSpriteSheet";
                colliderName = "jellyFishCollider.wpk";
                break;

            case JellyFishType.Little:
                textureName  = "jellyFishLittleSpriteSheet";
                colliderName = "jellyFishLittleCollider.wpk";
                break;

            default:
                textureName  = "jellyFishSpriteSheet";
                colliderName = "jellyFishCollider.wpk";
                break;
            }

            this.entity.AddComponent(new PerPixelCollider(Directories.TexturePath + colliderName, 0.5f)
            {
                IsGlobalAsset = true
            });
            this.entity.AddComponent(new Sprite(Directories.TexturePath + string.Format("{0}.wpk", textureName))
            {
                IsGlobalAsset = true
            });
            this.entity.AddComponent(Animation2D.Create <TexturePackerGenericXml>(Directories.TexturePath + string.Format("{0}.xml", textureName))
                                     .Add("swim", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 40, FramesPerSecond = 30
            }));
            this.entity.AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha));

            this.entity.FindComponent <Animation2D>().Play(true);


            // Animations
            float offset = 80;

            this.leftAnim            = new SingleAnimation(position.X + offset, position.X, TimeSpan.FromSeconds(3));
            this.leftAnim.Completed += (s, o) =>
            {
                this.animation.BeginAnimation(Transform2D.XProperty, this.rightAnim);
            };
            this.rightAnim            = new SingleAnimation(position.X, position.X + offset, TimeSpan.FromSeconds(3));
            this.rightAnim.Completed += (s, o) =>
            {
                this.animation.BeginAnimation(Transform2D.XProperty, this.leftAnim);
            };

            if (rightAnimation)
            {
                this.animation.BeginAnimation(Transform2D.XProperty, this.rightAnim);
            }
            else
            {
                this.animation.BeginAnimation(Transform2D.XProperty, this.leftAnim);
            }

            this.Collider = this.entity.FindComponent <Collider2D>(false);
        }