Game Design

Basic

How do I add keyboard controls to an Actor?

Use the {"func":"registerKeyTrigger"} code block and attach code to make the Actor move a certain way below it (e.g. {"func":"blockMotionPointDirection"}, {"func":"blockMotionMove"}).

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"left arrow"}],"containers":[],"next":{"func":"blockMotionPointDirection","values":[{"type":"string","value":-90}],"containers":[],"next":{"func":"blockControlForever","values":[],"containers":[{"func":"blockMotionMove","values":[{"type":"number","value":"10"}],"containers":[],"next":{"func":"blockControlWait","values":[{"type":"number","value":".1"}],"containers":[],"next":{"func":"blockMotionBounceOnEdge","values":[],"containers":[]}}}]}}} Add to my Backpack {"func":"registerKeyTrigger","values":[{"type":"choice","value":"right arrow"}],"containers":[],"next":{"func":"blockMotionPointDirection","values":[{"type":"string","value":"90"}],"containers":[],"next":{"func":"blockControlForever","values":[],"containers":[{"func":"blockMotionMove","values":[{"type":"number","value":"10"}],"containers":[],"next":{"func":"blockControlWait","values":[{"type":"number","value":".1"}],"containers":[],"next":{"func":"blockMotionBounceOnEdge","values":[],"containers":[]}}}]}}} Add to my Backpack


How do I make that box with a variable and its value show up on the Stage?

You can make any variable that has a check box to the left of it appear on the Stage by checking the box. This way, the user can see the variable’s value as it changes.


How do I make copies of an Actor?

The {"func":"blockControlCloneActor"} code block will activate the code under {"func":"registerCloned"} in the specified Actor’s code. {"func":"blockControlDeleteActor"} will delete the clone when you’re done!

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"space"}],"containers":[],"next":{"func":"blockControlCloneActor","values":[{"type":"string","value":"self"}],"containers":[]}} Add to my Backpack {"func":"registerCloned","values":[],"containers":[],"next":{"func":"blockMotionGoTo","values":[{"type":"wrapper","func":"valueOpRandom","values":[{"type":"wrapper","func":"valueSensingScreenRight","values":[]},{"type":"wrapper","func":"valueSensingScreenLeft","values":[]}]},{"type":"wrapper","func":"valueOpRandom","values":[{"type":"wrapper","func":"valueSensingScreenBottom","values":[]},{"type":"wrapper","func":"valueSensingScreenTop","values":[]}]}],"containers":[],"next":{"func":"blockControlWait","values":[{"type":"number","value":"10"}],"containers":[],"next":{"func":"blockControlDeleteActor","values":[],"containers":[]}}}} Add to my Backpack


How do I make Actors appear in random places?

Use the {"func":"blockMotionGoTo"} code block, and use the {"func":"valueOpRandom"} code block to determine the parameters.

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"space"}],"containers":[],"next":{"func":"blockMotionGoTo","values":[{"type":"wrapper","func":"valueOpRandom","values":[{"type":"wrapper","func":"valueSensingScreenRight","values":[]},{"type":"wrapper","func":"valueSensingScreenLeft","values":[]}]},{"type":"wrapper","func":"valueOpRandom","values":[{"type":"wrapper","func":"valueSensingScreenBottom","values":[]},{"type":"wrapper","func":"valueSensingScreenTop","values":[]}]}],"containers":[]}} Add to my Backpack


How do I make a platform that scrolls across the screen?

Add a platform, make it static, and put a {"func":"blockMotionMove"} and {"func":"blockControlWait"} block inside a forever loop. If you don’t want the platform to move off the edge, you will need to test if its x position is less than {"func":"valueSensingScreenLeft"} or greater than {"func":"valueSensingScreenRight"} inside the forever loop.


Add levels/scenes to my game/story?

You can use ‘Add Scene’ under the Looks tab of the Stage to create several scenes or levels. Use the {"func":"registerBackgroundChange"} block in each actor to get notified when the level changes.


Make a game that keeps score?

Add a variable, call it score, and add to it every time the user does something that earns points. Mark the check box next to the variable to make it show up on the screen.

