private void respawnData(PlayerID _id) { switch (_id) { case PlayerID.one: { Ship p2Ship = PlayerManager.getPlayer(PlayerID.two).playerShip; if (p2Ship.spriteRef.pos.Y < 95) { Data.Instance().createShip1(new Vector2(150, 130), (float)(90.0f * (Math.PI / 180.0f))); } else { Data.Instance().createShip1(new Vector2(150, 60), -(float)(90.0f * (Math.PI / 180.0f))); } break; } case PlayerID.two: Ship p1Ship = PlayerManager.getPlayer(PlayerID.one).playerShip; if (p1Ship.spriteRef.pos.Y > 95) { Data.Instance().createShip2(new Vector2(150, 60), -(float)(90.0f * (Math.PI / 180.0f))); } else { Data.Instance().createShip2(new Vector2(150, 130), (float)(90.0f * (Math.PI / 180.0f))); } break; } }
public void process() { int count = inpQ.Count; CollisionManager.GameObjManager pObj = CollisionManager.GameObjManager.Instance(); for (int i = 0; i < count; i++) { qHeader pInstance = inpQ.Dequeue(); switch (pInstance.type) { case QueueType.ship_impulse: ship_impulse imp = (ship_impulse)pInstance.obj; imp.execute(); break; case QueueType.ship_missile: Ship_Create_Missile_Message smiss = (Ship_Create_Missile_Message)pInstance.obj; CollisionManager.Player p2 = PlayerManager.getPlayer(smiss.id); p2.createMissile(); break; case QueueType.ship_rot_anti: Ship_rot_message srmsg = (Ship_rot_message)pInstance.obj; srmsg.rot = -0.1f; srmsg.execute(); break; case QueueType.ship_bomb: Ship_Create_Bomb_Message smsg = (Ship_Create_Bomb_Message)pInstance.obj; CollisionManager.GameObjManager.Instance().createBomb(smsg.id); break; case QueueType.EventMessage: EvenMessage msg = (EvenMessage)pInstance.obj; msg.execute(); break; case QueueType.ship_rot_clock: Ship_rot_message p3 = (Ship_rot_message)pInstance.obj; p3.rot = 0.1f; p3.execute(); break; } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // TODO: use this.Content to load your game content here spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load <SpriteFont>("SpriteFont1"); world = new World(new Vector2(0, 0), true); myContactListener myContactListener = new myContactListener(); world.ContactListener = myContactListener; Data.Instance().createData(); backgroundTexture = Content.Load <Texture2D>("background"); //backgroundTexture = Content.Load<Texture2D>("MainmenuLobby"); player1 = PlayerManager.getPlayer(PlayerID.one); player2 = PlayerManager.getPlayer(PlayerID.two); }
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(); } }
/// <summary> /// This event handler will be called whenever a new gamer joins the session. /// We use it to allocate a Tank object, and associate it with the new gamer. /// </summary> void GamerJoinedEventHandler(object sender, GamerJoinedEventArgs e) { int gamerIndex = networkSession.AllGamers.IndexOf(e.Gamer); if (Host == true && gamerIndex == 0) { e.Gamer.Tag = PlayerManager.getPlayer(PlayerID.one); } else if (Host == true && gamerIndex == 1) { e.Gamer.Tag = PlayerManager.getPlayer(PlayerID.two); } else if (Host == false && gamerIndex == 0) { e.Gamer.Tag = PlayerManager.getPlayer(PlayerID.two); } else if (Host == false && gamerIndex == 1) { e.Gamer.Tag = PlayerManager.getPlayer(PlayerID.one); } }
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); }
public override void execute() { CollisionManager.Player p = PlayerManager.getPlayer(this.id); p.playerShip.physicsObj.body.ApplyLinearImpulse(this.impulse, p.playerShip.physicsObj.body.GetWorldCenter()); }
public override void execute() { CollisionManager.Player p = PlayerManager.getPlayer(this.id); p.playerShip.physicsObj.body.Rotation += this.rot; }
private void checkInput() { newState = Keyboard.GetState(); P1newPadState = GamePad.GetState(PlayerIndex.One); P2newPadState = GamePad.GetState(PlayerIndex.Two); Player p; if (Host) { p = PlayerManager.getPlayer(PlayerID.one); } else { p = PlayerManager.getPlayer(PlayerID.two); } ////Player 1 controls if (oldState.IsKeyDown(Keys.D) || P1oldPadState.IsButtonDown(Buttons.DPadRight)) { Ship_rot_message pShip = new Ship_rot_message(p, 0.1f); pShip.serverRotvalue = p.playerShip.rotation; pShip.x = p.playerShip.location.X; pShip.y = p.playerShip.location.Y; OutQueue.add(QueueType.ship_rot_clock, pShip, p.id); } if (oldState.IsKeyDown(Keys.A) || P1oldPadState.IsButtonDown(Buttons.DPadLeft)) { Ship_rot_message pShip = new Ship_rot_message(p, -0.1f); pShip.serverRotvalue = p.playerShip.rotation; pShip.x = p.playerShip.location.X; pShip.y = p.playerShip.location.Y; OutQueue.add(QueueType.ship_rot_anti, pShip, p.id); } if (oldState.IsKeyDown(Keys.W) || P1oldPadState.IsButtonDown(Buttons.DPadUp)) { Ship Player1Ship = p.playerShip; Vector2 direction = new Vector2((float)(Math.Cos(Player1Ship.physicsObj.body.GetAngle())), (float)(Math.Sin(Player1Ship.physicsObj.body.GetAngle()))); direction.Normalize(); direction *= shipSpeed; ship_impulse p1 = new ship_impulse(p, direction); p1.rot = p.playerShip.rotation; OutQueue.add(QueueType.ship_impulse, p1, p.id); } if ((oldState.IsKeyDown(Keys.X) && newState.IsKeyUp(Keys.X)) || (P1oldPadState.IsButtonDown(Buttons.A) && P1newPadState.IsButtonUp(Buttons.A))) { if (player1.state == PlayerState.alive && player1.missileAvailable()) { Ship_Create_Bomb_Message p1 = new Ship_Create_Bomb_Message(p); p1.x = p.playerShip.location.X; p1.y = p.playerShip.location.Y; p1.rot = p.playerShip.rotation; OutQueue.add(QueueType.ship_bomb, p1, p.id); } } if (oldState.IsKeyDown(Keys.C) && newState.IsKeyUp(Keys.C) || (P1oldPadState.IsButtonDown(Buttons.B) && P1newPadState.IsButtonUp(Buttons.B))) { if (player1.state == PlayerState.alive && BombManager.Instance().bombAvailable(p.id)) { Ship_Create_Missile_Message p1 = new Ship_Create_Missile_Message(p); p1.x = p.playerShip.location.X; p1.y = p.playerShip.location.Y; p1.rot = p.playerShip.rotation; OutQueue.add(QueueType.ship_missile, p1, p.id); } } P1oldPadState = P1newPadState; P2oldPadState = P2newPadState; oldState = newState; }