Esempio n. 1
0
 public override void Act(IWorld world)
 {
     if (world.Time % 4 == 0 && world.ObjectsCount < 1000)
     {
         world.AddObject(new Fly(Location));
     }
 }
        public void mousebuttonteste(MouseState ms)
        {
            ///Create an object
            IObject physObj = SpawnPrimitive(_mundo.CameraManager.ActiveCamera.Position, Matrix.CreateRotationX(0.5f));

            _mundo.AddObject(physObj);
            physObj.PhysicObject.Velocity = (_mundo.CameraManager.ActiveCamera.Target - _mundo.CameraManager.ActiveCamera.Position) * Speed;
            physObj.Name = "FlyingBall " + ++i;
        }
Esempio n. 3
0
        void RecieveCreateNetworkObjectOnClient(NetMessageType NetMessageType, NetIncomingMessage NetIncomingMessage)
        {
            int    id    = NetIncomingMessage.ReadInt32();
            String ident = NetIncomingMessage.ReadString();

            if (NetWorkObjects.ContainsKey(ident))
            {
                IObject obj = NetWorkObjects[ident].HandleRemoteObjectOrder(NetIncomingMessage, id);
                world.AddObject(obj);
            }
        }
        public void mousebuttonteste(MouseState ms)
        {
            ///Create an object
            IObject physObj = SpawnPrimitive(_mundo.CameraManager.ActiveCamera.Position, Matrix.CreateRotationX(0.5f));

            physObj.PhysicObject.Velocity = (_mundo.CameraManager.ActiveCamera.Target - _mundo.CameraManager.ActiveCamera.Position) * 15.0f;

            ///Create a light that follow an object
            MoveablePointLight mvp = new MoveablePointLight(physObj.PhysicObject as SphereObject, new Color((float)rd.NextDouble(), (float)rd.NextDouble(), (float)rd.NextDouble()), 25, 5);

            mvp.UsePointLightQuadraticAttenuation = true;
            ///Add them to the world
            _mundo.AddLight(mvp);
            physObj.Name = "FlyingBall " + ++i;
            _mundo.AddObject(physObj);
        }
        public void Init()
        {
            // make the database used to accelerate proximity queries
            cyclePD = -1;
            NextPD();

            // create the specified number of Pedestrians
            population = 0;
            for (int i = 0; i < 10; i++)
            {
                population++;
                Pedestrian pedestrian = new Pedestrian(pd, path);
                pedestrian.Reset();

                world.AddObject(ObjectCreator(pedestrian));
                crowd.Add(pedestrian);
            }
        }
