示例#1
0
        public Tank(IControl Controller, Form1.delVoidEntity sendEntity, PointF pos, float rot, Color col) : base(pos, rot, col)
        {
            //set id
            ID = IDGen++;

            //assign controller
            controller = Controller;

            //setup delegate
            addBulletDelegate = sendEntity;

            //set attributes
            temporaryBarrelBullet.color = color;
            cannonAngle = rot;

            //create rectangle base for body of tank
            bodyModel = new GraphicsPath();
            bodyModel.AddPolygon(Utility.CreateRectangle(bodySize, bodySize * 1.5f));

            //create rectangle for cannon
            List <PointF> points = new List <PointF>();

            points.Add(new PointF(cannonSize * 4f, cannonSize / 2));
            points.Add(new PointF(cannonSize * 4f, -cannonSize / 2));
            points.Add(new PointF(0, -cannonSize / 2));
            points.Add(new PointF(0, cannonSize / 2));
            //create graphicspath from points
            cannonModel = new GraphicsPath();
            cannonModel.AddPolygon(points.ToArray());
        }
示例#2
0
        /// <summary>
        /// spans a tank using the controller and same inputs as tank
        /// </summary>
        /// <param name="PlayerToSpawn"></param>
        /// <param name="CallBack"></param>
        /// <param name="DangerousTanks"></param>
        /// <returns></returns>
        public static Tank SpawnTank(IControl PlayerToSpawn, Form1.delVoidEntity CallBack, List <Tank> DangerousTanks)
        {
            // should be null till we find one
            Spawn Safe = null;
            int   Pos  = 0;

            while (Safe == null)
            {
                // try for a random spawn point
                Pos = Rand.Next(0, Spawns.Count);
                // check to se iff there os an tank around
                foreach (Tank t in DangerousTanks)
                {
                    if (!(Utility.Distance(t.position, Spawns[Pos].position) < Spawns[Pos].CheckAtDistance + t.CheckAtDistance))
                    {
                        //none around set safe so we can break
                        Safe = Spawns[Pos];
                        break;
                    }
                }
            }
            //Make a tank there and return it
            return(new Tank(PlayerToSpawn, CallBack, Safe.position, Safe.rotation, PlayerToSpawn.PlayerColor));
        }