예제 #1
0
        /// <summary>
        /// Handler for when an entity is marked for death
        /// </summary>
        /// <param name="data">Integer containing entity key which is going to die</param>
        private void HandleDeath(object data)
        {
            var key = data as int?;

            if (!key.HasValue)
            {
                return;
            }
            // dead
            if (Game1.Inst.Scene.EntityHasComponent <CHealth>(key.Value))
            {
                var health = (CHealth)Game1.Inst.Scene.GetComponentFromEntity <CHealth>(key.Value);
                if (health.DeathSound != null)
                {
                    SfxUtil.PlaySound(health.DeathSound, randomPitch: true);
                }
            }
            if (Game1.Inst.Scene.EntityHasComponent <CAI>(key.Value))
            {
                var aiComp = (CAI)Game1.Inst.Scene.GetComponentFromEntity <CAI>(key.Value);
                var flock  = (CFlock)Game1.Inst.Scene.GetComponentFromEntity <CFlock>(aiComp.Flock);
                flock.Members.Remove(key.Value);
            }
            Game1.Inst.Scene.RemoveEntity(key.Value);
        }
        //--------------------------------------
        // PUBLIC METHODS
        //--------------------------------------

        /// <summary>Initializes the scene.</summary>
        public override void Init()
        {
            base.Init();

            // Ugly, but useful during development.
            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (!type.IsSubclassOf(typeof(Scene)) || type == GetType())
                {
                    continue;
                }

                CreateLabel(type.Name, () => {
                    Game1.Inst.EnterScene((Scene)Activator.CreateInstance(type));
                });
            }

            CreateLabel("Quit", () => {
                Game1.Inst.Exit();
            });

            SfxUtil.PlayMusic("Sounds/Music/MainMenu");

            OnEvent("selchanged", data => SfxUtil.PlaySound("Sounds/Effects/Click"));
        }
예제 #3
0
        public override void Init()
        {
            Game1.Inst.Scene.OnEvent("collision", data => {
                if (playersInt.Count == 0)
                {
                    foreach (var player in Game1.Inst.Scene.GetComponents <CPlayer>().Keys)
                    {
                        playersInt.Add(player);
                    }
                }
                var entity = ((PhysicsSystem.CollisionInfo)data).Entity1;
                if (playersInt.Contains(entity))
                {
                    if (isInAir)
                    {
                        if (Game1.Inst.Scene.EntityHasComponent <CInput>(entity))
                        {
                            isInAir    = false;
                            isOnGround = false;
                        }
                        var model    = (CImportedModel)Game1.Inst.Scene.GetComponentFromEntity <C3DRenderable>(entity);
                        model.animFn = SceneUtils.playerAnimation(entity, 24, 0.1f);
                    }
                }
            });

            //todo collisionwithground is raised all the time
            //not the best soultion displays another animtion when jumping for both players if network
            Game1.Inst.Scene.OnEvent("collisionwithground", data => {
                if (playersInt.Count == 0)
                {
                    foreach (var player in Game1.Inst.Scene.GetComponents <CPlayer>().Keys)
                    {
                        playersInt.Add(player);
                    }
                }
                var entity = ((PhysicsSystem.CollisionInfo)data).Entity1;
                if (playersInt.Contains(entity))
                {
                    if (isInAir)
                    {
                        if (Game1.Inst.Scene.EntityHasComponent <CInput>(entity))
                        {
                            isInAir    = false;
                            isOnGround = true;
                            SfxUtil.PlaySound("Sounds/Effects/jump_end", vol: 1, randomPitch: true);
                        }
                        var model    = (CImportedModel)Game1.Inst.Scene.GetComponentFromEntity <C3DRenderable>(entity);
                        model.animFn = SceneUtils.playerAnimation(entity, 24, 0.1f);
                    }
                }
            });

            base.Init();
        }
