Пример #1
0
        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            Entity foregroundEntity = Owner.FindChild("ForegroundEntity");

            this.foregroundTransform = foregroundEntity.FindComponent <Transform2D>();
            this.foregroundAnimation = foregroundEntity.FindComponent <AnimationUI>();

            Entity bulletEntity = Owner.FindChild("BulletEntity");

            this.bulletTransform = bulletEntity.FindComponent <Transform2D>();
            this.bulletAnimation = bulletEntity.FindComponent <AnimationUI>();

            this.textControl = Owner.FindChild("TextEntity").FindComponent <TextControl>();

            if (this.on)
            {
                this.bulletTransform.X          = DefaultOffset;
                this.foregroundTransform.XScale = DefaultOffset;
                this.textControl.Text           = this.onText;
            }
            else
            {
                this.bulletTransform.X          = 0;
                this.foregroundTransform.XScale = 0;
                this.textControl.Text           = this.offText;
            }
        }
Пример #2
0
        private void CreateToaster()
        {
            var toaster = new Entity("toaster")
                          .AddComponent(new SkinnedModel("Assets/Animation/toaster_template_animation_uv_fbx.wpk"))
                          .AddComponent(new MaterialsMap(new BasicMaterial("Assets/Textures/toaster_red.wpk")
            {
                LightingEnabled = true,
            }))
                          .AddComponent(new Transform3D()
            {
                Scale = new Vector3(1.5f, 1, 0.67f),
            })
                          .AddComponent(new Animation3D("Assets/Animation/toaster_template_animation_uv_fbx_animation.wpk"))
                          .AddComponent(new SkinnedModelRenderer())
                          .AddComponent(new ToasterBehavior())
                          .AddComponent(new Transform2D())
                          .AddComponent(new RectangleCollider())
                          .AddComponent(new TouchGestures());

            toaster.FindComponent <TouchGestures>().TouchPressed += new EventHandler <GestureEventArgs>(StartGame);

            EntityManager.Add(toaster);

            Animation3D anim = toaster.FindComponent <Animation3D>();

            anim.PlayAnimation("StartRoast", true);
        }
Пример #3
0
 protected override void Update(TimeSpan gameTime)
 {
     foreach (MapChange change in changes)
     {
         Entity ent = EntityManager.Find(change.woName);
         if (ent != null)
         {
             if (change.type == MOBILE)
             {
                 Map.map.SetMobile(change.x, change.y, ent.FindComponent <WorldObject>());
             }
             else if (change.type == WO)
             {
                 Map.map.SetWorldObject(change.x, change.y, ent.FindComponent <WorldObject>());
             }
             toRemove.Add(change);
         }
     }
     if (toRemove.Count > 0)
     {
         foreach (MapChange change in toRemove)
         {
             changes.Remove(change);
         }
         toRemove.Clear();
     }
 }
Пример #4
0
        public void ShootBullet(bool player, float initX, float initY, float velocityX, float velocityY)
        {
            Entity bullet          = player ? this.Bullets[BulletIndex] : this.EnemyBullets[EnemyBulletIndex];
            var    bulletTransform = bullet.FindComponent <Transform2D>();

            bulletTransform.X = initX;
            bulletTransform.Y = initY;

            var bulletBehavior = bullet.FindComponent <BulletBehavior>();

            bulletBehavior.SpeedX = velocityX;
            bulletBehavior.SpeedY = velocityY;

            bullet.Enabled = true;

            if (player)
            {
                switch (WaveServices.Random.Next(0, 3))
                {
                case 0:
                    WaveServices.GetService <SoundManager>().PlaySound(SoundManager.SOUNDS.Blast0);
                    break;

                case 1:
                    WaveServices.GetService <SoundManager>().PlaySound(SoundManager.SOUNDS.Blast1);
                    break;

                case 2:
                    WaveServices.GetService <SoundManager>().PlaySound(SoundManager.SOUNDS.Blast2);
                    break;
                }
            }
        }
