Irrigation Path Game - Visual Code

Sprite: GameController

Script: Initialize Game
when green flag clicked
set currentLevel to 1
hide variable temp_tileCostumeName
hide variable temp_tileCorrectRotation
hide variable temp_tileIsInteractive
hide variable temp_myTileID
Hide temporary variables used only during cloning.
broadcast setupLevel and wait
Script: Setup Level Grid
when I receive setupLevel
delete all clones of PathTile
set correctTilesCount to 0
set totalInteractiveTilesInLevel to 0
Reset counters for this level.
--- Define Level Data (Puzzle Info Only) ---
if
currentLevel = 1
then
set levelData to
list
Format: [CostumeName, CorrectAngle, IsInteractive]
list "curved" 90 true
list "straight" 0 true
list "curved" 0 true
list "straight" 90 true
list "empty_r" 0 false
list "straight" 90 true
list "curved" 180 true
list "straight" 0 true
list "curved" 270 true
else if
currentLevel = 2
then
--- Define levelData for level 2 here ---
--- Calculate total interactive tiles for win condition ---
set i to 1
repeat
length of levelData
set tileInfo to
item i of levelData
if
item 3 of tileInfo
= true
then
change totalInteractiveTilesInLevel by 1
change i by 1
--- Tile Creation Loop (Using ID system) ---
set tileIndexInLevelData to 1
This index becomes the Tile ID
repeat
length of levelData
set currentPuzzleInfo to
item tileIndexInLevelData of levelData
set temp_tileCostumeName to
item 1 of currentPuzzleInfo
set temp_tileCorrectRotation to
item 2 of currentPuzzleInfo
set temp_tileIsInteractive to
item 3 of currentPuzzleInfo
set temp_myTileID to tileIndexInLevelData
Pass ID to clone
create clone of PathTile
change tileIndexInLevelData by 1
Script: Check Win Condition
when I receive checkWinCondition
if
correctTilesCount = totalInteractiveTilesInLevel >
then
--- LEVEL COMPLETE! ---
broadcast animateWaterFlow
wait 1.5 secs
broadcast levelComplete
Script: Go to Next Level
when I receive levelComplete
change currentLevel by 1
Optional: Check if game is over
if
currentLevel > 2
then
Assuming 2 levels for now
say You Won! for 3 secs
stop [all v]
broadcast setupLevel

Sprite: PathTile

Script: Hide Template
when green flag clicked
hide
Script: Clone Initialization & Positioning
when I start as a clone
Sprite-Local Vars: myTileID, myBaseCostumeName, myCorrectAngle, myCurrentAngle, isInteractive, isCorrect
1. Copy data from GameController temps
set myTileID to temp_myTileID
set myBaseCostumeName to temp_tileCostumeName
set myCorrectAngle to temp_tileCorrectRotation
set isInteractive to temp_tileIsInteractive
2. Position self based on myTileID (Hardcoded)
if
myTileID = 1
then
R1,C1
go to x: -80 y: 80
else if
myTileID = 2
then
R1,C2
go to x: 0 y: 80
else if
myTileID = 3
then
R1,C3
go to x: 80 y: 80
else if
myTileID = 4
then
R2,C1
go to x: -80 y: 0
else if
myTileID = 5
then
R2,C2
go to x: 0 y: 0
else if
myTileID = 6
then
R2,C3
go to x: 80 y: 0
else if
myTileID = 7
then
R3,C1
go to x: -80 y: -80
else if
myTileID = 8
then
R3,C2
go to x: 0 y: -80
else if
myTileID = 9
then
R3,C3
go to x: 80 y: -80
3. Set base costume
switch costume to myBaseCostumeName
4. Set initial rotation
if isInteractive then
set myCurrentAngle to
pick random 0 to 3
* 90
else
set myCurrentAngle to myCorrectAngle
point in direction myCurrentAngle
5. Initialize correct status & check
set isCorrect to false
run checkMyOrientation_Simplified
Use custom block
6. Show self
show
Script: Player Interaction
when this sprite clicked
if isInteractive then
change myCurrentAngle by 90
set myCurrentAngle to
myCurrentAngle mod 360
Keep angle 0-359
point in direction myCurrentAngle
run checkMyOrientation_Simplified
broadcast checkWinCondition
Custom Block: checkMyOrientation_Simplified
define checkMyOrientation_Simplified
Directly compare angles (0, 90, 180, 270).
if
myCurrentAngle = myCorrectAngle >
then
TILE IS NOW CORRECT
if
not isCorrect
then
Was it previously incorrect?
set isCorrect to true
change correctTilesCount by 1
else
TILE IS NOW INCORRECT
if isCorrect then
Was it previously correct?
set isCorrect to false
change correctTilesCount by -1
Script: Animate Water Flow (Optional)
when I receive animateWaterFlow
if isCorrect then
Add visual effect here, e.g., switch to filled costume or temporary effect
set [ghost v] effect to 30
wait 0.5 secs
clear graphic effects