Intermediate Scratch – Challenge 12 – 2-Player Network Guessing Game

CDA-S2-Challenge12-2Player-GuessingGame

This week in CoderDojo Athenry, we continued to play with networking in Scratch.

As we learned last week, you can set up a Mesh network in Scratch so that Scratch programs running on two different computers can exchange information with each other. This week, we used those ideas in combination with our simple guessing game from Challenge 2, to create a 2-player network guessing game.

Since we have new members who have just joined us in the past week, they could focus on the one-player version while more experienced members could work on the networking aspect.

The big ideas behind this challenge were:

  1. Design of a 2-player game (need two programs with different roles and different code)
  2. Communications on the network using variables
  3. Broadcasts across the network
  4. Loops and Decisions: fundamental coding concepts

Here are my notes from the day (PDF format): CDA-S2-Challenge12-2Player-GuessingGame.pdf

Here are my versions of the game for both players:

  • GuessNumberNetwork: this is the one that plays the ‘guess a number game’ when the other one (the ‘boss’) chooses the number
  • GuessNumberNetwork-Boss: this is the one that allows you choose the number and then communicates with the other one that plays

Note that you must download these (they won’t run on the Scratch website) and enable Mesh networking as described in the notes for them to work.

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

Scratch Advanced – Week 13 – Gravity and Speed

What are we going to do this week?

  • Gravity
  • Speed
  • Momentum

We are going to look at Gravity and how it works here on Earth. We will also be looking at how, when you travel fast enough, you can appear to defy Gravity, this is how Satellites stay in orbit around the Earth.

We will also take a look at momentum and how things behave once they are moving.

And in order to demonstrate the effects of Gravity,  we will build a Spaceship Game, were you have to launch yourself into Orbit.

Depending upon how we get on this may run over two weeks.

Now back to Gravity. If you  want to get all smart, there is a very clever equation that Sir Issac Newton came up with back in 1687. But we won’t go there for now.

Gravity is basically a force of attraction and the closer you get to something the stronger that force is, also the bigger somehting is the more gravitational force it will have.

It’s a very small force, it takes the whole of the planet Earth to hold us down.

So how are we going to show this in Scrartch, well we will start with a Rocket on the Earth, that we have to Launch upwards, Rockets produce Thrust, which pushes them up into the air. The Earth has Gravity which is trying to pull the rocket back down, but the further you travel away from the Earth the weaker the Gravity and so the Less Thrust you need.

I think I just spotted three Variables there…

1. Thrust

2. Gravity

3. Height

They might come in useful in our program.

We are going to try and build a Scratch Game that will launch a rocket into orbit. This mioght take us a couple of weeks, but should be good fun.

So lets try and write down the rules that we need the Game to obey:

1. Pushing the up arrow should fire the rocket and get us moving.

2. If we stop firing the rocket then gravity will start to pull us back down

3. The higher we go the less Gravity can pull us back down.

4. If we travel fast enough, it can make us appear to defy Gravity, that’s how satellites stay in orbit, and the Moon for that matter. But we will leave this out to start off with as it can start to get really complicated 🙂

To start us off I found a Lunar Lander Game that has some of the elements that we need, this will be a good starting point to  get us going.

To start off we only need a simple sprite, a ball with two legs, that should do for our rocket 🙂

 

Intermediate Scratch – Challenge 11 – Learn About Networking

CDA-S2-Challenge11-NetworkChatThese are the notes from our first week of 2013 in CoderDojo Athenry.

This was a really exciting new challenge: to learn about how computers communicate with each other, and apply these ideas to setting up Meshing in Scratch so that Scratch programs running on two different computers can exchange information with each other.

The big ideas behind this challenge were:

  1. How networks work
  2. Communications between programs running on two different computers
  3. Variables (used for exchange of data).

We started to apply these ideas to build a multi-player, multi-computer chat game. We will extend this next week and move on to other networked games. Stay tuned!

Here are my notes from the day (PDF format): CDA-S2-Challenge11-NetworkChat

Here is my version of the chat program: http://scratch.mit.edu/projects/cdathenry/2591598 (note that you need a separate version for each person in the chat, and you have to have enabled Mesh networking as described in the notes.)

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

Scratch Advanced – Week 12 – Welcome back

What are we going to do this week:

1. Re Cap on the exam.

2. A Magic Eight Ball, Question and Answer Game.

3. Flow Charts – how to explain code with pictures 🙂

1. Re Cap on the exam

I though we might have a quick review of a couple of the questions from the Exam. There was one question that nearly everyone missed and I think it might have been the way I wrote the question, so we’ll just go over it quickly.

Question 8:

If you want two pieces of code to run together (parrallel processing) circle all the ones that you could use:

a. Broadcast

b Broadcast and wait

c. Green Flag

The Broadcast and wait will NOT run things in parallel, it will Wait for the other code to finsh before continueing.

2. A Magic Eight Ball, Question and Answer Game.

I thought we would use some of the List skills that we used in the Christmas Game to build a Magic Eight Ball type Question and Answer game.

So here are the requirements:

1. A Genie should appear from a Lamp.

2. There should be a friendly Sprite Character who will ask if you if you have any questions.

3. There will be a place to type in your Question

4. Questions can only be ones that have a Yes or No Answer.

5. A nice background to match your friendly Sprite

6. A random answer should be selected from the following list:

It is certain
It is decidedly so
Without a doubt
Yes – definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yes
Signs point to yes
Reply hazy, try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again
Don’t count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

I decided to use a Genie in the Desert, emerging from a Lamp to answer my Questions.

Here are my Sprites:

Genie

 

Lamp

 

 

 

 

And here is my stage:

Giraffe

 

 

 

The Code is Quite simple, again I have used the Stage as the Starting point for all the Code as I think this makes quite good sense as there is only one Stage, but generally many Sprites.

First we have to populate our Answer List with the different possible answers.

Then we can let the Genie know it is time to do the talking…

Now, I added the Lamp as, we need code under the Lamp to get things started. I decided that you should have to rub the Lamp to make the Genie appear. Once the Genie was out of the Lamp, we will let you ask the Genie a Question.

The code, well you know how to populate lists, so I’m not going to go through that.

For the Lamp, we need to check to see if the Mouse is touching the lamp and the Mouse Button is down, if it is we will keep counting up till we reach 10 and then let the Genie take over. We can do that with a Broadcast. But don’t forget that we also want the Genie to appear out of the Lamp, so as we are counting to 10, we need to make the Genie grow.

This is what I came up with…

LampCode

 

 

 

 

 

For the Genie, there are a few pieces of code, one to set him up, one to make him appear and grow, and finally the one where he gets you to ask a Question.

GenieCode

 

 

 

 

 

 

 

And finally, I came up with a third, invisible Sprite, but it allows the Giraffe on the background to say a few things as well. I came up with another list of things that he could say and populated those at the begining as well.

GiraffeCode

 

 

And I have been really kind and uploaded the finished Scratch Project onto the Scratch WebSite.