Пример #5
0
        protected override void Update(TimeSpan gameTime)
        {
            if (!started)
            {
                started = true;
                UIBehavior ui = Scene.EntityManager.Find("camera2D").FindComponent <UIBehavior>();
                Entity     p  = ui.CreateToTile("Person", 3, 3);
                p.AddComponent(new MovementBehaviorAlt());
                List <LayerTile> tiles = new List <LayerTile>();
                tiles.Add(Map.map.GetTileByMapCoordinates(3, 3));
                tiles.Add(Map.map.GetTileByMapCoordinates(2, 3));
                tiles.Add(Map.map.GetTileByMapCoordinates(2, 2));
                tiles.Add(Map.map.GetTileByMapCoordinates(2, 1));
                tiles.Add(Map.map.GetTileByMapCoordinates(3, 1));
                p.FindComponent <MovementBehaviorAlt>().SetPath(tiles);
                p = ui.CreateToTile("FakeTree", 2, 2);

                ui.playerButtons[1].IsChecked = true;

                p = ui.CreateToTile("FakeTree", 1, 2);
                p = ui.CreateToTile("Person", 1, 1);
                p.AddComponent(new MovementBehaviorAlt());
                tiles = new List <LayerTile>();
                tiles.Add(Map.map.GetTileByMapCoordinates(1, 1));
                tiles.Add(Map.map.GetTileByMapCoordinates(1, 2));
                tiles.Add(Map.map.GetTileByMapCoordinates(2, 2));
                tiles.Add(Map.map.GetTileByMapCoordinates(2, 1));
                tiles.Add(Map.map.GetTileByMapCoordinates(2, 0));
                tiles.Add(Map.map.GetTileByMapCoordinates(1, 0));
                tiles.Add(Map.map.GetTileByMapCoordinates(0, 0));
                tiles.Add(Map.map.GetTileByMapCoordinates(0, 1));
                p.FindComponent <MovementBehaviorAlt>().SetPath(tiles);
            }
        }
Пример #6
0
        private void RespondPlayerGhost(Entity player, Entity ghost)
        {
            //Debug.WriteLine("collision between player and ghost");

            //if ghost is chasing
            {
                //play ghost sound
                ComponentTransform ghostTransform = (ComponentTransform)ghost.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                ComponentAudio     ghostAudio     = (ComponentAudio)ghost.FindComponent(ComponentTypes.COMPONENT_AUDIO);

                Vector3 emitterPosition = (ghostTransform).Position;
                int     source          = (ghostAudio).Source;

                AL.Source(source, ALSource3f.Position, ref emitterPosition);

                ghostAudio.Play();

                //kill player
                ComponentLives livesComponent = (ComponentLives)player.FindComponent(ComponentTypes.COMPONENT_LIVES);
                livesComponent.Lives -= 1;

                ComponentTransform transformComponent = (ComponentTransform)player.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                transformComponent.Position = new Vector3(0, 1, 2);
                ComponentMovement movementComponent = (ComponentMovement)player.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);
                movementComponent.DesiredLocation = new Vector3(0, 1, 2);
            }
            //else if ghost is fleeing
            //kill ghost
            //add 100 points to player
        }
Пример #7
0
        private void ExecuteAction(object sender, IncomingMessage receivedMessage)
        {
            Entity owner = networkedScene.EntityManager.Find(receivedMessage.ReadString());
            Entity other = networkedScene.EntityManager.Find(receivedMessage.ReadString());

            if (owner != null && !owner.IsDisposed && other != null && !other.IsDisposed)
            {
                WorldObject wo  = owner.FindComponent <WorldObject>();
                CommandEnum cmd = (CommandEnum)receivedMessage.ReadInt32();
                foreach (ActionBehavior act in wo.allActions)
                {
                    if (act.GetCommand() == cmd)
                    {
                        bool store = receivedMessage.ReadBoolean();
                        if (store)
                        {
                            wo.EnqueueAction(() => act.Act(other.FindComponent <WorldObject>()));
                        }
                        else
                        {
                            act.Act(other.FindComponent <WorldObject>());
                        }
                        break;
                    }
                }
            }
        }
