Exemplo n.º 1
0
 public void OnShutdown(ShutdownContext context)
 {
     if (context == ShutdownContext.Deactivate)
     {
         GameObj.DisposeLater();
     }
 }
Exemplo n.º 2
0
 public void OnUpdate()
 {
     if (GameObj.Children.Count() == 0)
     {
         GameObj.DisposeLater();
     }
 }
Exemplo n.º 3
0
 public void OnUpdate()
 {
     if (_timer >= Delay)
     {
         GameObj.DisposeLater();
     }
     _timer += Time.SPFMult * Time.TimeMult;
 }
Exemplo n.º 4
0
 void ICmpUpdatable.OnUpdate()
 {
     TimeLeft -= Time.DeltaTime;
     if (TimeLeft <= 0)
     {
         GameObj.DisposeLater();
     }
 }
Exemplo n.º 5
0
 void ICmpUpdatable.OnUpdate()
 {
     lifetimeCounter += Time.TimeMult * Time.SPFMult;
     if (lifetimeCounter > BulletLifetime) //Make sure bullet does not last forever.
     {
         GameObj.DisposeLater();
     }
 }
Exemplo n.º 6
0
 void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
 {
     if (HitEffect.IsAvailable)
     {
         Scene.AddObject(HitEffect.Res.Instantiate());
     }
     args.CollideWith.FireEvent(this, new DamageEvent(Damage, DamageType));
     GameObj.DisposeLater();
 }
Exemplo n.º 7
0
        protected void DestroyPickup()
        {
            GameObj.DisposeLater();
            var uiRenderer = GameObj.ParentScene.FindComponent <UiRenderer>();

            if (uiRenderer.PickupToShow == this)
            {
                uiRenderer.PickupToShow = null;
            }
        }
Exemplo n.º 8
0
        public void OnCollisionBegin(Component sender, CollisionEventArgs args)
        {
            var scoreComponent = Scene.Current.FindComponent <ScoreComponent>();

            if (scoreComponent != null)
            {
                scoreComponent.IncreaseScore(1);
            }
            GameObj.DisposeLater();
        }
Exemplo n.º 9
0
        void ICmpUpdatable.OnUpdate()
        {
            if (CurrentHealth > MaxHealth)
            {
                CurrentHealth = MaxHealth;
            }

            if (CurrentHealth <= 0)
            {
                GameObj.DisposeLater();
            }
        }
Exemplo n.º 10
0
        public void OnUpdate()
        {
            GameObj.Transform.MoveBy(Vector2.UnitY * 10 * Time.TimeMult);

            if (GameObj.Transform.Pos.Y > 550)
            {
                if (active)
                {
                    Scene.Current.FindGameObject <MissText>(false).GetComponent <MissText>().Activate();
                }
                GameObj.DisposeLater();
            }
        }
Exemplo n.º 11
0
        void PickedUpByPlayer()
        {
            var gameManager = GameObj.ParentScene.FindComponent <GameManager> ();

            if (gameManager != null)
            {
                gameManager.PlayerPickup(Count, type);
            }
            else
            {
                Log.Game.WriteError("GameManager component is missing from scene!");
            }
            GameObj.DisposeLater();
        }
Exemplo n.º 12
0
        void ICmpCollisionListener.OnCollisionBegin(Component sender, CollisionEventArgs args)
        {
            if (args.CollideWith == Creator)
            {
                return; //Cancel the collision if it is with the creator of the bullet.
            }
            //We cast to RigidBodyCollisionEventArgs to get access to the info about the shapes involved.
            var rigidBodyArgs = args as RigidBodyCollisionEventArgs;

            if ((rigidBodyArgs != null) && rigidBodyArgs.OtherShape.IsSensor)
            {
                return;                                                               //Don't do anything if a sensor
            }
            EntityStats stats = args.CollideWith.GetComponent <EntityStats>();

            if (stats != null)
            {
                GameObj.DisposeLater();
                stats.CurrentHealth -= BulletDamage;
            }
        }
Exemplo n.º 13
0
 private void TimeExpire()
 {
     GameObj.DisposeLater();
 }
Exemplo n.º 14
0
 internal void DestroyProjectile()
 {
     GameObj.DisposeLater();
 }
Exemplo n.º 15
0
 public void OnLoaded()
 {
     Logs.Game.WriteWarning($"Transient component in GameObject {GameObj?.FullName ?? "<null>"} loaded.");
     GameObj?.DisposeLater();
 }
