Skip to content

Instantly share code, notes, and snippets.

@jcmiller11
Created June 19, 2022 17:29
Show Gist options
  • Select an option

  • Save jcmiller11/a620814c73261edfb4cee4bf70aa608e to your computer and use it in GitHub Desktop.

Select an option

Save jcmiller11/a620814c73261edfb4cee4bf70aa608e to your computer and use it in GitHub Desktop.
Wrapping Example (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
title Wrapping Example
author jcGyo
homepage www.puzzlescript.net
(IMPORTANT: The below directive allows us to run rules before the player performs any input)
run_rules_on_level_start
========
OBJECTS
========
(It's grass! Boring, boring grass.)
Background
lightgreen green
11111
01111
11101
11111
10111
(Here's our dude, you may recognize this dude from the built in puzzlescript examples)
Player
black orange white blue
.000.
.111.
22222
.333.
.3.3.
(This is my crate. There are many like it, but this one is mine.)
Crate
orange
00000
0...0
0...0
0...0
00000
(This is a wall, you may find them difficult to walk through, this fact can be confirmed by standing up and finding a nearby wall and attempting to walk through it)
Wall
grey darkgrey
01001
11111
00001
10011
11111
(Here's an invisible marker!
We're going to use it to make some rules only run on the first turn)
FirstTurn
transparent
(Below are the markers we'll use to make our "false border" around the level)
TopEdge
transparent
BotEdge
transparent
LeftEdge
transparent
RightEdge
transparent
=======
LEGEND
=======
. = Background
(We're placing our FirstTurn marker on top of the player, this way it will be there when the level starts playing since I assume you're always going to have a Player object in all of your levels)
P = Player and FirstTurn
* = Crate
0 = Wall
HorizontalEdges = TopEdge or BotEdge
VerticalEdges = LeftEdge or RightEdge
(A list of objects that Can be warped from one side of the screen to the other)
Warpable = Player or Crate
(A list of objects that can be pushed)
Pushable = Crate
(A list of objects that can stop things from being pushed)
BlocksPush = Crate or Wall
=======
SOUNDS
=======
================
COLLISIONLAYERS
================
Background
Player, Crate, Wall
(All of our markers get put on their own layers, this way they won't interfere with each other's movement nor will they delete each other if placed on the same block)
FirstTurn
TopEdge
BotEdge
LeftEdge
RightEdge
======
RULES
======
(If it's the first turn, place one of each edge marker on top of the first turn marker, which is also where the player is!)
[FirstTurn] -> [FirstTurn TopEdge BotEdge LeftEdge RightEdge]
(These rules will move each edge marker over to their corresponding edge.
Since PuzzleScript rules are hungry each of these will continue firing until the edge is reached)
UP [FirstTurn] [TopEdge |] -> [FirstTurn] [|TopEdge ]
DOWN [FirstTurn] [BotEdge |] -> [FirstTurn] [|BotEdge ]
LEFT [FirstTurn] [LeftEdge |] -> [FirstTurn] [|LeftEdge ]
RIGHT [FirstTurn] [RightEdge|] -> [FirstTurn] [|RightEdge]
(These two rules will duplicate each edge marker along the entire length of that edge)
HORIZONTAL [HorizontalEdges|no HorizontalEdges] -> [HorizontalEdges|HorizontalEdges]
VERTICAL [VerticalEdges |no VerticalEdges ] -> [VerticalEdges |VerticalEdges ]
(Now we delete the FirstTurn marker, having finished our book keeping for the first turn we can get rid of it to make sure the above rules no longer execute on subsequent turns!)
[FirstTurn] -> []
(Let the dude push that which can be pushed)
[> Player|Pushable] -> [> Player|> Pushable]
(If the dude pushes stuff over the edge, check for things that can be pushed in the way, if they can be, then push em!)
VERTICAL [HorizontalEdges Pushable|no BlocksPush|...|> Player HorizontalEdges] -> [HorizontalEdges Player|Pushable|...|HorizontalEdges]
HORIZONTAL [VerticalEdges Pushable|no BlocksPush|...|> Player VerticalEdges] -> [VerticalEdges Player|Pushable|...|VerticalEdges]
(If things that can be warped, such as dudes and pushables, go over the edge then warp them to the opposite one!)
VERTICAL [HorizontalEdges no BlocksPush|...|> Warpable HorizontalEdges] -> [HorizontalEdges Warpable|...|HorizontalEdges]
HORIZONTAL [VerticalEdges no BlocksPush|...|> Warpable VerticalEdges] -> [VerticalEdges Warpable|...|VerticalEdges]
(You may wonder why the above lines are separated into vertical and horizontal edges, and the reason can be shown by this example:
Suppose we tried to do the following
[AllEdges|...|> Player AllEdges] -> [AllEdges Player|...|AllEdges]
now suppose the player was standing on an edge such as the top edge
LTTPTTR
L.....R
L.....R
If they pressed right or left then the rule would still match since a left edge is an edge just like a top edge is, so [AllEdges| ... |AllEdges] would be true! The behavior of > is unfortunately less specific than we'd like here so the dude starts warping all over the place whenever input happens on an edge! If you can find a simpler way to avoid this issue please let me know!)
==============
WINCONDITIONS
==============
(The only true way to win the example is by mastering the techniques within)
=======
LEVELS
=======
.........
.*.......
..00P.*..
.00......
00.......
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment