/// <summary>
 /// Abstracts the processing of the cube
 /// </summary>
 /// <param name="cube"></param>
 private void ProcessJsonCube(Cube cube)
 {
     lock (world)
     {
         world.ProcessIncomingCube(cube);
     }
     
     Invalidate();
 }
        /// <summary>
        /// This does the nuts and bolts for drawing the cube
        /// </summary>
        /// <param name="cube"></param>
        /// <param name="e"></param>
        private void DrawCube(Cube cube, PaintEventArgs e)
        {
            Color color = Color.FromArgb(cube.Color);
            myBrush = new System.Drawing.SolidBrush(color);

            e.Graphics.FillRectangle(myBrush, new Rectangle((int)(cube.X - (cube.Width * world.Scale / 2)), (int)(cube.Y - (cube.Width * world.Scale / 2)), (int)(cube.Width * world.Scale), (int)(cube.Width * world.Scale)));

            System.Drawing.Font drawFont = new System.Drawing.Font("Quartz MS", (int)(10 * world.Scale));
            System.Drawing.SolidBrush nameBrush = new System.Drawing.SolidBrush(Color.FromName("yellow"));
            StringFormat string_format = new StringFormat();
            string_format.Alignment = StringAlignment.Center;
            string_format.LineAlignment = StringAlignment.Center;

            e.Graphics.DrawString(cube.Name, drawFont, nameBrush, new PointF(cube.GetCenterX() - (cube.Width / 2), cube.GetCenterY() - (cube.Width / 2)), string_format);

            //e.Graphics.ScaleTransform(1.5f, 1.5f);
        }
Exemple #3
0
        /// <summary>
        /// This takes care of what we need to do with a cube, depending on whether it exists and if it has mass.
        /// </summary>
        /// <param name="cube"></param>
        public void ProcessIncomingCube(Cube cube)
        {
            bool cubeExists = cubes.ContainsKey(cube.UID);

            if (cubeExists)
            {
                //If mass is 0, that means the cube has been eaten/destroyed, and should no longer be shown.
                if (cube.Mass == 0)
                {
                    cubes.Remove(cube.UID);
                }

                //If the mass isn't 0, it means the cube exists, and should be updated. The location may change, size, etc.
                else
                {
                    cubes[cube.UID] = cube;
                }
            }

            //If the cube doesn't exist, only add it if it has a mass.
            else
            {
                if (cube.Mass > 0)
                {
                    cubes.Add(cube.UID, cube);
                }
            }

        }