(version 1.0)
title Freeform Bal Ru's Curse
author Creative Windows [cloned by CHz]
homepage quiteajolt.com

run_rules_on_level_start


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

Background
Blue


Block1
Black
..0..
.000.
.000.
.000.
..0..

Block2
White
..0..
.000.
.000.
.000.
..0..

Block3
Black
.....
.000.
00000
.000.
.....

Block4
White
.....
.000.
00000
.000.
.....


Cursor
Orange
00.00
0...0
.....
0...0
00.00

LeftArrow
Orange
...0.
..00.
.000.
..00.
...0.

UpArrow
Orange
.....
..0..
.000.
00000
.....

RightArrow
Orange
.0...
.00..
.000.
.00..
.0...

DownArrow
Orange
.....
00000
.000.
..0..
.....


BlockStart
Transparent

BlockStorage
Transparent

WinToken
Green


=======
LEGEND
=======

. = Background

# = BlockStart
1 = Block1
2 = Block2
3 = Block3
4 = Block4
VertBlock = Block1 or Block2
HorizBlock = Block3 or Block4
Block = VertBlock or HorizBlock

@ = BlockStart and Cursor
Player = Cursor
Arrow = LeftArrow or UpArrow or RightArrow or DownArrow

- = BlockStorage


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

EndLevel 39733503
sfx0 13540905 (swap)


================
COLLISIONLAYERS
================

Background
BlockStorage WinToken
BlockStart Block
Arrow
Cursor


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

(================
 LEVEL GENERATION
 ================)

(Randomly place 4 of each block. I could make this nicer and generalize it to different grid sizes with a loop but nah.)
random [BlockStart] -> [Block1]
random [BlockStart] -> [Block1]
random [BlockStart] -> [Block1]
random [BlockStart] -> [Block1]
random [BlockStart] -> [Block2]
random [BlockStart] -> [Block2]
random [BlockStart] -> [Block2]
random [BlockStart] -> [Block2]
random [BlockStart] -> [Block3]
random [BlockStart] -> [Block3]
random [BlockStart] -> [Block3]
random [BlockStart] -> [Block3]
random [BlockStart] -> [Block4]
random [BlockStart] -> [Block4]
random [BlockStart] -> [Block4]
random [BlockStart] -> [Block4]


(===============
 PLAYER MOVEMENT
 ===============)

(If the player has arrows up but moves in a different direction, clear the arrows.)
[Arrow] [> Player | no Arrow] -> [] [> Player | no Arrow]

(Cancel movement if the player tries to move outside of the grid.)
[> Cursor | no Block] -> [Cursor | no Block]

(If the player moves in the direction of an arrow, swap the blocks and clear the arrows.)
[Arrow | > Cursor | Arrow] -> [ | > Cursor | Arrow]
[> Cursor Block | Arrow] [BlockStorage] -> [> Cursor | Arrow] [BlockStorage Block]
[> Cursor | Arrow Block] -> [> Cursor Block | Arrow]
[> Cursor | Arrow] [BlockStorage Block] -> [> Cursor | Arrow Block] [BlockStorage]
[> Cursor | Arrow] -> [ | Cursor] sfx0 (switch this rule with the one below it to keep the cursor active after the block moves)
([> Cursor | Arrow] -> [ | Action Cursor] sfx0)


(==============
 PLAYER ACTIONS
 ==============)

(If the player doesn't have arrows up and hits action, then pop up the appropriate arrows.) 
UP [no Arrow | Action Player VertBlock | no Arrow] -> [DownArrow | Player VertBlock | UpArrow]
[Arrow no Block] -> []
RIGHT [no Arrow | Action Player HorizBlock | no Arrow] -> [LeftArrow | Player HorizBlock | RightArrow]
[Arrow no Block] -> []

(If the player does have arrows up and hits action, then clear the arrows.)
[Action Player] [Arrow] -> [Action Player] []


(============
 WIN CHECKING
 ============)

(Check that all four blocks in a row or column are the same.)
[WinToken] -> []
[Block1 | Block1 | Block1 | Block1] -> [Block1 WinToken | Block1 WinToken | Block1 WinToken | Block1 WinToken]
[Block2 | Block2 | Block2 | Block2] -> [Block2 WinToken | Block2 WinToken | Block2 WinToken | Block2 WinToken]
[Block3 | Block3 | Block3 | Block3] -> [Block3 WinToken | Block3 WinToken | Block3 WinToken | Block3 WinToken]
[Block4 | Block4 | Block4 | Block4] -> [Block4 WinToken | Block4 WinToken | Block4 WinToken | Block4 WinToken]


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

All Block on WinToken


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

message Sort the blocks so each row of the grid contains only the same type of block. (Or you can sort by column.)
message Move the cursor with the arrow keys and press X to select a block. Swap that block with one next to it using the arrow keys or hit X to cancel.
message Long blocks can only move horizontally, and tall blocks can only move vertically.
message Press R to reset with a new puzzle.

-.....
.@###.
.####.
.####.
.####.
......