public void createBomb(PlayerID _id)
        {
            Player      player   = PlayerManager.getPlayer(_id);
            OutputQueue outqueue = new OutputQueue();

            player.removeBombSprite();

            Ship pShip     = player.playerShip;
            Body pShipBody = pShip.physicsObj.body;

            Bomb bomb;

            if (_id == PlayerID.one)
            {
                bomb = new Bomb(GameObjType.p1Bomb, _id, pShip);
            }
            else
            {
                bomb = new Bomb(GameObjType.p2Bomb, _id, pShip);
            }

            OutQueue.add(QueueType.bomb, bomb, _id);
        }
Пример #2
0
        public void createMissile()
        {
            OutputQueue p = new OutputQueue();

            Ship pShip     = playerShip;
            Body pShipBody = pShip.physicsObj.body;

            Sprite       missileSprite = (Sprite)DisplayManager.Instance().getDisplayObj(SpriteEnum.Missile);
            Sprite_Proxy proxyMissile  = new Sprite_Proxy(missileSprite, (int)pShip.spriteRef.pos.X, (int)pShip.spriteRef.pos.Y, 0.5f, pShip.spriteRef.color);
            Missile      missile       = new Missile(missileType, proxyMissile, id);

            SBNode missileBatch = SpriteBatchManager.Instance().getBatch(batchEnum.missiles);

            missileBatch.addDisplayObject(proxyMissile);

            World world = Game1.GameInstance.getWorld();

            var missileShape = new PolygonShape();

            missileShape.SetAsBox(3, 3);

            var fd = new FixtureDef();

            fd.shape       = missileShape;
            fd.restitution = 0.0f;
            fd.friction    = 0.0f;
            fd.density     = 0.0001f;
            fd.userData    = missile;

            // Grab ship orientation vector
            Vector2 direction = new Vector2((float)(Math.Cos(pShipBody.GetAngle())), (float)(Math.Sin(pShipBody.GetAngle())));

            direction.Normalize();

            BodyDef bd = new BodyDef();

            bd.fixedRotation = true;

            bd.type     = BodyType.Dynamic;
            bd.position = (new Vector2(pShip.spriteRef.pos.X, pShip.spriteRef.pos.Y)) + (direction * 10);



            var body = world.CreateBody(bd);

            body.SetBullet(true);
            body.Rotation = pShipBody.Rotation;
            body.CreateFixture(fd);
            body.SetUserData(missile);


            direction *= 1000;

            body.ApplyLinearImpulse(direction, body.GetWorldCenter());



            GameObjManager.Instance().addGameObj(missile);
            PhysicsMan.Instance().addPhysicsObj(missile, body);

            OutQueue.add(QueueType.missile, missile, this.id);
            //p.pushToNetwork();

            if (numMissiles > 0)
            {
                numMissiles--;
            }
        }