public override Component CreateFromReference(JObject engineObj, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1) { string path = SwinGame.AppPath() + engineObj.Value <string>("path"); Point2D offsetPos = engineObj["pos"].ToObject <Point2D>().Multiply(10); return(base.CreateFromReference(engineObj, entHandler, boundaryStrat, team, offsetPos)); }
public AIStrategy CreateByName(string strategy, IAIEntity aiEntity, IHandlesEntities entHandler) { switch (strategy.ToLower()) { case "crazyrotating": return(new CrazyRotatingStrategy(aiEntity, shootCooldown)); case "chase": return(new ChaseStrategy(aiEntity, entHandler, shootCooldown)); case "erratic": return(new ErraticStrategy(aiEntity, shootCooldown)); case "static": return(new StaticStrategy(aiEntity, shootCooldown)); case "forward": return(new ForwardStrategy(aiEntity, shootCooldown)); case "spreadforward": return(new SpreadForwardStrategy(aiEntity, shootCooldown)); default: return(new StaticStrategy(aiEntity, shootCooldown)); } }
public override Component CreateFromReference(JObject emitterObj, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1) { Point2D offsetPos = emitterObj["pos"].ToObject <Point2D>().Multiply(10); offsetPos = offsetPos.Add(parentPos); return(base.CreateFromReference(emitterObj, entHandler, boundaryStrat, team, offsetPos)); }
public Emitter( string id, string filePath, Point2D refPos, Point2D offsetPos, Vector vel, Vector dir, BoundaryStrategy boundaryStrat, Team team, float cooldownRate, List <Component> children, IHandlesEntities entHandler ) : base(id, filePath, refPos, offsetPos, null, null, 1, vel, dir, boundaryStrat, team) { childComponents = children; this.cooldownRate = cooldownRate; cdHandler = new CooldownHandler(1000 / cooldownRate); this.entHandler = entHandler; }
public EmittingAmmo(string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape, List <Color> colors, int mass, int damage, float lifetime, float vel, float maxVel, float primingDelay, float turnRate, List <Component> emitters, BoundaryStrategy boundaryStrat, IHandlesEntities entHandler, Team team ) : base(id, filePath, refPos, offsetPos, shape, colors, mass, damage, lifetime, vel, maxVel, turnRate, boundaryStrat, team) { primingTimer = new CooldownHandler(primingDelay); primingTimer.StartCooldown(); this.emitters = emitters; entityHandler = entHandler; }
public AISpawner(Difficulty diff, Rectangle playArea, ShipFactory shipFactory, IHandlesEntities entHandler) { entityHandler = entHandler; shipFac = shipFactory; difficulty = diff; this.playArea = playArea; cdHandler = new CooldownHandler(diff.SpawnTimer * 1000); cdHandler.StartCooldown(); }
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); }
public override Component Create(JObject ammoObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1) { try { string id = ammoObj.Value <string>("id"); List <Color> colors = Util.LoadColors(ammoObj.Value <JArray>("colors")); int mass = ammoObj.Value <int>("mass"); int damage = (int)(ammoObj.Value <int>("damage") * mod); float lifetime = ammoObj.Value <float>("lifetime") * mod; float vel = ammoObj.Value <float>("vel") * mod; float maxVel = ammoObj.Value <float>("maxVel") * mod; float turnRate = ammoObj.Value <float>("turnRate") * mod; float scale = ammoObj.Value <float>("scale"); JObject shapeObj = ammoObj.Value <JObject>("shape"); Shape shape = new ShapeFactory().Create(shapeObj, scale, parentPos); string strategy = ammoObj.Value <string>("strategy"); float primingDelay = 0; try { primingDelay = ammoObj.Value <float>("primingDelay"); } catch { } if (team == Team.Computer) { colors = new List <Color> { Color.Yellow } } ; JArray emitterObj = null; try { emitterObj = ammoObj.Value <JArray>("emitters"); } catch { } Ammo result; if (emitterObj != null) { List <Component> emitters = new EmitterFactory().CreateList(emitterObj, entHandler, boundaryStrat, team, parentPos, mod); result = new EmittingAmmo(id, path, SwinGame.PointAt(0, 0), parentPos, shape, colors, mass, damage, lifetime, vel, maxVel, primingDelay, turnRate, emitters, boundaryStrat, entHandler, team); } else { result = new Ammo(id, path, SwinGame.PointAt(0, 0), parentPos, shape, colors, mass, damage, lifetime, vel, maxVel, turnRate, boundaryStrat, team); } AIStrategyFactory aiStratFac = new AIStrategyFactory(0, 0); result.AIStrat = aiStratFac.CreateByName(strategy, result, entHandler); return(result); } catch (Exception e) { Console.WriteLine(e); return(null); } }
public Tool( string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape, List <Color> colors, int health, Vector vel, Vector dir, float cooldown, BoundaryStrategy boundaryStrat, Team team, List <Component> children, int mass, IHandlesEntities entHandler ) : base(id, filePath, refPos, offsetPos, shape, colors, health, vel, dir, boundaryStrat, team) { this.cooldown = cooldown; this.mass = mass <= 0 ? 1 : mass; childComponents = children; this.entHandler = entHandler; cdHandler = new CooldownHandler(cooldown * 1000); cdHandler.StartCooldown(); }
public override Component Create(JObject emitterObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D offsetPos, float mod = 1) { string id = emitterObj.Value <string>("id"); float cooldownRate = emitterObj.Value <float>("rate"); JObject particleObj = emitterObj.Value <JObject>("particle"); Component particle = new ParticleFactory().CreateFromReference(particleObj, entHandler, boundaryStrat, team, offsetPos); return(new Emitter(id, path, SwinGame.PointAt(0, 0), offsetPos, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1), boundaryStrat, team, cooldownRate, new List <Component>() { particle }, entHandler)); }
/// <summary> /// Create component from a filepath /// </summary> /// <param name="refObj">Json object containing the filepath</param> /// <param name="entHandler">entity handler</param> /// <param name="boundaryStrat">play area boundary behaviour</param> /// <param name="parentPos">position of object component is attached to</param> /// <param name="mod">modifier</param> /// <returns></returns> public virtual Component CreateFromReference(JObject refObj, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1) { string path = SwinGame.AppPath() + refObj.Value <string>("path"); //check that the path is valid if (!File.Exists(path)) { Console.WriteLine($"INVALID filepath: {path}"); return(null); } //load the full JObject from path refObj = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(path)); return(Create(refObj, path, entHandler, boundaryStrat, team, parentPos, mod)); }
public override Component Create(JObject particleObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D offsetPos, float mod = 1) { string id = particleObj.Value <string>("id"); List <Color> colors = Util.LoadColors(particleObj.Value <JArray>("colors")); float scale = particleObj.Value <float>("scale"); JObject shapeObj = particleObj.Value <JObject>("shape"); Shape shape = new ShapeFactory().Create(shapeObj, scale, offsetPos); float friction = particleObj.Value <float>("friction"); MinMax <float> lifetimeRange = particleObj["lifetimeRange"].ToObject <MinMax <float> >(); MinMax <float> velRange = particleObj["velRange"].ToObject <MinMax <float> >(); MinMax <float> turnRateRange = particleObj["turnRateRange"].ToObject <MinMax <float> >(); return(new Particle(id, path, SwinGame.PointAt(0, 0), offsetPos, shape, colors, friction, lifetimeRange, velRange, turnRateRange, boundaryStrat, team)); }
public virtual List <Component> CreateList(JArray compObj, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1) { if (compObj == null) { return(null); } List <Component> result = new List <Component>(); foreach (JObject obj in compObj) { result.Add(CreateFromReference(obj, entHandler, boundaryStrat, team, parentPos)); } return(result); }
public AIStrategy Create(IAIEntity aiEntity, IHandlesEntities entHandler) { //generate random number up to the difficulty level int n = Util.Rand(difficultyLevel); //return the hardest strategy that the number can get if (n < 5) { return(new CrazyRotatingStrategy(aiEntity, shootCooldown)); } else if (n < 10) { return(new StaticStrategy(aiEntity, shootCooldown)); } else if (n < 20) { return(new ErraticStrategy(aiEntity, shootCooldown)); } else { return(new ChaseStrategy(aiEntity, entHandler, shootCooldown)); } }
public override Component Create(JObject toolObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D offsetPos, float mod = 1) { string id = toolObj.Value <string>("id"); int mass = toolObj.Value <int>("mass"); float scale = toolObj.Value <float>("scale"); int health = toolObj.Value <int>("health"); float cooldown = toolObj.Value <float>("cooldown") / mod; JObject shapeObj = toolObj.Value <JObject>("shape"); List <Color> colors = Util.LoadColors(toolObj.Value <JArray>("colors")); Shape shape = new ShapeFactory().Create(shapeObj, scale, offsetPos); JObject ammoObj = toolObj.Value <JObject>("ammo"); Component ammo = new AmmoFactory().CreateFromReference(ammoObj, entHandler, boundaryStrat, team, offsetPos, mod); Tool result = new Tool(id, path, SwinGame.PointAt(0, 0), offsetPos, shape, colors, health, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1), cooldown, boundaryStrat, team, new List <Component>() { ammo }, mass, entHandler); entHandler.Track(result); return(result); }
public override Component Create(JObject engineObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D offsetPos, float mod = 1) { string id = engineObj.Value <string>("id"); float thrust = engineObj.Value <float>("thrust") * mod; float maxVel = engineObj.Value <float>("maxVel") * mod; float turnRate = engineObj.Value <float>("turnRate") * mod; int mass = engineObj.Value <int>("mass"); int health = engineObj.Value <int>("health"); float scale = engineObj.Value <float>("scale"); JObject shapeObj = engineObj.Value <JObject>("shape"); Shape shape = new ShapeFactory().Create(shapeObj, scale, offsetPos); JArray emitterObj = engineObj.Value <JArray>("emitters"); List <Component> emitters = new EmitterFactory().CreateList(emitterObj, entHandler, boundaryStrat, team, offsetPos); Engine result = new Engine(id, path, SwinGame.PointAt(0, 0), offsetPos, shape, new List <Color> { Color.White }, health, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1), boundaryStrat, team, emitters, thrust, maxVel, turnRate, mass); entHandler.Track(result); return(result); }
/// <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); } }
/// <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)); }
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); }
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); }
public override Component CreateFromReference(JObject particleObj, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1) { string path = SwinGame.AppPath() + particleObj.Value <string>("path"); return(base.CreateFromReference(particleObj, entHandler, boundaryStrat, team, parentPos)); }
public abstract Component Create(JObject compObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D offsetPos, float mod = 1);
public AsteroidFactory(IHandlesEntities entHandler) { this.entHandler = entHandler; }
public CollisionHandler(Rectangle playArea, IHandlesEntities entityHandler) { this.entityHandler = entityHandler; quadTree = new Node(null, playArea, 150); numberPopupFac = new NumberPopupFactory(playArea); }
public ChaseStrategy(IAIEntity controlled, IHandlesEntities entHandler, int shootCooldown = 0) : base(controlled, shootCooldown) { this.entHandler = entHandler; agroRange = SwinGame.ScreenWidth() / 1.5f; }