예제 #4
0
        public override void Init()
        {
            base.Init();

            var    screenCenter = new Vector2(Game1.Inst.GraphicsDevice.Viewport.Width * 0.5f, Game1.Inst.GraphicsDevice.Viewport.Height * 0.5f);
            string text         = "GAME";
            var    largeFont    = Game1.Inst.Content.Load <SpriteFont>("Fonts/FFFForward_Large");
            var    textSize     = largeFont.MeasureString(text);
            int    id           = AddEntity();

            AddComponent <C2DRenderable>(id, new CText {
                color    = Color.Black,
                font     = largeFont,
                format   = text,
                origin   = Vector2.Zero,
                position = new Vector2(
                    screenCenter.X - textSize.X * 0.5f,
                    screenCenter.Y - textSize.Y - 20
                    )
            });
            text     = "the game";
            textSize = mFont.MeasureString(text);
            id       = AddEntity();
            AddComponent <C2DRenderable>(id, new CText {
                color    = Color.Black,
                font     = mFont,
                format   = text,
                origin   = Vector2.Zero,
                position = new Vector2(
                    screenCenter.X - textSize.X * 0.5f,
                    screenCenter.Y
                    )
            });

            if (mIsMultiplayer)
            {
                addWatingForPlayers();
                OnEvent("update_peers", updatePeers);
            }
            else
            {
                SfxUtil.PlayMusic("Sounds/Music/MainMenu");
                CreateLabels();
            }

            OnEvent("selchanged", data => SfxUtil.PlaySound("Sounds/Effects/Click"));
        }
예제 #5
0
        public override void Draw(float t, float dt)
        {
            if (shouldLeave) // TODO: When we parallelise this probably won't work.
            {
                CScore score = (CScore)Game1.Inst.Scene.GetComponentFromEntity <CScore>(player);
                SfxUtil.PlaySound("Sounds/Effects/horny_end");
                Game1.Inst.LeaveScene();
                Game1.Inst.EnterScene(new EndGameScene(passedTime, score.Score, won));
            }

            var camera = (CCamera)GetComponentFromEntity <CCamera>(player);

            if (camera.Position.Y < configs.WaterHeight)
            {
                GfxUtil.SetRT(mRT);
                base.Draw(t, dt);
                GfxUtil.SetRT(null);
                mUnderWaterFx.Parameters["SrcTex"].SetValue(mRT);
                mUnderWaterFx.Parameters["Phase"].SetValue(t);
                GfxUtil.DrawFsQuad(mUnderWaterFx);
            }
            else if (configs.IsRaining)
            {
                GfxUtil.SetRT(mRT);
                base.Draw(t, dt);
                GfxUtil.SetRT(null);
                mPostProcessor.ApplyPostProcess(t, dt, mRT);
            }
            else
            {
                GfxUtil.SetRT(null);
                base.Draw(t, dt);
            }

            mHud.Update();
            mHud.Draw(player);
        }
