summaryrefslogtreecommitdiff
path: root/src/sokoban.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/sokoban.adb')
-rw-r--r--src/sokoban.adb35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/sokoban.adb b/src/sokoban.adb
index 16b646e..e70d1d6 100644
--- a/src/sokoban.adb
+++ b/src/sokoban.adb
@@ -8,6 +8,7 @@ with
Squares,
Things,
Moves,
+ Pathfinding,
Ada.Command_Line,
Ada.Directories,
Ada.Text_IO,
@@ -202,6 +203,39 @@ package body Sokoban is
+ function Mouseclick
+ (X, Y : in Integer)
+ return FLTK.Event_Outcome
+ is
+ Col, Row, DX, DY : Integer;
+ Movement : Moves.Path;
+ Temp : Squares.Square;
+ begin
+ My_Grid.Pixel_To_Colrow (X, Y, Col, Row);
+ if My_Grid.In_Bounds (Col, Row) then
+ Movement := Pathfinding.A_Star (My_Grid, Current_Man_X, Current_Man_Y, Col, Row);
+ Movement.Total_Delta (DX, DY);
+
+ Temp := My_Grid.Get_Square (Current_Man_X, Current_Man_Y);
+ Temp.Set_Contents (Things.Nothing);
+ My_Grid.Set_Square (Current_Man_X, Current_Man_Y, Temp);
+ Current_Man_X := Current_Man_X + DX;
+ Current_Man_Y := Current_Man_Y + DY;
+ Temp := My_Grid.Get_Square (Current_Man_X, Current_Man_Y);
+ Temp.Set_Contents (Things.Man);
+ My_Grid.Set_Square (Current_Man_X, Current_Man_Y, Temp);
+
+ Move_Record.Add (Movement);
+ My_Display.Set_Move_Number (Move_Record.Length);
+ My_Grid.Redraw;
+ return FLTK.Handled;
+ end if;
+ return FLTK.Not_Handled;
+ end Mouseclick;
+
+
+
+
-- Helper functions.
procedure Add_New_Grid_Item
@@ -342,6 +376,7 @@ begin
My_Display.Set_Grid (My_Grid);
My_Display.Set_Keyboard_Callback (Keypress'Access);
+ My_Display.Set_Mouse_Callback (Mouseclick'Access);
end Sokoban;