Пример #8
0
        private void RespondPlayerFood(Entity player, Entity food)
        {
            //play food sound
            ComponentTransform foodTransform = (ComponentTransform)food.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            ComponentAudio     foodAudio     = (ComponentAudio)food.FindComponent(ComponentTypes.COMPONENT_AUDIO);

            Vector3 emitterPosition = (foodTransform).Position;
            int     source          = (foodAudio).Source;

            AL.Source(source, ALSource3f.Position, ref emitterPosition);

            foodAudio.Play();

            //increase the score
            ComponentScore scoreComponent = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE);
            float          score          = scoreComponent.Score;

            ComponentValue valueComponent = (ComponentValue)food.FindComponent(ComponentTypes.COMPONENT_VALUE);
            float          value          = valueComponent.Value;

            score += value;

            scoreComponent.Score = score;
            food.Enabled         = false;
        }
Пример #9
0
        private void UpdateForces(Entity entity, IEnumerable <object> otherEntites)
        {
            var wRigidBody = entity.FindComponent <RigidBody3D>();
            var wTransform = entity.FindComponent <Transform3D>();

            if (wRigidBody == null || wTransform == null)
            {
                return;
            }

            foreach (Entity wOtherObject in otherEntites)
            {
                var wOtherTransform = wOtherObject.FindComponent <Transform3D>();
                var wOtherRigidBody = wOtherObject.FindComponent <RigidBody3D>();

                if (wOtherRigidBody == null || wOtherTransform == null)
                {
                    continue;
                }


                var wDistanceVector  = (wOtherTransform.Position - wTransform.Position);
                var wForceDirection  = Vector3.Normalize(wDistanceVector);
                var wDistanceSquared = wDistanceVector.LengthSquared();
                var wPhysicsStepSize = PhysicsManager.Simulation3D.FixedTimeStep;


                var wNewAccelerationVector = wForceDirection * cGravitationalConstant * wOtherRigidBody.Mass / wDistanceSquared;

                wRigidBody.LinearVelocity += wNewAccelerationVector;
            }
        }
Пример #10
0
        /// <summary>
        /// Create the tile layer as a child entity
        /// </summary>
        /// <param name="tmxLayer">The tmx layer.</param>
        /// <param name="layerIndex">The layer index</param>
        /// <param name="previousEntities">previousEntities</param>
        private void CreateChildTileLayer(TmxLayer tmxLayer, int layerIndex, IList <Entity> previousEntities)
        {
            var tmxLayerName = tmxLayer.Name;

            Entity        layerEntity  = null;
            TiledMapLayer tileMapLayer = null;

            if (previousEntities != null)
            {
                layerEntity = previousEntities.FirstOrDefault(e => e.Tag.StartsWith(TileLayerTag) && e.Name == tmxLayerName);
                previousEntities.Remove(layerEntity);
            }

            var tileLayerOffset = new Vector2((float)tmxLayer.OffsetX, (float)tmxLayer.OffsetY);

            if (layerEntity != null)
            {
                var tileMapTransform = layerEntity.FindComponent <Transform2D>();
                tileMapLayer = layerEntity.FindComponent <TiledMapLayer>();

                if (tileMapTransform != null &&
                    tileMapLayer != null)
                {
                    tileMapTransform.LocalPosition = tileLayerOffset;
                    tileMapLayer.TmxLayerName      = tmxLayerName;
                    layerEntity.Name = tmxLayerName;
                }
                else
                {
                    this.Owner.RemoveChild(layerEntity.Name);
                    layerEntity = null;
                }
            }

            if (layerEntity == null)
            {
                tileMapLayer = new TiledMapLayer()
                {
                    TmxLayerName = tmxLayerName
                };

                layerEntity = new Entity(tmxLayerName)
                {
                    Tag = TileLayerTag
                }
                .AddComponent(tileMapLayer)
                .AddComponent(new Transform2D()
                {
                    LocalPosition = tileLayerOffset,
                    Origin        = this.transform.Origin,
                    Opacity       = (float)tmxLayer.Opacity
                })
                .AddComponent(new TiledMapLayerRenderer());
            }

            this.Owner.AddChild(layerEntity);
            this.tileLayers.Add(tmxLayerName, tileMapLayer);
        }
