Beispiel #1
0
        public void Update()
        {
            int currentTile = level.GetTileID(position);


            if (Raylib.IsKeyDown(KeyboardKey.KEY_LEFT))
            {
                direction = new Vector2(-1, 0);
            }
            if (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT))
            {
                direction = new Vector2(1, 0);
            }
            if (Raylib.IsKeyDown(KeyboardKey.KEY_UP))
            {
                direction = new Vector2(0, -1);
            }
            if (Raylib.IsKeyDown(KeyboardKey.KEY_DOWN))
            {
                direction = new Vector2(0, 1);
            }

            //trying to get my head around this
            //once we reach endTile, we are resetting lerptime
            //this sets the startTile to the new Currenttile.
            //end tile is now set to the next tile

            //what is happening when there is now end tile set?
            //there will always be an end tile set, it's just that the player speed = 0


            lerpTime += Raylib.GetFrameTime() * speed;
            if (lerpTime > 1 || speed == 0.0f)
            {
                lerpTime     = 0;
                startTilePos = GetCurrentTilePos();
                endTilePos   = GetNextTilePos();

                var endTileValue = level.GetTileValue(endTilePos);

                speed = maxSpeed;
                if (endTileValue == TileType.WALL)
                {
                    speed = 0.0f;
                }
            }

            position = Vector2.Lerp(startTilePos, endTilePos, lerpTime);

            int newCurrentTile = level.GetTileID(position);

            if (currentTile != newCurrentTile)
            {
                OnTileEnter(newCurrentTile);
            }
        }
Beispiel #2
0
        public void Update()
        {
            int currentTile = level.GetTileID(position);

            //trying to get my head around this
            //once we reach endTile, we are resetting lerptime
            //this sets the startTile to the new Currenttile.
            //end tile is now set to the next tile

            //what is happening when there is now end tile set?
            //there will always be an end tile set, it's just that the player speed = 0
            //}

            lerpTime += Raylib.GetFrameTime() * speed;
            if (lerpTime > 1)
            {
                //get current location
                int row = level.GetYPosToRow(position.Y);
                int col = level.GetXPosToCol(position.X);

                //list of avail dirs
                List <Vector2> availDirs = new List <Vector2>();

                //work out what possible directions there are
                //is tileVal of tileUp/Down/Left/Right != TileType.WALL add to list if true
                if (level.GetTileValue(row + 1, col) != TileType.WALL)
                {
                    availDirs.Add(new Vector2(0, 1));
                }
                if (level.GetTileValue(row - 1, col) != TileType.WALL)
                {
                    availDirs.Add(new Vector2(0, -1));
                }
                if (level.GetTileValue(row, col - 1) != TileType.WALL)
                {
                    availDirs.Add(new Vector2(-1, 0));
                }
                if (level.GetTileValue(row, col + 1) != TileType.WALL)
                {
                    availDirs.Add(new Vector2(1, 0));
                }

                //randomly select an availDir
                int randomDirection = rand.Next(0, availDirs.Count);
                direction = availDirs.Count == 0 ? new Vector2(0, 0) : availDirs[randomDirection];

                lerpTime     = 0;
                startTilePos = GetCurrentTilePos();
                endTilePos   = GetNextTilePos();

                var endTileValue = level.GetTileValue(endTilePos);
                Console.WriteLine(endTileValue);
            }

            position = Vector2.Lerp(startTilePos, endTilePos, lerpTime);

            int newCurrentTile = level.GetTileID(position);

            if (currentTile != newCurrentTile)
            {
                OnTileEnter(newCurrentTile);
            }
        }