Esempio n. 1
0
        public override void Update(IMovingObject movingObject, GameTime gameTime)
        {
            if (currentPoint < 0)
            {
                var orderedList = Curve.Points.OrderBy(point => Vector3.DistanceSquared(movingObject.Position, point.Position)).ToList();
                currentPoint = Curve.Points.IndexOf(orderedList.First(point => IsInFrontOf(movingObject.Position, point)));
            }

            float currentDistance = Vector3.DistanceSquared(movingObject.Position, Curve.Points[currentPoint].Position);
            float distanceToNext = 0;
            int direction;
            if (Vector3.Dot(movingObject.Speed * movingObject.Heading, Curve.Points[currentPoint].Heading) >= .5f || keepProgress)
            {
                direction = 1;
            }
            else
            {
                direction = -1;
            }
            int nextPoint = (currentPoint + direction) % Curve.Points.Count;
            if (nextPoint < 0) nextPoint += Curve.Points.Count;
            distanceToNext = Vector3.DistanceSquared(movingObject.Position, Curve.Points[nextPoint].Position);

            if (distanceToNext < currentDistance && IsInFrontOf(movingObject.Position, Curve.Points[nextPoint]))
            {
                currentPoint = nextPoint;
                if (currentPoint == triggerPointIndex && (!preventReverse || direction > 0))
                    Trigger(currentPoint, movingObject, gameTime);
            }
        }
 protected void Trigger(int index, IMovingObject movingObject, GameTime gameTime)
 {
     if (Triggered != null)
     {
         Triggered(this, new TriggeredEventArgs(index, movingObject, gameTime));
     }
 }
Esempio n. 3
0
        private void Awake()
        {
            _transform = this.transform;

            if (this.resolveVelocityFromParent && _transform.parent != null)
            {
                _mover     = _transform.parent.As <IMovingObject>();
                _rigidBody = _transform.parent.GetComponent <Rigidbody>();
            }

            if (_mover == null && _rigidBody == null)
            {
                _mover     = this.As <IMovingObject>();
                _rigidBody = this.GetComponent <Rigidbody>();
            }

            this.isVelocityEnabled = (_mover != null || (_rigidBody != null && !_rigidBody.isKinematic));

            OnAwake();

            if ((this.updateMode == UpdateMode.OnRequest) && this.isVelocityEnabled)
            {
                Debug.LogWarning("Please note that this obstacle is marked to update on request, and will not be automatically updating after moving.");
            }
        }
Esempio n. 4
0
 public static List <Enemy> CollideObjects(List <Enemy> objectsCollection, IMovingObject controllableObject)
 {
     return(objectsCollection
            .Where(x => (x.GetLocation().X + 50 >= controllableObject.GetLocation().X) &&
                   (x.GetLocation().X - 40 <= controllableObject.GetLocation().X) &&
                   (x.GetLocation().Y + 40 >= controllableObject.GetLocation().Y) &&
                   (x.GetLocation().Y - 50 <= controllableObject.GetLocation().Y))
            .ToList());
 }
Esempio n. 5
0
        public List <ASSEvent> Create(IMovingObject imo)
        {
            List <ASSEvent> result = new List <ASSEvent>();
            //string pt0Str = @"{\blur3\bord4\p4}m 10 10 s 10 -10 -10 -10 -10 10";
            string pt0Str = @"{\blur" + (Pt0Size - 1) + @"\bord" + Pt0Size + @"\p4}m 10 10 s 10 -10 -10 -10 -10 10";
            string pt1Str = @"{\p4}m 0 100 l 1 1 100 0 1 -1 0 -100 -1 -1 -100 0 -1 1";

            for (double time = ParticleStartTime; time < ParticleEndTime; time += TimeStep)
            {
                for (int iDot = 0; iDot < ParticlePerStep; iDot++)
                {
                    ASSPointF   orgP      = imo.GetPosition(time);
                    double      orgX      = orgP.X;
                    double      orgY      = orgP.Y;
                    ParticleDot dot       = new ParticleDot(orgX, orgY, Common.RandomDouble(rnd, MinDX, MaxDX), Common.RandomDouble(rnd, MinDY, MaxDY), -Common.RandomDouble(rnd, MinDA, MaxDA));
                    double      liveTime  = -1.0 / dot.dA;
                    double      startTime = time;
                    double      endTime   = time + liveTime;
                    double      xEnd      = dot.X + dot.dX * liveTime;
                    double      yEnd      = dot.Y + dot.dY * liveTime;
                    result.Add(new ASSEvent
                    {
                        Effect  = "",
                        Layer   = 0,
                        MarginL = "0000",
                        MarginR = "0000",
                        MarginV = "0000",
                        Name    = "NTP",
                        Style   = "Default",
                        Start   = startTime,
                        End     = endTime,
                        Text    = ASSEffect.move(dot.X, dot.Y, xEnd, yEnd) + ASSEffect.a(1, "FF") + ASSEffect.c(3, ColorStart) + ASSEffect.fad(0, liveTime) + ASSEffect.t(0, liveTime, ASSEffect.c(3, ColorEnd).t()) + pt0Str
                    });
                    if (Star)
                    {
                        result.Add(new ASSEvent
                        {
                            Effect  = "",
                            Layer   = 0,
                            MarginL = "0000",
                            MarginR = "0000",
                            MarginV = "0000",
                            Name    = "NTP",
                            Style   = "Default",
                            Start   = startTime,
                            End     = endTime,
                            Text    = ASSEffect.move(dot.X, dot.Y - 1, xEnd, yEnd - 1) + ASSEffect.a(1, "77") + ASSEffect.c(1, ColorStart) + ASSEffect.fad(0, liveTime) + ASSEffect.t(0, liveTime, ASSEffect.c(1, ColorEnd).t()) + pt1Str
                        });
                    }
                }
            }
            return(result);
        }
