///<summary>Update takes a GraphicsObject as a parameter. If there is an object with the /// same ID we will update the existing object with the new info otherwise we add /// the object to our dictionary of object</summary> /// <param name="obj">The object that needs to be updated</param> public void Update(GraphicsObject obj) { if (obj != null) // we actually have an object { GraphicsObject value; if (this.dictionary.TryGetValue(obj.GetID(), out value)) { // we have it so we just need to update it value.SetX(obj.GetX()); value.SetY(obj.GetY()); value.SetAngle(obj.GetAngle()); } else { // we dont have it so we need to add it this.dictionary.Add(obj.GetID(), obj); } } }
/** * Renders the given GraphicsObject * * @param spriteBatch Contains graphics contexts for rendering on the game screen * @param obj The GraphicsObject that is to be rendered */ public void Render(SpriteBatch spriteBatch, GraphicsObject obj) { this.Render(spriteBatch, (int)obj.GetX(), (int)obj.GetY(), (int)obj.GetRadius(), obj.GetColor(), (int)obj.GetAngle(), 0.0f, 0, 0); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// </summary> protected override void Initialize() { // TODO: Add some name detection from forms. strName = "nicktest"; world = new WorldGraphics(); model = new GraphicsModel(); world.SetGraphicsModel(model); //Setup ships for players 1 & 2 (offscreen to start) //GraphicsObject(int id, float x, float y, float radius, float angle, int spriteID, int colorID) GraphicsObject ship1 = new GraphicsObject(1, 0, 0, 16, 0, 1, 5); model.Update(ship1); shipList.Add(ship1); GraphicsObject ship2 = new GraphicsObject(2, -16, -16, 16, 0, 1, 7); model.Update(ship2); shipList.Add(ship2); //Setup planet GraphicsObject planet = new GraphicsObject(3, 400, 300, 32, 0, 201, 0); model.Update(planet); planetList.Add(planet); //******** Networking Stuff ************* //Using UDP sockets clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; Console.WriteLine(ipAddress); //Server is listening on port 1000 IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 11000); epServer = (EndPoint)ipEndPoint; //Get message ready Data msgToSend = new Data(); msgToSend.cmdCommand = Command.Login; msgToSend.strMessage = null; msgToSend.strName = strName; byte[] byteData = msgToSend.ToByte(); //Login to the server clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null); byteData = new byte[1024]; //Start listening to the data asynchronously clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epServer, new AsyncCallback(OnReceive), null); //******** End Networking Stuff ************* base.Initialize(); }