Beispiel #1
0
 public AIShip(
     string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape,
     List <Color> colors, int health, Vector vel, Vector dir, BoundaryStrategy boundaryStrat, Team team,
     List <Component> components
     ) : base(id, filePath, refPos, offsetPos, shape, colors, health, vel, dir, 500, boundaryStrat, team, components)
 {
 }
Beispiel #2
0
 public NumberPopup(string id, int points, Point2D refPos, List <Color> colors, float vel,
                    Vector dir, float lifetime, BoundaryStrategy boundaryStrat, Team team, bool optimiseMe
                    ) : base(id, null, refPos, SwinGame.PointAt(0, 0), null, colors, 0, dir.Multiply(vel), dir, boundaryStrat, team, optimiseMe)
 {
     text      = $"+{points}";
     cdHandler = new CooldownHandler(lifetime * 1000);
     cdHandler.StartCooldown();
 }
Beispiel #3
0
        public Debris(string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape,
                      List <Color> colors, BoundaryStrategy boundaryStrat, int health, Vector vel, Vector dir,
                      float friction, float turnRate, float lifetime, Team team
                      ) : base(id, filePath, refPos, offsetPos, shape, colors, health, vel, dir, boundaryStrat, team)
        {
            this.friction = friction;
            this.turnRate = turnRate;

            cdHandler = new CooldownHandler(lifetime * 1000);
            cdHandler.StartCooldown();
        }
Beispiel #4
0
        public Component(
            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, vel, dir, boundaryStrat, team, optimiseMe)
        {
            childComponents = new List <Component>();

            hurtThreshhold = 500;
            hurtTimer      = SwinGame.CreateTimer();
            isHurting      = false;
        }
Beispiel #5
0
 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;
 }
Beispiel #6
0
        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;
        }
Beispiel #7
0
 public Engine(
     string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape,
     List <Color> colors, int health, Vector vel, Vector dir, BoundaryStrategy boundaryStrat,
     Team team, List <Component> components, float thrust, float maxVel, float turnRate, int mass
     ) : base(id, filePath, refPos, offsetPos, shape, colors, health, vel, dir, boundaryStrat, team)
 {
     this.mass       = mass <= 0 ? 1 : mass;
     Thrust          = thrust;
     MaxVel          = maxVel;
     this.turnRate   = turnRate;
     childComponents = components;
 }
Beispiel #8
0
 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();
 }
Beispiel #9
0
        public Ammo(
            string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape,
            List <Color> colors, int mass, int damage, float lifetime, float vel, float maxVel,
            float turnRate, BoundaryStrategy boundaryStrat, Team team
            ) : base(id, filePath, refPos, offsetPos, shape, colors, 1, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1), boundaryStrat, team)
        {
            Damage        = damage;
            this.lifetime = lifetime < 0 ? 0 : lifetime;
            this.mass     = mass <= 0 ? 1 : mass;

            MaxVel        = maxVel;
            thrustForce   = vel;
            this.turnRate = turnRate;
        }
Beispiel #10
0
        public Particle(
            string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape,
            List <Color> colors, float friction, MinMax <float> lifetimeRange, MinMax <float> velRange,
            MinMax <float> turnRateRange, BoundaryStrategy boundaryStrat, Team team
            ) : base(id, filePath, refPos, offsetPos, shape, colors, 1, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1), boundaryStrat, team, true)
        {
            this.friction      = friction;
            this.lifetimeRange = lifetimeRange;
            this.velRange      = velRange;
            this.turnRateRange = turnRateRange;

            thrustForce = 0;
            turnRate    = 0;
            lifetime    = 0;
        }
Beispiel #11
0
 public abstract Component Create(JObject compObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D offsetPos, float mod = 1);
Beispiel #12
0
        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);
        }
Beispiel #13
0
        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));
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
 public Asteroid(string id, string filePath, Point2D refPos, Point2D offsetPos, Shape shape,
                 List <Color> colors, int mass, int health, float thrustForce, Vector dir, float turnRate, BoundaryStrategy boundaryStrat,
                 Team team, int dmg, bool optimiseMe = false)
     : base(id, filePath, refPos, offsetPos, shape, colors, health, SwinGame.VectorFromAngle(dir.Angle, thrustForce), dir, boundaryStrat, team, optimiseMe)
 {
     this.turnRate    = turnRate;
     this.mass        = mass;
     this.thrustForce = thrustForce;
     MaxVel           = thrustForce;
     Vel    = dir.Multiply(thrustForce);
     Damage = dmg;
 }
Beispiel #16
0
        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));
        }
Beispiel #17
0
        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));
        }
Beispiel #18
0
        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);
            }
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        /// <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));
        }
Beispiel #21
0
        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));
        }
Beispiel #22
0
        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));
        }