void ProcessMissileMineMessage(MissileMineMessage msg) { if (msg.PlayerID == 1) { if (msg.pMissile) { Vec2 t = new Vec2(msg.direction_x, msg.direction_y); GameManager.FireMissile(player1, t); } if (msg.Mine) { GameManager.LayMine(player1); } } else if (msg.PlayerID == 2) { if (msg.pMissile) { Vec2 t = new Vec2(msg.direction_x, msg.direction_y); GameManager.FireMissile(player2, t); } if (msg.Mine) { GameManager.LayMine(player2); } } }
void ProcessPlayerInputMessage(PlayerInputMessage msg) { if (msg.playerID == 1) { player1.Rotate(msg.horzInput); player1.Move(msg.vertInput); if (msg.fireMissile) { GameManager.FireMissile(player1); } if (msg.layMine) { GameManager.LayMine(player1); } Vec2 t = player1.GetHeading(); MissileMineMessage p1MissileUpdate = new MissileMineMessage(1, msg.fireMissile, msg.layMine, t.X, t.Y); InputQueue.AddToQueue(p1MissileUpdate); } else if (msg.playerID == 2) { player2.Rotate(msg.horzInput); player2.Move(msg.vertInput); if (msg.fireMissile) { GameManager.FireMissile(player2); } if (msg.layMine) { GameManager.LayMine(player2); } Vec2 t = player2.GetHeading(); MissileMineMessage p2MissileUpdate = new MissileMineMessage(2, msg.fireMissile, msg.layMine, t.X, t.Y); InputQueue.AddToQueue(p2MissileUpdate); } }
public void SendMessageToClient(DataMessage msg) { if (server.ConnectionsCount > 0) { NetworkMessage sm = new NetworkMessage(); // Temporary switch (msg.type) { case DataMessage_Type.GAME_STATE: GameStateMessage gameStateMsg = msg as GameStateMessage; sm.Set_Data(gameStateMsg); break; case DataMessage_Type.PLAYER_UPDATE: PlayerUpdateMessage playerMsg = msg as PlayerUpdateMessage; sm.Set_Data(playerMsg); break; case DataMessage_Type.FENCE_HIT: FenceHitMessage fMsg = msg as FenceHitMessage; sm.Set_Data(fMsg); break; case DataMessage_Type.MISSLE_MINE: MissileMineMessage MMMsg = msg as MissileMineMessage; sm.Set_Data(msg); break; case DataMessage_Type.ROTATION: RotationMessage rMsg = msg as RotationMessage; sm.Set_Data(msg); break; case DataMessage_Type.MISSILEUPDATE: MissileUpdateMessage tmsg = msg as MissileUpdateMessage; sm.Set_Data(msg); break; case DataMessage_Type.GAME_OVER: GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE; sm.Set_Data(msg); break; default: break; } NetOutgoingMessage om = server.CreateMessage(); om.Write(sm.Serialize()); server.SendMessage(om, server.Connections, NetDeliveryMethod.ReliableOrdered, 4); server.FlushSendQueue(); } }
public static void RecieveMessage(DataMessage msg) { if (instance.state == GAME_STATE.LOBBY) { switch (msg.type) { case DataMessage_Type.GAME_STATE: instance.ProcessGameStateMessage(msg as GameStateMessage); break; } } else if (instance.state == GAME_STATE.PLAY) { switch (msg.type) { case DataMessage_Type.PLAYER_INPUT: PlayerInputMessage pMsg = msg as PlayerInputMessage; instance.ProcessPlayerInputMessage(pMsg); break; case DataMessage_Type.PLAYER_UPDATE: PlayerUpdateMessage updateMsg = msg as PlayerUpdateMessage; instance.ProcessPlayerUpdateMessage(updateMsg); break; case DataMessage_Type.FENCE_HIT: FenceHitMessage fenceMsg = msg as FenceHitMessage; instance.ProcessFenceHitMessage(fenceMsg); break; case DataMessage_Type.MISSLE_MINE: MissileMineMessage MMMsg = msg as MissileMineMessage; instance.ProcessMissileMineMessage(MMMsg); break; case DataMessage_Type.ROTATION: RotationMessage rMsg = msg as RotationMessage; instance.ProcessRotationMessage(rMsg); break; case DataMessage_Type.MISSILEUPDATE: MissileUpdateMessage MMsg = msg as MissileUpdateMessage; instance.ProcessMissileUpdateMessage(MMsg); break; case DataMessage_Type.GAME_OVER: GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE; instance.ProcessGameOverMessage(gomsg); break; default: break; } } }
public static MissileMineMessage Deserialize(ref BinaryReader reader) { MissileMineMessage output = new MissileMineMessage(); output.PlayerID = reader.ReadInt32(); output.pMissile = reader.ReadBoolean(); output.Mine = reader.ReadBoolean(); output.direction_x = reader.ReadSingle(); output.direction_y = reader.ReadSingle(); return(output); }
public static NetworkMessage Deserialize(byte[] bytes) { BinaryReader reader = new BinaryReader(new MemoryStream(bytes)); NetworkMessage output = new NetworkMessage(); output.data_type = (DataMessage_Type)reader.ReadInt32(); switch (output.data_type) { case DataMessage_Type.GAME_STATE: output.data = GameStateMessage.Deserialize(ref reader); break; case DataMessage_Type.PLAYER_UPDATE: output.data = PlayerUpdateMessage.Deserialize(ref reader); break; case DataMessage_Type.MISSLE_MINE: output.data = MissileMineMessage.Deserialize(ref reader); break; case DataMessage_Type.ROTATION: output.data = RotationMessage.Deserialize(ref reader); break; case DataMessage_Type.FENCE_HIT: output.data = FenceHitMessage.Deserialize(ref reader); break; case DataMessage_Type.MISSILEUPDATE: output.data = MissileUpdateMessage.Deserialize(ref reader); break; case DataMessage_Type.GAME_OVER: output.data = GAMEOVERMESSAGE.Deserialize(ref reader); break; default: Debug.Assert(false, "INVALID DATA TYPE"); break; } return(output); }