Beispiel #1
0
 public PlayerAIBehavior(Entity ball)
     : base("PlayerIABehavior")
 {
     this.trans2D = null;
     this.ball = ball;
     this.transBall2D = ball.FindComponent<Transform2D>();
     this.ballBehavior = ball.FindComponent<BallBehavior>();
     this.direction = ballBehavior.HorizontalDirection;
 }
Beispiel #2
0
 private void CreateJoystickButton(string name, float x, float y, float rotation, EventHandler<GestureEventArgs> pressed, EventHandler<GestureEventArgs> released)
 {
     var upButton = new Entity(name)
         .AddComponent(new Sprite("Content/JoystickButton.wpk"))
         .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
         .AddComponent(new Transform2D() { Origin = Vector2.One / 2, X = x, Y = y, Rotation = rotation })
         .AddComponent(new TouchGestures())
         .AddComponent(new RectangleCollider());
     upButton.FindComponent<TouchGestures>().TouchPressed += pressed;
     upButton.FindComponent<TouchGestures>().TouchReleased += released;
     EntityManager.Add(upButton);
 }
Beispiel #3
0
        public void Fire()
        {
            var bullet = new Entity()
                    .AddComponent(new Transform2D())
                    .AddComponent(new Sprite(WaveContent.Assets.Bullet_png))
                    .AddComponent(new SpriteRenderer());

            bullet.FindComponent<Transform2D>().Position = this.Transform.Position;
            bullet.FindComponent<Transform2D>().Origin = Vector2.One / 2;
            bullet.FindComponent<Transform2D>().DrawOrder = 10;

            bullet.AddComponent(new BulletBehavior());

            EntityManager.Add(bullet);
        }
        protected override void Update(TimeSpan gameTime)
        {
            var touches = WaveServices.Input.TouchPanelState;

            if (touches.Count > 0)
            {
                if (!pressed)
                {
                    pressed = true;

                    var sphere = new Entity()
                          .AddComponent(new Transform3D() { Scale = new Vector3(1) })
                          .AddComponent(new MaterialsMap())
                          .AddComponent(Model.CreateSphere())
                          .AddComponent(new SphereCollider3D())
                          .AddComponent(new RigidBody3D() { Mass = 2, EnableContinuousContact = true })
                          .AddComponent(new TimeAliveBehavior())
                          .AddComponent(new ModelRenderer());

                    this.EntityManager.Add(sphere);

                    RigidBody3D rigidBody = sphere.FindComponent<RigidBody3D>();
                    rigidBody.ResetPosition(Camera.Position);
                    var direction = Camera.Transform.WorldTransform.Forward;
                    direction.Normalize();
                    rigidBody.ApplyLinearImpulse(100 * direction);
                }
            }
            else
            {
                pressed = false;
            }
        }
Beispiel #5
0
        protected override void CreateScene()
        {            
            // Main Camera
            ViewCamera camera = new ViewCamera("MainCamera", new Vector3(0, 400, 1200), new Vector3(0, 400, 0));
            camera.BackgroundColor = Color.Black;
            EntityManager.Add(camera.Entity);            

            // Initialize particle system

            Entity entitySystem = new Entity("Particles")
                .AddComponent(new Transform3D())
                .AddComponent(new ParticleBehavior())
                .AddComponent(new ParticleSystemRenderer3D());

            var behavior = entitySystem.FindComponent<ParticleBehavior>();
            behavior.ApplyChanges();
            behavior.ApplyMaterial();

            EntityManager.Add(entitySystem);

            textBlock1 = new TextBlock()
            {
                Margin = new Thickness(10),
                Text = "Fire",
                TextWrapping = true,
            };
            EntityManager.Add(textBlock1.Entity);
        }
 public LinkedRopeBehavior(Entity from, Vector2 fromOrigin, Entity to, Vector2 toOrigin)
 {
     this.fromTransform = from.FindComponent<Transform2D>();
     this.toTransform = to.FindComponent<Transform2D>();
     this.fromOrigin = fromOrigin;
     this.toOrigin = toOrigin;
 }