Esempio n. 6
0
        public virtual void Initialize(GameObject unitObject)
        {
            _props             = unitObject.As <IUnitProperties>(false, true);
            _movable           = unitObject.As <IMovable>(false, false);
            _moving            = unitObject.As <IMovingObject>(false, true);
            _speeder           = unitObject.As <IDefineSpeed>(false, true);
            _pathFinderOptions = unitObject.As <IPathFinderOptions>(false, false) ?? new PathFinderOptions();
            _pathNavOptions    = unitObject.As <IPathNavigationOptions>(false, false) ?? new PathNavigationOptions();

            this.isMovable = _movable != null;
            if (!this.isMovable)
            {
                _movable = new MovableDummy(unitObject.name);
            }

            this.gameObject = unitObject;
            this.transform  = unitObject.transform;
            this.collider   = unitObject.GetComponent <Collider>();
        }
Esempio n. 7
0
        public override void Update(IMovingObject movingObject, GameTime gameTime)
        {
            if (currentPoint < 0)
            {
                var orderedList = Curve.Points.OrderBy(point => Vector3.DistanceSquared(movingObject.Position, point.Position)).ToList();
                currentPoint = Curve.Points.IndexOf(orderedList.First(point => IsInFrontOf(movingObject.Position, point)));
            }

            float currentDistance = Vector3.DistanceSquared(movingObject.Position, Curve.Points[currentPoint].Position);
            float distanceToNext  = 0;
            int   direction;

            if (Vector3.Dot(movingObject.Speed * movingObject.Heading, Curve.Points[currentPoint].Heading) >= .5f || keepProgress)
            {
                direction = 1;
            }
            else
            {
                direction = -1;
            }
            int nextPoint = (currentPoint + direction) % Curve.Points.Count;

            if (nextPoint < 0)
            {
                nextPoint += Curve.Points.Count;
            }
            distanceToNext = Vector3.DistanceSquared(movingObject.Position, Curve.Points[nextPoint].Position);

            if (distanceToNext < currentDistance && IsInFrontOf(movingObject.Position, Curve.Points[nextPoint]))
            {
                currentPoint = nextPoint;
                if (currentPoint == triggerPointIndex && (!preventReverse || direction > 0))
                {
                    Trigger(currentPoint, movingObject, gameTime);
                }
            }
        }
        /// <summary>
        /// Initializes the Unit Facade.
        /// </summary>
        /// <param name="unitObject">The unit game object.</param>
        public virtual void Initialize(GameObject unitObject)
        {
            _props = unitObject.As<IUnitProperties>(false, true);
            _movable = unitObject.As<IMovable>(false, false);
            _moving = unitObject.As<IMovingObject>(false, true);
            _speeder = unitObject.As<IDefineSpeed>(false, true);
            _pathFinderOptions = unitObject.As<IPathFinderOptions>(false, false) ?? new PathFinderOptions();
            _pathNavOptions = unitObject.As<IPathNavigationOptions>(false, false) ?? new PathNavigationOptions();

            this.isMovable = _movable != null;
            if (!this.isMovable)
            {
                _movable = new MovableDummy(unitObject.name);
            }

            this.gameObject = unitObject;
            this.transform = unitObject.transform;
            this.collider = unitObject.GetComponent<Collider>();

            this.isAlive = true;
            this.hasArrivedAtDestination = true;
        }
        protected virtual void Awake()
        {
            _thisMovingObject = GetComponent<IMovingObject>();
            _movementStats = _thisMovingObject.MovementStats;

            _rigidBody = GetComponent<Rigidbody>();
            _constantForce = GetComponent<ConstantForce>();

            _movementVector = transform.forward;

            _currentBoostCharges = _movementStats.MaxBoostCharges;
            //_boostParticlesR = transform.Find("BoostParticles_R").GetComponent<ParticleSystem>();
            //_boostParticlesR.gameObject.SetActive(false);
            //_boostParticlesL = transform.Find("BoostParticles_L").GetComponent<ParticleSystem>();
            //_boostParticlesL.gameObject.SetActive(false);
            _cruiserSpeedParticles = transform.FindChild("CruiserSpeedParticles").GetComponent<ParticleSystem>();
            _cruiserSpeedParticles.gameObject.SetActive(false);

            _cruiserSpeedCharger = new Cooldown(_movementStats.SecondsForCruiserSpeed, _thisMovingObject, true);
            _cruiserSpeedCharger.OnReady += (Cooldown cd) => EnableCruiserSpeed();
            _cruiserSpeedCharger.OnStop += (Cooldown cd) => DisableCruiserSpeed();

            _boostChargesWasteFixer = new Cooldown(BoostChargesWasteInterval, _thisMovingObject);
        }
