示例#1
0
        /// <summary>
        /// Create a random ship!
        /// </summary>
        /// <returns>a ship</returns>
        public Ship CreateRandomShip(Point2D pos, BoundaryStrategy boundaryStrat, ControllerType controller, Difficulty diff, IHandlesEntities entHandler)
        {
            int    i            = Util.Rand(FileRegistry.Count);
            string randomShipId = FileRegistry.ElementAt(i).Key;

            return(Create(randomShipId, pos, boundaryStrat, controller, diff, entHandler));
        }
示例#2
0
        private ControllableShip CreatePlayerShip(string shipId, Point2D pos, BoundaryStrategy boundaryStrat, ControllerType controller, IHandlesEntities entHandler)
        {
            JObject obj = Util.Deserialize(FileRegistry[shipId]);

            //int health = obj.Value<int>("health");
            List <Color> shipColors = new List <Color> {
                Util.GetRGBColor(obj.GetValue("color")), Color.Yellow, Color.White, Color.Red
            };
            float   scale       = obj.Value <float>("scale");
            JArray  enginesObj  = obj.Value <JArray>("engines");
            JArray  toolsObj    = obj.Value <JArray>("tools");
            JArray  emittersObj = obj.Value <JArray>("emitters");
            JObject shapeObj    = obj.Value <JObject>("shape");

            Team    team   = (Team)(int)controller;
            Point2D offset = SwinGame.PointAt(0, 0);

            //shape
            Shape shape  = new ShapeFactory().Create(shapeObj, scale, SwinGame.PointAt(0, 0));
            int   health = shape.Mass / 2;

            Console.WriteLine(health);
            //shape.TeleportTo(pos);

            //component
            List <Component> components = BuildComponents(enginesObj, toolsObj, emittersObj, entHandler, boundaryStrat, team, offset);

            ControllableShip result = new ControllableShip(shipId, FileRegistry[shipId], pos, SwinGame.PointAt(0, 0), shape, shipColors,
                                                           health, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1), 2000, boundaryStrat, team, components);

            result.TeleportTo(pos);
            return(result);
        }
示例#3
0
        private List <Component> BuildComponents(JArray enginesObj, JArray toolsObj, JArray emittersObj,
                                                 IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D offset, float mod = 1)
        {
            List <Component> result = new List <Component>();

            result.AddRange(new EngineFactory().CreateList(enginesObj, entHandler, boundaryStrat, team, offset, mod));
            result.AddRange(new ToolFactory().CreateList(toolsObj, entHandler, boundaryStrat, team, offset, mod));
            result.AddRange(new EmitterFactory().CreateList(emittersObj, entHandler, boundaryStrat, team, offset, mod = 1));

            return(result);
        }
示例#4
0
 public Ship(
     string id, string filePath, Point2D refPos, Point2D offsetPos,
     Shape shape, List <Color> colors, int health, Vector vel, Vector dir, int threshhold,
     BoundaryStrategy boundaryStrat, Team team, List <Component> components
     ) : base(id, filePath, refPos, offsetPos, shape, colors, health, vel, dir, boundaryStrat, team)
 {
     componentList  = components;
     Damage         = 1;
     hurtTimer      = SwinGame.CreateTimer();
     isHurting      = false;
     hurtThreshhold = threshhold;
 }
示例#5
0
        private bool isOptimisedUpdate;         // if true, do not update the object if it is off screen

        public Mover(
            string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape,
            List <Color> colors, int health, Vector vel, Vector dir, BoundaryStrategy boundaryStrat,
            Team team, bool optimiseMe = false
            ) : base(id, filePath, refPos, offsetPos, shape, colors, health, team)
        {
            this.boundaryStrat = boundaryStrat;
            Vel   = vel;
            Dir   = dir;
            theta = 0;

            isOptimisedUpdate = optimiseMe;
        }
示例#6
0
        /// <summary>
        /// Create specified ship
        /// </summary>
        /// <param name="shipId">ship id</param>
        /// <param name="pos">spawn position</param>
        /// <param name="boundaryStrat">behaviour at the play area boundary</param>
        /// <param name="controller">computer/players</param>
        /// <param name="diff">difficulty setting</param>
        /// <param name="entHandler">entity handler</param>
        /// <returns>player ship or ai ship depending on controller</returns>
        public Ship Create(string shipId, Point2D pos, BoundaryStrategy boundaryStrat, ControllerType controller, Difficulty diff, IHandlesEntities entHandler)
        {
            if (!FileRegistry.ContainsKey(shipId))
            {
                return(null);
            }

            switch (controller)
            {
            case ControllerType.Computer:
                return(CreateAIShip(shipId, pos, boundaryStrat, diff, entHandler));

            case ControllerType.Player1:
            case ControllerType.Player2:
            case ControllerType.Player3:
            case ControllerType.Player4:
                return(CreatePlayerShip(shipId, pos, boundaryStrat, controller, entHandler));

            default: return(null);
            }
        }
示例#7
0
        private AIShip CreateAIShip(string shipId, Point2D pos, BoundaryStrategy boundaryStrat, Difficulty diff, IHandlesEntities entHandler)
        {
            AIStrategyFactory strategyFac = new AIStrategyFactory(diff.DifficultyLevel, diff.ShootCooldown);

            JObject obj = Util.Deserialize(FileRegistry[shipId]);

            //int health = obj.Value<int>("health");
            List <Color> shipColors = new List <Color> {
                Color.Crimson, Color.Yellow, Color.White, Color.Red
            };
            float   scale       = obj.Value <float>("scale");
            JArray  enginesObj  = obj.Value <JArray>("engines");
            JArray  toolsObj    = obj.Value <JArray>("tools");
            JArray  emittersObj = obj.Value <JArray>("emitters");
            JObject shapeObj    = obj.Value <JObject>("shape");

            Team    team   = Team.Computer;
            Point2D offset = SwinGame.PointAt(0, 0);

            //shape
            Shape shape  = new ShapeFactory().Create(shapeObj, scale, SwinGame.PointAt(0, 0));
            int   health = shape.Mass / 2;

            shape.TeleportTo(pos);

            //components
            List <Component> components = BuildComponents(enginesObj, toolsObj, emittersObj, entHandler, boundaryStrat, team, offset, diff.AIMod);

            //build and return ship
            AIShip result = new AIShip(shipId, FileRegistry[shipId], pos, SwinGame.PointAt(0, 0), shape, shipColors,
                                       health, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1), boundaryStrat, team, components);

            //create strategy
            AIStrategy aiStrat = strategyFac.Create((IAIEntity)result, entHandler);

            result.AIStrategy = aiStrat;

            result.TeleportTo(pos);
            return(result);
        }