Beispiel #7
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.Black;

            var startButtonEntity = new Entity("StartButton")
            .AddComponent(new Transform2D())
            .AddComponent(new TextControl("Content/SegoeBlack20.wpk")
            {
                Text = "Press here",
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Foreground = Color.White,
            })
            .AddComponent(new TextControlRenderer())
            .AddComponent(new RectangleCollider())
            .AddComponent( new TouchGestures());

            startButtonEntity.FindComponent<TouchGestures>().TouchPressed += new EventHandler<GestureEventArgs>(MyScene_TouchPressed);

            EntityManager.Add(startButtonEntity);

            var screenLayerStateEntity = new Entity("ScreenLayerStateButton")
            .AddComponent(new Transform2D())
            .AddComponent(new TextControl("Content/SegoeBlack20.wpk")
            {
                Text = string.Format("Screen state: {0}", WaveServices.ScreenLayers.Tag),
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Bottom,
                Foreground = Color.White,
            })
            .AddComponent(new TextControlRenderer());

            EntityManager.Add(screenLayerStateEntity);
        }
        private RectangleF GetTotalRectangle(Entity entity, Transform2D parentTransform2D)
        {
            RectangleF result = RectangleF.Empty;
            var entityTransform = entity.FindComponent<Transform2D>();

            if (entityTransform != null)
            {
                result = entityTransform.Rectangle;

                if (parentTransform2D != null)
                {
                    result.Offset(
                        entityTransform.X - (entityTransform.Rectangle.Width * entityTransform.Origin.X),
                        entityTransform.Y - (entityTransform.Rectangle.Height * entityTransform.Origin.Y));

                    result.Offset(
                        -1 * (parentTransform2D.X - (parentTransform2D.Rectangle.Width * parentTransform2D.Origin.X)),
                        -1 * (parentTransform2D.Y - (parentTransform2D.Rectangle.Height * parentTransform2D.Origin.Y)));
                }

                foreach (var child in entity.ChildEntities)
                {
                    var childTotalRectangle = this.GetTotalRectangle(child, entityTransform);

                    RectangleF.Union(ref result, ref childTotalRectangle, out result);
                }
            }

            return result;
        }
Beispiel #9
0
        protected override void CreateScene()
        {
            var camera2D = new FixedCamera2D("Camera2D") { BackgroundColor = Color.Black };
            EntityManager.Add(camera2D);

            int offset = 100;

            //var title = new Entity("Title")
            //                   .AddComponent(new Sprite("Content/Texture/TitlePong.wpk"))
            //                   .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
            //                   .AddComponent(new Transform2D()
            //                   {
            //                       Y = WaveServices.Platform.ScreenHeight / 2 - offset,
            //                       X = WaveServices.Platform.ScreenWidth / 2 - 150
            //                   });

            //EntityManager.Add(title);

            var multiplayerButtonEntity = new Entity("MultiplayerButton")
                                .AddComponent(new Transform2D()
                                {
                                    Y = WaveServices.Platform.ScreenHeight / 2 + 50,
                                    X = WaveServices.Platform.ScreenWidth / 2 - offset,
                                    XScale = 2f,
                                    YScale = 2f
                                })
                                .AddComponent(new TextControl()
                                {
                                    Text = "Multiplayer",
                                    Foreground = Color.White,
                                })
                                .AddComponent(new TextControlRenderer())
                                .AddComponent(new RectangleCollider())
                                .AddComponent(new TouchGestures());

            multiplayerButtonEntity.FindComponent<TouchGestures>().TouchPressed += new EventHandler<GestureEventArgs>(Multiplayer_TouchPressed);

            EntityManager.Add(multiplayerButtonEntity);

            var singleplayerButtonEntity = new Entity("SingleplayerButton")
                                .AddComponent(new Transform2D()
                                {
                                    Y = WaveServices.Platform.ScreenHeight / 2,
                                    X = WaveServices.Platform.ScreenWidth / 2 - offset,
                                    XScale = 2f,
                                    YScale = 2f
                                })
                                .AddComponent(new TextControl()
                                {
                                    Text = "Single Player",
                                    Foreground = Color.White,
                                })
                                .AddComponent(new TextControlRenderer())
                                .AddComponent(new RectangleCollider())
                                .AddComponent(new TouchGestures());

            singleplayerButtonEntity.FindComponent<TouchGestures>().TouchPressed += new EventHandler<GestureEventArgs>(Singleplayer_TouchPressed);

            EntityManager.Add(singleplayerButtonEntity);
        }
