Exemple #1
0
        void RunningInit(TortugaStates previous)
        {
            _tortuga.GetComponent <APhysics>().maxSpeed = 15f;
            vanishingStateTask = TaskScheduler.AddTask(() => Init(TortugaStates.Vanishing), vanishingTime, vanishingTime, _tortuga.id);

            //
            // Choose a direction away from the player.
            //

            Action directionChooser = () =>
            {
                var player = GameObjectManager.FindObjectWithTag("player");
                if (player != null)
                {
                    var awayDir = _tortuga.transform.position - player.transform.position;

                    // Find a random direction vector that is the direction away from the player rotated
                    // by at most 90 or -90 degrees, making sure that the resulting vector is still facing
                    // away from the player.
                    var randAngle = GameManager.random.NextDouble() * Math.PI - Math.PI / 2;
                    _tortuga.transform.direction = new Vector2(
                        awayDir.X * (float)Math.Cos(randAngle) - awayDir.Y * (float)Math.Sin(randAngle),
                        awayDir.X * (float)Math.Sin(randAngle) + awayDir.Y * (float)Math.Cos(randAngle));
                }
            };

            directionChooser();

            directionChooserTask = TaskScheduler.AddTask(directionChooser, changeDirectionTime, -1, _tortuga.id);
        }
        void OpenedStateInit(string previous)
        {
            TaskScheduler.AddTask(() => {
                GameObjectManager.AddObject(
                    new Explosion(
                        this.transform.position + new Vector2(
                            8 + (float)GameManager.random.NextDouble() * 8 - 4,
                            8 + (float)GameManager.random.NextDouble() * 8 - 4)));
                ((Camera)GameObjectManager.FindObjectWithTag("camera"))?.AddShake(0.1);
            },
                                  0.3, 1.8, this.id
                                  );

            TaskScheduler.AddTask(() => {
                done = true;
                for (int i = 0; i < 4; i += 1)
                {
                    GameObjectManager.AddObject(
                        new Explosion(
                            this.transform.position + new Vector2(
                                8 + (float)GameManager.random.NextDouble() * 8 - 4,
                                8 + (float)GameManager.random.NextDouble() * 8 - 4)));
                }
                ((Camera)GameObjectManager.FindObjectWithTag("camera"))?.AddShake(0.4);

                //
                // Remove map cell.
                //

                var celPos = util.CorrespondingCelIndex(this.transform.position);
                GameManager.pico8.Memory.Mset((int)celPos.X, (int)celPos.Y, 0);
            },
                                  2, 2, this.id
                                  );
        }
