In this session we will be kicking off our games by creating some of the first assets and maps. We'll touch on controls, tilemaps, and possibly animation whilst we experiment with our art style and story thread.
If you want to skip ahead and see the code for this session working, you can download a copy of Lost in Wales . To download, click the link below to open the image. Then save the image to your computer and follow the instructions for Loading.
The first thing we’ll do is get acquainted with MakeCode Arcade.
Firstly, visit arcade.makecode.com and click New Project. Give your game a name (it can be changed later) and have a look around the Interface.
Before we get started we should find out how to save.That way, if we keep saving we won’t lose our game.
Find the Save icon near the bottom. When you click it, you are asked to save a .png file. This image is secretly hiding your game data beneath the picture.
Now we’ve saved, we can load. You can load any .png made by MakeCode Arcade.
That way you can share games and view other peoples. It’s a good way of viewing my code as an example.
Now we can start on our game. The first thing to make is the image of our player character.
All Images are Assets. Assets are images that we can come back to when we need them.
Switch to the Asset tab and click new Asset. Draw a new character or choose one from the Gallery. Make sure to give it a sensible name.
Sprites are the interactive objects of a game. They can be controlled with code and can collide with other sprites.
Switch back to the Blocks tab. With our player asset drawn we can now use it in the game code.
Inside an 'on start' block, use a 'set mySprite to sprite [ ] of kind player' block from the Sprites menu.
Use the drop-down arrow on mySprite to rename it to playerSpr. Click the [ ] to select your player asset.
Now your sprite is wearing your player character image. You can see this in the Simulator on the left.
If we visit the Controller menu, we can grab the 'move mySprite with buttons' block and put in inside on start too.
Use the drop-down arrow to change mySprite to playerSpr.
Now press play on the Simulator to see our player move around with user control!
We've now got a player character, but currently they're walking through the void.
To give them a world to explore we're going to add a Tilemap. This is a grid of squares or Tiles. Each Tile can have a design.
Create a new Tilemap in the Assets tab and use the Tiles to create a world for your game.
Now we have the Asset we can use the 'set tilemap to [ ]' block and place it in 'on start'.
If we press Play and move our character around we can see that they quickly disappear off screen. This isn't good.
To fix this, we're going to find the Scene tab and place the 'camera follow sprite mySprite' in 'on start'. Obviously we need to change mySprite out.
Now when we move the player around the Camera follows. But notice how the player can move through rocks, cliffs and trees?
To fix that we're going to visit our Tilemap in the Assets tab and use the Wall Tool to draw walls over everything we want solid in the world.
For the next session we'll need something to fight!
Use your knowledge to create an Enemy asset the exact same way you created the player. Make sure to use sensible names!
An RPG needs lots of different types of enemy. You could start by adding more enemy Assets of different types for later use.
On top of that, many RPGs use variations of certain enemy types. For example, you could make an evolved version of your enemy that is more powerful, or a version that has a different style, or attack, or behaviour.
At the moment we just have an Enemy Asset.
To make a sprite, we'll place another 'set mySprite to sprite [ ] of kind player' in 'on start' but this time we change the kind to enemy. This is important for later. Don't forget to rename mySprite something new as well.
MakeCode Arcade is based on a grid of pixels.
We count horizontal (side-to-side) pixels from left to right. The furthest pixels on the left are always horizontal pixels at number 0. The rightmost pixels have a number that depends on the width of the thing we're measuring. To remember, use low numbers left, high numbers right.
This is similar for vertical (up-down) pixels. Here the topmost pixels are 0 and the bottom most are higher numbers.
We say the horizontal pixels are on the x axis and the vertical pixels are on the y axis.
At the moment our player sprite is at postion (80, 60). This means they are 80 pixels away from the left and 60 pixels away from the top.
This is because the x position of the player is 80 and the y position is 60.
If we move the player around this changes. We can see that change by looking in the Sprite panel and finding the 'set playerSprite auto destory off' block and changing auto destroy to show physics and off to on.
At the moment we jhave one Enemy.
We can surround our 'set myEnemy to sprite [ ] of kind enemy' block with a block from the Loops panel called 'repeat 4'.
This creates 4 enemies all on top of each other.
To spread the enemies out we're going to set their x position and y position to something random.
From the Sprites panel, find 'set mySprite position to x 0 y 0'.
Using two 'pick random 0 to 10' blocks from the Math panel in the place of the 0s in x and y we can get the enemies to spawn across the map!
You will need to change the 10 in the 'pick random' blocks to a higher number. Too high and they'll appear outside your map. Too low and they'll be confined to a small area.
We're all done for the first session, but you may notice some bugs:
Sometimes the Enemies spawn stuck inside tiles or on top of the Player.
To fix that we need to rethink how enemies spawn.
Instead of setting a random position for the enemies, generate a random number and store it in a variable.
If that number is 0, send them to a position that you've already chosen.
If that number is 1, send them to a different position.
And so on...