Пример #11
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;
 }
Пример #12
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);
        }
Пример #13
0
        /// <summary>
        /// Create the tile layer as a child entity
        /// </summary>
        /// <param name="tmxLayer">The tmx layer.</param>
        /// <param name="layerIndex">The layer index</param>
        private void CreateChildTileLayer(TmxLayer tmxLayer, int layerIndex)
        {
            var tag          = "TileLayer_" + layerIndex;
            var tmxLayerName = tmxLayer.Name;

            Entity        layerEntity  = null;
            TiledMapLayer tileMapLayer = null;

            layerEntity = this.Owner.FindChildrenByTag(tag).FirstOrDefault();
            var tileLayerOffset = new Vector2((float)tmxLayer.OffsetX, (float)tmxLayer.OffsetY);

            if (layerEntity != null)
            {
                var tileMapTransform = layerEntity.FindComponent <Transform2D>();
                tileMapLayer = layerEntity.FindComponent <TiledMapLayer>();

                if (tileMapTransform != null &&
                    tileMapLayer != null)
                {
                    tileMapTransform.LocalPosition = tileLayerOffset;
                    tileMapLayer.TmxLayerName      = tmxLayerName;
                    layerEntity.Name = tmxLayerName;
                }
                else
                {
                    this.Owner.RemoveChild(layerEntity.Name);
                    layerEntity = null;
                }
            }

            if (layerEntity == null)
            {
                tileMapLayer = new TiledMapLayer()
                {
                    TmxLayerName = tmxLayerName
                };

                layerEntity = new Entity(tmxLayerName)
                {
                    Tag = tag
                }
                .AddComponent(tileMapLayer)
                .AddComponent(new Transform2D()
                {
                    LocalPosition = tileLayerOffset,
                    Origin        = this.transform.Origin,
                    Opacity       = (float)tmxLayer.Opacity
                })
                .AddComponent(new TiledMapLayerRenderer());
                this.Owner.AddChild(layerEntity);
            }

            this.tileLayers.Add(tmxLayerName, tileMapLayer);
        }
Пример #14
0
        private void RerouteDestroy(object sender, IncomingMessage receivedMessage)
        {
            string nameWO = receivedMessage.ReadString();
            Entity ent    = networkedScene.EntityManager.Find(nameWO);

            if (ent != null)
            {
                ent.FindComponent <WorldObject>().SDestroy();
                ent.FindComponent <WorldObject>().CDestroy();
            }
        }
Пример #15
0
        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            this.textControl      = Owner.FindChild("TextEntity").FindComponent <TextControl>();
            this.textBeforeCursor = this.textControl.Text;

            Entity cursorEntity = Owner.FindChild("CursorEntity");

            this.cursorTransform = cursorEntity.FindComponent <Transform2D>();
            this.cursorAnimation = cursorEntity.FindComponent <AnimationUI>();
        }
