Beispiel #1
0
        public static void Update(ref PhysicsBuffer_Message pPBMsg)
        {
            if (pPBMsg == null)
            {
                return;
            }

            PhysicsMan pMan = PhysicsMan.Instance();
            //PhysicsObj physNode = null;
            GameObject gameObj = null;

            for (int i = 0; i < pPBMsg.count; i++)
            {
                //physNode = pMan.FindByID(pPBMsg.pBuff[i].id);
                gameObj = GameObjManager.Instance().FindByID(pPBMsg.pBuff[i].id);
                // We might have removed since the last update, so if Im null, do nothing.
                if (gameObj != null)
                {
                    gameObj.pushPhysics(pPBMsg.pBuff[i].rotation, pPBMsg.pBuff[i].position);
                }
                else
                {
                    // do nothing
                }
            }
        }
Beispiel #2
0
 public static PhysicsMan Instance()
 {
     if (instance == null)
     {
         instance = new PhysicsMan();
     }
     return(instance);
 }
Beispiel #3
0
        private void createFence1()
        {
            World world = Game1.GameInstance.getWorld();

            Rectangle gameScreenSize = Game1.GameInstance.gameScreenSize;

            // Sprite Animation ///////////


            Sprite wallSprite = (Sprite)DisplayManager.Instance().getDisplayObj(SpriteEnum.fence1);

            // Sprite wallSprite = (Sprite)DisplayManager.Instance().getDisplayObj(SpriteEnum.Wall);
            Sprite_Proxy wallProxy = new Sprite_Proxy(wallSprite, 40, 5, fenceScale, Color.White);
            Wall         wall1     = new Wall(GameObjType.horzWalls, wallProxy);


            SBNode wallBatch = SpriteBatchManager.Instance().getBatch(batchEnum.boxs);

            wallBatch.addDisplayObject(wallProxy);

            //////////////////

            // Box2D /////////////

            var wallShape = new PolygonShape();

            wallShape.SetAsBox(wall1.spriteRef.sprite.width / 2, wall1.spriteRef.sprite.height / 2);

            var fd = new FixtureDef();

            fd.shape       = wallShape;
            fd.restitution = 0.9f;
            fd.friction    = 0.0f;
            fd.density     = 1.0f;
            fd.userData    = wall1;

            BodyDef bd = new BodyDef();

            bd.allowSleep = false;
            bd.type       = BodyType.Static;
            bd.position   = wall1.spriteRef.pos;

            var body = world.CreateBody(bd);

            body.CreateFixture(fd);
            body.SetUserData(wall1);
            body.Rotation = (float)(90.0f * (Math.PI / 180.0f));


            GameObjManager.Instance().addGameObj(wall1);

            PhysicsMan.Instance().addPhysicsObj(wall1, body);

            /////////////////////
        }
        public static void pushToBuffer(ref physics_buffer[] p)
        {
            PhysicsMan pMan = PhysicsMan.instance;

            ManLink    ptr     = pMan.active;
            PhysicsObj phyNode = null;
            Body       body    = null;

            int i = 0;

            while (ptr != null)
            {
                phyNode = (PhysicsObj)ptr;
                body    = phyNode.body;

                p[i].id       = phyNode.gameObj.gameId;
                p[i].position = body.Position;
                p[i].rotation = body.GetAngle();

                i++;
                ptr = ptr.next;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            HandleInput();
            if ((networkSession == null && gameState.ready == state))
            {
                // If we are not in a network session, update the
                // menu screen that will let us create or join one.
                UpdateMenuScreen();
            }
            else if (state == gameState.game && networkSession != null)
            {
                // If we are in a network session, update it.
                UpdateNetworkSession();

                // TODO: Add your update logic here
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    this.Exit();
                }

                GraphicsDevice.Clear(Color.Black);
                base.Update(gameTime);

                if (state == gameState.game)
                {
                    world.Step((float)gameTime.ElapsedGameTime.TotalSeconds, 5, 8);
                    checkInput();
                    PhysicsMan.Instance().Update();
                    ScoreManager.Instance().Update();
                    GameObjManager.Instance().Update(world);
                    Timer.Process(gameTime);
                }
                Game1.Camera.Update(gameTime);
            }
            base.Update(gameTime);
        }
