Create puzzle games on Puzzle Script

 3r33055. 3r3-31. Puzzle Script is a minimalistic game engine for creating puzzles for HTML? has open source. Examples of ready-made games can be viewed here is . 3r33040.  3r33055. 3r33040.  3r33055.

Part 1. Create the first game on Puzzle Script.

3r33040.  3r33055. 3r31412. Puzzle Script
- is a free online program that is used to create puzzle games. She is best known for creating push puzzles like my The Nodus . In this part we will create a game by examining the basic functions of the Puzzle Script, and in the next we proceed to programming. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. Create puzzle games on Puzzle Script engine. Click Make a Game to open Puzzle editor Script . 3r33040.  3r33055. 3r3333.
3r33040.  3r33055.

Download examples

3r33040.  3r33055. First, let's look at a few examples. At the top of the screen, open the “Load Example” list and select the first example called “Basic”. Now click on “Run”. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r33051. 3r33040.  3r33055. The game screen will appear. Click inside its window and press Enter on the keyboard. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. Making the first game
3r33040.  3r33055. Now we will create several levels. I will create one with you, while others advise you to come up with it yourself. Click on “Level Editor” in the top menu. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. Create a new level
3r33040.  3r33055. At the top are game objects. When left-clicked, the selected object is drawn. Right-click renders the “background” object. Left click on the edge of the map increases its size, right click reduces it. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r3394. 3r33051. 3r33040.  3r33055. To complete a level, you need to put a box on each of the goals, so each level must have a minimum: 3r33040.  3r33055. 3r33040.  3r33055.
 3r33055. 3r33026. 1 box of 3r33027.  3r33055. 3r33026. 1 goal 3r33027.  3r33055. 3r33026. 1 player 3r33027.  3r33055. 3r33029. 3r33040.  3r33055. For now, right click will turn everything into grass. Then left-click on the edge of the level to make it bigger, and finally draw a level that looks like the one shown below. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. Add it to the list of levels
3r33040.  3r33055. Having finished creating the level, we will add it to the list of levels. In the level editor, click on the white letter S next to the list of game objects to save the created level. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r3133. 3r33051. 3r33040.  3r33055. A message about successful compilation and a grid of funny characters should appear under the level editor, as shown below. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r3143. 3r33051. 3r33040.  3r33055. These funny symbols represent the level we have just created. Each character represents a separate object. On the left side of the screen, go down and find LEGEND. The legend provides an explanation for each of the symbols: 3r33040.  3r33055. 3r33040.  3r33055.
3r32991. . = Background
3r33040.  3r33055. 3r32991. # = Wall
3r33040.  3r33055. 3r32991. P = Player
3r33040.  3r33055. 3r32991. * = Crate
3r33040.  3r33055. 3r32991. @ = Crate and Target
3r33040.  3r33055. 3r32991. O = Target
3r32994. 3r33040.  3r33055. All that is on the left side of the screen is the game code, divided into different parts, such as OBJECTS or LEGEND. Drop down to LEVELS. Here we see the levels that are used in the example. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r3182. 3r33051. 3r33040.  3r33055. To add a new level, create a new blank line at the bottom of the level section. Then copy the symbols generated for our level and paste them there. Everything, level is added. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r3191. 3r33051. 3r33040.  3r33055. Test it. After creating a new level, you need to press the “Run” button at the top of the screen again to restart the game with a new level. Sometimes it does not work, and then you need to click the "Rebuild" button, and then click "Run" again. 3r33040.  3r33055. 3r33040.  3r33055.

Save and load the game

3r33040.  3r33055. Try to create some more new levels. When you are ready to save the game, go up to the top of the code and enter your own name, author name and homepage, and then click on the “Save” button. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r3208. 3r33051. 3r33040.  3r33055. 3r33042. 3r33051. 3r33040.  3r33055. One of the links is the source code of your project. The second is a link to a playable version of the game that can be shared with friends. I recommend periodically creating a new link to the source code and saving it in some text document so that you have a permanently stored version of the project. 3r33040.  3r33055. 3r33040.  3r33055.

Exporting games

3r33040.  3r33055. You can also export the game as an html5 file, which you can then upload to game portals, for example, itch.io , Kongregate or Newgrounds . Just click "Export" and upload the downloaded html file to the game portal. 3r33040.  3r33055. 3r33040.  3r33055. Our sample project can be viewed here is . 3r33040.  3r33055. 3r33040.  3r33055.

Part 2. Starting to program in Puzzle Script