Beispiel #10
0
        protected override void CreateScene()
        {
            FixedCamera2D camera2d = new FixedCamera2D("camera");
            EntityManager.Add(camera2d);

            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 #11
0
        protected override void CreateScene()
        {
            this.Load(WaveContent.Scenes.MyScene);

            this.teapot = this.EntityManager.Find("teapot");
            this.disappearMaterial = new DisappearMaterial(WaveContent.Assets.Textures.tile1_png,
                                                                        WaveContent.Assets.Textures.Noise_png,
                                                                        WaveContent.Assets.Textures.Burn_png);
            teapot.FindComponent<MaterialsMap>().DefaultMaterial = disappearMaterial;
        }
Beispiel #12
0
        /// <summary>
        /// Create User Interface (UI)
        /// </summary>
        private void CreateUI()
        {
            var isisBehavior = EntityManager.Find("isis").FindComponent<IsisBehavior>();
            CreateJoystickButton("UpButton", 200, WaveServices.Platform.ScreenHeight - 300, 0,
                (o, e) => { isisBehavior.GoUp = true; },
                (o, e) => { isisBehavior.GoUp = false; });
            CreateJoystickButton("DownButton", 200, WaveServices.Platform.ScreenHeight - 100, MathHelper.Pi,
                (o, e) => { isisBehavior.GoDown = true; },
                (o, e) => { isisBehavior.GoDown = false; });
            CreateJoystickButton("LeftButton", 100, WaveServices.Platform.ScreenHeight - 200, -MathHelper.PiOver2,
                (o, e) => { isisBehavior.GoLeft = true; },
                (o, e) => { isisBehavior.GoLeft = false; });
            CreateJoystickButton("RightButton", 300, WaveServices.Platform.ScreenHeight - 200, MathHelper.PiOver2,
                (o, e) => { isisBehavior.GoRight = true; },
                (o, e) => { isisBehavior.GoRight = false; });

            var shiftButton = new Entity("ShiftButton")
                .AddComponent(new Sprite("Content/ShiftButton.wpk"))
                .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                .AddComponent(new Transform2D() { X = WaveServices.Platform.ScreenWidth - 250, Y = WaveServices.Platform.ScreenHeight - 250 })
                .AddComponent(new TouchGestures())
                .AddComponent(new RectangleCollider());
            shiftButton.FindComponent<TouchGestures>().TouchPressed += (o, e) => { isisBehavior.Run = true; };
            shiftButton.FindComponent<TouchGestures>().TouchReleased += (o, e) => { isisBehavior.Run = false; };
            EntityManager.Add(shiftButton);

            var wireframeModeToggle = new ToggleSwitch()
            {
                IsOn = false,
                OnText = "Wireframe?",
                OffText = "Wireframe?",
                Width = 175,
                Margin = new Thickness(50, 50, 0, 0)
            };

            wireframeModeToggle.Toggled += (o, e) =>
            {
                ((OpaqueLayer)RenderManager.FindLayer(DefaultLayers.Opaque)).FillMode = wireframeModeToggle.IsOn ? FillMode.Wireframe : FillMode.Solid;
            };

            EntityManager.Add(wireframeModeToggle.Entity);
        }
Beispiel #13
0
        public BallBehavior(Entity player, Entity barBot, Entity barTop, Entity barLeft, Entity barRight, Entity brick)
            : base("BallBehavior")
        {
            this.trans2D = null;
            //			this.player = player;
            //			this.rectPlayer = player.FindComponent<RectangleCollider>();
            this.barBot = barBot;
            this.rectBarBot = barBot.FindComponent<RectangleCollider>();
            playerTrans = barBot.FindComponent<Transform2D>();
            this.barTop = barTop;
            this.rectBarTop = barTop.FindComponent<RectangleCollider>();
            this.barLeft = barLeft;
            this.rectBarLeft = barLeft.FindComponent<RectangleCollider>();
            this.barRight = barRight;
            this.rectBarRight = barRight.FindComponent<RectangleCollider>();

            this.brick = brick;
            this.rectBrick = brick.FindComponent<RectangleCollider>();

            //this.circleBall = this.Owner.FindComponent<CircleCollider>();
        }
        public Follower2DBehavior(Entity entity, FollowTypes followType)
        {
            this.followedTranform = entity.FindComponent<Transform2D>();
            this.followType = followType;

            this.lastFollowPosition = Vector2.Zero;

            if (this.lastFollowPosition == null)
            {
                throw new NotImplementedException("The Transform2D component must be used by the entity to follow");
            }
        }
Beispiel #15
0
 public BallBehavior(Entity player, Entity barBot, Entity barTop, Entity playerIA)
     : base("BallBehavior")
 {
     this.trans2D = null;
     this.player = player;
     this.rectPlayer = player.FindComponent<RectangleCollider>();
     this.player2 = playerIA;
     this.rectPlayer2 = playerIA.FindComponent<RectangleCollider>();
     this.barBot = barBot;
     this.rectBarBot = barBot.FindComponent<RectangleCollider>();
     this.barTop = barTop;
     this.rectBarTop = barTop.FindComponent<RectangleCollider>();
 }
Beispiel #16
0
        private Entity CreateGround(string name, float x, float y, float angle)
        {
            Entity sprite = new Entity(name)
                .AddComponent(new Transform2D() { X = x, Y = y})
                .AddComponent(new RectangleCollider())
                .AddComponent(new Sprite("Content/Ground.wpk"))
                .AddComponent(new RigidBody2D() { IsKinematic = true, Friction = 1 })
                .AddComponent(new SpriteRenderer(DefaultLayers.Opaque));

            sprite.FindComponent<RigidBody2D>().Rotation = angle;

            return sprite;
        }
Beispiel #17
0
        protected override void CreateScene()
        {
            FixedCamera2D camera2d = new FixedCamera2D("camera")
            {
                BackgroundColor = Color.Black,
                ClearFlags = ClearFlags.DepthAndStencil,
            };
            camera2d.BackgroundColor = Color.Black;
            EntityManager.Add(camera2d);

            Entity logo = new Entity()
            .AddComponent(new Transform2D() { X = WaveServices.ViewportManager.VirtualWidth / 2, Y = 227, Origin = Vector2.Center, DrawOrder = 0.1f })
            .AddComponent(new Sprite("Content/DeepSpace_logo.wpk"))
            .AddComponent(new AnimationUI())
            .AddComponent(new SpriteRenderer(DefaultLayers.Alpha));

            this.labelAnimation = logo.FindComponent<AnimationUI>();

            this.EntityManager.Add(logo);
           
            var button = new Button()
            {
                Margin = new Thickness(0, 657, 0, 0),
                HorizontalAlignment = WaveEngine.Framework.UI.HorizontalAlignment.Center,
                VerticalAlignment = WaveEngine.Framework.UI.VerticalAlignment.Top,
                Text = string.Empty,
                IsBorder = false,
                BackgroundImage = "Content/PressStart.wpk",
                PressedBackgroundImage = "Content/PressStart.wpk"

            };

            button.Click += (o, e) =>
            {
                var gameScene = WaveServices.ScreenContextManager.FindContextByName("GamePlayContext").FindScene<GamePlayScene>();

                gameScene.State = GameState.Game;

                WaveServices.ScreenContextManager.Pop(new CrossFadeTransition(TimeSpan.FromSeconds(0.5f)));
                ////WaveServices.ScreenContextManager.Push(gameContext, new CrossFadeTransition(TimeSpan.FromSeconds(1.5f)));
            };

            button.Entity.AddComponent(new AnimationUI());
            this.playAnimation = button.Entity.FindComponent<AnimationUI>();

            this.EntityManager.Add(button);


            this.playScaleAppear = new SingleAnimation(0.2f, 1f, TimeSpan.FromSeconds(2), EasingFunctions.Back);
            this.playOpacityAppear = new SingleAnimation(0, 1, TimeSpan.FromSeconds(1), EasingFunctions.Cubic);
        }
Beispiel #18
0
        protected override void CreateScene()
        {
            var startButtonEntity = new Entity("StartButton")
            .AddComponent(new Transform2D())
            .AddComponent(new TextControl("Content/SegoeBlack20.wpk")
            {
                Text = "Main menu",
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Bottom,
                Margin = new Thickness(0f,0f,0f,25f),
                Foreground = Color.White,
            })
            .AddComponent(new TextControlRenderer())
            .AddComponent(new RectangleCollider())
            .AddComponent( new TouchGestures());

            startButtonEntity.FindComponent<TouchGestures>().TouchPressed += new EventHandler<GestureEventArgs>(MyScene_TouchPressed);

            EntityManager.Add(startButtonEntity);

            var optionsEntity = new Entity("OptionsButton")
            .AddComponent( new Transform2D())
               .AddComponent(new TextControl("Content/SegoeBlack20.wpk")
               {
               Text = "Options",
               HorizontalAlignment = HorizontalAlignment.Left,
               VerticalAlignment = VerticalAlignment.Bottom,
               Foreground = Color.White,
               })
               .AddComponent(new TextControlRenderer())
               .AddComponent(new RectangleCollider())
               .AddComponent(new TouchGestures());

            optionsEntity.FindComponent<TouchGestures>().TouchPressed += new EventHandler<GestureEventArgs>(SecondScene_TouchPressed);

            EntityManager.Add(optionsEntity);

            var screenLayerStateEntity = new Entity("ScreenLayerStateButton")
            .AddComponent(new Transform2D())
            .AddComponent(new TextControl("Content/SegoeBlack20.wpk")
            {
                Text = string.Format("Screen state: {0}", WaveServices.ScreenLayers.Tag),
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Bottom,
                Foreground = Color.White,
            })
            .AddComponent(new TextControlRenderer());

            EntityManager.Add(screenLayerStateEntity);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ScaleTo3DGameAction"/> class.
        /// </summary>
        /// <param name="entity">The target entity</param>
        /// <param name="to">The target scale</param>
        /// <param name="time">Animation duration</param>
        /// <param name="ease">The ease function</param>
        /// /// <param name="local">If the scale is in local coordinate</param>
        public ScaleTo3DGameAction(Entity entity, Vector3 to, TimeSpan time, EaseFunction ease = EaseFunction.None, bool local = false)
            : base(entity, Vector3.Zero, to, time, ease)
        {
            this.local = local;

            if (local)
            {
                this.updateAction = this.LocalScaleAction;
            }
            else
            {
                this.updateAction = this.ScaleAction;
            }

            this.transform = entity.FindComponent<Transform3D>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RotateTo2DGameAction"/> class.
        /// </summary>
        /// <param name="entity">The target entity</param>
        /// <param name="to">The target angle</param>
        /// <param name="time">Animation duration</param>
        /// <param name="ease">The ease function</param>
        /// <param name="local">If the rotation is local</param>
        public RotateTo2DGameAction(Entity entity, float to, TimeSpan time, EaseFunction ease = EaseFunction.None, bool local = false)
            : base(entity, 0, to, time, ease)
        {
            this.local = local;

            if (local)
            {
                this.updateAction = this.LocalRotateAction;
            }
            else
            {
                this.updateAction = this.RotateAction;
            }

            this.transform = entity.FindComponent<Transform2D>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MoveTo2DGameAction"/> class.
        /// </summary>
        /// <param name="entity">The target entity</param>
        /// <param name="to">The target position</param>
        /// <param name="time">Animation duration</param>
        /// <param name="ease">The ease function</param>
        /// <param name="local">If the position is in local coordinates.</param>
        public MoveTo2DGameAction(Entity entity, Vector2 to, TimeSpan time, EaseFunction ease = EaseFunction.None, bool local = false)
            : base(entity, Vector2.Zero, to, time, ease)
        {
            this.local = local;

            if (local)
            {
                this.updateAction = this.LocalMoveAction;
            }
            else
            {
                this.updateAction = this.MoveAction;
            }

            this.transform = entity.FindComponent<Transform2D>();
        }
Beispiel #22
0
        protected override void CreateScene()
        {            
            ViewCamera camera = new ViewCamera("MainCamera", new Vector3(2, 1, 2), new Vector3(0, 1, 0));
            camera.BackgroundColor = Color.CornflowerBlue;
            EntityManager.Add(camera.Entity);            

            Entity animatedModel = new Entity("Isis")
                .AddComponent(new Transform3D())
                .AddComponent(new BoxCollider())
                .AddComponent(new SkinnedModel("Content/isis.wpk"))
                .AddComponent(new MaterialsMap(new BasicMaterial("Content/isis-difuse.wpk")))
                .AddComponent(new Animation3D("Content/isis-animations.wpk"))
                .AddComponent(new SkinnedModelRenderer());

            anim = animatedModel.FindComponent<Animation3D>();
            EntityManager.Add(animatedModel);
        }
Beispiel #23
0
        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;
            bestValue = float.MaxValue;
            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                // Calculate the ray
                CalculateRay();

                // Look for all entities in the game...
                for (int i = 0; i < EntityManager.Count; i++)
                {
                    currentEntity = EntityManager.EntityGraph.ElementAt(i); ;

                    entityCollider = currentEntity.FindComponent<BoxCollider>();
                    // ... but only a collidable entities ( entities which have a boxCollider component)
                    if (entityCollider != null)
                    {
                        // Intersect our calculated ray with the entity's boxCollider
                        collisionResult = entityCollider.Intersects(ref ray);
                        // If any collision
                        if (collisionResult.HasValue)
                        {
                            // Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
                            if (collisionResult.Value < bestValue)
                            {
                                // Send to the scene the new entity picked name
                                (WaveServices.ScreenContextManager.CurrentContext[0] as MyScene).ShowPickedEntity(currentEntity.Name);
                                bestValue = collisionResult.Value;
                            }
                        }
                    }
                }
            }
            else
            {
                (WaveServices.ScreenContextManager.CurrentContext[0] as MyScene).ShowPickedEntity("None");
            }
        }
Beispiel #24
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.CornflowerBlue;

            var ryu = new Entity("ryu");
            ryu.AddComponent(new Transform2D()
                                 {
                                     X = WaveServices.Platform.ScreenWidth /2,
                                     Y  = WaveServices.Platform.ScreenHeight /2

                                 })
                .AddComponent(Animation2D.Create<RyuXml>("Content/ryu.xml")
                .Add("idle", new SpriteSheetAnimationSequence()
                                                                  {
                                                                             First  = 0,
                                                                             Length = 6,
                                                                             FramesPerSecond = 5
                                                                           }))
                .AddComponent(new Sprite("Content/ryu.wpk"))
                .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha));

            EntityManager.Add(ryu);
            ryu.FindComponent<Animation2D>().Play(true);
        }