예제 #6
0
        public override void Update(float t, float dt)
        {
            KeyboardState currentState = Keyboard.GetState();

            Keys[] pressedKeys = currentState.GetPressedKeys();
            yaw = 0;

            foreach (var input in Game1.Inst.Scene.GetComponents <CInput>())
            {
                CBody body = null;
                if (Game1.Inst.Scene.EntityHasComponent <CBody>(input.Key))
                {
                    body = (CBody)Game1.Inst.Scene.GetComponentFromEntity <CBody>(input.Key);
                }
                var transform  = (CTransform)Game1.Inst.Scene.GetComponentFromEntity <CTransform>(input.Key);
                var inputValue = (CInput)input.Value;

                //For Network Chat
                foreach (Keys key in pressedKeys)
                {
                    if (lastPressedKeys != null && !lastPressedKeys.Contains(key))
                    {
                        Game1.Inst.RaiseInScene("key_to_write", key);
                    }
                }
                lastPressedKeys = pressedKeys;
                if (!Game1.Inst.Scene.EntityHasComponent <CBody>(input.Key))
                {
                    continue;
                }
                if (currentState.IsKeyDown(Keys.Escape))
                {
                    Game1.Inst.Exit(); // TODO: We Should leave the scene
                }
                var movementSpeed = dt * 100f * body.SpeedMultiplier;
                var rotationSpeed = dt * 2.4f * body.RotationMultiplier;

                Vector3 acceleration = Vector3.Zero;

                if (currentState.IsKeyDown(Keys.LeftShift))
                {
                    movementSpeed *= 0.4f;
                }
                if (currentState.IsKeyDown(inputValue.ForwardMovementKey))
                {
                    var w = transform.Frame.Forward;

                    if (!isInAir && isOnGround)
                    {
                        var tx = transform.Position.X;
                        var tz = transform.Position.Z;

                        var fv1 = w;
                        fv1.Normalize();

                        var fv2 = fv1;
                        fv2 *= 0.05f;

                        // Compute height delta.
                        var y1 = Heightmap.HeightAt(tx, tz);
                        var y2 = Heightmap.HeightAt(tx + fv2.X, tz + fv2.Z);
                        fv2.Y = (float)Math.Max(0.0f, y2 - y1);

                        fv2.Normalize();

                        var maxAngle = (float)Math.Cos(MathHelper.ToRadians(70.0f));
                        var fac      = (float)Math.Max(0.0f, Vector3.Dot(fv1, fv2) - maxAngle);
                        movementSpeed *= fac;
                    }

                    acceleration += movementSpeed * w;
                }

                if (currentState.IsKeyDown(inputValue.BackwardMovementKey))
                {
                    var w = transform.Frame.Backward;

                    if (!isInAir && isOnGround)
                    {
                        var tx = transform.Position.X;
                        var tz = transform.Position.Z;

                        var fv1 = w;
                        fv1.Normalize();

                        var fv2 = fv1;
                        fv2 *= 0.05f;

                        // Compute height delta.
                        var y1 = Heightmap.HeightAt(tx, tz);
                        var y2 = Heightmap.HeightAt(tx + fv2.X, tz + fv2.Z);
                        fv2.Y = (float)Math.Max(0.0f, y2 - y1);

                        fv2.Normalize();

                        var maxAngle = (float)Math.Cos(MathHelper.ToRadians(70.0f));
                        var fac      = (float)Math.Max(0.0f, Vector3.Dot(fv1, fv2) - maxAngle);
                        movementSpeed *= fac;
                    }

                    acceleration += movementSpeed * w;
                }


                acceleration.Y = 0.0f;
                body.Velocity += acceleration - dt * body.Velocity * 10.0f * new Vector3(1.0f, 0.0f, 1.0f);



                //if (acceleration.X + body.Velocity.X < body.MaxVelocity && acceleration.X + body.Velocity.X > -body.MaxVelocity)
                ///body.Velocity.X += acceleration.X;
                //if (acceleration.Y + body.Velocity.Y < body.MaxVelocity || acceleration.Y + body.Velocity.Y > -body.MaxVelocity)
                //  body.Velocity.Y += acceleration.Y;
                //if (acceleration.Z + body.Velocity.Z < body.MaxVelocity && acceleration.Z + body.Velocity.Z > -body.MaxVelocity)
                //body.Velocity.Z += acceleration.Z;

                if (currentState.IsKeyDown(inputValue.LeftMovementKey))
                {
                    yaw = rotationSpeed;
                }
                if (currentState.IsKeyDown(inputValue.RightMovementKey))
                {
                    yaw = -rotationSpeed;
                }
                if (currentState.IsKeyDown(Keys.K) && !prevState.IsKeyDown(Keys.K))
                {
                    if (Game1.Inst.Scene.EntityHasComponent <CPlayer>(input.Key))
                    {
                        var cp = (CPlayer)Game1.Inst.Scene.GetComponentFromEntity <CPlayer>(input.Key);
                        var p  = (CHit)Game1.Inst.Scene.GetComponentFromEntity <CHit>(cp.HitId);
                        if (!p.IsAttacking)
                        {
                            SfxUtil.PlaySound("Sounds/Effects/Swing", vol: 1, randomPitch: true);

                            Game1.Inst.Scene.Raise("attack", new HitSystem.HitInfo {
                                EntityID    = input.Key,
                                IsAttacking = true,
                                StartTime   = t
                            });
                        }
                    }
                }


                if (currentState.IsKeyDown(Keys.Space) && !prevState.IsKeyDown(Keys.Space) && !isInAir)
                {
                    body.Velocity.Y += 11f;

                    if (transform.Position.Y > WaterY)
                    {
                        isInAir = true;
                    }
                    SfxUtil.PlaySound("Sounds/Effects/jump_start", vol: 1, randomPitch: true);
                    var model = (CImportedModel)Game1.Inst.Scene.GetComponentFromEntity <C3DRenderable>(input.Key);
                    model.animFn = SceneUtils.playerAnimation(input.Key, 12, 0.01f);
                }
                if (currentState.IsKeyDown(Keys.H) && !prevState.IsKeyDown(Keys.H))
                {
                    if (Game1.Inst.Scene.GetType() == typeof(WorldScene))
                    {
                        var scene = (WorldScene)Game1.Inst.Scene;
                        var list  = Game1.Inst.Scene.GetComponents <CPickUp>();
                        var inv   = (CInventory)Game1.Inst.Scene.GetComponentFromEntity <CInventory>(input.Key);
                        foreach (var ball in list)
                        {
                            var ballBody = (CBody)Game1.Inst.Scene.GetComponentFromEntity <CBody>(ball.Key);

                            if (body.ReachableArea.Intersects(ballBody.Aabb) && !inv.isFull)
                            {
                                var b = new CInventoryItem(ballBody);
                                inv.items.Add(b);
                                inv.IdsToRemove.Add(ball.Key);
                                prevState = currentState;
                                // Return so only one item will be picked up.
                                return;
                            }
                        }
                    }
                }
                if (currentState.IsKeyDown(Keys.J) && !prevState.IsKeyDown(Keys.J))
                {
                    if (Game1.Inst.Scene.EntityHasComponent <CInventory>(input.Key))
                    {
                        var inv = (CInventory)Game1.Inst.Scene.GetComponentFromEntity <CInventory>(input.Key);
                        if (inv.items.Count > 0)
                        {
                            var item = inv.items.ElementAt(inv.items.Count - 1);

                            var ts      = dt * 100f * item.itemBody.SpeedMultiplier;
                            var newItem = item;
                            newItem.itemBody.Velocity += /*transform.Rotation.Forward
                                                          */new Vector3(item.itemBody.Aabb.Max.X * 2 + .5f, 0f, item.itemBody.Aabb.Max.Z * 2 + .5f) * ts;

                            inv.items.Remove(item);
                            inv.itemsToRemove.Add(newItem);
                        }
                    }
                }
                prevState = currentState;

                addRot              = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll);
                transform.Heading  += yaw;
                transform.Rotation *= addRot;
            }
        }