Beispiel #6
0
        public static void PushToBuffer(ref PhysicsBuffer[] physicsBuff)
        {
            PhysicsMan pMan = PhysicsMan.Instance();

            ManLink    ptr      = pMan.active;
            PhysicsObj physNode = null;
            Body       body     = null;

            int i = 0;

            while (ptr != null)
            {
                physNode = (PhysicsObj)ptr;
                body     = physNode.body;

                //Push to buffer
                physicsBuff[i].id       = physNode.gameObj.GameID;
                physicsBuff[i].position = body.Position;
                physicsBuff[i].rotation = body.GetAngle();

                i++;
                ptr = ptr.next;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // TODO: Add your update logic here
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            GraphicsDevice.Clear(Color.Black);

            HandleInput();

            if (networkSession == null)
            {
                // If we are not in a network session, update the
                // menu screen that will let us create or join one.
                UpdateMenuScreen();
            }
            else
            {
                // If we are in a network session, update it.
                UpdateNetworkSession();
            }

            base.Update(gameTime);

            if (state == gameState.game)
            {
                //Input Queue -> msg process
                InputQueue.Process3();

                world.Step((float)gameTime.ElapsedGameTime.TotalSeconds, 5, 8);


                // Out 0) contact listener fires collisions
                // events created in world step

                //Out 1) physics event(contact listener) msg -> Output queue

                if (Game1.networkSession != null)
                {
                    if (Game1.networkSession.IsHost)
                    {
                        // create Buffer
                        PhysicsBuffer[] physicsBuff = new PhysicsBuffer[PhysicsMan.Instance().getCount()];
                        int             num         = PhysicsMan.Instance().getCount();


                        // Update PhysicsObject to PhysicsBuffer for a message transmission
                        PhysicsMan.PushToBuffer(ref physicsBuff);

                        //// out 2) physics buffer msg => OutputQueue
                        PhysicsBuffer_Message msg = new PhysicsBuffer_Message(ref physicsBuff);
                        PhysicsBuffer_Message_outQueue.add(msg);
                    }
                }

                // ON remote ---------------------------------------------
                // read Physics Buffer from OutputQueue
                // no physics simulator

                // On Both----------------------------------------------

                // Out 3) input msg -> OutputQueue
                // InputQueue.Update ?? maybe this is checkinput()???

                checkInput();

                //OutputQueue -> InputQueue
                OutputQueue.PushToNetwork();

                // I put this down here to get pBuffGlobal to have the same amount of items as number of physics bodies
                // InputQueue.Process3();

                //Both----------------------------------------------

                //PhsicsBuffer to GameObject
                PhysicsMan.Update(ref PhysicsBuffer_Message.pBuffGlobal);

                //PhysicsMan.Instance().Update();

                ScoreManager.Instance().Update();

                GameObjManager.Instance().Update(world);

                Timer.Process(gameTime);
            }

            Game1.Camera.Update(gameTime);
        }
Beispiel #8
0
        public void createShip1(Vector2 pos, float _rot)
        {
            World world = Game1.GameInstance.getWorld();

            ////////////////  For Sprite System use ///////////////
            Sprite       shipSprite = (Sprite)DisplayManager.Instance().getDisplayObj(SpriteEnum.Ship);
            Sprite_Proxy proxyShip  = new Sprite_Proxy(shipSprite, pos.X, pos.Y, shipScale, Color.Blue);
            Ship         p1         = new Ship(GameObjType.p1ship, proxyShip);


            SBNode shipBatch = SpriteBatchManager.Instance().getBatch(batchEnum.ships);

            shipBatch.addDisplayObject(proxyShip);

            //////////////////////////////////////


            // Box2D Body Setup/////////////////////////
            var shipShape = new PolygonShape();

            Vector2[] verts = new Vector2[5];


            verts[0] = new Vector2(-5.0f, -5.0f);
            verts[1] = new Vector2(4.8f, -0.10f);
            verts[2] = new Vector2(5.0f, 0.00f);
            verts[3] = new Vector2(4.8f, 0.10f);
            verts[4] = new Vector2(-5.0f, 5.0f);

            shipShape.Set(verts, 5);
            shipShape._centroid = new Vector2(0, 0);


            var fd = new FixtureDef();

            fd.shape       = shipShape;
            fd.restitution = 0.9f;
            fd.friction    = 0.0f;
            fd.density     = 1.0f;
            fd.userData    = p1;

            BodyDef bd = new BodyDef();

            bd.allowSleep    = false;
            bd.fixedRotation = true;
            bd.type          = BodyType.Dynamic;
            bd.position      = p1.spriteRef.pos;


            var body = world.CreateBody(bd);

            body.CreateFixture(fd);
            body.SetUserData(p1);
            body.Rotation = _rot;
            ///////////////////////////////////////

            // Set sprite body reference


            PhysicsMan.Instance().addPhysicsObj(p1, body);
            //////////////////

            // Set Player's ship and add it to the GameObjManager //////////////
            PlayerManager.getPlayer(PlayerID.one).setShip(p1);

            GameObjManager.Instance().addGameObj(p1);
        }
Beispiel #9
0
 public void clear()
 {
     this.active = null;
     instance = null;
 }
Beispiel #10
0
 public static PhysicsMan Instance()
 {
     if (instance == null)
         instance = new PhysicsMan();
     return instance;
 }