public bool MoveSpritesheet(Spritesheet spritesheet, Direction direction, int speed, bool turn = true) { //if actor moving if (spritesheet.enableMovement) { if (turn) { TurnSpritesheet(spritesheet, direction); } if (!CollisionCheck(spritesheet, MoveRectangle(spritesheet.core, direction, speed))) { Vector2 destination = MoveVector(spritesheet.position, speed, spritesheet.direction); Player player = spritesheet as Player; if (player != null) { if (player.impassableTilesTag != null && !player.passable) { if (player.impassableTilesTag.Count > 0) { MapCell currentCell; if (direction == Direction.right || direction == Direction.down) { Vector2 checkingDestination = MoveVector(destination, player.bounds.Width, Direction.right); checkingDestination = MoveVector(checkingDestination, player.bounds.Height, Direction.down); currentCell = player.map.GetTileByPosition(checkingDestination, 0); } else { currentCell = player.map.GetTileByPosition(destination, 0); } if (currentCell != null) { if (currentCell.tags.Contains(player.impassableTilesTag[0])) { return(false); } } } } } spritesheet.StartAnimation(direction); spritesheet.position = destination; spritesheet.FixOutsideCollision(); return(true); } } return(false); }
public void Draw(SpriteBatch spriteBatch, Camera camera, bool low) { if (low) { //draw tilemap (low) tileMap.Draw(spriteBatch, camera.screenRect, camera.mapRect, true); //draw gameobjects foreach (GameObject gameObject in gameObjectList) { if (camera.InCamera(gameObject)) { Sprite sprite = gameObject as Sprite; if (sprite == null) { Window window = gameObject as Window; if (window != null) { if (window.offsetRect) { window.Draw(spriteBatch, camera.mapRect); } else { window.Draw(spriteBatch, new Rectangle()); } } Spritesheet spritesheet = gameObject as Spritesheet; if (spritesheet != null) { spritesheet.Draw(spriteBatch, camera.mapRect); } } else { sprite.Draw(spriteBatch, camera.mapRect); } } } } else { //draw tilemap (high) tileMap.Draw(spriteBatch, camera.screenRect, camera.mapRect, false); movementManager.DrawDebug(spriteBatch, camera.mapRect); } }
public void TurnSpritesheet(Spritesheet spritesheet, Direction direction) { spritesheet.view = direction; spritesheet.direction = direction; spritesheet.StartAnimation(direction, false); }