Esempio n. 10
0
	void Start () {
		
		#if (UNITY_EDITOR)
		if(!EditorApplication.isPlaying) {
		} else {
		#endif

	
			var go = this.gameObject;
			ApexComponentMaster master;
			Rigidbody rb;
			
			//Add the required components
		/*	go.AddIfMissing<Rigidbody>(go, false, out rb);
			bool toggleAll = go.AddIfMissing<ApexComponentMaster>(false, out master);
			go.AddIfMissing<HumanoidSpeedComponent>(false);
			go.AddIfMissing<UnitComponent>(false);
			go.AddIfMissing<SteerableUnitComponent>(go, false);
			go.AddIfMissing<DefaultHeightNavigator>(go, false);
			go.AddIfMissing<PathOptionsComponent>(go, false);
			go.AddIfMissing<SteerToAlignWithVelocity>(go, false);
			go.AddIfMissing<SteerForPathComponent>(go, 5);
			go.AddIfMissing<PathVisualizer>(go, false);
			
*/
			
			Rigidbody r;
			this.gameObject.AddIfMissing<Rigidbody>(out r);

			ApexComponentMaster apexM; 
			HumanoidSpeedComponent hsc;
			PathOptionsComponent poc;
			UnitComponent uni;
			SteerToAlignWithVelocity steer;
			SteerForPathComponent sfp;
			WanderBehaviour wand;
			DefaultHeightNavigator dfn;
			SteerableUnitComponent suc;
			SpeedComponent sc;
			this.gameObject.AddIfMissing<ApexComponentMaster>(out apexM);
			
			this.gameObject.AddIfMissing<HumanoidSpeedComponent>(out hsc);
			
			this.gameObject.AddIfMissing<UnitComponent>(out uni);
			this.gameObject.AddIfMissing<SteerForPathComponent>(out sfp);
			this.gameObject.AddIfMissing<SteerableUnitComponent>(out suc);
			
			this.gameObject.AddIfMissing<DefaultHeightNavigator>(out dfn);
			this.gameObject.AddIfMissing<PathOptionsComponent>(out poc);
			this.gameObject.AddIfMissing<SteerToAlignWithVelocity>(out steer);
			
			this.gameObject.AddIfMissing<SpeedComponent>(out sc);
			apexMain = this.GetComponent<IMovingObject> ();
			if(apexMain==null) {
				apexMain = gameObject.AddComponent<SteerableUnitComponent>();
			}
			apexM.ToggleAll();
			
			unit = this.GetUnitFacade (true);
			this.gameObject.AddIfMissing<WanderBehaviour>(out wand);
			anim = this.GetComponentInChildren<Animator> ();
			steerable = (SteerableUnitComponent) apexMain;
			
			suc.enabled = true;
			sc.enabled = true;
			uni.enabled = true;
			poc.enabled = true;
			dfn.enabled = true;
			sfp.enabled = true;
			steer.enabled = true;
			apexM.enabled = true;

			
			BattleMonster m = this.GetComponentInChildren<BattleMonster> ();
			if (m != null) {
				Destroy (m);
			}
			#if (UNITY_EDITOR)
			}
			#endif
		player = GameObject.FindGameObjectWithTag ("Player");
		wander = GetComponent<WanderBehaviour> ();
		StartCoroutine(toggleOnOffRootMotion());
	} 
 public TriggeredEventArgs(int index, IMovingObject movingObject, GameTime gameTime)
 {
     Index  = index;
     Object = movingObject;
     Time   = gameTime;
 }
 public abstract void Update(IMovingObject movingObject, GameTime gameTime);
Esempio n. 13
0
 public TriggeredEventArgs(int index, IMovingObject movingObject, GameTime gameTime)
 {
     Index = index;
     Object = movingObject;
     Time = gameTime;
 }
Esempio n. 14
0
 protected void Trigger(int index, IMovingObject movingObject, GameTime gameTime)
 {
     if (Triggered != null)
         Triggered(this, new TriggeredEventArgs(index, movingObject, gameTime));
 }
Esempio n. 15
0
 public abstract void Update(IMovingObject movingObject, GameTime gameTime);