Creators – Finishing Pin Bowling

This week, despite a small group, we finished off the Pin Bowling game. After Christmas we’ll move onto a different game – most likely something 1st person in design.

UI Elements – Text and Buttons

We added two UI Text elements to our game and aligned them to the top left and top right hand corners respectively. One is used for showing the current score and one is used for showing the number of shots remaining. Note that when we add UI elements, Unity automatically adds a Canvas and an EventSystem for us.

UI elements don’t have a standard Transform component, instead they have a RectTransform component which is used to describe their position within their Canvas. To align to a particular location we click on the square below the words “Rect Transform” and select how we’d like to align within the Canvas by clicking one of the options while holding the Shift and Alt keys to set both the pivot and position.

screen-shot-2016-11-29-at-22-41-48

Continue reading

Beginners Scratch – Challenge 9 – Create a Breakout Game

CDA-S2-Challenge09-BrickGame

This week, the challenge in Beginners’ Scratch was to write your own version of the classic Breakout game.

This game uses lots of the big ideas that we have encountered in previous weeks, and that are good to know about when preparing to get yellow belts. These big ideas include:

  • Loops and Decisions
  • Variables and Broadcasts
  • Making Sprites Move
  • Animation and Sound

Here are my notes from the day (PDF format): CDA-S2-Challenge09-BrickGame.pdf

Here is my version of the game: http://scratch.mit.edu/projects/cdathenry/2964870

If you would like a copy of my slides in PowerPoint format, get in touch via Twitter or the comments.

Scratch Advanced – Week 10 – Christmas Game – Final Episode

What are we going to learn this week.

1. Global Variables – A  Variable that all Sprites can see.

2. More requirements

3. Ninja Belts

And that is about it for new things. We are primarily going to be concerned with getting the Present working in the Christmas Game and the final display of what you have caught.

Now, we will start in reverse and look at the “more requirements” part first. Remember we had a requirement for the game that a present should fall and if we catch it, it should be put under the tree. Well we can write that out a little better as another set of Requirements, so here goes:

More Requirements:

The present should:

1. There should be Ten presents.

2. The presents should fall in the two minutes at random times.

3. Each present should fall from the Sleigh to the ground.

4. If the present touches the fire, then it is caught, and should be moved under the tree, anywhere under the tree, but not all on top of each other.

5. Each present should be a different size and colour.

6. If a present is caught we need to keep track of how many we have caught.

So, what we can do is create one present that meets all of the above requirements and then copy it.

For number 6, it looks like we need a Global Variable so all the Present Sprites can update it. So lets make that..

And while we are on the subject of Global Variables, if the Present Sprite needs to drop from the Sleigh, it needs to know where it is, so the Sleigh needs to update a Global Variable with it’s X value all the time.

If you select the Stage, when you create a variable it is automatically a Global Variable. You don’t get the option to create it “for this Sprite only”

We need one for the X Position of the Sleigh and one to record the number of Presents.  Don’t forget to update the Sleigh Sprite so that it updates the X Position variable. Something like this:

SleighCode

Notice that I don’t have the Green Flag to Start the Game, I have used a GameStart broadcast, this is Broadcast from the Stage where I have all my initialisation code as well.

While we are creating the Global Variables, we can also create the two lists that we need to store the names and descriptions, so two lists as well.

This is what I have to set the lists at the begining of the Game:

StageCode

Now back to the Present and the requirements.

This is the code that I have that meets the requirements… Random Colour, Random time delay, after the delay, go the X Position of the Sleigh…

Present01

Now we have to sort out how to recognise if the present has been caught by the fireplace. I picked one of the colours in the fire, and used the if touching code to find out if it has been caught. If it is caught, then we move it to the Tree.

We don’t just move the Present to the same point though otherwise they would all land on top of each other. I pick a random point under the Tree. Like this: