public void DrawrobotNames(SpriteBatch spriteBatch, WorldObjectRobot robot, GraphicsDevice graphicsDevice, ArcBallCamera camera, Matrix projection) { GameObjectRobot gameObjectRobot = (GameObjectRobot)robot.GameObject; Vector3 screenSpace = graphicsDevice.Viewport.Project(Vector3.Zero, projection, camera.ViewMatrix, Matrix.CreateTranslation(robot.PositionX, robot.PositionY, robot.PositionZ)); // Get 2D coordinates from screenspace vector Vector2 textPosition; textPosition.X = screenSpace.X; textPosition.Y = screenSpace.Y; // Center the text Vector2 stringCenter = FontSmall.MeasureString(gameObjectRobot.FullName) * 0.5f; // Calculate position textPosition.X = (int)(textPosition.X - stringCenter.X); //textPosition.Y = (int)(textPosition.Y - stringCenter.Y); textPosition.Y = (int)(textPosition.Y + stringCenter.Y); // Skip if out of screen if (textPosition.X < 0 || textPosition.X > graphicsDevice.Viewport.Width) { return; } if (textPosition.Y < 0 || textPosition.Y > graphicsDevice.Viewport.Height) { return; } // Draw the text spriteBatch.DrawString(FontSmall, gameObjectRobot.FullName, textPosition, Color.White); }
public void Draw(SpriteBatch spriteBatch, GameObjectRobot robot, TournamentRules rules) { spriteBatch.Draw(textureRadar, positionRadar, Color.White); spriteBatch.Draw(textureRadarBar, positionRadarBar, null, Color.White, (float)robot.RotationRadar, new Vector2(textureRadarBar.Width / 2.0f, textureRadarBar.Height / 2.0f), 1.0f, SpriteEffects.None, 0.5f); spriteBatch.Draw(textureMissile, positionStaus, Color.White); //spriteBatch.Draw(textureHitpoints, positionStaus, Color.White); int hpheight = (int)(robot.Hitpoints * 1.0f / rules.Hitpoints * textureHitpoints.Height); spriteBatch.Draw(textureHitpoints, new Rectangle(0, textureHitpoints.Height - hpheight, textureHitpoints.Width, hpheight), new Rectangle(0, textureHitpoints.Height - hpheight, textureHitpoints.Width, hpheight), Color.White); //spriteBatch.Draw(textureHeat, positionStaus, Color.White); int h = (int)(robot.Heat * 1.0f / rules.MaxHeat * textureHeat.Height); spriteBatch.Draw(textureHeat, new Rectangle(0, textureHeat.Height - h, textureHeat.Width, h), new Rectangle(0, textureHeat.Height - h, textureHeat.Width, h), Color.White); string missileCount = robot.Missiles.ToString(CultureInfo.InvariantCulture); Vector2 fontOriginMissile = font.MeasureString(missileCount) / 2; spriteBatch.DrawString(font, missileCount, positionMissileFont, Color.White, 0, fontOriginMissile, 1.0f, SpriteEffects.None, 0.5f); }
public void DrawrobotNames(SpriteBatch spriteBatch, GameObjectRobot robot, Vector2 camera) { Vector2 fontOriginRobotName = FontSmall.MeasureString(robot.FullName) / 2; fontOriginRobotName.X = (float)Math.Ceiling(fontOriginRobotName.X); // Move to full pixel fontOriginRobotName.Y = (float)Math.Ceiling(fontOriginRobotName.Y); spriteBatch.DrawString(FontSmall, robot.FullName, new Vector2((int)(camera.X + robot.PositionX), (int)(camera.Y + robot.PositionY - robot.Radius)), Color.White, 0, fontOriginRobotName, 1.0f, SpriteEffects.None, 0.5f); }
public void DrawObjectsOnRadar(SpriteBatch spriteBatch, GameObjectRobot scanner, Vector2 target, float mapScale, GameObjectsType objectType) { Texture2D drawingTexture = null; //Set drawing texture and map accuracy switch (objectType) { case GameObjectsType.Robot: drawingTexture = textureRadarRobot; target.X = (float)(Math.Ceiling(target.X / mapScale) * mapScale); target.Y = (float)(Math.Ceiling(target.Y / mapScale) * mapScale); break; case GameObjectsType.Bullet: break; case GameObjectsType.Missile: break; case GameObjectsType.Wall: drawingTexture = textureRadarWall; target.X *= mapScale; target.Y *= mapScale; break; default: break; } double angleBetweenObjects = Math.Atan2(target.Y - scanner.PositionY, target.X - scanner.PositionX); double destinationToObject = Math.Sqrt(Math.Pow(target.Y - scanner.PositionY, 2) + Math.Pow(target.X - scanner.PositionX, 2)); //Zone radar vision float radarVision = 7 * mapScale; double CofScaleRadar = (textureRadar.Height / 2.0f) / radarVision; float sizeObjectOnRadar = (float)(mapScale * CofScaleRadar); if (radarVision > Math.Floor(destinationToObject + (sizeObjectOnRadar / CofScaleRadar) / 2)) { destinationToObject *= CofScaleRadar; Vector2 positionOnRadar = new Vector2(); positionOnRadar.X = positionRadar.X + textureRadar.Width / 2 - sizeObjectOnRadar + (float)(destinationToObject * Math.Cos(angleBetweenObjects)); positionOnRadar.Y = positionRadar.Y + textureRadar.Height / 2 - sizeObjectOnRadar + (float)(destinationToObject * Math.Sin(angleBetweenObjects)); Rectangle ScaleObject = new Rectangle(Convert.ToInt32(positionOnRadar.X), Convert.ToInt32(positionOnRadar.Y), Convert.ToInt32(sizeObjectOnRadar), Convert.ToInt32(sizeObjectOnRadar)); spriteBatch.Draw(drawingTexture, ScaleObject, Color.White); spriteBatch.Draw(textureOuter, positionRadar, Color.White); } }
/// <summary> /// Find a nice and free place for the robot /// </summary> /// <param name="robot"></param> public void PlaceRobot(GameObjectRobot robot) { int r = rand.Next(robotSpawnPlaces.Count); robot.PositionX = robotSpawnPlaces[r].X; robot.PositionY = robotSpawnPlaces[r].Y; robotSpawnPlaces.Remove(robotSpawnPlaces[r]); robot.Rotation = rand.Next(0, (int)(Math.PI * 2)); robot.RotationGun = robot.Rotation; robot.RotationRadar = robot.Rotation; }
/// <summary> /// Event from robot /// </summary> /// <param name="sender">The robot raising the event</param> /// <param name="e">The event arguments</param> void RobotCore_HandleRobotEvents(object sender, MarvinsArena.Robot.Core.MessageExchangeFromRobotEventArgs e) { GameObjectRobot senderRobot = (GameObjectRobot)sender; if (e.FireProjectile != null) { WorldObject projectile; if (e.FireProjectile.FireType == MarvinsArena.Robot.Core.ProjectileType.Bullet) { projectile = new WorldObjectBullet(e.FireProjectile.Power); } else { projectile = new WorldObjectMissile(); } projectile.Load(Content); projectile.PositionX = (float)senderRobot.PositionX; projectile.PositionY = (float)senderRobot.PositionY; projectile.Rotation = (float)senderRobot.RotationGun; // Move away from spawn position immediately or this would collide with the spawning robot projectile.PositionX += 30.0f * (float)Math.Cos(projectile.Rotation); projectile.PositionY += 30.0f * (float)Math.Sin(projectile.Rotation); projectiles.Add(projectile); } foreach (string msg in e.PrintMessage) { hud.AddMessage(String.Format("{0} says: {1}", senderRobot.FullName, msg)); } foreach (MarvinsArena.Robot.Core.CoreMessageReceivedFromTeammateEventArgs tmsg in e.TeamMessage) { foreach (WorldObjectRobot worrobot in robots) { GameObjectRobot robot = (GameObjectRobot)worrobot.GameObject; if (robot.Team == tmsg.Team && robot.SquadNumber != tmsg.SquadNumber) { robot.NotifyMessageToTeammate(tmsg); } } } if (CoreMain.Instance.Debug) { foreach (string msg in e.DebugMessage) { hud.AddMessage(String.Format("DEBUG ({0}): {1}", senderRobot.FullName, msg)); } } }
/// <summary> /// Draws the texture /// </summary> public override void Draw(SpriteBatch spriteBatch, Vector2 camera, Vector2 cameraScreen) { Vector2 position = new Vector2(PositionX, PositionY); position.X += camera.X; position.Y += camera.Y; // Skip out of screen elements if (position.X + Texture.Width > cameraScreen.X || position.X < -Texture.Width || position.Y + Texture.Height > cameraScreen.Y || position.Y < -Texture.Height) { return; } GameObjectRobot robot = (GameObjectRobot)GameObject; Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2); spriteBatch.Draw(Texture, position, null, Color, (float)robot.Rotation, origin, 1, SpriteEffects.None, 0); spriteBatch.Draw(textureTurret, position, null, Color.White, (float)robot.RotationGun, origin, 1, SpriteEffects.None, 0); spriteBatch.Draw(textureRadar, position, null, Color.White, (float)robot.RotationRadar, origin, 1, SpriteEffects.None, 0); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { // Light render target if (lightActive) { GraphicsDevice.SetRenderTarget(lightRenderTarget); GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Additive); foreach (WorldObjectRobot obj in robots) { spriteBatch.Draw(textureLight, new Rectangle((int)(obj.PositionX + camera.X - (textureLight.Width / 2)), (int)(obj.PositionY + camera.Y - (textureLight.Height / 2)), textureLight.Width, textureLight.Height), obj.Color); } foreach (WorldObject obj in projectiles) { spriteBatch.Draw(textureLight, new Rectangle((int)(obj.PositionX + camera.X - (textureLight.Width / 8)), (int)(obj.PositionY + camera.Y - (textureLight.Height / 8)), textureLight.Width / 4, textureLight.Height / 4), Color.White); } spriteBatch.End(); } // Normale rendering GraphicsDevice.SetRenderTarget(null); GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); map.Draw(spriteBatch, camera, cameraScreen); foreach (WorldObjectRobot obj in robots) { obj.Draw(spriteBatch, camera, cameraScreen); // Scanner /*bool scannedSomething = false; * * foreach(WorldObject robot2 in robots) * { * if(obj == robot2) * continue; * * if(GameObject.ObjectInScannerRange(((GameObjectRobot)obj.GameObject), robot2.GameObject)) * { * scannedSomething = true; * } * } * * Vector2 start = new Vector2(obj.PositionX + camera.PositionX, obj.PositionY + camera.PositionY); * Vector2 end = start + new Vector2(200, 200); * int distance = (int)Vector2.Distance(start, end); * Color color = scannedSomething ? Color.Green : Color.Red; * * float alpha = (float)(((GameObjectRobot)obj.GameObject).RotationRadar) - 0.34906585f; * spriteBatch.Draw(texturePixel, new Rectangle((int)start.PositionX, (int)start.PositionY, distance, 1), * null, color, alpha, new Vector2(0, 0), SpriteEffects.None, 0); * * float alpha2 = (float)(((GameObjectRobot)obj.GameObject).RotationRadar) + 0.34906585f; * spriteBatch.Draw(texturePixel, new Rectangle((int)start.PositionX, (int)start.PositionY, distance, 1), * null, color, alpha2, new Vector2(0, 0), SpriteEffects.None, 0);*/ } foreach (WorldObject obj in projectiles) { obj.Draw(spriteBatch, camera, cameraScreen); } spriteBatch.End(); if (lightActive) { // Draw light render target texture over the screen spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); GraphicsDevice.BlendState = transparentBlendState; spriteBatch.Draw(lightRenderTarget, new Rectangle(0, 0, lightRenderTarget.Width, lightRenderTarget.Height), Color.White); spriteBatch.End(); } // Draw Hud spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); // Draw robot names foreach (WorldObjectRobot obj in robots) { hud.DrawrobotNames(spriteBatch, (GameObjectRobot)obj.GameObject, camera); } // Only show hud if robot is selected if (cameraTargetIndex != -1 && cameraTargetIndex < robots.Count) { GameObjectRobot robot = (GameObjectRobot)robots[cameraTargetIndex].GameObject; hud.Draw(spriteBatch, robot, Program.Tournament.Rules); //Show walls on radar for (int x = 0; x < map.Heightmap.GetLength(0); x++) { for (int y = 0; y < map.Heightmap.GetLength(1); y++) { if (map.Heightmap[x, y] > 0) { hud.DrawObjectsOnRadar(spriteBatch, robot, new Vector2((float)x, (float)y), map.MapScale, GameObjectsType.Wall); } } } //Show robots on radar foreach (WorldObject robot2 in robots) { if (robots[cameraTargetIndex] == robot2) { continue; } if (GameObject.ObjectInScannerRange(robot, robot2.GameObject)) { hud.DrawObjectsOnRadar(spriteBatch, robot, new Vector2((float)robot2.GameObject.PositionX, (float)robot2.GameObject.PositionY), map.MapScale, GameObjectsType.Robot); } } } hud.DrawMessages(spriteBatch); //viewSelectionMenu.Draw(spriteBatch, from robot in robots select robot.GameObject as GameObjectRobot); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); ResetStatesFor3D(); map.Draw(); foreach (WorldObjectRobot obj in robots) { obj.Draw(world, view, projection); } foreach (WorldObject obj in projectiles) { obj.Draw(world, view, projection); } /*foreach(WorldObject obj in robots) * { * obj.RenderBoundingSphere(GraphicsDevice, view, projection, Color.Green); * } * foreach(WorldObject obj in projectiles) * { * obj.RenderBoundingSphere(GraphicsDevice, view, projection, Color.Green); * }*/ sky.Draw(graphics.GraphicsDevice, camera, projection); spriteBatch.Begin(); // Draw robot names foreach (WorldObjectRobot obj in robots) { hud.DrawrobotNames(spriteBatch, obj, GraphicsDevice, camera, projection); } // Only show hud if robot is selected if (cameraTargetIndex != -1 && cameraTargetIndex < robots.Count) { GameObjectRobot robot = (GameObjectRobot)robots[cameraTargetIndex].GameObject; hud.Draw(spriteBatch, robot, Program.Tournament.Rules); foreach (WorldObjectRobot obj in robots) { hud.DrawrobotNames(spriteBatch, obj, GraphicsDevice, camera, projection); //Show walls on radar for (int x = 0; x < map.Heightmap.GetLength(0); x++) { for (int y = 0; y < map.Heightmap.GetLength(1); y++) { if (map.Heightmap[x, y] > 0) { hud.DrawObjectsOnRadar(spriteBatch, robot, new Vector2((float)x, (float)y), map.MapScale, GameObjectsType.Wall); } } } //Show robots on radar foreach (WorldObject robot2 in robots) { if (robots[cameraTargetIndex] == robot2) { continue; } if (GameObject.ObjectInScannerRange(robot, robot2.GameObject)) { hud.DrawObjectsOnRadar(spriteBatch, robot, new Vector2((float)robot2.GameObject.PositionX, (float)robot2.GameObject.PositionY), map.MapScale, GameObjectsType.Robot); } } } } hud.DrawMessages(spriteBatch); //viewSelectionMenu.Draw(spriteBatch, from robot in robots select robot.GameObject as GameObjectRobot); spriteBatch.End(); base.Draw(gameTime); }