Пример #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ListView" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="margin">The margin</param>
        public ListView(string name, Thickness margin)
        {
            entity = new Entity(name)
                     .AddComponent(new Transform2D())
                     .AddComponent(new RectangleCollider2D())
                     .AddComponent(new TouchGestures(false))
                     .AddComponent(new PanelControl())
                     .AddComponent(new PanelControlRenderer
            {
                LayerType = DefaultLayers.Alpha
            })
                     .AddComponent(new ListViewBehavior())
                     .AddComponent(new ListBoxBehavior(Color.Black))
                     .AddChild(new Entity("BackgroundEntity")
                               .AddComponent(new Transform2D
            {
                DrawOrder = 0.5f
            })
                               .AddComponent(new ImageControl(Color.Blue, 1, 1))
                               .AddComponent(new ImageControlRenderer
            {
                LayerType = DefaultLayers.Alpha
            }))
                     .AddChild(new Entity("ForegroundEntity")
                               .AddComponent(new Transform2D
            {
                DrawOrder = 0.45f
            })
                               .AddComponent(new ImageControl(Color.LightBlue, 1, 1))
                               .AddComponent(new ImageControlRenderer
            {
                LayerType = DefaultLayers.Alpha
            }))
                     .AddChild(new Entity("BulletEntity")
                               .AddComponent(new Transform2D
            {
                DrawOrder = 0.4f
            })
                               .AddComponent(new ImageControl(Color.White, 1, 1))
                               .AddComponent(new ImageControlRenderer
            {
                LayerType = DefaultLayers.Alpha
            }));

            // Events
            entity.FindComponent <ListViewBehavior>().ValueChanged         -= OnSliderValueChanged;
            entity.FindComponent <ListViewBehavior>().RealTimeValueChanged -= OnSliderRealTimeValueChanged;
            entity.FindComponent <ListViewBehavior>().ValueChanged         += OnSliderValueChanged;
            entity.FindComponent <ListViewBehavior>().RealTimeValueChanged += OnSliderRealTimeValueChanged;

            Margin = margin;
        }
Пример #17
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="e">Provides a snapshot of timing values.</param>
        public override void Update(FrameEventArgs e)
        {
            if (GamePad.GetState(1).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Key.Escape))
            {
                sceneManager.Exit();
            }

            CheckInput();
            //ai input

            systemManager.ActionUpdateSystems(entityManager);

            //Add your update logic here

            Entity player = entityManager.FindEntity("Player");

            if (player != null)
            {
                ComponentLives playerLivesComponent = (ComponentLives)player.FindComponent(ComponentTypes.COMPONENT_LIVES);

                ComponentScore scoreComp = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE);
                float          score     = scoreComp.Score;

                if (playerLivesComponent.Lives <= 0)
                {
                    sceneManager.SetScene(new GameOverScene(sceneManager, score));
                }

                List <Entity> foodList = entityManager.FindEntities("Food_");
                if (foodList.Count == 0)
                {
                    sceneManager.SetScene(new GameOverScene(sceneManager, score));
                }
            }

            //--------------------

            systemManager.ActionCollisionSystems(entityManager);

            //final systems must action last
            systemManager.ActionFinalSystems(entityManager);

            //move camera
            camera.Update();

            // update OpenAL
            listenerPosition  = camera.Position;
            listenerDirection = camera.Direction;
            listenerUp        = camera.Up;
            AL.Listener(ALListener3f.Position, ref listenerPosition);
            AL.Listener(ALListenerfv.Orientation, ref listenerDirection, ref listenerUp);
        }
 private void Move(Entity toastEntity, Entity textureEntity)
 {
     if (toastEntity.FindComponent <Transform2D>().X < WaveServices.Platform.ScreenWidth / 2)
     {
         toastEntity.FindComponent <Transform2D>().X++;
         textureEntity.FindComponent <Transform2D>().X++;
     }
     else
     {
         toastEntity.FindComponent <Transform2D>().X--;
         textureEntity.FindComponent <Transform2D>().X--;
     }
 }
Пример #19
0
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            if (this.followEntity == null && !string.IsNullOrEmpty(this.followEntityPath))
            {
                this.followEntity = EntityManager.Find(this.followEntityPath);
            }

            var followTransform = followEntity.FindComponent <Transform3D>();

            this.positionOffset = this.transform.Position - followTransform.Position;
        }