3r33040.  3r33055. In this part we will learn how to start programming in 3r33254. Puzzle Script
. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. Code
3r33040.  3r33055. Open example project . The program code is located on the left side of the screen, it is divided into parts: Objects, Legend, Sounds, etc. The Rules section defines the rules for the interaction of objects Go into it. There should be only one line of code:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | Crate ]->[> Player | > Crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. This line means that if a player is near the box and moves in his direction, the game moves the player and pushes the box. To explain how this works, you need to understand that the Puzzle Script code follows this structure:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[Условие ]->[Событие ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. This means the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[Если это условие выполняется ]-> then[Делать это ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. Puzzle Script checks if the conditions to the left of the arrow are true, for example, whether the player’s object is near the box object. If the condition is true, then we are doing something, for example, pushing the box. 3r33040.  3r33055. 3r33040.  3r33055.

Examples of conditions 3r333006. 3r33040.  3r33055. Here is an example of a condition: 3r33030.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[object1 | object2 ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. This event checks if object1 is near object2. You can check whether two objects are next to each other by placing 3r-32990 between them. 3r32991. direct | line
3r32993. entered by pressing shift +. Conditions are always enclosed in 3r32990. 3r32991. square[]brackets
3r32993. . 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[crate | crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. The code above checks to see if there are two boxes next to each other. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[crate | crate | crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. This condition checks if there are three boxes nearby. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[crate target ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. This condition checks whether the box is on top of the target, because 3r332320. 3r32991. straight | lines
3r32993. between two objects no. Objects can be on top of each other if they are located in different layers of collisions, which we will look at in the following parts of the tutorial. 3r33040.  3r33055. 3r33040.  3r33055.
Maintaining equality

3r33040.  3r33055. Rules must be balanced. Both the condition check and the event following it should be described in the same way. I will show what it means. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[player | crate ]->[player | ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. This line of code destroys the box if there is a player next to it. You can not write:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[player | crate ]->[player ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. because the condition on the left checks for the presence of neighboring objects in two separate grid spaces, but the event describes only one grid space that the player takes. Puzzle Script needs to know what to do with the spaces it checks. The correct code for destroying the box should be the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[Если игрок | рядом с ящиком ]-> then[игрок не делает ничего | ящик удаляется ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055.
3r32990. 3r32991.[player | crate ]->[player | ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. That is, even empty spaces in the code matter. However, the following entry is valid:
0.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[player target ]->[player ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. Since in the condition we are talking only about one grid space, the event describes the same grid space. 3r33040.  3r33055. 3r33040.  3r33055.

How to move the boxes

3r33040.  3r33055. Let's go back to the source code line. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | Crate ]->[> Player | > Crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. In other words: 3r33030.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[Если игрок двигается к ящику | и находится рядом с ящиком ]-> then[переместить игрока | толкнуть ящик ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. Arrow> underlines movement. 3r33040.  3r33055. 3r33040.  3r33055. Sometimes we need to write comments to remember what the code does. Puzzle Script ignores comments - they are intended only for the user. To write a comment, you need to put the text in brackets. We write above our rule a comment describing what it does: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. (The player pushes the box) 3r33040.  3r33055.[> Player | Crate ]->[> Player | > Crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. Now, under the push code of the box, we write the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. (Player drags the box) 3r33040.  3r33055.[< Player | Crate ]->[< Player | < Crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. An inverted arrow means that if a player moves away from the box, he pulls the box. Click “Run” to test this action. You should be able to push and pull boxes. In programming, even with a typo in one letter, the computer may not understand the code, so get rid of all errors. When making changes to the code, click “Run” again to download the changes. If the game does not behave as it should, try clicking on “Rebuild” to clear the program’s memory, and then click “Run.” 3r33040.  3r33055. 3r33040.  3r33055. Sometimes you need to deactivate a line of code. Just turn it into a comment to save for the future. Let's commentWe test the pushing code of the boxes so that the player can only carry boxes: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. (The player pushes the box) 3r33040.  3r33055. ([> Player | Crate ]->[> Player | > Crate ]) 3r33040.  3r33055. (Player drags the box) 3r33040.  3r33055.[< Player | Crate ]->[< Player | < Crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. If it worked, then comment out the box pulling code and try the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[< Player | Crate ]->[< Player | > Crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. If the player moves away from the box, then the player and the box will move in opposite directions. The arrows determine in which direction the object either moves or will move. Now comment out this and try the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | Crate ]->[Player | > Crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. The box moves, but the player remains in place. Experiment with ^ and v (the letter v) to see how the objects will move. 3r33040.  3r33055. 3r33040.  3r33055.

Errors 3r333336. 3r33040.  3r33055. Let's intentionally write the wrong rule and see what happens. Enter the following line: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[< Player | Crate ]->[< Player ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. Try running the program. You should see this message:
0.  3r33055. 3r33040.  3r33055.
3r32991. The line 81 is the number of cells. 3r32992. 3r32994. 3r33040.  3r33055. Usually Puzzle Script describes the error very well. However, sometimes Puzzle Script is wrong. In such cases, you need to go through the code yourself and figure out where the error is. 3r33040.  3r33055. 3r33040.  3r33055.
A little more experiment

3r33040.  3r33055. Try experimenting and writing rules yourself. Here are some examples. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | … | Crate ]->[> Player | … | > Crate ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. In the example shown above, the player will push the box if they are anywhere on the same level row, and the player moves to the box. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | Crate ]->[Crate | Player ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. This code changes the player and the box in some places. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | Crate ]->[Player | Target ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. In this code, if the player is near the box and moves towards it, the player will stop moving, but the box will turn into a goal. The best thing about Puzzle Script is the simplicity of creating new and the possibility of experiments. 3r33040.  3r33055. 3r33040.  3r33055.

Part 3. Creating Objects

3r33040.  3r33055. All graphic fragments in games on Puzzle Script designate objects. To create games on Puzzle Script you need to create your own objects. In this part, I will tell you how to create them and add them to your code. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. General information 3r333336. 3r33040.  3r33055. Open example project . The process of creating an object consists of the following steps: 3r33040.  3r33055. 3r33040.  3r33055.
 3r33055. 3r33026. Create it in the list of objects 3r33027.  3r33055. 3r33026. Adding object to the legend 3r33027.  3r33055. 3r33026. Adding collisions to the layer
 3r33055. 3r33029. 3r33040.  3r33055. Having done all these steps, you can start using the object. 3r33040.  3r33055. 3r33040.  3r33055.

Creating an object

3r33040.  3r33055. Several objects already exist. Each game must have a background object. All objects are created from a grid of 5 x 5 pixels and have at least one color. The following is a background object. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Background
3r33040.  3r33055. 3r32991. LIGHTGREEN GREEN
3r33040.  3r33055. 3r32991. 11111 3r33040.  3r33055. 01111 3r33040.  3r33055. 11101 3r33040.  3r33055. 11111 3r33040.  3r33055. 10111 3r332322. 3r32993. 3r32994. 3r33040.  3r33055. Numbers denote image pixels. Each number corresponds to its color. The first color has the number ? the second - ? and so on up to 9. There can be up to ten colors. In our case, each 1 colors a pixel in light green (Light Green), and 0 - in green (Green). The result is: 3r33030.  3r33055. 3r33040.  3r33055. 3r33042. 3r337. 3r33051. 3r33040.  3r33055. Objects are always created as follows: 3r33040.  3r33055. 3r33040.  3r33055.
 3r33055. 3r33026. The name is 3r33027.  3r33055. 3r33026. Colors
 3r33055. 3r33026. Image
 3r33055. 3r33029. 3r33040.  3r33055. The name is always on the top line. The colors are always in the second line, and the image takes the next 5 lines, 5 characters per line, which forms a 5 x 5 grid. Or you can do the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Background
3r33040.  3r33055. 3r32991. LIGHTGREEN
3r32993. 3r32994. 3r33040.  3r33055. This code will create an object called “Background”, which will be a 5 x 5 pixel grid in light green. If you do not describe the image grid, then we get a block of solid color, which can sometimes be useful. 3r33040.  3r33055. 3r33040.  3r33055.

We give the names of the objects

3r33040.  3r33055. Objects can be called as you like, but the name cannot begin with a symbol and it must be in one word without spaces. Give objects clear names, but do not overdo it. PlayerStill is a good name, PlayerThatIsStandingStill is too long and verbose. 3r33040.  3r33055. 3r33040.  3r33055.

Colors

3r33040.  3r33055. You must declare the colors you want to use for the object, and separate them with a space. Puzzle Script has predefined colors:
 3r33055. 3r33040.  3r33055.
 3r33055. 3r33026. black 3r33027.  3r33055. 3r33026. white
 3r33055. 3r33026. gray 3r33027.  3r33055. 3r33026. darkgrey
 3r33055. 3r33026. lightgrey
 3r33055. 3r33026. gray
 3r33055. 3r33026. darkgray
 3r33055. 3r33026. lightgray
 3r33055. 3r33026. red
 3r33055. 3r33026. darkred
 3r33055. 3r33026. lightred
 3r33055. 3r33026. brown
 3r33055. 3r33026. darkbrown
 3r33055. 3r33026. lightbrown 3r3303027.  3r33055. 3r33026. orange
 3r33055. 3r33026. yellow
 3r33055. 3r33026. green
 3r33055. 3r33026. darkgreen
 3r33055. 3r33026. lightgreen
 3r33055. 3r33026. blue
 3r33055. 3r33026. lightblue
 3r33055. 3r33026. darkblue
 3r33055. 3r33026. purple
 3r33055. 3r33026. pink
 3r33055. 3r33026. transparent
 3r33055. 3r33029. 3r33040.  3r33055. You can also set colors in hexadecimal, which gives us a much larger range of colors. Web sites can be used to select hexadecimal colors, for example 3r34848. such
. Select the desired color and then rewrite the color code shown above the image. Hexadecimal color codes are written to the Puzzle Script as follows: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. The name is 3r32992. 3r33040.  3r33055. 3r32991. # 51A2BD # ff0000 #ffffff
3r32993. 3r32994. 3r33040.  3r33055. The color code is always preceded by a #. 3r33040.  3r33055. 3r33040.  3r33055.

Add an object to the legend

3r33040.  3r33055. Creating an object, you need to add it to the legend. The legend looks like this:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991. . = Background
3r33040.  3r33055. 3r32991. # = Wall
3r33040.  3r33055. 3r32991. P = Player
3r33040.  3r33055. 3r32991. * = Crate
3r33040.  3r33055. 3r32991. @ = Crate and Target
3r33040.  3r33055. 3r32991. O = Target
3r32993. 3r32994. 3r33040.  3r33055. Each symbol represents an object in a level. That is, when we see a grid of characters: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. #p. *. ##
3r33040.  3r33055. 3r32991. #. **. ##
3r33040.  3r33055. 3r32991. # # #
3r33040.  3r33055. 3r32991. ## #
3r33040.  3r33055. 3r32991. ## o #
3r33040.  3r33055. 3r32991. #######
3r32993. 3r32994. 3r33040.  3r33055. then it actually describes our level:
 3r33055. 3r33040.  3r33055. 3r33042. 3r33943. 3r33051. 3r33040.  3r33055. Each object to be created must be assigned a letter, symbol or number denoting this object at the level. Like this: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. P = player
3r32993. 3r32994. 3r33040.  3r33055.

Group the objects in the legend

3r33040.  3r33055. We can also create groups of objects in the legend. For example, if we have several multi-colored boxes, we can do this: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. O = OrangeCrate
3r33040.  3r33055. 3r32991. B = BlueCrate
3r33040.  3r33055. 3r32991. G = GreenCrate
3r32993. 3r32994. 3r33040.  3r33055. That will allow us to use the boxes in the editor level. But to create code, you can group them together in Legend, like this: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Crates = OrangeCrate or GreenCrate or BlueCrate
3r32993. 3r32994. 3r33040.  3r33055. And all together it will look like this: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. =======
3r33040.  3r33055. 3r32991. LEGEND
3r33040.  3r33055. 3r32991. =======
3r33040.  3r33055. 3r32991. O = OrangeCrate
3r33040.  3r33055. 3r32991. B = BlueCrate
3r33040.  3r33055. 3r32991. G = GreenCrate
3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Crates = OrangeCrate or GreenCrate or BlueCrate
3r32993. 3r32994. 3r33040.  3r33055. Why do this? Because then instead of creating such rules: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | OrangeCrate ]->[> Player | > OrangeCrate ]3r32992. 3r33040.  3r33055. 3r32991.[> Player | BlueCrate]->[> Player | > BlueCrate ]3r32992. 3r33040.  3r33055. 3r32991.[> Player | GreenCrate]->[> Player | > GreenCrate]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. You can simply write: 3r330340.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | Crates ]->[> Player | > Crates ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. And this code will work for the entire group of objects. 3r33040.  3r33055. 3r33040.  3r33055. Also in section 3-3332991. Collision Layers
it will be possible to refer to the layer in which the group is located, and not to enter each individual object. 3r33040.  3r33055. 3r33040.  3r33055.

Collision Layers

3r33040.  3r33055. The default partition of the collision layer is as follows: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Background
3r33040.  3r33055. 3r32991. Target
3r33040.  3r33055. 3r32991. Player, Wall, Crate
3r32993. 3r32994. 3r33040.  3r33055. Each line selects objects in its own layer. The order of the object layers determines which objects will be on top of others. The objects in the top row will be on the bottom layer, the next line will be in the layer above it, and so on. The background should always be in the top row in order to be on the bottom layer. Objects in the same layer cannot be on top of each other. That is, this can not be: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[player wall ]->[player wall ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. You can make objects in different layers interact with each other. For example, you can write:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | Target ]->[> Player | > Target ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055.

Experiment

3r33040.  3r33055. Create some new objects. Create a box type that can only be pushed. Create another box that can only be dragged. Create a box that disappears when you touch it. Continuing the experiments, you will better remember how everything is done. 3r33040.  3r33055. 3r33040.  3r33055.

Part 4. Terms of victory

3r33040.  3r33055. Everyone loves to win. We, as players, want to win. In this part we will learn how to program the conditions of victory in the game. 3r33040.  3r33055. 3r33040.  3r33055.

Victory conditions 3r30033. 3r33040.  3r33055. Download example project and go to the Win Conditions code section. You should see the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. All Target on Crate
3r32993. 3r32994. 3r33040.  3r33055. The game is won if there is a box on each goal. If you have 3 boxes and 2 goals, you will win by setting only 2 boxes on goals. If you swap: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. All crate on target
3r32993. 3r32994. 3r33040.  3r33055. then each box must be on target. 3r33040.  3r33055. 3r33040.  3r33055. Conditions may be one or more. In the case of multiple conditions, they must all be met. For example, we may have the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. All Target on Crate
3r33040.  3r33055. 3r32991. All Target2 on Crate2
3r32993. 3r32994. 3r33040.  3r33055. If there are target and target2 at the level, then crate and crate2 are on them, respectively. If at the level there is none of the objects necessary to fulfill a certain victory condition, for example, target2 is not present, then this condition is fulfilled automatically. 3r33040.  3r33055. 3r33040.  3r33055.
Different types of win conditions

3r33040.  3r33055. There are several different types of victory conditions. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. No Object
3r32993. 3r32994. 3r33040.  3r33055. In this case, victory comes when there are no such objects at the level. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Some Object
3r32993. 3r32994. 3r33040.  3r33055. You win when there is at least one object of the specified type on the level. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Some Object1 on Object2
3r32993. 3r32994. 3r33040.  3r33055. You need at least one of Object1 to be on Object2. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. No Object1 On Object2
3r32993. 3r32994. 3r33040.  3r33055. This condition is the opposite of r3r32990. 3r32991. All Target on Crate
3r32993. . In this case, we need all the specified objects to be located separately from each other, and not on top of each other. You can also combine with each other various conditions of victory. 3r33040.  3r33055. 3r33040.  3r33055.

Experiment

3r33040.  3r33055. Let's experiment with different victory conditions. Try to create a game in which the gain comes, if all the boxes are not on targets. Or make a game in which you want to destroy all the boxes of a certain type, but other pushed boxes are on your way. 3r33040.  3r33055. 3r33040.  3r33055. My completed example of the project can be viewed here is . 3r33040.  3r33055. 3r33040.  3r33055.

Part 5. Team late

3r33040.  3r33055. PuzzleScript has a very useful command called "late." The order of origin of events in the game is important, and sometimes to get the results you need, you need a code that runs later. In this section, I will discuss the use of the command 3r-32991. late
. 3r33040.  3r33055. 3r33040.  3r33055.

Why do we need it

3r33040.  3r33055. Open example project , then paste the following code into the game and run it: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[player | target ]->[player | ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. It can be expected that as soon as the player gets close to the target, the target will be destroyed, but this does not happen. Instead, the target disappears in the course of 3r-32991.
after
3r32992. how the player stood next to her. Therefore, try another code:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[player | target ]->[player | ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. As soon as you stand next to the target, it will disappear. It happened because everything is designated as 3r32991. late
, occurs after the execution of the rest of the code. Sometimes it is necessary. 3r33040.  3r33055. 3r33040.  3r33055.

The order of events

3r33040.  3r33055. Here is how the code is executed in Puzzle Script with each move. 3r33040.  3r33055. 3r33040.  3r33055.
 3r33055. 3r33026. Puzzle Script detects that a player wants to move
 3r33055. 3r33026. Where possible, the rules are read and executed from top to bottom 3r33027.  3r33055. 3r33026. The player moves, if possible 3r33027.  3r33055. 3r33026. Late-rules apply
 3r33055.
3r33040.  3r33055. The computer starts with the top line of code and reads down, line by line. checking every condition. So when you try to move, Puzzle Script reads all the rules and checks if the conditions are true, and if so, it does something. For example, the first line might be:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[player | spikeTrap ]->[| spikeTrap ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. If the player does not stand next to the stake trap, the code continues execution. This means that the order of writing lines of code is important. You can use the late command in some cases, which you will learn over time in practice. 3r33040.  3r33055. 3r33040.  3r33055.

Ways of using Late in practice

3r33040.  3r33055. In my experience, it is best to use the late command when you check whether objects are on top of each other or next to each other, but there are other cases. If you check whether one object is on another, the event will not register until the next turn, unless you use the late command:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[player spikeTrap ]->[spikeTrap ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. In the above case, the player will not be killed by a trap with stakes until the next turn after moving into the trap. To make a player die instantly, just add the command late, 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[player spikeTrap ]->[spikeTrap ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. To restart the entire level when a character dies, you can do the following:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[player spikeTrap ]-> restart
3r32993. 3r32994. 3r33040.  3r33055. And the level will restart when the player falls into the trap with stakes. 3r33040.  3r33055. 3r33040.  3r33055. A complete example of the project can be viewed here is . 3r33040.  3r33055. 3r33040.  3r33055.

Part 6. Working with sound effects

3r33040.  3r33055. We made a great game on 3r31412. Puzzle Script
but now you need to add sounds to it. How to do it? Now I will tell you! 3r33040.  3r33055. 3r33040.  3r33055.

Generate sounds

3r33040.  3r33055. Open 3r31422. example project
. Add sounds to it. Under the screen of the game you can see black squares with white characters. They are used to generate sound. Each symbol generates a unique sound type, and a cross deletes the sounds created. Try to click on the squares and listen to the sounds. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r31429. 3r33051. 3r33040.  3r33055. Yellow numbers are unique codes that need to be copied and pasted into those parts of the code where sounds are necessary. 3r33040.  3r33055. 3r33040.  3r33055.

How to use sounds

3r33040.  3r33055. Having found a suitable sound, you should insert it into section
Sounds
game code. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r31448. 3r33051. 3r33040.  3r33055. Sounds can be used in several ways. The simplest is to create a new sound effect (sfx). They should be numbered. We create a new sfx by assigning it a number from 0 to 10 when inserting a numeric sound ID. In the Sounds list, create a new sfx called sfx0 and assign it the generated sound:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991. sfx0
3r32991. 36301705 3-3332992. 3r32993. 3r32994. 3r33040.  3r33055. To use sound, you need to insert it into the rules after the event. Let's attach the newly created sfx0 to the box destruction event (the event is already present in the sample project): 3r33030.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. (The player destroys a crate)
3r33040.  3r33055. 3r32991.[> Player | CrateVanish ]->[Player | ]sfx0
3r32993. 3r32994. 3r33040.  3r33055. You can also announce sounds for playback with certain events, for example: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Crate MOVE 36772507 3r332322. 3r32993. 3r32994. 3r33040.  3r33055. In this case, the sound will play when you move Crate. Generate a new sound effect for dragging CratePull objects and make it play when you move CratePull:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991. CratePull MOVE 12735307
3r32993. 3r32994. 3r33040.  3r33055. Event sounds need to be declared only in the Sounds section: they are not required to be mentioned in the rules. 3r33040.  3r33055. 3r33040.  3r33055.

List of ways to play sounds

3r33040.  3r33055. Below is a list of the various event sounds that you can use, taken from 3r31514.
documentation. Puzzle Script. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Object Action 541566
- reproduced when the object during the course is exposed to action (action). 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Object Create 641667
- reproduced when creating a specific object. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. EndGame 5416789
- is played when the game ends. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. EndLevel 6417822
- Played after completing a level. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Object CantMove 781673
- reproduced when the object tried unsuccessfully to move in any direction. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Player CantMove Down Left 464674
- is played when the object tried unsuccessfully to move down or to the left. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. CloseMessage 344456
- is played when the player closes the message box. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Object Destroy 187975
- reproduced when the object is destroyed. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Object Move 264567
- reproduced when the object successfully moves in any direction. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Object Move Down Left 765432
- is played when the object has successfully moved down or to the left. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Object Move Horizontal 345367
- reproduced when the object successfully moved horizontally. You can also use Vertical. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Restart 7865435
- is played when the player presses the restart button R.
 3r33055. 3r33040.  3r33055. 3r32991. SFX???r3r32992. - can be anything from SFX0 to SFX10. These are special sound events that can be performed from the rules. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. ShowMessage 478483
- is played when the message is displayed. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. StartGame 234626
- reproduced at the beginning new game. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Startlevel 765436
- reproduced at the beginning of each level. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. TitleScreen 876543 3-3332992. - is played after the screen saver is loaded. 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. Undo 436234
- is played when the player presses the cancel key (Z). 3r33040.  3r33055. 3r33040.  3r33055. For move and cantmove You can specify the direction so that when moving in different directions, different sounds are played. 3r33040.  3r33055. 3r33040.  3r33055. The finished sample project is here is . 3r33040.  3r33055. 3r33040.  3r33055.

Part 7. Playing music

3r33040.  3r33055. We learned how to create games on Puzzle Script, but wouldn't it be great to add music to them? It is possible, and now I will tell how it is done. 3r33040.  3r33055. 3r33040.  3r33055.
3r32991. Note:
it seems that at the moment this function in Puzzle Script is broken, so go to the next part. 3r32994. 3r33040.  3r33055.

What you need to do

3r33040.  3r33055. Open procurement of the project . Music works in Puzzle Script as follows: you can insert a link to one video from Youtube into the game. PuzzleScript will automatically play all sounds of this video. Open Youtube and select any video, or use the following: 3r33040.  3r33055. 3r33040.  3r33055. 3r32991. 3r31667. youtube.com/watch?v=
CKAc3nYEatw
3r32992. 3r33040.  3r33055. 3r33040.  3r33055. To play music from a video, we need to get a unique video ID. The green part in the line above is a unique ID. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r31681. 3r33051. 3r33040.  3r33055. Under the label of the author’s home page at the beginning of the project, add the youtube label, and after it the unique video ID, for example:
 3r33055. 3r33040.  3r33055. 3r32991. youtube CKAc3nYEatw
3r33040.  3r33055. 3r33040.  3r33055. To make sure that it works correctly, click on “Share” and click on the game link (not on the source code link). During testing inside the editor, the Puzzle Script music cannot be played. If you want the game to have music, then you need to upload it as a video on Youtube and insert a unique ID into your project. In each project there can be only one Youtube video. 3r33040.  3r33055. 3r33040.  3r33055.

Project example 3r?3006. 3r33040.  3r33055. An example of the Puzzle Script project can be found
here is 3r32992. . 3r33040.  3r33055. 3r33040.  3r33055.
Part 8. How to use the Action command

3r33040.  3r33055. We already know how to move, push and drag blocks, but what if we need to do something by pressing a certain key, for example
Spacer 3r? 32992. ? 3r33040.  3r33055. 3r33040.  3r33055. The input options in PuzzleScript are quite limited, mostly the arrow keys, Z to cancel, R to restart, and we cannot change them. But the engine gives us an extra key for 3r-32991. action
- click on
space 3r? 32992. or the 3r399991 key. X
. 3r33040.  3r33055. 3r33040.  3r33055. Working with the team
Action
follows the above format. We used the basic code format of PuzzleScript:
 3r33055. 3r33040.  3r33055.
3r32990. [Условие ]->[Событие ] 3r32993. 3r32994. 3r33040.  3r33055. If the condition is true, then we execute the event. Team 3r32991. action
used in the same way, but it has its own rules. It looks like this: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. [Action дополнительные условия ]->[Событие ] 3r32993. 3r32994. 3r33040.  3r33055. Here is an example of using the Action command:
 3r33055. 3r33040.  3r33055.
3r32990.[ActionPlayer ]->[Crate ]3r32993. 3r32994. 3r33040.  3r33055. First,
Action
always the first word of a condition. 3r33040.  3r33055. 3r33040.  3r33055. Secondly, if we want to influence a certain object in the game, then we need to mention this object both in the condition and in the event (if we mention another object, the program will delete the original one and replace it with a new object, and if the object is not specified, then it will just go away). 3r33040.  3r33055. 3r33040.  3r33055. Finally, the word 3r3-32991. Action
only need to be used in subject to However, sometimes it is worth using it both in the condition and in the event. I will tell about it below. 3r33040.  3r33055. 3r33040.  3r33055. Check the code shown above in the game project. You can start with 3r31793. of this example
. You will see that when you click on
space 3r? 32992. or
X
the player becomes a box. 3r33040.  3r33055. 3r33040.  3r33055. The condition reports[Если мы нажимаем клавишу Actionи на уровне есть объект Player ]-> then[заменитьобъект игрока на ящик ]
3r33040.  3r33055. 3r33040.  3r33055. Now let's try the following code in the sample project:
 3r33055. 3r33040.  3r33055.
3r32990.[Action Player | Crate ]->[Player | > Crate ]3r32993. 3r32994. 3r33040.  3r33055. 3r33042. 3r31828. 3r33051. 3r33040.  3r33055. 3r33040.  3r33055. Make sure that you are surrounded by boxes on all sides, as in the image above. You will notice that the action only affects one box at a time. I do not know exactly what the reason is, but if you want to influence with the help of the command 3r-32991. Action
on several objects, then you need to specify it both in the condition and in the event. 3r33040.  3r33055. 3r33040.  3r33055. Replace the code with the updated version: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990.[Action Player | Crate ]->[Action Player | > Crate ]3r32993. 3r32994. 3r33040.  3r33055. 3r33042. 3r31855. 3r33051. 3r33040.  3r33055. Now we can push all the boxes at the same time. If you need to apply an action to multiple objects, then place
Action
and in the condition, and in the event. 3r33040.  3r33055. 3r33040.  3r33055.

Part 9. Verification of multiple conditions

3r33040.  3r33055. Let's learn to check several conditions, for example, the presence of a bomb AND a destructible block. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r31874. 3r33051. 3r33040.  3r33055. Open
8. example project
. Now add the following code: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[Player Switch] [DoorClosed]->[Player Switch] [DoorOpen]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. The code corresponds to this format:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[Условие 1 ] [Условие 2 ]->[Действие 1 ] [Действие 2 ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. If condition 1 is true and condition 2 is true, then action 1 and action 2 are performed. In our case, condition 1 checks if the Player is on the Switch. If so, is condition 2 checked, that is, the presence at the level of a closed door? If the condition is true, then the DoorClosed object is transformed into a DoorOpen object, opening the door. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r31909. 3r33051. 3r33040.  3r33055. Suppose we need the door to close when the hero leaves the switch, because we want the player to push the box to the switch to open the door. You can write something like this:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[Player | Switch] [DoorOpen]->[Player | Switch] [DoorClosed]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. If a player is standing next to a switch and somewhere on the level there is an open door, then we close the door. Finally, we need the door to remain open if we push the drawer to the switch: 3r3303040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[Crate Switch] [DoorClosed]->[Crate Switch] [DoorOpen]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. Now the door will remain open while there is a drawer on the switch. 3r33040.  3r33055. 3r33040.  3r33055. A complete example of the project can be viewed here is . 3r33040.  3r33055. 3r33040.  3r33055.

Part 10. Creating control points

3r33040.  3r33055. Perhaps you have a good idea to play Puzzle Script, but you need checkpoints (checkpoints) for the player to recover from them in case of death. How to do it? Pretty simple, and now I will explain how. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. 3r31956. 3r33051. 3r33040.  3r33055.

Creating control points

3r33040.  3r33055. Open example project . Now we need to program the control point. Just one line of code is sufficient for this:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[Player FlagRed ]-> CHECKPOINT
3r32993. 3r32994. 3r33040.  3r33055. FlagRed is a control point. When a player is on top of a flag, this code creates a checkpoint (CHECKPOINT). If you do not use late, the checkpoint function will not work. 3r33040.  3r33055. 3r33040.  3r33055. Test the game. Go over the control point, and then a little further and press R. You will need to start from the control point. 3r33040.  3r33055. 3r33040.  3r33055.

Several control points

3r33040.  3r33055. If there are several control points, the game uses the last one activated by the player. 3r33040.  3r33055. 3r33040.  3r33055. To avoid re-activation of the already used control point, you need to change it to another object. To do this, create a white copy in the OBJECTS section of the code under the red flag. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. FlagWhite
 3r33055. White Orange 3r33040.  3r33055. .1 3r33040.  3r33055. .00 3r33040.  3r33055. .000. 3r33040.  3r33055. .1 3r33040.  3r33055. .1…
3r32993. 3r32994. 3r33040.  3r33055. Now rewrite this line in the legend: 3r3303040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Flag = FlagRed or FlagWhite
3r32993. 3r32994. 3r33040.  3r33055. We can create a group of objects. In this case, Flag will be either FlagRed, or FlagWhite. As long as at least one of the grouped objects is assigned a symbol (we assigned the symbol F to the FlagRed), we will not need to assign symbols to other objects of the group, and you can only access them in the code, not in the level editor. You can then assign collision layers to the group, which we did. A call to a group of objects, such as Flag, refers to the entire group. Therefore: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991.[> Player | Flag ]->[> Player | ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. This code will affect both the red and the white flag. 3r33040.  3r33055. 3r33040.  3r33055.

Change the flag object

3r33040.  3r33055. Here's how to change FlagRed to FlagWhite:
 3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[Player FlagRed ]->[Player FlagWhite ]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. If at the end of the turn the player is on a red flag, then we turn it into white. However, you need to make the flag graphics change
after
create a breakpoint because the code is read from top to bottom. Test the program. 3r33040.  3r33055. 3r33040.  3r33055.

Change the second flag

3r33040.  3r33055. There are two flags in the project. Let's make it so that when the second flag is activated, the old white flag turns black, so that it cannot be used again. We write the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. late[Player FlagRed ] [FlagWhite]->[Player FlagRed ] [FlagBlack]3r32992. 3r32993. 3r32994. 3r33040.  3r33055. The code says: if a player is on a red flag and somewhere in the game there are white flags, then you need to make the white flags black. Since the code is read from top to bottom, we need to do this in the following order:
 3r33055. 3r33040.  3r33055.
3r32990. late[Player FlagRed ]-> CHECKPOINT
 3r33055. late[Player FlagRed ] [FlagWhite]->[Player FlagRed ] [FlagBlack]3r33040.  3r33055. late[Player FlagRed ]->[Player FlagWhite ]
3r32993. 3r32994. 3r33040.  3r33055. If you do not understand why the code should be in this order, then try changing the order of the lines and test the program. To solve your own problems, you need to learn how to step back and think about what the code does. But I will give you a hint - when you play, where are the red flags at the time of the last line of code in the following wrong example? 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. [> Player | Crate ]->[> Player | > Crate ]
 3r33055.[> Crate | Flag ]->[Crate | Flag ]3r33040.  3r33055. late[Player FlagRed ]-> CHECKPOINT
 3r33055. late[Player FlagRed ]->[Player FlagWhite ]3r33040.  3r33055. late[Player FlagRed ] [FlagWhite]->[Player FlagRed ] [FlagBlack]
3r32993. 3r32994. 3r33040.  3r33055. You can view a finished sample project here is . In addition, I just showed you the simplest way to animate. In the next part I will talk about creating more complex animations, such as explosions. 3r33040.  3r33055. 3r33040.  3r33055.

Part 11. Animations

3r33040.  3r33055. There are two ways to create animations in PuzzleScript. In one of them real time is used, but in this part I will not talk about it. The other is used for quick, one-time animations, such as an explosion or a character walking down a vertical staircase. 3r33040.  3r33055. 3r33040.  3r33055. Open example project . We will create a bomb and a series of explosion frames, and then animate them. 3r33040.  3r33055. 3r33040.  3r33055.

Animation of objects

3r33040.  3r33055. For 2D animations, you need several drawings of an object moving from one state to another, for example, a running Mario sprite. It contains 4 frames of animation. 3r33040.  3r33055. 3r33040.  3r33055. 3r33042. Bomb
3r33040.  3r33055. Create such an object bomb. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. Bomb 3r33040.  3r33055. black yellow gray
 3r33055. 1 3r33040.  3r33055. 1 3r33040.  3r33055. .000. 3r33040.  3r33055. 00020 3r33040.  3r33055. .000.
3r32993. 3r32994. 3r33040.  3r33055. Do not forget to add it to the layers and to the legend. 3r33040.  3r33055. 3r33040.  3r33055. To animate the explosion, we need to create each frame of the animation as a separate object, and then switch between them in code. Let's create explosion objects. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. Explosion1 3r33040.  3r33055. black yellow gray red
 3r33055. 1 3r33040.  3r33055. 1 3r33040.  3r33055. .000. 3r33040.  3r33055. 00320 3r3303040  3r33055. .000. 3r33040.  3r33055. 3r33040.  3r33055. Explosion2 3r3303040.  3r33055. black yellow gray red
 3r33055. 1 3r33040.  3r33055. 1 3r33040.  3r33055. .333. 3r33040.  3r33055. 03330 3r3303040.  3r33055. .333. 3r33040.  3r33055. 3r33040.  3r33055. Explosion3 3r3303040.  3r33055. black yellow gray red
 3r33055. 1 3r33040.  3r33055. .333. 3r33040.  3r33055. 33333 3r3303040.  3r33055. 33333 3r3303040.  3r33055. .333. 3r33040.  3r33055. 3r33040.  3r33055. Explosion4 3r3303040.  3r33055. black yellow gray red
 3r33055. .333. 3r33040.  3r33055. 33333 3r3303040.  3r33055. 33333 3r3303040.  3r33055. 33333 3r3303040.  3r33055. .333. 3r33040.  3r33055. 3r33040.  3r33055. Explosion5 3r3303040.  3r33055. black yellow gray red
 3r33055. .333. 3r33040.  3r33055. 33333 3r3303040.  3r33055. ???r33040.  3r33055. 33333 3r3303040.  3r33055. .333. 3r33040.  3r33055. 3r33040.  3r33055. Explosion6 3r3303040.  3r33055. black yellow gray red
 3r33055. .333. 3r33040.  3r33055. 3 3 3r33040.  3r33055. 3 3 3r33040.  3r33055. 3 3 3r33040.  3r33055. .333. 3r33040.  3r33055. 3r33040.  3r33055. Explosion7 3r33040.  3r33055. black yellow gray red
 3r33055. 3r33040.  3r33055. 3r33040.  3r33055. 3r33040.  3r33055. 3r33040.  3r33055.
3r32993. 3r32994. 3r33040.  3r33055. It will be correct to number the objects in order to know which frame of the animation we need. After adding them to the layers and the legend, we can add a few lines of code. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. [Explosion7]->[]3r33040.  3r33055.[Explosion6]->[Explosion7]3r33040.  3r33055.[Explosion5]->[Explosion6]3r33040.  3r33055.[Explosion4]->[Explosion5]3r33040.  3r33055.[Explosion3]->[Explosion4]3r33040.  3r33055.[Explosion2]->[Explosion3]3r33040.  3r33055.[Explosion1]->[Explosion2]3r33040.  3r33055.[Bomb]->[Explosion1] 3r32993. 3r32994. 3r33040.  3r33055. Try adding this code, then place a bomb on the level and start the game. You will notice that each time you move, the bomb animation changes by one frame. Switching between objects, we create an animation. 3r33040.  3r33055. 3r33040.  3r33055. The order of switching between animations is crucial. The last frame should be at the top, and the first one at the bottom. Do not forget that the code is read from top to bottom. If the animation frames are in a different order, then we will never see the changes. We will see only the last frame, and in our case the bomb will just disappear. It will change to the first frame, then to the second, and so on, in one frame, before you see the graphics. Placing the last frame in the beginning, we will see the next change in each turn. 3r33040.  3r33055. 3r33040.  3r33055.

Using the Again Team

3r33040.  3r33055. To animate everything together, we need the command
again
. 3r32991. Again
means that after reading all the code, PuzzleScript will pause, and then count the code again, executing all the commands 3r-32991. again
. It can be used for gravity, sliding on ice, and in our case for animations. All that is needed is to rewrite the code as follows:
 3r33055. 3r33040.  3r33055.
3r32990. [Explosion7]->[]3r33040.  3r33055.[Explosion6]->[Explosion7]again
 3r33055.[Explosion5]->[Explosion6]again
 3r33055.[Explosion4]->[Explosion5]again
 3r33055.[Explosion3]->[Explosion4]again
 3r33055.[Explosion2]->[Explosion3]again
 3r33055.[Explosion1]->[Explosion2]again
 3r33055.[Bomb]->[Explosion1]again
3r32993. 3r32994. 3r33040.  3r33055. Test the game. You will see that the entire bomb animation is played immediately. If you think it is too slow or fast, then the speed can be changed. At the very beginning of the text of the program, under
homepage
Write the following code: 3r33030.  3r33055. 3r33040.  3r33055.
3r32990. again_interval 0.1 r3r32932. 3r32993. 3r32994. 3r33040.  3r33055. This is part of what PuzzleScript is called
prelude
. This is the place where, before the rest of the code, you can set additional rules that determine the behavior of the game. Now the animation should play faster. Try changing the number after again_interval and check what has changed. 3r33040.  3r33055. 3r33040.  3r33055. A complete example of the project can be viewed here is . 3r33040.  3r33055. 3r33040.  3r33055.

Part 12. Gravity

3r33040.  3r33055. PuzzleScript is usually used to create games with a top view (top down), but in fact you can simulate some elements of side scrollers, albeit with limited rules of PuzzleScript, that is, they will still be step by step. In this part I will tell you how to implement gravity. 3r33040.  3r33055. 3r33040.  3r33055.

Project example 3r?3006. 3r33040.  3r33055. Open example project . I created a simple level, it has a player, a box on the ledge and a door below. We want to make sure that when a player pushes a box from a ledge, he will fall to the ground. We also want the player to fall off the edge, also fall to the ground. 3r33040.  3r33055. 3r33040.  3r33055.
Fall, stage 1

3r33040.  3r33055. Here is the first part of the code we'll use: 3r3303040.  3r33055. 3r33040.  3r33055.
3r32990. down[Player | no Object ]->[| Player ]3r33040.  3r33055. down[Crate | no Object no Player ]->[| Crate ] 3r32993. 3r32994. 3r33040.  3r33055. Try to push the box off the edge. You will notice that after moving the box freezes in the air, but after another move it falls to the ground. Several things happen here. 3r33040.  3r33055. 3r33040.  3r33055. First, let's talk about the keyword 3r32991. down
. Adding
down
, we limit the rule to that it applies only in the "down" direction. That is why the drawer moves down. If you replace 3r399991. down
on 3r? 32991. right
, then you will see that the box is stuck in the right wall, as in a game with anti-gravity. Try this. 3r33040.  3r33055. 3r33040.  3r33055. Next, do something unusual. Instead of checking whether a player is near a certain object (for example, a box), we check whether he is near a generalized 3r32991. object
. If you look at the legend in the example code, you will see that we have defined object as a group of objects, that is, with each use of the word 3r-32991. object
we mean a group of objects. That is, we check if there are any of these objects under the player. If not, we order the player to occupy this empty space and leave the previous space, because of the word
down
following downward. 3r33040.  3r33055. 3r33040.  3r33055. But it can also be noted that after pushing the ledge off the box does not fall until the next turn, and that it instantly reaches the ground. To eliminate this pending drop, you can use the late keyword:
 3r33055. 3r33040.  3r33055.
3r32990. late down[Player | no Object ]->[| Player ]3r33040.  3r33055. late down[Crate | no Object no Player ]->[| Crate ] 3r32993. 3r32994. 3r33040.  3r33055. But how to make it fall gradually, frame by frame? 3r33040.  3r33055. 3r33040.  3r33055.

The fall, stage 2

3r33040.  3r33055. Now we use the keyword
random
. Rewrite the code as follows: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. random down[Player | no Object ]->[| Player ]3r33040.  3r33055. random down[Crate | no Object no Player ]->[| Crate ] 3r32993. 3r32994. 3r33040.  3r33055. Run the code. It works very much like the previous code, but one important difference. The box hangs in the air, but each time a player moves, he falls down one cell. This is due to the word
random
. Strictly speaking,
random
intended for creating games with random elements, but it is useful to us here. It forces the corresponding line of code to be executed once per turn. PuzzleScript performs each rule as many times as possible in one move, and only then the player sees the graphic changes. That is why it seems that the box falls to the ground instantly. But when using the word
random
we allow it to fall only one cell at a time. 3r33040.  3r33055. 3r33040.  3r33055.

The fall, stage 3

3r33040.  3r33055. Now we add the keyword
again
: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. random down[Player | no Object ]->[| Player ]again
 3r33055. random down[Crate | no Object no Player ]->[| Crate ]again
3r32993. 3r32994. 3r33040.  3r33055. Run the game. All
almost
perfect. The box freezes for a while in the air, but if you move again, it gradually falls to the ground. We are already familiar with the keyword
again
in essence, it means that at the end of the turn, PuzzleScript reads the code again and tries to execute all the commands 3r-32991. again
as a separate move, after which it pauses, then repeats them again as many times as it can. The important thing here is that he pauses between moves 3r-32991. again
That allows us to see the drop box. 3r33040.  3r33055. 3r33040.  3r33055.

The last stage

3r33040.  3r33055. And the final touch. In order for the box to fall to the ground immediately after pushing it off the edge, we need to add another line of code above the one we just wrote: 3r3303040.  3r33055. 3r33040.  3r33055.
3r32990. [moving Player]->[moving Player]again
 3r33055. random down[Player | no Object ]->[| Player ]again 3r33040.  3r33055. random down[Crate | no Object no Player ]->[| Crate ]again
3r32993. 3r32994. 3r33040.  3r33055. Keyword
moving
used in brackets[]before 3r399991. player
means that we check if the player is moving. This means that if a player moves, then we order him to continue moving and launch the team 3r-32991. again
. Then everything that uses the keyword 3r32991 will work right away. again
; in our case, this is a drop box animation. 3r33040.  3r33055. 3r33040.  3r33055. A complete example of the project can be viewed here is . 3r33040.  3r33055. 3r33040.  3r33055.

Part 13. Checking the direction of movement

3r33040.  3r33055.

Indication of the direction

3r33040.  3r33055. Sometimes it happens that you need to check something only in one direction. For example, you need to make blocks that can be pushed only horizontally, or create a duck that can only walk to the left. 3r33040.  3r33055. 3r33040.  3r33055. Be that as it may, we can indicate that events take place only in certain directions. 3r33040.  3r33055. 3r33040.  3r33055. Open PuzzleScript, create a game based on the example
Basic
and replace it with
Rules
The following code: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. [[b]LeftPlayer ]->[Crate ]
3r32993. 3r32994. 3r33040.  3r33055. Start the game and see what happens. 3r33040.  3r33055. 3r33040.  3r33055. If you try to go left, the player will turn into a box. This is a good example of how directions are working. 3r33040.  3r33055. 3r33040.  3r33055. We are already accustomed to the format in which I explained the code PuzzleScript:
 3r33055. 3r33040.  3r33055.
3r32990. [Условие ]->[Событие ] 3r32993. 3r32994. 3r33040.  3r33055. If the event is true, then the event occurs. 3r33040.  3r33055. 3r33040.  3r33055. But now, when we need to check directions, it will follow the new rules: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990.[Movement DirectionObject Affected ]->[New State of Object ]3r32993. 3r32994. 3r33040.  3r33055. That is our previous code:
 3r33055. 3r33040.  3r33055.
3r32990.[LeftPlayer ]->[Crate ]3r32993. 3r32994. 3r33040.  3r33055. checks if the player is moving left (3r32-2991. Left 3r3-332992.). If yes, then we replace the player with the box object. 3r33040.  3r33055. 3r33040.  3r33055.

Types of directions

3r33040.  3r33055. You can choose from the following types of directions: 3r33040.  3r33055. 3r33040.  3r33055.
 3r33055. 3r33026. Up
 3r33055. 3r33026. Down
 3r33055. 3r33026. Left
 3r33055. 3r33026. Right
 3r33055. 3r33026. Horizontal (checks if there is horizontal movement)
 3r33055. 3r33026. Vertical (checks if there is vertical movement)
 3r33055. 3r33029. 3r33040.  3r33055. 3r33040.  3r33055.

Part 14. Creating custom movements

3r33040.  3r33055. For some reason, the game may require custom movement. Ducks can only walk to the left, boxes can be pushed only horizontally, and so on. Make it very easy. Let's take another look at the basic code format of PuzzleScript:
 3r33055. 3r33040.  3r33055.
3r32990. [Условие ]->[Событие ] 3r32993. 3r32994. 3r33040.  3r33055. If the condition is true, then an event occurs. To create a custom move, do the following: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990.[Condition ]->[Movement Direction Object To Move]3r32993. 3r32994. 3r33040.  3r33055. Here is how the example will look like:
 3r33055. 3r33040.  3r33055.
3r32990.[Player | Crate ]->[Player | Left Crate ]3r32993. 3r32994. 3r33040.  3r33055. Download PuzzleScript , open example
Basic
, paste this code and see what happens. Approach the box, around which there are no walls. 3r33040.  3r33055. 3r33040.  3r33055. You will see that when a player is near the box, the box is pushed to the left. However, since the keyword
Late
No, it happens during
after 3r? 32992. how you took the first step to it. 3r33040.  3r33055. 3r33040.  3r33055. When specified in 3r32991. Event
besides the object also
directions of movement
for example 3r399991. Left
, PuzzleScript will attempt to move the object in the specified direction. That is why the box, and not the player moves to the left - 3r3-32991. Left
located near r3r32991. Crate
. 3r33040.  3r33055. 3r33040.  3r33055. Remember this code from the previous part? 3r33040.  3r33055. 3r33040.  3r33055.
3r32990.[НаправлениедвиженияОбъект]->[Новое состояние объекта]3r32993. 3r32994. 3r33040.  3r33055. If you specify 3r399991. direction of movement
in 3r32991. subject to
next to the object, it checks whether this object is moving in a given direction. This is an important difference. You can rewrite it like this: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. [Проверяем это ]->[Делаем это ] 3r32993. 3r32994. 3r33040.  3r33055.

Allowable custom movements

3r33040.  3r33055. Customizable movements can be created with any of these words: 3r33040.  3r33055. 3r33040.  3r33055.
 3r33055. 3r33026. 3r32991. Up
3r33027.  3r33055. 3r33026. 3r32991. Down
3r33027.  3r33055. 3r33026. 3r32991. Left
3r33027.  3r33055. 3r33026. 3r32991. Right
3r33027.  3r33055. 3r33029. 3r33040.  3r33055. Can not use 3r399991. Horizontal
or
Vertical
because PuzzleScript will not understand in which direction you want to move the object, or it will take a lot of workarounds to do this. Need to specify a specific direction. 3r33040.  3r33055. 3r33040.  3r33055.

Part 15. Checking cells next to objects

3r33040.  3r33055. Sometimes it is necessary to check what is near the object. Make it pretty simple. Let's look again at the format of the code PuzzleScript: 3r330340.  3r33055. 3r33040.  3r33055.
3r32990. [Условие ]->[Событие ] 3r32993. 3r32994. 3r33040.  3r33055. i.e. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. [Проверяем это ]-> if this is true[То делаем это ] 3r32993. 3r32994. 3r33040.  3r33055. To check the sides of the object, we need to add one element. The format is as follows: 3r33030.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Checked side
[проверяемый object1 | object2 рядом ]->[object1 | object2]3r32993. 3r32994. 3r33040.  3r33055. Before the condition, we check which side of the object we want to perform the check. 3r33040.  3r33055. 3r33040.  3r33055. Inside the condition, we assume that you need at least two cells. A cell is, in fact, any objects that are in the same space and not next to each other. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. [Это одна ячейка ]3r33040.  3r33055. 3r33040.  3r33055.[Это первая ячейка | это вторая ячейка | это третья ячейка ] 3r32993. 3r32994. 3r33040.  3r33055. The first cell is the object whose sides we are checking. The second cell is an object that we check for. Try the following examples: 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Left
[Player | Crate ]->[Player | ]3r32993. 3r32994. 3r33040.  3r33055. The code shown above removes the boxes if they are in the box to the left of the player. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Left
[Crate | Crate ]->[Player | Crate ]3r32993. 3r32994. 3r33040.  3r33055. This code checks if the box is to the left of the other box. If so, then the box whose side is being checked will become a new player object. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Left
[Crate | Crate ]->[Crate | Player ]3r32993. 3r32994. 3r33040.  3r33055. In the above code, there is the same check, but the player’s object becomes the box on the left. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Left
[Crate | Crate | Crate ]->[Crate | Player | Crate ]3r32993. 3r32994. 3r33040.  3r33055. This code also uses a similar pattern. The box immediately to the left of the test player becomes a player if the 3 boxes are next to each other horizontally. 3r33040.  3r33055. 3r33040.  3r33055.
3r32990. 3r32991. Left
[Crate | Crate | Crate ]->[Crate | Crate | Player ]3r32993. 3r32994. 3r33040.  3r33055. If the 3 boxes are next to each other horizontally, then the leftmost one becomes a player. 3r33040.  3r33055. 3r33040.  3r33055. If you test each of these examples, you will begin to understand the pattern. The first cell is an object that we check to see what is nearby. The following cells, from the nearest to the far, are the objects whose presence we check. 3r33040.  3r33055. 3r33040.  3r33055.

Keywords

3r33040.  3r33055.
 3r33055. 3r33026. Up - checks on an object
 3r33055. 3r33026. Down - checks under the object 3r33027.  3r33055. 3r33026. Left - checks to the left of the object 3r33027.  3r33055. 3r33026. Right - checks to the right of the object 3r33027.  3r33055. 3r33026. Horizontal - checks left and right of the object
 3r33055. 3r33026. Vertical - checks above and below the object 3r33027.  3r33055. 3r33029. 3r33040.  3r33055. 3r33042. 3r33033. 3r33051. 3r33040.  3r33055. 3r33042. 3r33038. 3r33051. 3r33040.  3r33055. 3r33042. 3r33043. 3r33051. 3r33051. 3r33055. 3r33055. 3r33048. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r330349. 3r33055. 3r33051. 3r33055. 3r33055. 3r33055. 3r33055.
+ 0 -

Add comment