public void remove(batchEnum _enum, GameObject _obj) { GameObjNode node = findGameObj(_obj); if (node != null) { if (node.prev != null) { // middle or last node node.prev.next = node.next; } else { // first this.active = node.next; } if (node.next != null) { // middle node node.next.prev = node.prev; } addBodyToDestroy(_obj.physicsObj.body); if (_obj.spriteRef != null) { SBNode SBNode = SpriteBatchManager.Instance().getBatch(_enum); SBNode.removeDisplayObject(_obj.spriteRef); } if (_obj.physicsObj != null) { PhysicsMan.Instance().removePhysicsObj(_obj.physicsObj); } } }
private void armed(object obj) { World world = Game1.GameInstance.getWorld(); Ship ship = PlayerManager.getPlayer(owner).playerShip; Body shipBody = ship.physicsObj.body; var bombShape = new PolygonShape(); bombShape.SetAsBox(5, 5); var fd = new FixtureDef(); fd.shape = bombShape; fd.restitution = 0.0f; fd.friction = 0.0f; fd.density = 0.0001f; fd.userData = this; BodyDef bd = new BodyDef(); bd.fixedRotation = true; bd.type = BodyType.Static; bd.position = orgPos; var body = world.CreateBody(bd); body.CreateFixture(fd); body.SetUserData(this); TimeSpan currentTime = Timer.GetCurrentTime(); TimeSpan t_1 = currentTime.Add(new TimeSpan(0, 0, 0, 0, 0)); CallBackData nodeData = new CallBackData(0, Timer.GetCurrentTime()); bombAnim(nodeData); GameObjManager.Instance().addGameObj(this); PhysicsMan.Instance().addPhysicsObj(this, body); playBombArmedSound(); }
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--; } }