Пример #20
0
        private void RespondCreatureWall(Entity creature, Entity wall)
        {
            //dont allow them to move
            //Debug.WriteLine("collsion between creature and wall");

            ComponentTransform transformComponent = (ComponentTransform)creature.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
            Vector3            position           = transformComponent.Position;

            ComponentMovement movementComponent = (ComponentMovement)creature.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);
            Vector3           desiredLocation   = movementComponent.DesiredLocation;

            movementComponent.DesiredLocation = position;
        }
Пример #21
0
        private void CreateCube3D()
        {
            Entity cube = new Entity("Cube")
                          .AddComponent(new Transform3D())
                          .AddComponent(Model.CreateCube())
                          .AddComponent(new MaterialsMap(new BasicMaterial("Content/crate.jpg")))
                          .AddComponent(new ModelRenderer());


            this.cubeTransform = cube.FindComponent <Transform3D>();
            this.cubeMaterial  = (BasicMaterial)cube.FindComponent <MaterialsMap>().DefaultMaterial;

            EntityManager.Add(cube);
        }
Пример #22
0
        /// <summary>
        /// Create the tile image layer as a child entity
        /// </summary>
        /// <param name="tmxImageLayer">The tmx image layer.</param>
        /// <param name="layerIndex">The layer index</param>
        private void CreateChildTileImageLayer(TmxImageLayer tmxImageLayer, int layerIndex)
        {
            var tag          = "TileImageLayer_" + layerIndex;
            var tmxLayerName = tmxImageLayer.Name;

            var tiledMapImageLayer = new TiledMapImageLayer(tmxImageLayer, this);

            Entity layerEntity = null;

            layerEntity = this.Owner.FindChildrenByTag(tag).FirstOrDefault();
            var tileLayerOffset = new Vector2((float)tmxImageLayer.OffsetX, (float)tmxImageLayer.OffsetY);

            if (layerEntity != null)
            {
                var tileMapTransform = layerEntity.FindComponent <Transform2D>();
                var sprite           = layerEntity.FindComponent <Sprite>();

                if (tileMapTransform != null &&
                    sprite != null)
                {
                    tileMapTransform.LocalPosition = tileLayerOffset;
                    sprite.TexturePath             = tiledMapImageLayer.ImagePath;
                    layerEntity.Name = tmxLayerName;
                }
                else
                {
                    this.Owner.RemoveChild(layerEntity.Name);
                    layerEntity = null;
                }
            }

            if (layerEntity == null)
            {
                layerEntity = new Entity(tmxLayerName)
                {
                    Tag = tag
                }
                .AddComponent(new Sprite(tiledMapImageLayer.ImagePath))
                .AddComponent(new Transform2D()
                {
                    LocalPosition = tileLayerOffset,
                    Origin        = this.transform.Origin,
                    Opacity       = (float)tmxImageLayer.Opacity
                })
                .AddComponent(new SpriteRenderer());
                this.Owner.AddChild(layerEntity);
            }

            this.imageLayers.Add(tmxLayerName, tiledMapImageLayer);
        }
Пример #23
0
        public override void ReadSyncData(IncomingMessage binaryReader)
        {
            int nChanges = binaryReader.ReadInt32();

            for (int i = 0; i < nChanges; i++)
            {
                int changeType = binaryReader.ReadInt32();
                int x          = binaryReader.ReadInt32();
                int y          = binaryReader.ReadInt32();
                if (changeType == OCCUPIED)
                {
                    map.SetTileOccupied(x, y, binaryReader.ReadBoolean());
                }
                else
                {
                    string woName = binaryReader.ReadString();
                    if (string.IsNullOrEmpty(woName))
                    {
                        if (changeType == MOBILE)
                        {
                            map.SetMobile(x, y, null);
                        }
                        else if (changeType == WO)
                        {
                            map.SetWorldObject(x, y, null);
                        }
                    }

                    else
                    {
                        Entity ent = EntityManager.Find(woName);
                        if (ent != null)
                        {
                            if (changeType == MOBILE)
                            {
                                map.SetMobile(x, y, ent.FindComponent <WorldObject>());
                            }
                            else if (changeType == WO)
                            {
                                map.SetWorldObject(x, y, ent.FindComponent <WorldObject>());
                            }
                        }
                        else
                        {
                            recover.AddChange(x, y, woName, changeType);
                        }
                    }
                }
            }
        }