Beispiel #25
0
        protected override void CreateScene()
        {
            #region Scene creation
            // Create the camera
            ViewCamera camera = new ViewCamera("MainCamera", new Vector3(2, 1, 2), new Vector3(0, 1, 0));
            camera.BackgroundColor = Color.CornflowerBlue;
            EntityManager.Add(camera.Entity);            

            // Create the model. Note of we add the Animation3D component.
            Entity animatedModel = new Entity("Isis")
                .AddComponent(new Transform3D())
                .AddComponent(new BoxCollider())
                .AddComponent(new SkinnedModel("Content/isis.wpk"))
                .AddComponent(new MaterialsMap(new BasicMaterial("Content/isis-difuse.wpk")))
                .AddComponent(new Animation3D("Content/isis-animations.wpk"))
                .AddComponent(new SkinnedModelRenderer())
                .AddComponent(new IsisBehavior());

            // Create the sound bank
            SoundBank spankerSlamSounds = new SoundBank();
            spankerSlamSounds.Add(SoundsManager.FootStep1);
            spankerSlamSounds.Add(SoundsManager.FootStep2);
            WaveServices.SoundPlayer.RegisterSoundBank(spankerSlamSounds);            
            #endregion

            #region Key Events
            // Add the key frames. The first parameter is the name of the animation, the second the number of frames and the third the name of the event. As you can see, we raise two events when
            // the animation is "Attack" ( see the Animation3D example for further information ). The first event is raised on frame 10 and the second on frame 25. See the SpankerBehavior class
            animation = animatedModel.FindComponent<Animation3D>()
                .AddKeyFrameEvent("Jog", 1, "DoFootstep")
                .AddKeyFrameEvent("Jog", 14, "DoFootstep")
                .AddKeyFrameEvent("Jog", 26, "DoFootstep")
                .AddKeyFrameEvent("Jog", 39, "DoFootstep");
            EntityManager.Add(animatedModel);
            #endregion
        }