Esempio n. 6
0
        void RecieveCreateNetworkObjectOnServer(NetMessageType NetMessageType, NetIncomingMessage NetIncomingMessage)
        {
            String ident = NetIncomingMessage.ReadString();

            if (NetWorkObjects.ContainsKey(ident))
            {
                ServerIObject obj = NetWorkObjects[ident].CreateLoadObjectOrder(NetIncomingMessage);
                world.AddObject(obj);

                //skip the message type
                NetIncomingMessage.Position = sizeof(short) * 8;

                NetOutgoingMessage o = CreateMessage(NetWorking.NetMessageType.CreateNetworkObjectOnClient);
                o.Write(obj.GetId());
                NetOutgoingMessage mes = NetWorkObjects[ident].CreateRedistributeOrder(obj, NetIncomingMessage, o);
                this.SendMessageToAllClients(mes, NetDeliveryMethod.ReliableOrdered);
            }
        }
        public BallThrowBepu(IScene scene, GraphicFactory factory, GestureType type)
            : base(scene)
        {
            this.Start();
            this.factory = factory;
            _mundo = scene.World;

            SimpleConcreteGestureInputPlayable SimpleConcreteGestureInputPlayable = new SimpleConcreteGestureInputPlayable(type,
               (sample) =>
               {
                   IObject physObj = SpawnPrimitive(_mundo.CameraManager.ActiveCamera.Position, Matrix.CreateRotationX(0.5f));
                   physObj.PhysicObject.Velocity = (_mundo.CameraManager.ActiveCamera.Target - _mundo.CameraManager.ActiveCamera.Position) * 15.0f;
                   physObj.Name = "FlyingBall " + ++i;
                   _mundo.AddObject(physObj);
               }
           );
            scene.BindInput(SimpleConcreteGestureInputPlayable);
        }
        public void Execute()
        {
            if (!davis.DeadFlag)
            {
                if (davis.DavisProjectile.Count > 0)
                {
                    var count = davis.DavisProjectile.Count;
                    davis.DavisProjectile.Clear();
                    Random random = new Random();
                    for (int i = count; i > 0; i--)
                    {
                        switch (davis.DavisStatus)
                        {
                        case (DavisStatus.Davis):
                            davis.DavisProjectile.Add(new DavisProjectile((davis.Location + new Vector2(0, 30f + random.Next(10))), davis.FacingDirection));
                            break;

                        case (DavisStatus.Woody):
                            davis.DavisProjectile.Add(new WoodyProjectile((davis.Location + new Vector2(0, 15f + random.Next(10))), davis.FacingDirection));
                            break;

                        case (DavisStatus.Bat):
                            davis.DavisProjectile.Add(new BatProjectile((davis.Location + new Vector2(0, 20f + random.Next(10))), davis.FacingDirection));
                            break;
                        }
                    }
                    world.AddObject(davis.DavisProjectile[davis.DavisProjectile.Count - 1]);
                    davis.DavisProjectile.RemoveAt(davis.DavisProjectile.Count - 1);
                    davis.DavisState.ShootBullet();
                    if (davis.DavisStatus == DavisStatus.Davis)
                    {
                        Sounds.Instance.PlayDavisShootBullet();
                    }
                    else if (davis.DavisStatus == DavisStatus.Woody)
                    {
                        Sounds.Instance.PlayWoodyShootBullet();
                    }
                    else
                    {
                        Sounds.Instance.PlayBatShootBullet();
                    }
                }
            }
        }
Esempio n. 9
0
        public BallThrowBepu(IScene scene, GraphicFactory factory, GestureType type)
            : base(scene)
        {
            this.Start();
            this.factory = factory;
            _mundo       = scene.World;

            SimpleConcreteGestureInputPlayable SimpleConcreteGestureInputPlayable = new SimpleConcreteGestureInputPlayable(type,
                                                                                                                           (sample) =>
            {
                IObject physObj = SpawnPrimitive(_mundo.CameraManager.ActiveCamera.Position, Matrix.CreateRotationX(0.5f));
                physObj.PhysicObject.Velocity = (_mundo.CameraManager.ActiveCamera.Target - _mundo.CameraManager.ActiveCamera.Position) * 15.0f;
                physObj.Name = "FlyingBall " + ++i;
                _mundo.AddObject(physObj);
            }
                                                                                                                           );

            scene.BindInput(SimpleConcreteGestureInputPlayable);
        }
        public BallThrowBepu(IScene scene, GraphicFactory factory, GestureType type)
            : base(scene)
        {
            this.Start();
            this.factory = factory;
            _mundo = scene.World;

            SimpleConcreteGestureInputPlayable SimpleConcreteGestureInputPlayable = new SimpleConcreteGestureInputPlayable(type,
               (sample) =>
               {
                   IObject physObj = SpawnPrimitive(_mundo.CameraManager.ActiveCamera.Position, Matrix.Identity);
                   physObj.PhysicObject.Velocity = (_mundo.CameraManager.ActiveCamera.Target - _mundo.CameraManager.ActiveCamera.Position) * 10.0f;
                   physObj.Name = "FlyingBall " + ++i;
                   _mundo.AddObject(physObj);
                   (physObj.Material.Shader as ForwardXNABasicShader).BasicEffect.EnableDefaultLighting();
               }
           );
            scene.BindInput(SimpleConcreteGestureInputPlayable);
        }