Sample Code:
{"func":"registerFlagTrigger","values":[],"containers":[],"next":{"func":"blockControlForever","values":[],"containers":[{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueSensingTouchingSprite","values":[{"type":"string","value":"turtle"}]}],"containers":[{"func":"blockVarChangeBy","values":[{"type":"string","value":"score"},{"type":"number","value":"1"}],"containers":[],"next":{"func":"blockLooksHide","values":[],"containers":[]}}]}]}} Add to my Backpack {"func":"registerBroadcastTrigger","values":[{"type":"string","value":"addScore"}],"containers":[],"next":{"func":"blockVarChangeBy","values":[{"type":"string","value":"Score"},{"type":"number","value":"1"}],"containers":[]}} Add to my Backpack


Make a leaderboard?

Use a list variable to keep track of players and their scores. To save this across game invocations, use a cloud variable.

Sample Code:
{"func":"registerFlagTrigger","values":[],"containers":[],"next":{"func":"blockListAdd","values":[{"type":"string","value":"0"},{"type":"string","value":"LeaderBoard"}],"containers":[],"next":{"func":"blockListAdd","values":[{"type":"string","value":"0"},{"type":"string","value":"LeaderBoard"}],"containers":[],"next":{"func":"blockListAdd","values":[{"type":"string","value":"0"},{"type":"string","value":"LeaderBoard"}],"containers":[],"next":{"func":"blockPenClear","values":[],"containers":[],"next":{"func":"blockVarSet","values":[{"type":"string","value":"winner"},{"type":"string","value":"1"}],"containers":[],"next":{"func":"blockVarSet","values":[{"type":"string","value":"counter"},{"type":"string","value":"1"}],"containers":[],"next":{"func":"blockControlWait","values":[{"type":"number","value":"10"}],"containers":[],"next":{"func":"blockControlRepeat","values":[{"type":"wrapper","func":"valueListLength","values":[{"type":"string","value":"LeaderBoard"}]}],"containers":[{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueOpGreater","values":[{"type":"wrapper","func":"valueListItem","values":[{"type":"wrapper","func":"valueVar","name":"counter"},{"type":"string","value":"LeaderBoard"}]},{"type":"wrapper","func":"valueListItem","values":[{"type":"wrapper","func":"valueVar","name":"winner"},{"type":"string","value":"LeaderBoard"}]}]}],"containers":[{"func":"blockVarSet","values":[{"type":"string","value":"winner"},{"type":"wrapper","func":"valueVar","name":"counter"}],"containers":[]}],"next":{"func":"blockVarChangeBy","values":[{"type":"string","value":"counter"},{"type":"number","value":"1"}],"containers":[]}}],"next":{"func":"blockPenDrawTextAt","values":[{"type":"wrapper","func":"valueOpJoin","values":[{"type":"string","value":"The winner is player: "},{"type":"wrapper","func":"valueVar","name":"winner"}]},{"type":"number","value":"-15"},{"type":"number","value":"0"}],"containers":[]}}}}}}}}}} Add to my Backpack


Make an Actor “shoot”?

Create a shooter Actor and a bullet Actor. In the shooter’s code, send a message to the bullet when you want it to shoot (e.g. when the user presses the spacebar). Then in the bullet’s code, use the {"func":"blockMotionGoTo"} block and set the x and y values to be the location of the shooter. Below that, add a {"func":"blockMotionGlide"} block to make the bullet move. For more advanced shooting, you can use cloning to make copies of the bullet each time you shoot.

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"space"}],"containers":[],"next":{"func":"blockControlPostMessage","values":[{"type":"string","value":"shoot"},{"type":"string","value":"bullet"},{"type":"wrapper","func":"valueMotionXPosition","values":[]}],"containers":[]}} Add to my Backpack {"func":"registerBroadcastTrigger","values":[{"type":"string","value":"shoot"}],"containers":[],"next":{"func":"blockMotionPointDirection","values":[{"type":"string","value":"90"}],"containers":[],"next":{"func":"blockLooksShow","values":[],"containers":[],"next":{"func":"blockMotionGoTo","values":[{"type":"wrapper","func":"valueControlMessageValue","values":[]},{"type":"wrapper","func":"valueOpAdd","values":[{"type":"wrapper","func":"valueSensingScreenBottom","values":[]},{"type":"number","value":"40"}]}],"containers":[],"next":{"func":"blockMotionGlide","values":[{"type":"number","value":"1"},{"type":"wrapper","func":"valueControlMessageValue","values":[]},{"type":"wrapper","func":"valueOpAdd","values":[{"type":"wrapper","func":"valueSensingScreenTop","values":[]},{"type":"number","value":"120"}]}],"containers":[]}}}}} Add to my Backpack


Detect collisions?

You can use the {"func":"blockControlWaitUntil"} or {"func":"blockControlIf"} block, and pass in the {"func":"valueSensingTouchingSprite"} block as the parameter. Choose whatever Actor you want to detect a collision with as the parameter for the {"func":"valueSensingTouchingSprite"} block, or use ‘any’ to detect any collision. There are three different blocks that you can use here depending on your need: {"func":"valueSensingTouchingSprite"}, {"func":"valueSensingTouchingColor"} and {"func":"valueSensingSeeColor"}.

Sample Code:
{"func":"registerFlagTrigger","values":[],"containers":[],"next":{"func":"blockControlForever","values":[],"containers":[{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueSensingTouchingSprite","values":[{"type":"string","value":"Baseball-06"}]}],"containers":[{"func":"blockControlBroadcast","values":[{"type":"string","value":"collision"}],"containers":[]}]}]}} Add to my Backpack


How do I collect coins?

In the coins’ code, detect a collision with your main Actor. Once a collision is detected, use the {"func":"blockLooksHide"} block so the coins disappear. Keep track of the score!


Advanced

How do make a Platformer game with the level editor?

Click on the level editor button at the top of the screen. Drag and place actors and tiles from the level editor palette to get started.


How do I make a Top Down game with the level editor?

Click on the level editor button at the top of the screen. Select the “top down” tab on the palette to the left of your screen. Drag and place actors and tiles from the level editor palette to get started.


How do I add another level to my game with the level editor?

Make sure you are in the “level editor” mode by clicking on the toggle button at the top of the screen. Once you are in level editor mode, click on the large “New Level” button near the bottom of your screen.


How do I make a Platformer game’s background scroll with the level editor?

Double click on the stage and select the "Advanced" properties tab. Make sure the "Enable Tilemap" and "Enable Background Scroll" options are checked.


iHow do I change my world size with the level editor?

Double click on the stage and select the "Advanced" properties tab. The "World Size" section will let you enter how many tiles wide and high you want your world to be.


How do I make a Platformer game’s background tile with the level editor?

Double click on the stage and select the "Advanced" properties tab. Make sure the "Tile" option is checked.


How do set a character's health and power with the level editor?

Use the "set properties" block in the Platformer and Top Down Libraries. Replace the text with the number you want that value to be.

Sample Code:
{"func":"registerFlagTrigger","next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.topdown::set properties","label":"set properties {string:max hp} {string:atk} {string:critical} {string:speed}","values":[{"type":"string","value":"5"},{"type":"string","value":"1"},{"type":"string","value":"0"},{"type":"string","value":"5"}],"next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.topdown::setup and run character","label":"setup and run character"}}} Add to my Backpack


How do I make a character good or bad with the level editor?

Use the "become good guy" or "become bad guy" blocks in the Platformer or Top Down Libraries. Good guys will fight bad guys and vice versa.

Sample Code:
{"func":"registerFlagTrigger","next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.topdown::become good guy","label":"become good guy","next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.topdown::setup and run character","label":"setup and run character"}}} Add to my Backpack


How do I make a Platformer character move around with the level editor?

Attach a "when key pressed" event block with a "walk left" or "walk right" block from the Platformer Library. Type a number where it says "speed" in the block to determine how fast the character moves.

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"left arrow"}],"next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.platformer::walk left","label":"walk left {string:speed}","values":[{"type":"string","value":"10"}]}} Add to my Backpack


How do I make a Top Down character move around with the level editor?

Attach a "when key pressed" event block with a "move with key" block from the Top Down Library. Type a number where it says "speed" in the block to determine how fast the character moves.

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"right arrow"}],"next":{"func":"blockMotionPointDirection","values":[{"type":"string","value":"90"}],"next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.topdown::move with key","label":"move with key {string:speed}","values":[{"type":"string","value":"5"}]}}} Add to my Backpack


How do I make my Platformer character attack with the level editor?

Attach an "attack" block from the Platformer Library to a "when key pressed" event block. The character will attack when the key in the event block is pressed.

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"a"}],"next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.platformer::attack","label":"attack"}} Add to my Backpack


