Added Tile collision detection
This commit is contained in:
28
PuzzleTile.cs
Normal file
28
PuzzleTile.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Godot;
|
||||
|
||||
public partial class PuzzleTile : Sprite2D
|
||||
{
|
||||
// Public properties so the GameBoard can read/write them
|
||||
public int GridX { get; set; }
|
||||
public int GridY { get; set; }
|
||||
public bool IsMoving { get; private set; } = false;
|
||||
|
||||
private int _tileSize = 128;
|
||||
|
||||
// The board will call this method when it calculates a valid move
|
||||
public void SlideTo(int targetX, int targetY)
|
||||
{
|
||||
// Calculate distance for animation speed
|
||||
float distance = Mathf.Abs(targetX != GridX ? targetX - GridX : targetY - GridY) * _tileSize;
|
||||
float tweenDuration = distance / 600.0f;
|
||||
|
||||
GridX = targetX;
|
||||
GridY = targetY;
|
||||
Vector2 targetPixelPos = new Vector2(GridX * _tileSize, GridY * _tileSize);
|
||||
|
||||
IsMoving = true;
|
||||
Tween tween = CreateTween();
|
||||
tween.TweenProperty(this, "position", targetPixelPos, tweenDuration);
|
||||
tween.Finished += () => IsMoving = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user