Пример #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
                }
            }
        }
Пример #2
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);

            /////////////////////
        }
Пример #3
0
 private void clearData()
 {
     TextureManager.Instance().clear();
     ImageManager.Instance().clear();
     SpriteBatchManager.Instance().clear();
     SpriteProxyManager.Instance().clear();
     DisplayManager.Instance().clear();
     AnimManager.Instance().clear();
     GameObjManager.Instance().clear();
     Timer.Clear();
     PlayerManager.Instance().clear();
     BombManager.Instance().clear();
 }
Пример #4
0
        public void removeBomb(Bomb b)
        {
            if (b.state == BombState.alive)
            {
                b.state = BombState.dead;

                b.spriteRef.sprite.image = b.image1;

                GameObjManager.Instance().remove(batchEnum.bomb, b);

                BombManager.Instance().addBomb(b);

                playBombHitSound();

                PlayerManager.getPlayer(b.owner).addBombSprite();
            }
        }
Пример #5
0
        public void removeBomb(Bomb b, Vector2 _pos, Color _color)
        {
            if (b.state == BombState.alive)
            {
                b.state = BombState.dead;

                b.spriteRef.sprite.image = b.image1;

                GameObjManager.Instance().addExplosion(_pos, _color);

                GameObjManager.Instance().remove(batchEnum.bomb, b);

                BombManager.Instance().addBomb(b);

                playBombHitSound();

                PlayerManager.Instance().getPlayer(b.owner).addBombSprite();
            }
        }
        public override void execute()
        {
            GameObject A = GameObjManager.FindByID(this.gameIdA);
            GameObject B = GameObjManager.FindByID(this.gameIdB);

            if (A != null && B != null)
            {
                if (A.CollideAvailable == true && B.CollideAvailable == true)
                {
                    if (A.type < B.type)
                    {
                        A.Accept(B, CollisionPt);
                    }
                    else
                    {
                        B.Accept(A, CollisionPt);
                    }
                }
            }
        }
Пример #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)
        {
            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);
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
0
 // Use this for initialization
 void Start()
 {
     MH       = canvas.transform.GetChild(1).GetComponent <MainMenuHandler> ();
     instance = this;
 }
Пример #11
0
 public static void Init(Transform t, RectTransform uT)
 {
     instance          = new GameObjManager();
     instance.target   = t;
     instance.uiTarget = uT;
 }
Пример #12
0
 void Start()
 {
     GOM = GetComponent <GameObjManager>();
 }