How do I make my Top Down character attack with the level editor?

Attach an "attack" block from the Top Down Library to a "when key pressed" event block. The character will attack when the key in the event block is pressed.

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"a"}],"next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.topdown::attack","label":"attack"}} Add to my Backpack


How do I make characters fight each other with the level editor?

The Platformer and Top Down Libraries have "Automation" blocks that can be used to make characters attack each other. Use the "run attack" library blocks inside a "forever" loop to make characters fight.

Sample Code:
{"func":"registerFlagTrigger","next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.platformer::become bad guy","label":"become bad guy","next":{"func":"blockControlForever","containers":[{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.platformer::run attack enemies","label":"run attack enemies {string:range} {string:speed}","values":[{"type":"string","value":"500"},{"type":"string","value":"5"}]}]}}} Add to my Backpack {"func":"registerKeyTrigger","values":[{"type":"choice","value":"a"}],"next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.topdown::attack","label":"attack"}} Add to my Backpack


How do I go to the next level with the level editor?

Attach the "set level" block to an event block. Set the value of the next level block to the name of the level you want it to go to.

Sample Code:
{"func":"registerTrigger","values":[{"type":"wrapper","func":"valueOpGreater","values":[{"type":"string","value":"100"},{"type":"wrapper","func":"valueSensingDistanceToSprite","values":[{"type":"string","value":"knight"}]}]}],"next":{"func":"blockLooksSetLevel","values":[{"type":"string","value":"2"}]}} Add to my Backpack


How do I make characters move through tiles with the level editor?

Tiles are active by default. To make them inactive, use the "set active" block with the name of the tile set you want to affect. Set the tile set to false if you want actors to pass through it.

Sample Code:
{"func":"registerFlagTrigger","hiddenInSandbox":true,"next":{"func":"blockPhysicsSetActorActive","values":[{"type":"string","value":"waterfall- tiles"},{"type":"boolean","value":"false"}]}} Add to my Backpack


How do I make an Underwater Platformer level with the level editor?

Try selecting an underwater background and setting the gravity to a low value. Then use the "fly" blocks instead of the "walk" blocks to make it look like your character is swimming through the water.

Sample Code:
{"func":"registerFlagTrigger","next":{"func":"blockPhysicsSetGravity","values":[{"type":"number","value":"0"},{"type":"number","value":2}]}} Add to my Backpack {"func":"registerKeyTrigger","values":[{"type":"choice","value":"right arrow"}],"next":{"func":"blockControlCallLibrary","cat":"functions","name":"tynker.platformer::fly right","label":"fly right {string:speed}","values":[{"type":"string","value":"10"}]}} Add to my Backpack


How do I remove or place tiles at my actor’s location?

Use the "set tile" block and place your character’s X-Y coordinates in the X and Y valuesof the tile. Setting the tile to "empty" will remove it. Setting any other kind of tile will make that type of tile appear in your character’s location.

Sample Code:
{"func":"registerKeyTrigger","values":[{"type":"choice","value":"space"}],"next":{"func":"blockLooksSetTileAt","values":[{"type":"wrapper","func":"valueOpAdd","values":[{"type":"wrapper","func":"valueMotionXPosition"},{"type":"number","value":"0"}]},{"type":"wrapper","func":"valueOpAdd","values":[{"type":"wrapper","func":"valueMotionXPosition"},{"type":"number","value":-80}]},{"type":"string","value":"empty"}]}} Add to my Backpack


How do I make actors fall out of the Stage with the level editor?

The Stage is active by default. Use the "set active" block to make the stage inaactive (set active to false). This will let actors pass outside the Stage boundaries.

Sample Code:
{"func":"registerFlagTrigger","next":{"func":"blockPhysicsSetActive","values":[{"type":"boolean","value":"false"}]}} Add to my Backpack


Player

{"func":"blockPlayerSetGameMode","values":[{"type":"string","value":"add player block here"},{"type":"string","value":"survival"}]}

Set Game Mode of Player

"Set Game Mode of Player" is a block that sets the Minecraft game mode, such as survival or creative, for a player.

Parameters:

Mode: This is the game mode that will be set for the given player.

Player: This is the Minecraft player whose game mode will be set.

Related Blocks:
{"func":"blockPlayerTeleport"} ,     {"func":"blockPlayerFlightMode"} ,     {"func":"blockPlayerSetCompassTarget"} ,     {"func":"blockWorldSetPvP"}

Sample Code:
{"func":"blockControlForEach","values":[{"type":"wrapper","func":"valueWorldGetEntitiesByType","values":[{"type":"string","value":"player"}]},{"type":"wrapper","func":"valueScriptVar","name":"p"}],"containers":[{"func":"blockPlayerSetGameMode","values":[{"type":"wrapper","func":"valueScriptVar","name":"p"},{"type":"string","value":"survival"}]}]} Add to my Backpack