예제 #7
0
        /// <summary>Initializes the scene.</summary>
        public override void Init()
        {
            base.Init();
        #if DBG_MENU
            // Ugly, but useful during development.
            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (!type.IsSubclassOf(typeof(Scene)) || type == GetType())
                {
                    continue;
                }

                CreateLabel(type.Name, () => {
                    Game1.Inst.EnterScene((Scene)Activator.CreateInstance(type));
                });
            }
        #endif
            CreateLabel("Single-Player", () => {
                Game1.Inst.EnterScene(new ConfigSceneMenu(false, _args));
            });

            CreateLabel("Multi-Player", () => {
                Game1.Inst.EnterScene(new ConfigSceneMenu(true, _args));
            });


            CreateLabel("Quit", () => {
                Game1.Inst.Exit();
            });
            addArrow();

            var    screenCenter = new Vector2(Game1.Inst.GraphicsDevice.Viewport.Width * 0.5f, Game1.Inst.GraphicsDevice.Viewport.Height * 0.5f);
            string text         = "GAME";
            var    mFont        = Game1.Inst.Content.Load <SpriteFont>("Fonts/FFFForward_Large");
            var    textSize     = mFont.MeasureString(text);
            int    id           = AddEntity();
            AddComponent <C2DRenderable>(id, new CText {
                color    = Color.Black,
                font     = mFont,
                format   = text,
                origin   = Vector2.Zero,
                position = new Vector2(
                    screenCenter.X - textSize.X * 0.5f,
                    screenCenter.Y - textSize.Y - 20
                    )
            });
            text     = "the game";
            mFont    = Game1.Inst.Content.Load <SpriteFont>("Fonts/FFFForward");
            textSize = mFont.MeasureString(text);
            id       = AddEntity();
            AddComponent <C2DRenderable>(id, new CText {
                color    = Color.Black,
                font     = mFont,
                format   = text,
                origin   = Vector2.Zero,
                position = new Vector2(
                    screenCenter.X - textSize.X * 0.5f,
                    screenCenter.Y
                    )
            });

            SfxUtil.PlayMusic("Sounds/Music/MainMenu");

            OnEvent("selchanged", data => SfxUtil.PlaySound("Sounds/Effects/Click"));
        }