Exemple #3
0
        void RunningState(GameTime gameTime)
        {
            var player = GameObjectManager.FindObjectWithTag("player");

            if (player != null &&
                Vector2.Dot(_tortuga.transform.position - player.transform.position, _tortuga.transform.direction) < 0)
            {
                var awayDir = _tortuga.transform.position - player.transform.position;

                // Find a random direction vector that is the direction away from the player rotated
                // by at most 90 or -90 degrees, making sure that the resulting vector is still facing
                // away from the player.
                var randAngle = GameManager.random.NextDouble() * Math.PI - Math.PI / 2;
                _tortuga.transform.direction = new Vector2(
                    awayDir.X * (float)Math.Cos(randAngle) - awayDir.Y * (float)Math.Sin(randAngle),
                    awayDir.X * (float)Math.Sin(randAngle) + awayDir.Y * (float)Math.Cos(randAngle));

                if ((player.transform.position - _tortuga.transform.position).LengthSquared() > 1000)
                {
                    Init(TortugaStates.Wondering);
                    TaskScheduler.RemoveTask(vanishingStateTask);
                    TaskScheduler.RemoveTask(directionChooserTask);
                }
            }
        }
		private void FollowingStateUpdate(GameTime gameTime) {
			Vector2 targetPosition = this.transform.position;
			var gate = GameObjectManager.FindObjectWithTag("gate");
			if (gate != null &&
					util.CorrespondingMapIndex(gate.transform.position) == util.CorrespondingMapIndex(transform.position)) {
				targetPosition = (gate.collisionBox == null ? gate.transform.position : gate.collisionBox.middle) - colMiddle;
			}
			else {
				var player = GameObjectManager.FindObjectWithTag("player");
				if (player != null) {
					targetPosition = (player.collisionBox == null ? player.transform.position : player.collisionBox.middle) - colMiddle;
				}
			}

			//
			// Go to position
			//

			Vector2 finalPos = new Vector2();

			finalPos.X = Misc.util.Lerp(
					transform.position.X,
					targetPosition.X,
					(transform.position.X - targetPosition.X) * followingSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
			finalPos.Y = Misc.util.Lerp(
					transform.position.Y,
					targetPosition.Y,
					(transform.position.Y - targetPosition.Y) * followingSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);

			transform.position = finalPos;
		}
        public override void OnCollision(GameObject other)
        {
            base.OnCollisionEnter(other);

            if (doesDamage && other.tags.Contains("player"))
            {
                var inflicted = ((Player)other).TakeHit(damage);
                if (inflicted <= 0)
                {
                    return;
                }

                var repelDir = Vector2.Zero;

                if (transform.direction == Vector2.Zero)
                {
                    // if enemy is still, try to use the other GO's direction.
                    if (other.transform.direction == Vector2.Zero)
                    {
                        var dir = other.transform.position - transform.position;

                        // First try to use the direction between the two GOs
                        // positions. If that is zero, use the other GO's
                        // facing direction.
                        if (dir == Vector2.Zero)
                        {
                            var physics = other.GetComponent <APhysics>();
                            if (physics != null)
                            {
                                repelDir = -physics.facingDirection;
                            }
                        }
                        else
                        {
                            dir.Normalize();
                            repelDir = dir;
                        }
                    }
                    else
                    {
                        repelDir = -other.transform.direction;
                    }
                }
                else
                {
                    repelDir = transform.direction;
                }

                other.GetComponent <APhysics>().velocity = repelDir * repelSpeed;
                timePiecesSpawned = TimePiece.SpawnParticles(
                    (int)inflicted, other.collisionBox == null ? other.transform.position : other.collisionBox.middle,
                    null,
                    8);

                ((Camera)GameObjectManager.FindObjectWithTag("camera")).AddShake(0.1);
            }
        }
Exemple #6
0
        void StillStateUpdate(GameTime gameTime)
        {
            var player = GameObjectManager.FindObjectWithTag("player");

            if (player != null && (player.transform.position - transform.position).LengthSquared() < 1000)
            {
                InitState("Following");
            }
        }
Exemple #7
0
        void WonderingInit(GooseStates previous)
        {
            var physics = _goose.GetComponent <APhysics>();

            if (physics != null)
            {
                physics.maxSpeed = _goose.baseSpeed;
            }

            _goose.transform.direction = Vector2.Zero;

            Action wonderingDirFunc = () =>
            {
                // Find a random direction vector that is the direction away from the player rotated
                // by at most 90 or -90 degrees, making sure that the resulting vector is still facing
                // away from the player.
                var randAngle = GameManager.random.NextDouble() * 2 * Math.PI;
                targetDir = new Vector2((float)Math.Sin(randAngle), (float)Math.Cos(randAngle));
                targetDir.Normalize();

                Debug.Log($"{_goose.GetType().FullName} Wondering State direction angle is {randAngle}");

                targetPosition = _goose.transform.position + targetDir * 20;
            };

            wonderingDirTask = TaskScheduler.AddTask(wonderingDirFunc, changeDirTime, -1, _goose.id);

            //
            // Choose a direction away from the player at first.
            //

            var p = GameObjectManager.FindObjectWithTag("player");

            if (p != null)
            {
                var awayDir = _goose.transform.position - p.transform.position;

                // Find a random direction vector that is the direction away from the player rotated
                // by at most 90 or -90 degrees, making sure that the resulting vector is still facing
                // away from the player.
                var randAngle = GameManager.random.NextDouble() * Math.PI - Math.PI / 2;
                targetDir = new Vector2(
                    awayDir.X * (float)Math.Cos(randAngle) - awayDir.Y * (float)Math.Sin(randAngle),
                    awayDir.X * (float)Math.Sin(randAngle) + awayDir.Y * (float)Math.Cos(randAngle));
                targetDir.Normalize();

                Debug.Log($"{_goose.GetType().FullName} Wondering State direction angle is {randAngle}");

                targetPosition = _goose.transform.position + targetDir * 10;
            }
        }
Exemple #8
0
        public override void OnCollision(GameObject other)
        {
            base.OnCollision(other);

            if (other.tags.Contains("attackable"))
            {
                //
                // TODO(matheusmortatti) remove time from enemy and give to the player.
                //

                var inflicted = ((Enemy)other).TakeHit(Damage);
                if (inflicted <= 0)
                {
                    return;
                }

                //
                // Camera shake, brief pause and time particles.
                //

                ((Camera)GameObjectManager.FindObjectWithTag("camera"))?.AddShake(0.1);

                if (other.lifeTime <= 0)
                {
                    GameObjectManager.AddPause(0.2f);
                }

                TimePiece.SpawnParticles((int)Math.Ceiling(inflicted / timeGivenAdjustment), other.collisionBox == null ? other.transform.position : other.collisionBox.middle, GameObjectManager.playerInstance);

                Debug.Log($"Damage Inflicted to {other.GetType().FullName} : {Math.Ceiling(inflicted).ToString()}");

                //
                // Add force to repel enemy.
                //

                Vector2 repelDir = transform.direction;

                var physics = other.GetComponent <APhysics>();
                if (physics == null)
                {
                    Debug.Log($"{other.GetType().FullName} does not have a physics component. Attacking it does not send it back.");
                }
                else
                {
                    physics.velocity = (repelDir * _repelSpeed);
                }
            }
        }
Exemple #9
0
        void WonderingState(GameTime gameTime)
        {
            var player = GameObjectManager.FindObjectWithTag("player");

            if (player != null && Vector2.Dot(player.GetComponent <APhysics>().facingDirection, player.transform.position - _goose.transform.position) >= 0 && GameManager.random.NextDouble() < 0.005)
            {
                Init(GooseStates.Following);
                TaskScheduler.RemoveTask(wonderingDirTask);
            }

            _goose.transform.direction = targetPosition - _goose.transform.position;

            if (Vector2.Dot(_goose.transform.direction, targetDir) < 0)
            {
                _goose.transform.direction = Vector2.Zero;
            }
        }
Exemple #10
0
        void WonderingState(GameTime gameTime)
        {
            _tortuga.transform.direction = targetPosition - _tortuga.transform.position;

            if (Vector2.Dot(_tortuga.transform.direction, targetDir) < 0)
            {
                _tortuga.transform.direction = Vector2.Zero;
            }

            var player = GameObjectManager.FindObjectWithTag("player");

            if (player != null && (player.transform.position - _tortuga.transform.position).LengthSquared() < 500)
            {
                Init(TortugaStates.Running);
                TaskScheduler.RemoveTask(targetPosTask);
            }
        }
Exemple #11
0
        public static void Draw()
        {
            GameObjectManager.DrawObjects();
            ParticleManager.Draw();

            ((Camera)GameObjectManager.FindObjectWithTag("camera"))?.ResetCamera();

            if (Debug.debugMode)
            {
                pico8.Graphics.Rectfill(3, 119, 64, 125, 0);
                pico8.Graphics.Print(framerate.ToString("0.##"), 4, 120, 14);
                pico8.Graphics.Print(GameObjectManager.numberOfObjects, 32, 120, 14);
                pico8.Graphics.Print(TaskScheduler.numberOfTasks, 42, 120, 14);
                pico8.Graphics.Print(ParticleManager.numberOfParticles, 52, 120, 14);
            }

            ((Camera)GameObjectManager.FindObjectWithTag("camera"))?.RestoreCamera();
        }
        void FullInit(SpikeStates previous)
        {
            _spike.sprite.index = 122;

            for (int i = 0; i < particleNumber; i += 1)
            {
                var smoke =
                    new Smoke(_spike.transform.position + new Vector2(1 + GameManager.random.Next(6), GameManager.random.Next(6)));
                smoke.SetRadius(1, 1.5f);
                smoke.SetMaxMoveSpeed(10f + (float)GameManager.random.NextDouble() * 5f);
                smoke.SetRadiusDecreaseSpeed(3f + (float)GameManager.random.NextDouble());
                ParticleManager.AddParticle(smoke);
            }

            _spike.collisionBox = new Box(_spike.transform.position, new Vector2(6, 6), false, new Vector2(1, 1));

            ((Camera)GameObjectManager.FindObjectWithTag("camera"))?.AddShake(0.1);

            task = TaskScheduler.AddTask(() => Init(SpikeStates.Down), changeStateTime, changeStateTime, _spike.id);
        }
Exemple #13
0
        void FollowingState(GameTime gameTime)
        {
            var player = GameObjectManager.FindObjectWithTag("player");

            if (player == null)
            {
                return;
            }

            _goose.transform.direction = player.transform.position - _goose.transform.position;

            if ((player.transform.position - _goose.transform.position).LengthSquared() < 500)
            {
                Init(GooseStates.Still);
            }

            if (GameManager.random.NextDouble() < 0.05)
            {
                ParticleManager.AddParticle(new TextParticle(_goose.transform.position + new Vector2(-8, -8), "HONK", 7));
            }
        }
Exemple #14
0
        void ChasingState(GameTime gameTime)
        {
            var player = GameObjectManager.FindObjectWithTag("player");

            if (player == null)
            {
                return;
            }

            _goose.transform.direction = player.transform.position - _goose.transform.position;

            //if (Vector2.Dot(player.GetComponent<APhysics>().facingDirection, player.transform.position - _goose.transform.position) < 0)
            //{
            //    Init(GooseStates.Wondering);
            //}

            if (GameManager.random.NextDouble() < 0.05)
            {
                ParticleManager.AddParticle(new TextParticle(_goose.transform.position + new Vector2(-8, -8), "HONK", 7));
            }
        }
        public override void Draw()
        {
            base.Draw();

            var player = (Player)GameObjectManager.FindObjectWithTag("player");
            var camera = (Camera)GameObjectManager.FindObjectWithTag("camera");

            if (camera == null)
            {
                return;
            }

            camera.ResetCamera();

            var life = player == null ? 0 : Math.Floor(player.lifeTime);
            var digits = life.ToString().Length;
            int x1 = 4, y1 = 4, x2 = x1 + 3 * (int)digits + (int)digits - 1 + 3, y2 = y1 + 8;

            GameManager.pico8.Graphics.Rectfill(x1, y1, x2, y2, 0);
            GameManager.pico8.Graphics.Rect(x1, y1, x2, y2, 9);
            GameManager.pico8.Graphics.Print(life, x1 + 2, y1 + 2, 9);

            camera.RestoreCamera();
        }