Beispiel #26
0
        /// <summary>
        /// Create Sphere
        /// </summary>
        /// <param name="name"></param>
        /// <param name="position"></param>
        private void CreateSphere(Vector3 position)
        {
            Entity primitive = new Entity("Sphere" + instances++)
                .AddComponent(new Transform3D() { Position = position, Scale = Vector3.One / 2 })
                .AddComponent(new SphereCollider())
                .AddComponent(Model.CreateSphere())
                .AddComponent(new RigidBody3D() { KineticFriction = 10, Restitution = 1 })
                .AddComponent(new MaterialsMap(new BasicMaterial(GetRandomColor())))
                .AddComponent(new ModelRenderer());

            RigidBody3D rigidBody3D = primitive.FindComponent<RigidBody3D>(false);
            if (rigidBody3D != null)
            {
                rigidBody3D.OnPhysic3DCollision += rigidBody3D_OnPhysic3DCollision;
            }

            EntityManager.Add(primitive);

            // Sets sphere Time To Live. Remove timer from WaveServices after use.
            WaveServices.TimerFactory.CreateTimer("Timer" + primitive.Name, TimeSpan.FromSeconds(10), () =>
            {
                EntityManager.Remove(primitive);
                WaveServices.TimerFactory.RemoveTimer("Timer" + primitive.Name);
            });
        }
        private void UpdateTile(LayerTile layerTile, Entity tileEntity)
        {
            tileEntity.IsVisible = layerTile != null;

            if (layerTile != null)
            {
                tileEntity.FindComponent<Transform2D>().LocalPosition = layerTile.LocalPosition;
            }
        }