Пример #24
0
        public monster2(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("Enemy2 " + 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/Monster2/Monster2XML.wpk"))
                  .AddComponent(Animation2D.Create <TexturePackerGenericXml>("Content/Monsters/Monster2/Monster2XML.xml")
                                .Add("Idle", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 1, FramesPerSecond = 30
            })
                                .Add("Running", new SpriteSheetAnimationSequence()
            {
                First = 1, Length = 4, FramesPerSecond = 20
            }))
                  .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha));

            Mob.FindComponent <Transform2D>().DrawOrder = 0;
            anim2D = Mob.FindComponent <Animation2D>();
            anim2D.CurrentAnimation = "Running";
            anim2D.Play(true);
        }
Пример #25
0
        protected bool Check_Range(int Pos_x, int Pos_y)
        {
            var X = Tower.FindComponent <Transform2D>().X;
            var Y = Tower.FindComponent <Transform2D>().Y;

            if ((Pos_x >= X - Tower_range) && (Pos_x <= X + Tower_range) &&
                (Pos_y >= Y - Tower_range) && (Pos_y <= Y + Tower_range))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #26
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);
        }
        private void UpdateAnchorEntity(Entity entity, ARMobileAnchor anchor)
        {
            var transform = entity.FindComponent <Transform3D>();

            transform.LocalPosition    = anchor.Transform.Translation;
            transform.LocalOrientation = anchor.Transform.Orientation;
            transform.LocalScale       = anchor.Transform.Scale;

            var planeAnchor = anchor as ARMobilePlaneAnchor;

            if (planeAnchor == null)
            {
                return;
            }

            var plane = entity.FindChild(SubplaneEntityName);

            if (plane == null)
            {
                return;
            }

            var planeTransform = plane.FindComponent <Transform3D>();

            planeTransform.LocalPosition = planeAnchor.Center;
            planeTransform.LocalScale    = planeAnchor.Size;
        }
Пример #28
0
        private Entity CreateExplosion()
        {
            var explode = new Entity()
            {
                IsSerializable = false
            }
            .AddComponent(new Transform2D()
            {
                Origin = Vector2.Center, XScale = 2, YScale = 2
            })
            .AddComponent(new SpriteAtlas(WaveContent.Assets.ExplodeSprite_spritesheet))
            .AddComponent(new SpriteAtlasRenderer()
            {
                LayerType = DefaultLayers.Additive
            })
            .AddComponent(new Animation2D()
            {
                CurrentAnimation = "explosion", PlayAutomatically = false
            });

            explode.Enabled = false;

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

            this.Owner.AddChild(explode);

            return(explode);
        }
Пример #29
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.Black;

            // Main Camera
            ViewCamera camera = new ViewCamera("MainCamera", new Vector3(0, 400, 1200), new Vector3(0, 400, 0));

            EntityManager.Add(camera.Entity);
            RenderManager.SetActiveCamera(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);
        }
Пример #30
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.Black;

            // Main Camera
            ViewCamera camera = new ViewCamera("MainCamera", new Vector3(0, 400, 1200), new Vector3(0, 400, 0));

            EntityManager.Add(camera.Entity);
            RenderManager.SetActiveCamera(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);
        }
