コード例 #1
0
        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);
        }
コード例 #2
0
        /// <summary>
        /// Set everything required for a new round
        /// </summary>
        private void InitializeRound()
        {
            round++;

            // Clear lists
            projectiles.Clear();
            robots.Clear();
            //hud.Clear();
            hud.AddMessage("New Round: " + round, true);
            foreach (KeyValuePair <string, int> score in scoreKeeper.GetAllScores())
            {
                hud.AddMessage(String.Format("Team {0} has {1,3} Point{2}", score.Key, score.Value, score.Value != 1 ? "s" : ""));
            }

            // Get all game objects from manager
            Collection <GameObjectRobot> gameObjectRobots = Program.Tournament.RobotManager.CreateGameObjects(Program.Tournament);

            foreach (GameObjectRobot gorobot in gameObjectRobots)
            {
                // Set position to free map area
                map.PlaceRobot(gorobot);
                // Set round values after positioning the object so positions are correct for notification event
                gorobot.SetRoundValues(Program.Tournament.Rules);
                // create world object and load model
                WorldObjectRobot worldObject = new WorldObjectRobot(gorobot);
                worldObject.Load(Content);
                // Assign all event handler
                ((GameObjectRobot)worldObject.GameObject).HandleRobotEvents += RobotCore_HandleRobotEvents;
                // Add robot to the list
                robots.Add(worldObject);
            }

            // Place camera to see whole map
            cameraTargetIndex = -1;
            if (map.MapHeight > map.MapWidth)
            {
                cameraOverviewScaleFactor = map.MapHeight;
            }
            else
            {
                cameraOverviewScaleFactor = map.MapWidth;
            }

            if (round == 1)
            {
                hud.StatusMessage = String.Format("Ready...\n\nRound {0} of {1}", round, Program.Tournament.Rules.Rounds);
            }
            else
            {
                hud.StatusMessage = String.Format("{0}\n\nRound {1} of {2}", hud.StatusMessage, round, Program.Tournament.Rules.Rounds);
            }
        }