Beispiel #28
0
        protected override void CreateScene()
        {
            FixedCamera2D camera2d = new FixedCamera2D("camera");
            camera2d.ClearFlags = ClearFlags.DepthAndStencil;
            EntityManager.Add(camera2d);
            
            Entity logo = new Entity()
            .AddComponent(new Transform2D() { X = WaveServices.ViewportManager.VirtualWidth / 2, Y = 300, Origin = new Vector2(0.5f, 0), DrawOrder = 0.1f })
            .AddComponent(new Sprite("Content/GameOver.wpk"))
            .AddComponent(new AnimationUI())
            .AddComponent(new SpriteRenderer(DefaultLayers.Alpha));

            this.gameStorage = Catalog.GetItem<GameStorage>();

            this.EntityManager.Add(logo);

            this.labelAnimation = logo.FindComponent<AnimationUI>();

            this.playScaleAppear = new SingleAnimation(0.2f, 1f, TimeSpan.FromSeconds(2), EasingFunctions.Back);
            this.playOpacityAppear = new SingleAnimation(0, 1, TimeSpan.FromSeconds(1), EasingFunctions.Cubic);

            var button = new Button()
            {
                Margin = new Thickness(0, 657, 0, 0),
                HorizontalAlignment = WaveEngine.Framework.UI.HorizontalAlignment.Center,
                VerticalAlignment = WaveEngine.Framework.UI.VerticalAlignment.Top,
                Text = string.Empty,
                IsBorder = false,
                BackgroundImage = "Content/restart.wpk",
                PressedBackgroundImage = "Content/restart.wpk"

            };

            button.Click += (o, e) =>
            {
                GamePlayScene scene = WaveServices.ScreenContextManager.FindContextByName("GamePlayContext").FindScene<GamePlayScene>();

                scene.State = Behaviors.GameState.Game;

                scene.Reset();

                WaveServices.ScreenContextManager.Pop(new CrossFadeTransition(TimeSpan.FromSeconds(0.5f)));
            };

            button.Entity.AddComponent(new AnimationUI());
            this.playAnimation = button.Entity.FindComponent<AnimationUI>();

            this.EntityManager.Add(button);

            var stackPanel = new StackPanel()
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Bottom,
                Orientation = Orientation.Horizontal,
                Margin = new Thickness(0, 0, (WaveServices.ViewportManager.VirtualWidth - WaveServices.ViewportManager.RightEdge), 20)// (WaveServices.ViewportManager.VirtualWidth - WaveServices.ViewportManager.RightEdge), 20)
            };

            var bestScoreLabel = new Image("Content/BestScore.wpk")
            {
                VerticalAlignment = VerticalAlignment.Center
            };

            stackPanel.Add(bestScoreLabel);

            var bestScoreText = new TextBlock()
            {
                Text = this.gameStorage.BestScore.ToString(),
                FontPath = "Content/Space Age.wpk",
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(5,0,0,10)
            };
            stackPanel.Add(bestScoreText);

            this.EntityManager.Add(stackPanel);
        }
