title Mouse Dragging Blocks
author Tom H.
homepage https://auroriax.github.io/PuzzleScript/Documentation/prelude.html#psplus

verbose_logging (Don't forget to use the visual debugger to see how mouse objects are created at the start of the turn)

mouse_left MouseClick
mouse_drag MouseDrag
(We don't use mouse_up here, instead we'll clean up the previous cursor whenever a new mouse_left object is detected. See the Rules.)

========
OBJECTS
========

background .
#222

(Even though we're not using it, every game requires a player defined)
player
green

Cursor
blue
00.00
0...0
.....
0...0
00.00

DragTarget
blue
.....
.....
..0..
.....
.....

MouseClick
pink
0...0
.0.0.
.....
.0.0.
0...0

MouseDrag
pink
0..0.
.0.0.
..00.
0000.
.....

BlockA A
red

BlockB B
orange

BlockC C
green

Wall #
#111

GoalA !
red #222
.....
.111.
.101.
.111.
.....

=======
LEGEND
=======
Block = BlockA or BlockB or BlockC

=======
SOUNDS
=======

================
COLLISIONLAYERS
================
background
MouseClick, MouseDrag
BlockA, BlockB, BlockC, Wall
player
GoalA

DragTarget
Cursor

======
RULES
======

(Whenever mouse is clicked, create cursor at that position)
[MouseClick] [Cursor] -> [MouseClick] []
[MouseClick] [DragTarget] -> [MouseClick] []
[MouseClick] -> [Cursor DragTarget]

(When mouse is dragged, actually add movement to cursor in this direction)
[Cursor] [DragTarget | MouseDrag] -> [> Cursor ] [ | DragTarget]

(Pass movement onto block rigidly, so they can't break apart. See documentation on Rigid Bodies for more info.)
rigid [> Cursor Block] -> [> Cursor > Block]
+ rigid [moving a |  a] -> [moving a | moving a]
+ rigid [moving b |  b] -> [moving b | moving b]
+ rigid [moving c |  c] -> [moving c | moving c]

(Clean up for the start of the next turn, in case these were not cleaned up by the other rules)
[MouseClick] -> []
[MouseDrag] -> []

==============
WINCONDITIONS
==============

all BlockA on GoalA

=======
LEVELS
=======

#########
#.....!!#
#.aa..!.#
#.a.b...#
#...b...#
#..cbc..#
#..ccc..#
#.......#
#########