Tutorial 2: Collectable Cheese

Last time I left you with a map with a few pizzas on. Now we have better table-cloth tiles and something we can make into a wall or obstacle. Because of the odd perspective we’re using I’ve decided to make the “wall” 1.5 blocks high. The top half will be a foreground tile so you can pass behind it while the bottom half will be a normal tile flagged as “IsSolid”

As promised, the tutorial 2 graphics are improving. Almost looks tasty?

To make a tile impassable we’ll need to edit the tileset – so press this button in Tiled.

Then, select the tile that is half light, half dark and tick “isSolid” in the properties to the left. Don’t forget to save the tileset afterwards!

Now for the tops of the platforms you need to make sure you place them on the layer called “foreground” in Tiled.

We’ll need to add something for the rat to eat, too.. In the Blocks tab of Scorpion Editor, press the + button (top left) and choose the cheese from the animations folder. Then save the block as cheese.block to a “blocks” folder inside the project. Now press “Edit Map” from the Maps tab in Scorpion (this is important as it will force Scorpion to populate the blocks palette with the new cheese block) After putting down some cheese blocks, and some walls – you can see that the cheese blocks can be behind the wall top (foreground layer) too.

Now lets make the game aware of how many cheese blocks there are. In our startup codeblock (code tab in SE) we’re going to declare two new variables.. CheeseMax (the number of cheeses in a level) and CheeseGot (the amount of cheese consumed) and a third variable called Cheese2go (this one we’re going to use for the game’s UI.

You can press “D” to declare a new variable.

Now, we could hard code the cheese block totals but that’s extremely inefficient given that you’ll probably want a different amount of cheese per level.

Lets make some code to count the cheese blocks in the level as the level starts! I’ve created a new codeblock called cheesecount that we’ll GoSub to in the Startup codeblock. It looks like this;

That’s a Level/Countblock command that’s dropping the number of Cheese blocks into the Cheesemax variable. It’s also resetting the other variables, so we can use it at every level start.

Now we need some way to see the Cheese count, so we’re going to make a panel. I’ll try the new floating panels for this (I’ve never tried these before so hopefully it won’t break!) In the Panels tab, press + and choose window panel..

I’ve called the panel GameUI and I’ve put it in a new panels folder inside the project.Then select the CheeseUI.png when it asked for a panel image.

Create an element, set it’s variable to Cheese2Go and the numberfont to defaultnumberfont. Then give it a max Value of 999 and drag the text so it’s centred nicely.

A couple of codeblock additions we need to get this working.. The collision for the cheese block, and the code telling it to display this new panel.

Now we need to add window GameUI X=100 Y=3 to the startup codeblock!

So the startup codeblock now looks like this:

Finally.. The code to collect the cheese! In a new codeblock called EatCheese I’ve added these lines:

Setblock none destroys the cheese. Set CheeseGot to CheeseGot +1 is adding 1 to our eaten Cheese tally. The next line is setting Cheese2Go to the CheeseMax (as calculated on level start) minus the new cheesegot value!

Now we just need to rig the cheese code up to the block.. In the blocks tab:

Now.. Lets see if things work and compile..

Wonderful! I have to leave things at this point, so monsters will have to be next time. The UI works (if a little jankily!) the cheese can be collected. If you want to experiment more, maybe you could add some sound effects or music. Or maybe even create a codeblock that happens when CheeseGot = CheeseMax? Can you think of a way to make the player fall off the table at the bottom of the level?

I hope to have a lot more to say about my projects’ progress soon. If you need the support files for this tutorial you can download them at mixelslab.com/scorpion. Good luck experimenting!

Leave a Comment

Your email address will not be published. Required fields are marked *