Ejemplo n.º 1
0
        // TEMP
        // TODO: A* algorithm if there will ever be obstacles
        // TODO: (futuro) algoritmo intelligente che mette in conto dove sta andando il player
        private void Follow(Player player)
        {
            // regga tangente per due punti (x - player.x) / (this.x - player.x) = (y - player.y) / (this.y - player.y)

            var playerV = new Vector2(player.x, player.y);
            var agentV = new Vector2(x, y);
            var paddingV = new Vector2(10, 10);
            //List<Vector> points = new List<Vector> ();
            var distance = (int) ((playerV - agentV).Length*2); // sucks
            double bestDelta = engine.width; // flag?
            nextStep = new Vector2();
            for (var i = 0; i <= distance; i++)
            {
                var newPoint = (playerV - agentV)*((float) i/distance) + agentV;
                //newPoint.X = (int)newPoint.X;
                //newPoint.Y = (int)newPoint.Y;
                //if (!points.Contains(newPoint)) // sucks
                //	points.Add (newPoint);
                double pointDelta = Math.Abs(level.speed - (newPoint - agentV).Length);
                // tries to get point closer to character's speed, usually is perfect or close to
                if (bestDelta > pointDelta)
                {
                    bestDelta = pointDelta;
                    nextStep = newPoint;
                    if (bestDelta <= MINBESTDELTA)
                    {
                        break;
                    }
                }
            }
            if (distance > 0)
            {
                //Console.WriteLine("{0} {1} {2} {3} {4}", playerV, agentV, nextStep, bestDelta, level.speed);
                var utopiaX = (nextStep.X - x);
                var utopiaY = (nextStep.Y - y);
                //if (utopiaX > (playerV.X - paddingV) && this.x < (playerV.X - paddingV))
                //	utopiaX = playerV.X - paddingV;
                virtPos.X = utopiaX*(deltaTicks/100f);
                virtPos.Y = utopiaY*(deltaTicks/100f);

                if (Math.Abs(virtPos.X) > 1)
                {
                    x += (int) virtPos.X;
                    virtPos.X -= (int) virtPos.X;
                }
                if (Math.Abs(virtPos.Y) > 1)
                {
                    y += (int) virtPos.Y;
                    virtPos.Y -= (int) virtPos.Y;
                }
            }
        }
Ejemplo n.º 2
0
        private void StartGame()
        {
            OnDestroyHelper((SpriteObject) engine.objects["logo"]);
            mainWindow = "game";

            player = new Player();
            player.x = 40;
            player.y = 40;
            player.currentSprite = (SpriteAsset) engine.GetAsset("player");
            engine.SpawnObject("player", player);

            var hud = new Hud();
            engine.SpawnObject("hud", hud);

            InitializeNewFloor();
        }