Beispiel #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToggleSwitch" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public ToggleSwitch(string name)
        {
            this.entity = new Entity(name)
                           .AddComponent(new Transform2D())
                           .AddComponent(new RectangleCollider())
                           .AddComponent(new TouchGestures())
                           .AddComponent(new GridControl(100, 42))
                           .AddComponent(new GridRenderer())
                           .AddComponent(new ToggleSwitchBehavior());

            GridControl gridPanel = this.entity.FindComponent<GridControl>();
            gridPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Proportional) });
            gridPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
            gridPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Proportional) });

            // Text
            Entity textEntity = new Entity("TextEntity")
                                .AddComponent(new Transform2D()
                                {
                                    DrawOrder = 0.4f
                                })
                                .AddComponent(new TextControl()
                                {
                                    Text = "Off",
                                    Margin = DefaultTextMargin
                                })
                                .AddComponent(new TextControlRenderer());

            TextControl text = textEntity.FindComponent<TextControl>();
            text.SetValue(GridControl.RowProperty, 0);
            text.SetValue(GridControl.ColumnProperty, 0);

            this.entity.AddChild(textEntity);

            // Background
            Entity backgroundEntity = new Entity("BackgroundEntity")
                                .AddComponent(new Transform2D()
                                {
                                    DrawOrder = 0.5f
                                })
                                .AddComponent(new ImageControl(Color.Blue, DefaultWidth, DefaultHeight)
                                {
                                    Margin = DefaultSliderMargin
                                })
                                .AddComponent(new ImageControlRenderer());

            ImageControl background = backgroundEntity.FindComponent<ImageControl>();
            background.SetValue(GridControl.RowProperty, 0);
            background.SetValue(GridControl.ColumnProperty, 1);

            this.entity.AddChild(backgroundEntity);

            // Foreground
            Entity foregroundEntity = new Entity("ForegroundEntity")
                                .AddComponent(new Transform2D()
                                {
                                    DrawOrder = 0.45f
                                })
                                .AddComponent(new AnimationUI())
                                .AddComponent(new ImageControl(Color.LightBlue, 1, DefaultHeight)
                                {
                                    Margin = DefaultSliderMargin
                                })
                                .AddComponent(new ImageControlRenderer());

            ImageControl foreground = foregroundEntity.FindComponent<ImageControl>();
            foreground.SetValue(GridControl.RowProperty, 0);
            foreground.SetValue(GridControl.ColumnProperty, 1);

            this.entity.AddChild(foregroundEntity);

            // Bullet
            Entity bulletEntity = new Entity("BulletEntity")
                                .AddComponent(new Transform2D()
                                {
                                    DrawOrder = 0.4f
                                })
                                .AddComponent(new AnimationUI())
                                .AddComponent(new ImageControl(Color.White, DefaultHeight, DefaultHeight)
                                {
                                    Margin = DefaultSliderMargin
                                })
                                .AddComponent(new ImageControlRenderer());

            ImageControl bullet = bulletEntity.FindComponent<ImageControl>();
            bullet.SetValue(GridControl.RowProperty, 0);
            bullet.SetValue(GridControl.ColumnProperty, 1);

            this.entity.AddChild(bulletEntity);

            // Event
            this.entity.FindComponent<ToggleSwitchBehavior>().Toggled += this.ToggleSwitch_Toggled;
        }
Beispiel #30
0
        /// <summary>
        /// Creates main character.
        /// </summary>
        private void CreateIsis()
        {
            PointLight light = new PointLight("light", new Vector3(-1.783f, 2.503f, 0))
            {
                IsVisible = true,
                Color = new Color("f0f2ff"),
                Attenuation = 20
            };
            EntityManager.Add(light);

            Entity isis = new Entity("Isis")
            .AddComponent(new Transform3D() { Position = Vector3.UnitY * 0.15f, Scale = Vector3.One * 1.14f, Rotation = Vector3.UnitY * MathHelper.ToRadians(-25) })
            .AddComponent(new SkinnedModel("Content/Models/isis.wpk"))
            .AddComponent(new SkinnedModelRenderer())
            .AddComponent(new Animation3D("Content/Models/isis-animations.wpk"))
            .AddComponent(new MaterialsMap(new NormalMappingMaterial("Content/Textures/isis-difuse.wpk", "Content/Textures/isis-normal.wpk", DefaultLayers.Opaque) { AmbientColor = Color.White * 0.6f }));

            EntityManager.Add(isis);
            isis.FindComponent<Animation3D>().PlayAnimation("Idle", true);
        }