Skip to content

Instantly share code, notes, and snippets.

@Draknek
Last active September 23, 2024 12:17
Show Gist options
  • Save Draknek/2eb3eea974f4d8bf6afcb8da4a5b5547 to your computer and use it in GitHub Desktop.
Save Draknek/2eb3eea974f4d8bf6afcb8da4a5b5547 to your computer and use it in GitHub Desktop.
Treasure Dive
https://puzzlescriptnext.polyomino.com/editor.html
// adding a grabber, partly implemented
title Treasure Dive
author Alan Hazelden & Andrew Shouldice
homepage alan.draknek.org
tween_length 0.1
//again_interval 0.075
realtime_interval 0.16
smoothscreen 15x9 5x3
//verbose_logging
// enable one-line comments
========
OBJECTS
========
Background
blue
NormalWall
darkred
Current:right
lightblue #1d3ff6
10111
11011
11101
11011
10111
Current:directions
lightblue #1d3ff6
copy: Current:right rot:right:directions
ToDissipate
lightblue
.....
..0..
.0.0.
..0..
.....
CurrentEmitter:right
darkred red
00000
00001
00001
00001
00000
CurrentEmitter:directions
darkred red
copy: CurrentEmitter:right rot:right:directions
Player
yellow
.000.
00000
00000
00000
.000.
WoodCrate
brown orange
00000
01110
01110
01110
00000
MetalCrate
darkgrey grey
00000
01110
01110
01110
00000
Mine
grey red
.0.0.
00000
.010.
00000
.0.0.
Wire
red
..0..
..0..
..0..
..0..
..0..
GrabberGrabbing
red
00000
0...0
0...0
.....
.....
GrabberDescending
red
copy: GrabberGrabbing
GrabberAscending
red
copy: GrabberGrabbing
ActiveCurrentBlocker
transparent
====
TAGS
====
=======
LEGEND
=======
. = Background
# = NormalWall
P = Player
* = WoodCrate
@ = MetalCrate
! = Mine
Wall = NormalWall or CurrentEmitter:directions
PushedByCurrent = Player or WoodCrate or Mine
PushedByPlayer = PushedByCurrent or MetalCrate
Solid = Wall or Player or PushedByPlayer or Mine
PushableCurrentBlocker = WoodCrate or MetalCrate
BlocksCurrent = Wall or ActiveCurrentBlocker
Grabbable = WoodCrate or MetalCrate or Mine
HasGravity = WoodCrate or MetalCrate
Grabber = GrabberGrabbing or GrabberDescending or GrabberAscending
a = CurrentEmitter:left
b = CurrentEmitter:right
c = CurrentEmitter:up
d = CurrentEmitter:down
(e = Current:left
f = Current:right
g = Current:up
h = Current:down)
=======
SOUNDS
=======
================
COLLISIONLAYERS
================
Background
Current:directions, ActiveCurrentBlocker
ToDissipate
Player, Wall, WoodCrate, MetalCrate, Mine
Wire, Grabber
======
RULES
======
// spawn new currents
[ CurrentEmitter:> no Current:directions ] -> [ CurrentEmitter:> Current:> ]
// If player is caught in current, don't let them move
[ moving Player Current:> | no Solid ] -> [ stationary Player Current:> | ]
// If player has active grabber, don't let them move
down [ moving Player | Wire ] -> [ stationary Player | Wire ]
down [ moving Player | GrabberAscending ] -> [ stationary Player | GrabberAscending ]
down [ moving Player | GrabberDescending ] -> [ stationary Player | GrabberDescending ]
// grabber
down [ stationary GrabberDescending | Wall ] -> [ action GrabberAscending | Wall ]
down [ stationary GrabberDescending | no Wall ] -> [ Wire | action GrabberDescending ]
down [ Player | stationary GrabberAscending Grabbable ] -> [ Player | GrabberGrabbing Grabbable ]
down [ Player | stationary GrabberAscending no Grabbable ] -> [ Player | ]
down [ Wire | stationary GrabberAscending Grabbable ] -> [ action GrabberAscending Grabbable | ]
down [ Wire | stationary GrabberAscending no Grabbable ] -> [ action GrabberAscending | ]
down [ action Player | no Grabber no Wall ] -> [ Player | action GrabberDescending ]
down [ action Player | GrabberGrabbing ] -> [ Player | ]
[ action GrabberDescending Grabbable ] -> [ action GrabberAscending Grabbable ]
// Push objects
[ > Player | PushedByPlayer ] -> [ > Player | > PushedByPlayer ]
[ > PushedByPlayer | PushedByPlayer ] -> [ > PushedByPlayer | > PushedByPlayer ]
// pushing/carrying things on current, and gravity
once [] -> gosub current_push
// redirect currents
[ stationary MetalCrate ] -> [ MetalCrate ActiveCurrentBlocker ] // non-falling metal crates block and redirect current
[ PushableCurrentBlocker Current:directions ] -> [ PushableCurrentBlocker ] // crates remove current on their tile
once [] -> gosub current_redirect
once [] -> gosub current_push
[ stationary WoodCrate ] -> [ WoodCrate ActiveCurrentBlocker ] // non-falling wood crates block and redirect current - then recalculate
once [] -> gosub current_redirect
[ > Current:> | BlocksCurrent ] -> [ | BlocksCurrent ] // this handles if we're blocked but don't have anything to the side to redirect
[ action Current:> PushedByCurrent ] -> [ Current:> > PushedByCurrent ]
[ action Current:> Wall ] -> [ Wall ]
// dissipate conflicting current
[ ToDissipate ] -> []
[ Current:> | no ToDissipate ] -> [ Current:> | < ToDissipate ]
[ Current:> | > ToDissipate ] -> [ Current:> | action ToDissipate ]
[ Current:> | perpendicular ToDissipate ] -> [ Current:> | action ToDissipate ]
[ Current:> | action ToDissipate ] -> [ | action ToDissipate no Current:directions ]
[ > ToDissipate ] -> []
// mark currents for movement
[ Current:> ] -> [ > Current:> ]
// cleanup
[ action Grabber ] -> [ Grabber ]
[ up Grabbable ] -> [ Grabbable ]
[ > PushableCurrentBlocker | Current:directions ] -> [ > PushableCurrentBlocker | ]
late [ ActiveCurrentBlocker ] -> []
subroutine current_push
[ stationary PushedByCurrent Current:> ] -> [ > PushedByCurrent Current:> ]
[ Current:> | stationary WoodCrate ] -> [ Current:> | > WoodCrate ]
[ > PushedByCurrent | stationary PushedByCurrent ] -> [ > PushedByCurrent | > PushedByCurrent ]
[ stationary HasGravity no Grabber ] -> [ down HasGravity ]
[ stationary HasGravity GrabberAscending ] -> [ up HasGravity GrabberAscending ]
startloop
[ > PushedByCurrent | stationary Solid ] -> [ action PushedByCurrent | Solid ]
down [ action WoodCrate | Current:< ] -> [ WoodCrate | Current:< ]
down [ action HasGravity | no Solid ] -> [ down HasGravity | ]
[ action PushedByCurrent ] -> [ PushedByCurrent ]
down [ > HasGravity | stationary Solid ] -> [ HasGravity | Solid ]
endloop
subroutine current_redirect
[ Current:> | BlocksCurrent ] -> [ > Current:> | BlocksCurrent ] // detect blocked current
[ perpendicular Current:perpendicular | BlocksCurrent ] -> [ < Current:perpendicular | BlocksCurrent ] // if current is blocked, try changing direction
[ > Current:perpendicular | BlocksCurrent ] -> [ | BlocksCurrent ] // if new direction is still blocked, current is blocked on 3 sides
[ > Current:perpendicular ] -> [ action Current:> ] // otherwise we can change direction
==============
WINCONDITIONS
==============
=======
LEVELS
=======
###############
#####..########
###...p.##...##
##......#..@.##
#b........##..#
#......##.....#
#............a#
#..##.......###
#####.......###
##....@...#####
##..###..######
##..#.#..##..##
##.....@......#
#......##.....#
#..##c###.....#
#....###.....##
#............a#
#..##...###..##
#####...#######
#####....#d####
#####..*...#..#
####...@......#
####...#.....##
#####.......###
######..#######
###############
// test levels
###############
#...*.@...*.###
#...@.##c.@.###
#...a.....#...#
#.....#.......#
#####.*.......#
#...a.#c......#
#[email protected].......#
############c##
###############
####......*.###
####......#.###
#.............#
#..*..........#
#..*.......!!!#
#..*..........#
#..*[email protected]
##c############
###############
#..#..###..#..#
#..#..###..#..#
#..#..###..#..#
#.............#
#......p......#
#...*...*.*...#
#.*.*.*.*.*.*.#
##c#c#c#c#c#c##
// undefined or unexpected behaviour
// When current is blocked by 2x wood crates, it doesn't push either
// - even if one could be pushed and one couldn't be
// Do we want this behaviour?
// If not, what is the intended behaviour?
// My instinct: in this specific scenario, both should be pushed
// (so bottom-left would push both, and then current would be unchanged, and bottom-right would push the one that can be pushed, and then current would redirect)
####d#####d####
##...........##
##...........##
##.*.@...@.@.##
####d##p##d####
##...........##
##...........##
##.*.*.##*.*.##
###############
// When wood crate hits two competing currents, the one that the crate was not in wins.
// Do we want this behaviour?
// If not, what is the intended behaviour?
###############
#b.*..###..*.a#
##.#.......#.##
#b...........a#
##..p........##
##...a#.#b...##
##...........##
##...*...*...##
###c#######c###
// When wood crate hits two competing currents, and one is upwards, it can bounce up and down
// Do we want this behaviour?
// If not, what is the intended behaviour?
######d#d######
##...........##
#b.*.......*.a#
##.#.......#.##
##..p#####...##
##...........##
#b.*.......*.a#
##.#.......#.##
######c#c######
// mini-puzzles
###############
#######....####
###..!......###
###.###.......#
#.....##..*.p.#
#.....##..*..##
#.....###c#####
###############
###############
#####.***....##
#####.#d#.....#
#####.#.#.....#
###........####
###...##....###
###.!.#..p..###
#######.....###
#######....####
###############
############
###...######
##.....#####
##.*...#####
#####.######
##.@*.....##
#..#d##....#
#..#.##....#
#.......####
##c##..p..##
#####.....##
#####....###
#####c######
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment