Tuesday, 6 June 2017

Rivermead - How To Write Games 101

For this challenge, they're going to need (this is not an exhaustive list ...)
  • An idea
  • Some planning/design skills, so they can work out how they're going to implement said game
  • Preferably, some means of describing the game and design so that if/when they don't finish, at least they can show what they thought of as a set of sketches or whatever
  • Familiarity with the Scratch features that are required to implement the game
  • Obvs, Scratch coding skills!
  • Presentation skills of some sort
Pretty non-trivial...

Ideas

What kind of games could be of interest?
  • Maths games
    • Counting
    • Shape recognition/matching
    • Sum of numbers up to 10
    • Times tables
  • Word games
    • Thing/name match
    • Spell game (say word, have player pick/drop letters)
    • hangman type game
  • Story games
    • Not sure how these could work but could be interesting!
One of the big questions is "Do you expect your player(s) to be able to read?". For kids younger than Year 4, some will, some won't. There's a lot of possibilities for games that don't require reading, or teach reading/numeracy without prior reading skills.

Scratch - what can it do?

Scratch can (not an exhaustive list)
  • "say" things i.e. have a sprite with a speech bubble
  • really say things i.e. replay recorded sound, which could be speech
  • detect keyboard key depressions
  • display sprites, and have them change their appearance ("costumes")
  • move sprites around, or have the player drag and drop them
  • sprites can detect when they're clicked, or touching other sprites, colours etc.
  • switch the stage "background", and the relationship of sprites/stage (forward/backward in layer)
  • play tones, with pitch and timing i.e. simple tunes if you programme it
  • change colours of sprites, stage etc.
  • clone sprites, which can then know if they are clones
  • stage and sprites can 
    • broadcast messages
    • receive messages

Planning

Given the two basic types of entity in Scratch, sprite and stage, how will you set up your game? Just about everything will have to be a sprite, in fact, the stage can provide a backdrop, and can also contain code that isn't sprite-specific e.g. initialisation, choice of random values to drive game etc. 

You will probably need to have at least one sprite that "interacts" with the player, by "say"ing things, or using recorded speech to actually say them. It's also possible that could be done by a stage "background" which is switched appropriately, but the stage doesn't have the "say" verb.

How does the player interact with the game? It's probably easiest to click on a sprite, or use arrow keys to move a sprite. You probably need a start/stop/reset capability e.g. "ask me another". It's also possible to drag a sprite and drop it on another sprite, and have them detect that. 

Make a sketch of a stage. Put sprites on it to show the starting positions. Add storyboard images to show the progress of the game. Or just do it in Scratch if you're fluent enough!

An Example

Let's make a counting game. Show the player a number of objects, and have them "say" how many they count. Let's say 1-9 objects to start with.

How do we decide how many objects to show?
Example random number setting code
What will we use for "objects"? We have to show the number "number_to_count" objects. How do we do that? Various ways...
  • Sprites, obviously... 
    • Have the required maximum number of objects in existence, and display only the number we need
    • Make the required number of objects, and put them in position on the stage
  • Have a stage with at least N different backdrop, where maximum number of objects is N, with each having a different count of objects
    • This seems pretty clumsy... also hard to change the type of objects, since any change requires a whole new backdrop!
I opted for the first option (sprites, N in existence, display ("show") as required). The sprites are just dropped in various positions on the stage, and live there all the time, shown/hidden as required.
Example countable object code - shows/hides depending on "number_to_count"
How will the player interact with the game to say how many objects they've counted? Scratch doesn't do voice recognition... so they will have to click on something or drag/drop something. How about we show the integers 1-9, and they click on the one they think it is?
Simple stage with integers displayed
The integers are all sprites, because it makes it easy to detect them being clicked. They have to detect if 
  1. they are clicked 
  2. they are the right answer
and then tell someone that this has happened.
Code for integer "1" sprite
How are we going to tell the player what to do, and if their answer is correct or not? I know, let's use a sprite... and pick the default cat, because it's Scratch.
Game stage showing interaction sprite, count sprite(s) and answer sprites
The interaction sprite needs some code...

The whole thing can be test driven at https://scratch.mit.edu/projects/164774926/#player.

Improvements and Enhancements

Some possible ideas for making it better or more interesting:
  • Enable it for non-readers
    • Use recorded speech instead of text for all messages
    • Have the integer sprites announce themselves when clicked
    • Maybe have the object sprites say what ordinal number they are when clicked
  • Vary the difficulty - start with say 1-4, increase to 1-9 as number of right answers increases
  • More exciting rewards
    • Score - get a number of right answers, get a splash page
    • Different, random rewards/reward answers to mix it up a bit
  • Vary the type of objects
    • All the same, but randomly different each time
    • All randomly different every time!
  • Count a particular type of object from a selection of different objects e.g. apples/pears/lemons - how many apples are there?



New Victims - Rivermead!

I started out with Code Club as an assistant to Peter Higginson, and as part of that joined the STEM Ambassador programme. This is a great initiative that gets people from the "real world" (whatever the f... that is!) to go into schools and work with children on Science, Technology, Engineering and Maths related projects - not sure where computers fit, oh, possibly Engineering? Anyway, they get you your DBS certification so that you can actually get into a school. Which is quite hard these days - Hawkedon for example has checkpoints on the front and inner doors, with releases controlled from reception etc.

Since the Hawkedon sessions finished at Easter, I wondered if there was anyone out there needing some help. The STEM network people in Winchester send out an email with requests, and Rivermead Primary was looking for someone to help with a "Scratch games challenge" for their Year 4 (8-9 year olds). The Challenge is for the kids, working in pairs with a kid from another school they haven't met before, to design and code a game in Scratch that will teach someone younger than them something. Efforts to be judged by a panel of head teachers, on the basis of a presentation given by the children. Interesting... Target date 30th June, it's already May, and we only get an hour a week, after school (3.30-4.30). Could be a challenge for everyone!

Another (virgin) STEM Ambassador, Graham, had also volunteered - has experience with Cubs and other things like that though, and was a school governor. I also roped in Peter, on the basis that even though I was leading it, he would provide great backup, especially as I'm on holiday some of the times that the club runs.

At the time of writing, we've run three sessions, which have been based on material for the first two lessons at Hawkedon. It's been hard - the kids are a lot younger than the Hawkedon guys, and it seems they haven't had the same exposure to Scratch, although they have had some. There are also logistical problems - we're using Scratch2 online, rather than Scratch1 installed, and once they have had to use tiny netbooks that struggle to run the browser-based IDE. Gosh. Still, everything we do is better than doing nothing, right? And they are starting to think about it more.

Sunday, 12 March 2017

micro:bit and Bluetooth

We have 8 BBC micro:bit micro controller boards (are they computers?? Not sure - is a washing machine?! (time travel!)), and although the club has had a bit of a fiddle with them, writing random messages, playing music, listening to bananas and other fruit, we could do with something a bit more challenging.

Martin Woolley (Bitty Software) has developed some smartphone applications that can connect to uBits using Bluetooth and retrieve data etc. Maybe we need to look into these...

First, I've downloaded the Bitty Data Logger app for my aging iPhone 4S from the Apple App Store. Yeah, I should be using Android, but it still works and owes me nothing, ok?

Let's check the tutorials website - I like PXT because it means I don't have to mess around with C/C++, been there, done that, got paid for it.

The tutorial is pretty simple, although the current PXT facilities, assisting nRF bluetooth application and procedure is different.

Writing Bluetooth code in uBit

Start a new project in PXT. Add the Bluetooth package, accepting to discard the Radio package.

The tutorial gives you the general idea, but I had to use the following:


Obviously, more could be done! Download the hex file and load into the uBit.

Pairing with the iPhone

Note:
I used the app that requires pairing - there is also another version which does not require pairing, which we used in conjunction with an iPad. It worked perfectly fine.

This doesn't work without a helper app - I tried! The video here shows the basic approach:

  1. Put the uBit into pairing mode (Reset + A + B - display shows PAIRING)
  2. Use the uRF Connect application from Nordic (NOT the suggested one in the video!)
    1. Scan shows the uBit available
    2. Click on Connect 
  3. Job done!
The screen now shows all the uBit service IDs which are loaded into the uBit hex file, and the uBit is visible on the Services Bluetooth 

Iphone Bluetooth screen
nRF Connect screen




















Use Bitty Data Logger!

This bit was easy - start the app, Scan, see the uBit listed, click on its entry, then Start.

I then dropkicked the uBit around a tad, and had some results! Marvellous.


Screen shot of actual captured data!

Update:

The Data Logger application has a settings page - you can add Magnetometer and Temperature data to the logging. Marvellous.

Child Testing Notes:

The uBit/app combination generated some interest. I took some bubble wrap and tape so we could protect a uBit whilst doing dynamic things with it. After getting it working with the school's iPad, using the non-pairing version of the application, various experiments were tried:

  • How far will the uBit go before it loses contact with the iPad?
    • About 30 ft, which involved a partition wall and various interspersed children
  • What happens if you drop it?
    • The batteries wiggle in the box and it cuts out, enough to sever the Bluetooth connection. We tried taping them in, but this requires more thought. 
  • Can you strap it to your shoe and get any interesting data?
    • You can!! But it would require lots of attempts and study of the data, using some kind of "normalised" or standard setup, to get enough reliable data to make statements about gait and so on. Lots of interest in that though.
All in all, a worthwhile session!


Code Club - the start

I went to Reading Geek Night - 2nd Tuesday of the month, upstairs at a large central pub. There I met Peter Higginson and got talking, ending up suggesting that I might be interested in assisting in running coding classes and an associated Code Club at a local primary school. Inevitably, his current assistant backed out, and I was called in.

Four weeks of Scratch lessons to two Year 6 classes (10 year olds), then Dec - April lunchtime Code Clubs, one hour once a week. It's fun. The kids are amazingly interested!

We started Code Club with some additional Scratch work, then moved onto the 8 micro:bits that the club has. They were quite fun, with kids getting involved in making music and various other things than can easily be done. It's quite hard to

  1. Help all the people with questions, as they're all working at different speeds and levels, with only two people
  2. Address/fix the problems they encounter when one has little or no experience of the tools yet, especially as some of the difficulties are because they deleted something!
Subsequently, we've moved onto Javascript, modifying a "shoot down the airliner" game. I'd forgotten lots about JS...

Ideally, I'd like to have some slightly longer term projects running, that involve multiple people doing various sub-tasks, that would carry us from week to week. But they are coming back, and enthusiastic, amazingly, so should I be asking for more at all?