Exemplo n.º 16
0
        public void OnUpdate()
        {
            Logs.Game.Write(string.Format("dTime: {0}, Length: {1}, Expected max:{2}", Time.DeltaTime, (GameObj.Transform.Pos.Xy - previousPosition.Xy).Length, _rigidbody.LinearVelocity.Length * Time.TimeMult * 1.25));
            //Only check for world collisions if we've gone a short way.  Going further was due to a world loop.
            if ((GameObj.Transform.Pos.Xy - previousPosition.Xy).Length < _rigidbody.LinearVelocity.Length * Time.TimeMult * 1.25)
            {
                //Feel for whether we've impacted!
                //Rather than try to figure out where we need to cast to based on bullet size and position realtive to the sprite and delta time, and speed, and and and and...
                //just cheat and see if we did impact.  So we might be a frame late...  but seriously, this is a game jam.  It'll be okay.
                RayCastData hit;
                if (RigidBody.RayCast(previousPosition.Xy, GameObj.Transform.Pos.Xy, (data) => data.Body.CollisionCategory == CollisionCategory.Cat1 ? 1 : -1, out hit))
                {
                    if (hit.Body != null)
                    {
                        if (hit.Body.CollisionCategory == CollisionCategory.Cat1)
                        {
                            var projectile = GameObj.GetComponent <Projectile>();
                            if (projectile != null)
                            {
                                var response = projectile.WorldImpact(hit.Normal);
                                switch (response)
                                {
                                case ProjectileImpactResponse.DestroyProjectile:
                                    GameObj.DisposeLater();
                                    break;

                                case ProjectileImpactResponse.Bounce:
                                    var rigidbody = this.GameObj.GetComponent <RigidBody>();
                                    if (hit.Normal.X != 0)
                                    {
                                        //Left /  right
                                        rigidbody.LinearVelocity = new Vector2(-rigidbody.LinearVelocity.X, rigidbody.LinearVelocity.Y);
                                    }

                                    if (hit.Normal.Y != 0)
                                    {
                                        //up /  down
                                        rigidbody.LinearVelocity = new Vector2(rigidbody.LinearVelocity.X, -rigidbody.LinearVelocity.Y);
                                    }

                                    GameObj.Transform.Pos = previousPosition;
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }

                    //_log
                    //    .DrawCircle(Vector3.Zero, hit.Body.BoundRadius)
                    //    .AnchorAt(hit.GameObj)
                    //    .WithColor(ColorRgba.Green.WithAlpha(128));

                    //Rect hitShapeRect = hit.Shape.AABB;
                    //_log
                    //    .DrawCircle(new Vector3(hitShapeRect.Center), hitShapeRect.BoundingRadius - hitShapeRect.Center.Length)
                    //    .AnchorAt(hit.GameObj)
                    //    .WithColor(ColorRgba.Blue.WithAlpha(128));

                    //_log
                    //    .DrawConnection(previousPosition, hit.Pos)
                    //    .WithColor(ColorRgba.Red);
                    //_log
                    //    .DrawVector(new Vector3(hit.Pos), hit.Normal * 25)
                    //    .WithColor(ColorRgba.Red);
                }
                else
                {
                    //_log.DrawConnection(previousPosition, GameObj.Transform.Pos.Xy);
                }
            }
            previousPosition = GameObj.Transform.Pos;


            if (GameObj.Transform.Pos.X <= 0)
            {
                GameObj.Transform.Pos = new Vector3(GameObj.Transform.Pos.X + GameLevel.Instance.HumperWidth, GameObj.Transform.Pos.Y, GameObj.Transform.Pos.Z);
            }
            else
            {
                if (GameObj.Transform.Pos.X > GameLevel.Instance.HumperWidth)
                {
                    GameObj.Transform.Pos = new Vector3(GameObj.Transform.Pos.X - GameLevel.Instance.HumperWidth, GameObj.Transform.Pos.Y, GameObj.Transform.Pos.Z);
                }
            }

            if (GameObj.Transform.Pos.Y <= -GameLevel.Instance.HumperHeight)
            {
                GameObj.Transform.Pos = new Vector3(GameObj.Transform.Pos.X, GameObj.Transform.Pos.Y + GameLevel.Instance.HumperHeight, GameObj.Transform.Pos.Z);
            }
            else
            {
                if (GameObj.Transform.Pos.Y >= 0)
                {
                    GameObj.Transform.Pos = new Vector3(GameObj.Transform.Pos.X, GameObj.Transform.Pos.Y - GameLevel.Instance.HumperHeight, GameObj.Transform.Pos.Z);
                }
            }
        }