예제 #8
0
        public override void Init()
        {
            InitGameComponents();

            mPostProcessor = new PostProcessor();
            mUnderWaterFx  = Game1.Inst.Content.Load <Effect>("Effects/UnderWater");
            mRT            = GfxUtil.CreateRT();

            var physicsSys = new PhysicsSystem();

            physicsSys.Bounds          = new BoundingBox(-worldSize * Vector3.One, worldSize * Vector3.One);
            physicsSys.InvSpatPartSize = 0.07f;
            physicsSys.Gravity        *= 2.0f;
            physicsSys.WaterY          = configs.WaterHeight;
            var inputSys = new InputSystem();

            inputSys.WaterY = configs.WaterHeight;
            AddSystems(
                physicsSys,
                inputSys,
                new AISystem(),
                new AnimationSystem(),
                mParticleSys = new ParticleSystem(),
                new InventorySystem(),
                new CameraSystem(),
                new LogicSystem(),
                mRenderer = new RenderingSystem(),
                new Rendering2DSystem(),
                new HealthSystem(),
                new HitSystem()
                );

#if DEBUG
            AddSystem(new DebugOverlay());
#endif

            var heightmap = Heightmap.Load("Textures/" + configs.Map,
                                           stepX: 8,
                                           stepY: 8,
                                           smooth: false,
                                           scale: configs.HeightMapScale,
                                           yScale: configs.YScaleMap,
                                           randomTris: true,
                                           blur: 16,
                                           colorFn: configs.colorsMap);

            physicsSys.Heightmap = heightmap;
            inputSys.Heightmap   = heightmap;


            base.Init();


            WaterFactory.Create(configs.WaterHeight, configs.HeightMapScale, configs.HeightMapScale);

            SceneUtils.SpawnEnvironment(heightmap, configs.HeightMapScale);

            //add network after init since we dont want reinit and lose our connections.
            if (_networkSystem != null)
            {
                var sync = new GameObjectSyncSystem(_networkSystem._isMaster);
                _networkSystem.AddGameEvents();
                sync.Init();
                AddSystem(_networkSystem);
                AddSystem(sync);
            }

            // Camera entity
            float fieldofview = MathHelper.PiOver2;
            float nearplane   = 0.1f;
            float farplane    = 100f;

            player = AddEntity();



            AddComponent(player, new CBody()
            {
                MaxVelocity     = 5f,
                InvMass         = 0.01f,
                SpeedMultiplier = 1,
                Radius          = 0.7f,
                Aabb            = new BoundingBox(new Vector3(-0.5f, -0.9f, -0.5f), new Vector3(0.5f, 0.9f, 0.5f)),
                LinDrag         = 0.8f,
                ReachableArea   = new BoundingBox(new Vector3(-1.5f, -2.0f, -1.5f), new Vector3(1.5f, 2.0f, 1.5f)),
                Restitution     = 0.1f
            });

            AddComponent(player, new CInput());
            var playery = (heightmap.HeightAt(configs.Playerx, configs.Playerz));
            var chitid  = AddEntity();
            AddComponent(chitid, new CHit()
            {
                PlayerId = player
            });
            AddComponent(chitid, new CTransform()
            {
                Heading = MathHelper.PiOver2, Position = new Vector3(configs.Playerx, playery, configs.Playerz) + new CHit().HitBoxOffset
            });
            AddComponent(chitid, new CBody()
            {
                Aabb = new BoundingBox(new Vector3(-0.4f, -1.3f, -0.4f), new Vector3(0.4f, 0.9f, 0.4f))
            });
            AddComponent(player, new CPlayer()
            {
                HitId = chitid
            });



            var playerTransf = new CTransform()
            {
                Heading = MathHelper.PiOver2, Position = new Vector3(configs.Playerx, playery, configs.Playerz), Scale = new Vector3(0.5f)
            };

            AddComponent(player, playerTransf);

            // Glossy helmet, lol!
            //var cubeMap = Game1.Inst.Content.Load<Effect>("Effects/CubeMap");
            //var envMap = new EnvMapMaterial(mRenderer, player, playerTransf, cubeMap);

            AddComponent <C3DRenderable>(player,
                                         new CImportedModel()
            {
                animFn   = SceneUtils.playerAnimation(player, 24, 0.1f),
                model    = Game1.Inst.Content.Load <Model>("Models/viking"),
                fileName = "viking",

                /*materials = new Dictionary<int, MaterialShader> {
                 *  { 8, envMap }
                 * }*/
            });
            AddComponent(player, new CSyncObject {
                fileName = "viking"
            });

            AddComponent(player, new CInventory());
            AddComponent(player, new CHealth {
                MaxHealth = 3, Health = 3, DeathSound = "Sounds/Effects/entia"
            });
            AddComponent(player, new CScore {
            });

            /*
             * AddComponent(player, new CLogic {
             *  InvHz = 1.0f/30.0f,
             *  Fn = (t, dt) => {
             *      var cam = (CCamera)GetComponentFromEntity<CCamera>(player);
             *      envMap.Update();
             *  }
             * });
             */
            AddComponent(player, new CCamera
            {
                Height     = 3.5f,
                Distance   = 3.5f,
                Projection = Matrix.CreatePerspectiveFieldOfView(fieldofview, Game1.Inst.GraphicsDevice.Viewport.AspectRatio, nearplane, farplane)
                ,
                ClipProjection = Matrix.CreatePerspectiveFieldOfView(fieldofview * 1.2f, Game1.Inst.GraphicsDevice.Viewport.AspectRatio, nearplane * 0.5f, farplane * 1.2f)
            });

            // Heightmap entity

            var mapMat = new ToonMaterial(Vector3.One * 0.2f,
                                          new Vector3(1.0f, 0.0f, 1.0f), // ignored
                                          Vector3.Zero,
                                          40.0f,
                                          null,  // diftex
                                          null,  // normtex
                                          1.0f,  // normcoeff
                                          5,     // diflevels
                                          2,     // spelevels,
                                          true); // use vert col


            int hme = AddEntity();
            AddComponent <C3DRenderable>(hme, new C3DRenderable {
                model             = heightmap.Model,
                enableVertexColor = true,
                specular          = 0.03f,
                // materials = new Dictionary<int, MaterialShader> { {0, mapMat } }
            });
            AddComponent(hme, new CTransform {
                Position = Vector3.Zero,
                Rotation = Matrix.Identity,
                Scale    = Vector3.One
            });

            int heightMapId   = AddEntity();
            var heightMapComp = new CHeightmap()
            {
                Image = Game1.Inst.Content.Load <Texture2D>("Textures/" + configs.Map)
            };
            var heightTrans = new CTransform()
            {
                Position = new Vector3(-590, 0, -590), Rotation = Matrix.Identity, Scale = new Vector3(1, 0.5f, 1)
            };
            AddComponent <C3DRenderable>(heightMapId, heightMapComp);
            AddComponent(heightMapId, heightTrans);
            // manually start loading all heightmap components, should be moved/automated

            OnEvent("hit", data => {
                var key = data as int?;
                if (key == null)
                {
                    return;
                }
                var transform         = (CTransform)GetComponentFromEntity <CTransform>(key.Value);
                var id                = AddEntity();
                Func <float> rndSize  = () => 0.05f + 0.1f * (float)rnd.NextDouble();
                Func <Vector3> rndVel = () => new Vector3((float)rnd.NextDouble() - 0.5f,
                                                          (float)rnd.NextDouble(),
                                                          (float)rnd.NextDouble() - 0.5f);
                mParticleSys.SpawnParticles(100, () => new EcsComponent[] {
                    new CParticle     {
                        Position = transform.Position,
                        Velocity = 6.0f * rndVel(),
                        Life     = 1.7f,
                        F        = () => new Vector3(0.0f, -9.81f, 0.0f)
                    },
                    new C3DRenderable {
                        model = Game1.Inst.Content.Load <Model>("Models/blood")
                    },
                    new CTransform    {
                        Position = transform.Position,
                        Rotation = Matrix.Identity,
                        Scale    = rndSize() * Vector3.One
                    }
                });
                SceneUtils.CreateSplatter(transform.Position.X, transform.Position.Z, heightmap);
                SfxUtil.PlaySound("Sounds/Effects/Hit", randomPitch: true);
            });

            OnEvent("game_end", data =>
            {
                won         = Game1.Inst.Scene.EntityHasComponent <CInput>((int)data);
                shouldLeave = true;
                // We reached the goal and wants to leave the scene-
            });


            if ((_networkSystem != null && _networkSystem._isMaster) || _networkSystem == null)
            {
                Utils.SceneUtils.CreateAnimals(configs.NumFlocks, configs.HeightMapScale / 2);
                Utils.SceneUtils.CreateTriggerEvents(configs.NumTriggers, configs.HeightMapScale / 2);
                Utils.SceneUtils.CreateCollectables(configs.NumPowerUps, configs.HeightMapScale / 2);
                SceneUtils.SpawnBirds(configs);
                // Add tree as sprint goal
                int sprintGoal = AddEntity();
                AddComponent(sprintGoal, new CBody()
                {
                    Radius = 5, Aabb = new BoundingBox(new Vector3(-5, -5, -5), new Vector3(5, 5, 5)), LinDrag = 0.8f
                });
                AddComponent(sprintGoal, new CTransform()
                {
                    Position = new Vector3(100, -0, 100), Scale = new Vector3(1f)
                });
                var treefilename = "tree";
                AddComponent(sprintGoal, new CSyncObject());
                AddComponent <C3DRenderable>(sprintGoal, new CImportedModel()
                {
                    model = Game1.Inst.Content.Load <Model>("Models/" + treefilename), fileName = treefilename
                });

                OnEvent("collision", data => {
                    foreach (var key in Game1.Inst.Scene.GetComponents <CPlayer>().Keys)
                    {
                        if ((((PhysicsSystem.CollisionInfo)data).Entity1 == key &&
                             ((PhysicsSystem.CollisionInfo)data).Entity2 == sprintGoal)
                            ||
                            (((PhysicsSystem.CollisionInfo)data).Entity2 == key &&
                             ((PhysicsSystem.CollisionInfo)data).Entity1 == sprintGoal))
                        {
                            Game1.Inst.Scene.Raise("network_game_end", key);
                            Game1.Inst.Scene.Raise("game_end", key);
                        }
                    }
                });
            }

            Log.GetLog().Debug("WorldScene initialized.");

            InitHud();

            SfxUtil.PlaySound("Sounds/Effects/horn_start");

            var billboards = new [] {
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Grass", 1.0f),
                new Tuple <string, float>("Bush", 1.2f),
                new Tuple <string, float>("Flowers", 0.6f)
            };

            var billboards2 = new [] {
                new Tuple <string, float>("Seaweed1", 0.6f),
                new Tuple <string, float>("Seaweed2", 0.6f),
            };
            ;
            for (var i = 0; i < 10000; i++)
            {
                var bbs = billboards;

                var x = configs.HeightMapScale * ((float)rnd.NextDouble() - 0.5f);
                var z = configs.HeightMapScale * ((float)rnd.NextDouble() - 0.5f);
                var y = heightmap.HeightAt(x, z);

                if (y < configs.WaterHeight)
                {
                    bbs = billboards2;
                }

                var bb = bbs[rnd.Next(0, bbs.Length)];
                var s  = (1.0f + 0.8f * (float)rnd.NextDouble()) * bb.Item2;

                AddComponent(AddEntity(), new CBillboard {
                    Pos   = new Vector3(x, y + 0.5f * s, z),
                    Tex   = Game1.Inst.Content.Load <Texture2D>("Textures/" + bb.Item1),
                    Scale = s
                });
            }

            //CreatePlatforms(heightmap);
        }