Esempio n. 11
0
        public BallThrowBepu(IScene scene, GraphicFactory factory, GestureType type)
            : base(scene)
        {
            this.Start();
            this.factory = factory;
            _mundo       = scene.World;

            SimpleConcreteGestureInputPlayable SimpleConcreteGestureInputPlayable = new SimpleConcreteGestureInputPlayable(type,
                                                                                                                           (sample) =>
            {
                IObject physObj = SpawnPrimitive(_mundo.CameraManager.ActiveCamera.Position, Matrix.Identity);
                physObj.PhysicObject.Velocity = (_mundo.CameraManager.ActiveCamera.Target - _mundo.CameraManager.ActiveCamera.Position) * 10.0f;
                physObj.Name = "FlyingBall " + ++i;
                _mundo.AddObject(physObj);
                (physObj.Material.Shader as ForwardXNABasicShader).BasicEffect.EnableDefaultLighting();
            }
                                                                                                                           );

            scene.BindInput(SimpleConcreteGestureInputPlayable);
        }
Esempio n. 12
0
        public void Load(IEnumerable <string> lines, IWorld world)
        {
            var cells = lines
                        .SelectMany((line, row) => line.ToCharArray().Select((c, col) => new { row, col, c }))
                        .Where(cell => factories.ContainsKey(cell.c)).ToList();

            if (borderSign.HasValue)
            {
                int rowsCount = cells.Max(c => c.row) + 1;
                int colsCount = cells.Max(c => c.col) + 1;
                cells = cells.Select(c => new { row = c.row + 1, col = c.col + 1, c.c })
                        .Concat(Enumerable.Range(0, rowsCount + 2).Select(row => new { row, col = 0, c = borderSign.Value }))
                        .Concat(Enumerable.Range(0, rowsCount + 2).Select(row => new { row, col = colsCount + 1, c = borderSign.Value }))
                        .Concat(Enumerable.Range(1, colsCount).Select(col => new { row = 0, col, c = borderSign.Value }))
                        .Concat(Enumerable.Range(1, colsCount).Select(col => new { row = rowsCount + 1, col, c = borderSign.Value }))
                        .ToList();
            }
            foreach (var cell in cells)
            {
                var factory = factories[cell.c];
                world.AddObject(factory(new Point(cell.col, cell.row)));
            }
            world.FreezeWorldSize();
        }
 protected void AddToWorld(IObject obj)
 {
     world.AddObject(obj);
 }
        public void LoadWorld(GraphicFactory factory, GraphicInfo ginfo, IWorld world, ModelLoaderData worldData)
        {
            objinfos.Clear();
            foreach (var item in worldData.ModelMeshesInfo)
            {
                if (objinfos.ContainsKey(item.modelName + item.meshIndex))
                {
                    objinfos[item.modelName + item.meshIndex].Add(item);
                }
                else
                {
                    objinfos[item.modelName + item.meshIndex] = new List <ObjectInformation>();
                    objinfos[item.modelName + item.meshIndex].Add(item);
                }
            }

            foreach (var item in objinfos.Keys)
            {
                if (OnCreateIObject != null)
                {
                    IObject[] obj = OnCreateIObject(world, factory, ginfo, objinfos[item].ToArray());
                    if (obj != null)
                    {
                        foreach (var ob in obj)
                        {
                            world.AddObject(ob);
                        }
                    }
                }
                else
                {
                    foreach (var obj in WorldLoader.CreateOBJ(world, factory, ginfo, objinfos[item].ToArray()))
                    {
                        world.AddObject(obj);
                    }
                }
            }



            foreach (var item in worldData.ConstraintInfo)
            {
                List <IObject> obb = world.Objects.ToList();

                IObject o1 = obb.First(delegate(IObject o) { return(o.Name == item.bodyA); });
                IObject o2 = obb.First(delegate(IObject o) { return(o.Name == item.bodyB); });

                if (o1.PhysicObject.PhysicObjectTypes != PhysicObjectTypes.TRIANGLEMESHOBJECT && o2.PhysicObject.PhysicObjectTypes != PhysicObjectTypes.TRIANGLEMESHOBJECT)
                {
                    if (OnCreateIConstraint != null)
                    {
                        IPhysicConstraint constr = OnCreateIConstraint(world, factory, ginfo, item, o1, o2);
                        if (constr != null)
                        {
                            world.PhysicWorld.AddConstraint(constr);
                        }
                    }
                    else
                    {
                        IPhysicConstraint constr = WorldLoader.CreateConstraint(world, factory, ginfo, item, o1, o2);
                        world.PhysicWorld.AddConstraint(constr);
                    }
                }
            }

            foreach (var item in worldData.LightsInfo)
            {
                if (OnCreateILight != null)
                {
                    ILight l = OnCreateILight(world, factory, ginfo, item);
                    if (l != null)
                    {
                        world.AddLight(l);
                    }
                }
                else
                {
                    world.AddLight(item);
                }
            }

            foreach (var item in worldData.CameraInfo)
            {
                if (OnCreateICamera != null)
                {
                    ICamera cam = OnCreateICamera(world, factory, ginfo, item);
                    if (cam != null)
                    {
                        world.CameraManager.AddCamera(cam);
                    }
                }
                else
                {
                    world.CameraManager.AddCamera(WorldLoader.CreateCamera(world, factory, ginfo, item));
                }
            }

            foreach (var item in worldData.DummyInfo)
            {
                if (OnProcessDummies != null)
                {
                    OnProcessDummies(world, item);
                }
            }

            foreach (var item in worldData.ParticleInfo)
            {
                if (OnCreateIParticle != null)
                {
                    IParticleSystem part = OnCreateIParticle(world, item);
                    if (part != null)
                    {
                        world.ParticleManager.AddAndInitializeParticleSystem(part);
                        (part as DPFSParticleSystem).IDPSFParticleSystem.Emitter.PositionData.Position       = item.Position;
                        (part as DPFSParticleSystem).IDPSFParticleSystem.Emitter.OrientationData.Orientation = item.Orientation;
                    }
                }
            }
        }