Пример #31
0
        /// <summary>
        /// Creates Main Scene
        /// </summary>
        protected override void CreateScene()
        {
            FixedCamera2D camera2d = new FixedCamera2D("camera");

            camera2d.BackgroundColor = Color.CornflowerBlue;
            EntityManager.Add(camera2d);

            // Border and UI
            this.CreateClosures();
            this.CreateUI();

            // Sample Crate and Collision Event Register
            Entity      box          = this.CreateCrate(200, 100);
            RigidBody2D boxRigidBody = box.FindComponent <RigidBody2D>();

            if (boxRigidBody != null)
            {
                boxRigidBody.OnPhysic2DCollision += BoxRigidBody_OnPhysic2DCollision;
            }
            EntityManager.Add(box);

            // Sample Circle and Collision Event register
            Entity      circle          = this.CreateCircle(600, 100);
            RigidBody2D circleRigidBody = circle.FindComponent <RigidBody2D>();

            if (circleRigidBody != null)
            {
                circleRigidBody.OnPhysic2DCollision += CircleRigidBody_OnPhysic2DCollision;
            }
            EntityManager.Add(circle);

            // Mouse Handler.
            this.AddSceneBehavior(new MouseBehavior(), SceneBehavior.Order.PostUpdate);
        }
Пример #32
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.CornflowerBlue;

            ViewCamera camera = new ViewCamera("MainCamera", new Vector3(2, 1, 2), new Vector3(0, 1, 0));
            EntityManager.Add(camera.Entity);

            RenderManager.SetActiveCamera(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);
        }
Пример #33
0
        protected override void CreateScene()
        {
            RenderManager.BackgroundColor = Color.CornflowerBlue;

            //ViewCamera camera = new ViewCamera("MainCamera", new Vector3(0, 2f, -2.5f), new Vector3(0, 1, 0));
            camera = new FreeCamera("freeCamera", new Vector3(0, 2f, -3.5f), Vector3.UnitY * 0.9f)
            {
                Speed = 5
            };
            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") { ReferenceAlpha = 0.5f }))
                .AddComponent(new Animation3D("Content/isis-animations.wpk"))
                .AddComponent(new SkinnedModelRenderer())
                .AddComponent(new TimBehavior());

            anim = animatedModel.FindComponent<Animation3D>();
            EntityManager.Add(animatedModel);

            Entity floor = new Entity("Floor")
                       .AddComponent(new Transform3D())
                       .AddComponent(new BoxCollider())
                       .AddComponent(new Model("Content/Model/floor.wpk"))
                       .AddComponent(new MaterialsMap(new BasicMaterial("Content/Texture/floorNight.wpk")))
                       .AddComponent(new ModelRenderer());

            //Suddenly columns! Thousand of them!  (4x2 columns)

            EntityManager.Add(floor);

            //Suddenly columns! Thousand of them!  (4x2 columns)
            /*int nColumns = 0;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Entity column = new Entity("column_" + nColumns++)
                        .AddComponent(new Transform3D() { Position = new Vector3(4 - (8 * j), 0, 8 * i) })
                       .AddComponent(new Model("Content/Model/floor.wpk"))
                        .AddComponent(new ModelRenderer())
                       .AddComponent(new MaterialsMap(new BasicMaterial("Content/Texture/floorNight.wpk")));

                    EntityManager.Add(column);
                    Entity fern = new Entity("Fern" + nColumns++)
                             .AddComponent(new Transform3D() { Position = new Vector3(2f - (8 * j), 0f, 2.5f*i) })
                             .AddComponent(new BoxCollider())
                             .AddComponent(new Model("Content/Model/fern.wpk"))
                             .AddComponent(new MaterialsMap(new BasicMaterial("Content/Texture/FernTexture.wpk") { ReferenceAlpha = 0.5f }))
                             .AddComponent(new ModelRenderer());

                    EntityManager.Add(fern);
                }
            }*/

            camera.Entity.AddComponent(new CameraBehavior(EntityManager.Find("Isis")));

            //Add some light!
            PointLight light = new PointLight("light", Vector3.Zero)
            {
                Attenuation = 75,
                Color = new Color(1, 0.6f, 0.4f),
                IsVisible = true
            };
            light.Entity.AddComponent(new FollowCameraBehavior(camera.Entity));
            light.Entity.AddComponent(new TorchLightBehaviour());

            EntityManager.Add(light);
            EntityManager.Add(camera);
            RenderManager.SetActiveCamera(camera.Entity);
        }