Esempio n. 15
0
        public static void HandleCollision(IDavis davis, IBlock block, CollisionSide side, IWorld world)
        {
            switch (side)
            {
            case CollisionSide.Bottom:
                if (block is HiddenBlock && davis.PhysicsState is JumpState)
                {
                    block.SpecialState();
                }
                if (block is CoinBrick && davis.PhysicsState is JumpState)
                {
                    CoinBrick coinBrick = (CoinBrick)block;
                    if (coinBrick.CoinCounter > 0)
                    {
                        world.AddObject(new Coin(new Vector2(block.Location.X, block.Location.Y - 45)));
                        coinBrick.CoinCounter--;
                        coinBrick.IsBumped = true;
                    }
                }
                else if (block is QuestionBlock)
                {
                    block.SpecialState();
                }
                else if (block is Brick)
                {
                    Brick brick = (Brick)block;
                    brick.Bumped();
                }
                else if (block is MushroomBlock)
                {
                    if (!block.IsBumped)
                    {
                        world.AddObject(new Mushroom(new Vector2(block.Location.X, block.Location.Y - 25)));
                        block.SpecialState();
                        block.IsBumped = true;
                    }
                }
                else if (block is CoinBlock)
                {
                    if (!block.IsBumped)
                    {
                        world.AddObject(new Mushroom(new Vector2(block.Location.X, block.Location.Y - 25)));
                        block.SpecialState();
                        block.IsBumped = true;
                    }
                }
                else if (block is FlowerBlock)
                {
                    if (!block.IsBumped)
                    {
                        world.AddObject(new Flower(new Vector2(block.Location.X, block.Location.Y - 30)));
                        block.SpecialState();
                        block.IsBumped = true;
                    }
                }
                if (!(block is EmptyBlock))
                {
                    davis.Location     = new Vector2(davis.Location.X, block.Location.Y + block.HitBox.Height);
                    davis.PhysicsState = new FallState(davis);
                }

                break;

            case CollisionSide.Top:
                //if not hidden block
                if (!block.IsHidden && !(davis.PhysicsState is FlyingKneeState) && !(davis.PhysicsState is ShoryukenState) && !(davis.PhysicsState is ShunpoState))
                {
                    davis.DavisState.Land();
                    davis.PhysicsState = new StandingState(davis);
                    davis.Location     = new Vector2(davis.Location.X, block.Location.Y - davis.HitBox.Height);
                }
                break;

            case CollisionSide.Left:
                if (!(block.IsHidden))
                {
                    if (!((block is CastleDoor) && davis.KeyFlag))
                    {
                        if (!(block is Door && world.HUD.score > Variables.Variable.doorOpenScore))
                        {
                            davis.Location = new Vector2(block.Location.X - davis.HitBox.Width, davis.Location.Y);
                        }
                    }
                }
                break;

            case CollisionSide.Right:
                if (!(block.IsHidden))
                {
                    if (!(block is Door && world.HUD.score > Variables.Variable.doorOpenScore))
                    {
                        davis.Location = new Vector2(block.Location.X + block.HitBox.Width, davis.Location.Y);
                    }
                }
                break;

            case CollisionSide.None:
                break;
            }
        }
        public void LoadWorld(GraphicFactory factory, GraphicInfo ginfo, IWorld world, ModelLoaderData worldData)
        {
            objinfos.Clear();
            foreach (var item in worldData.ModelMeshesInfo)
            {
                if(objinfos.ContainsKey(item.modelName + item.meshIndex))
                {
                    objinfos[item.modelName + item.meshIndex].Add(item);
                }
                else
                {
                    objinfos[item.modelName + item.meshIndex] = new List<ObjectInformation>();
                    objinfos[item.modelName + item.meshIndex].Add(item);
                }
            }

            foreach (var item in objinfos.Keys)
            {
                if (OnCreateIObject != null)
                {
                    IObject[] obj = OnCreateIObject(world, factory, ginfo, objinfos[item].ToArray());
                    if (obj != null)
                    {
                        foreach (var ob in obj)
	                    {
		                    world.AddObject(ob);
	                    }                        
                    }
                }
                else
                {
                    foreach (var obj in WorldLoader.CreateOBJ(world, factory, ginfo, objinfos[item].ToArray()))
                    {
                        world.AddObject(obj);    
                    }                    
                }
            }

            

            foreach (var item in worldData.ConstraintInfo)
            {

                List<IObject> obb = world.Objects.ToList();                

                IObject o1 = obb.First(delegate(IObject o) { return o.Name == item.bodyA; });
                IObject o2 = obb.First(delegate(IObject o) { return o.Name == item.bodyB; });

                if (o1.PhysicObject.PhysicObjectTypes != PhysicObjectTypes.TRIANGLEMESHOBJECT && o2.PhysicObject.PhysicObjectTypes != PhysicObjectTypes.TRIANGLEMESHOBJECT)
                {
                    if (OnCreateIConstraint != null)
                    {
                        IPhysicConstraint constr = OnCreateIConstraint(world, factory, ginfo, item, o1, o2);
                        if (constr != null)
                            world.PhysicWorld.AddConstraint(constr);

                    }
                    else
                    {
                        IPhysicConstraint constr = WorldLoader.CreateConstraint(world, factory, ginfo, item, o1, o2);
                        world.PhysicWorld.AddConstraint(constr);
                    }
                }
            }

            foreach (var item in worldData.LightsInfo)
            {
                if (OnCreateILight != null)
                {
                    ILight l = OnCreateILight(world, factory, ginfo, item);
                    if (l != null)
                        world.AddLight(l);
                }
                else
                {
                    world.AddLight(item);
                }
            }

            foreach (var item in worldData.CameraInfo)
            {
                if (OnCreateICamera != null)
                {
                    ICamera cam = OnCreateICamera(world, factory, ginfo, item);
                    if (cam != null)
                        world.CameraManager.AddCamera(cam);
                }
                else
                {
                    world.CameraManager.AddCamera(WorldLoader.CreateCamera(world, factory, ginfo, item));
                }
            }

            foreach (var item in worldData.DummyInfo)
            {
                if (OnProcessDummies != null)
                    OnProcessDummies(world, item);
            }

            foreach (var item in worldData.ParticleInfo)
            {
                if (OnCreateIParticle != null)
                {
                    IParticleSystem part = OnCreateIParticle(world, item);
                    if (part != null)
                    {
                        world.ParticleManager.AddAndInitializeParticleSystem(part);
                        (part as DPFSParticleSystem).IDPSFParticleSystem.Emitter.PositionData.Position = item.Position;
                        (part as DPFSParticleSystem).IDPSFParticleSystem.Emitter.OrientationData.Orientation = item.Orientation;

                    }
                }
                
            }
        }