Week 4 2017 – Explorers – Piano

Hello everyone,

Thank you all for coming yesterday on such a lovely day.

This week we did a simple Piano.

piano

We only had to draw two keys, and then could duplicate these and change the names. The same applied to the code. The code is the same for each key apart from one small change so the note is the appropriate for the key.

REMEMBER! You need to make four changes each time you duplicate:

Change the name of the spite to the next Note

Change the name of the TWO costumes

Change the NOTE played

Piano2

Piano3

Remember, no sessions for the next two weeks. Have a nice break and for anyone with confirmations to attend next week I hope the weather is extra nice for you.

See you back on the 4th of March

Here are notes from this week in PDF cda-s6-week-4-17-piano.pdf

Martha

Creators – Starting Our First Game

This week we started our first game in earnest. Let’s talk about the design and the steps we took to begin implementing it.

PinBowling.jpg

Game Design

The game involves a simple play area with pins. The players tries to knock down the pins by controlling the direction and force at which the ball is projected. The number of pins knocked constitutes the score. The game shares element of classic games such as pinball, bowling and skittles, to name a few.

Setting up the play area

To establish the play area, we used a plane (for the ground) and four cubes stretched to size to provide the walls:

gameboard

Because we don’t want gaps in our walls, we’ve been careful to be precise with the positions of everything.

Applying a Force to our Sphere

We added a sphere to our scene and made sure that it had a RigidBody body component. The RigidBody component makes it so that the physic engine takes care of the movement of the sphere.

To test adding a force to the sphere we added a temporary script to the sphere and had it add a force to the RigidBody as soon as the game starts.

Immediately it was clear that the force was too weak, so we added a property to the script which allowed us to scale the force. In testing 1000 proved to be a good value. Here is the script:

 using UnityEngine;
 using System.Collections;
 
 public class PushSphere : MonoBehaviour 
 {
   public float PushStrength = 1.0f;
 
   // Use this for initialization
   void Start ()
   {
     Rigidbody rb;
     rb = GetComponent<Rigidbody> ();
     rb.AddForce (Vector3.back * PushStrength);
   }
   
   // Update is called once per frame
   void Update () 
   {
   }
 }

 

We also experimented with creating a physic material and assigning it to the sphere. Different levels of friction and bounciness give different behaviours.

Testing With a Single Pin

To test the sphere colliding with a pin we added a single cylinder to the scene. Like the sphere, we made sure it had a RigidBody component attached to it. When the game started the ball shot forward and knocked the pin, as we’d hoped.

Aimer

To aim our sphere and control the strength of our shot, we created an aimer. The aimer is composed of an empty object containing two cylinders, one pointing forwards and one pointing crossways.

We didn’t want the aimer cylinders interacting with anything so we made sure to remove the colliders from the cylinders.

We also wanted the aimer to be partially transparent so we created a new material, setting the Rendering Mode to “Transparent”, choosing a colour from the Albedo colour picker and setting the Alpha value to a value less than 255.

Screen Shot 2016-10-10 at 22.39.21.png

Project

Updated project files for this week’s project can be found here. This requires Unity Version 5.4.1f1 or later.

Week 4 Explorers – Ghostcatcher

Hello Everyone

Great to see so many of you there on Saturday, 77 Ninjas!. Hope you had a good time. And a special welcome to our new Ninjas.

This week we created a Ghostcatcher game. We used the paint editor in Scratch for the first time. As I said on Saturday, It makes things easier if you think in shapes.

PACMAN

Using the code we have learned so far, we moved the Ghostcatcher with the mouse and the Ghosts randomly. We also added some sound.

PACMAN2

We are going to continue on next week and improve this game, adding some Variables and some levels.

Here are this weeks notes in PDF. cda-s6-week_04-ghostcatcher.pdf

ModderDojo Athenry Topic 6: JavaScript Operators and ScriptCraftJS Drone Functions

Operators:

Operators in any programming language are used when you want to calculate something new: they operate on values. variables, or expressions to produce a new value.

Since ScriptCraft is built on the JavaScript langauge, it uses standard JavaScript operators. As it happens, many other programming languages (including C, C++ and Java) use the same operators or very similar ones.

JavaScript Operators

Drone Functions:

As we have seen before, in ScriptCraft you use a drone to do your building for you. The drone has functions that are part of it.

Here are some of the main drone functions that are useful when building your mods:

ScriptCraft Drone Functions

You can find lots more about these and other functions in the ScriptCraft API Reference: https://github.com/walterhiggins/ScriptCraft/blob/master/docs/API-Reference.md

Example: Build a Pyramid

This example is based on a very nice program writing by Ruaidhri from Coderdojo Athenry last year, updated slightly because some ScriptCraft commands have changed in the meantime.


// Copyright Ruaidhri from ModderDojo Athenry,
// slightly updated by Michael and Alex.
// Builds a pyramid with entrance and lights inside.

exports.pyramid = function()
{
echo('making a pyramid');
var d = new Drone(self); // 'self' means start drone beside me
d.up(1);

d.chkpt('begin');

var size=31;

// Make the walls
while (size &gt; 0)
{
d.box0(blocks.sandstone,size,1,size);
d.right(1);
d.fwd(1);
d.up(1);
size=size-2;
}

// Entrance
d.move('begin');
d.right(15);
d.box(blocks.air,1,2,3);

// Lights inside
d.move('begin');
d.right(4);
d.fwd(4);
d.up(3);
d.turn(2);
var t = 0;
while (t&lt;4)
{
d.hangtorch();
d.left(11);
d.hangtorch();
d.left(11);
d.turn(3);
t = t + 1;
}
d.move('begin');
}

Scratch Beginners Week 4 – A Better Ghost Catcher Game

This week we improved on Martha’s original Ghost Catcher game! The notes can be found on this website as CDA-S5-Challenge_04-BetterGhostCatcher.

We animated our ghosts by creating a simple change costume script that runs forever,Season 5 Better ghostcatcher- animate ghost - costume

Season 5 Better ghostcatcher- animate ghost - Code

We made our ghosts broadcast a message when they are caught to make ghostcatcher (aka Bob) change his costume (Hint!: First, we made a new costume for Ghostcatcher Bob to make his mouth look closed!),

Season 5 Better ghostcatcher- broadcasts

Season 5 Better ghostcatcher- broadcasts- make ghostcatcher react

We also got Ghostcatcher Bob to broadcast a message that makes the stage change it’s background to each time a level is changed.

Season 5 Better ghostcatcher- broadcasts - use score var to chg background color

If you have any questions about all the variables, ghostscaught and speed, that you saw in my version of the program, please review the notes on this website for the previous week: CDA-S5-Week_03-Ghostcatcher.pdf. Check out the last few slides.

Thanks to Martha Fahy for all her notes so that we could really make huge progress with our Ghost Catcher game!

Have a very Happy Halloween and we will see ye all back on Saturday November 7th at 12.00!

Julie OBeirn

Python Games – Week 4: Lists and For Loops

We learned about some new concepts today in the Python Games group – multi-line strings, lists, for loops, methods, elif statements and the dictionary data type.

We had a quick look at the Hangman Game from Invent Your Own Computer Games with Python (http://inventwithpython.com/chapter9.html). We covered Lists which are a way of storing a number of values in one variable and had some fun writing code snippets mainly based around X-Factor. We looked at some new ways of working with strings called multi-line strings.  We also learned about new types of functions called methods and a new type of loop called a for loop. At the end of the session we started to get to grips with Pygame. Our code snippets are available here and my slides from today are here python session_4

ModderDojo Athenry Topic 6: JavaScript Operators and ScriptCraftJS Drone Functions

Our mods:

Download them here: https://cdathenry.wordpress.com/2013/11/10/modderdojo-athenry-our-scriptcraftjs-minecraft-mods/

Operators:

Operators in any programming language are used when you want to calculate something new: they operate on values. variables, or expressions to produce a new value.

Since ScriptCraftJS is built on the JavaScript langauge, it uses standard JavaScript operators. As it happens, many other programming languages (including C, C++ and Java) use the same operators or very similar ones.

JavaScript Operators

Drone Functions:

As we have seen before, in ScriptCraft you use a drone to do your building for you. The drone has functions that are part of it.

Here are some of the main drone functions that are useful when building your mods:

ScriptCraft Drone Functions

You can find lots more about these and other functions in the ScriptCraft API Reference:
https://github.com/walterhiggins/ScriptCraft/blob/master/docs/API-Reference.md

ModderDojo Topic 5: Moving from Scratch to JavaScript

GeneralFeaturesOfProgrammingLanguages

Reminder: JavaScript is a well-established programming language, mainly used in web development. ScriptCraft is a Minecraft mod that allows you to write JavaScript code for building structures in Minecraft and writing new Minecraft mods. (So it’s a mod for creating other mods.)

Steps 1 and 2: Try out ScriptCraft commands and write simple mods

Please look back to last week’s notes for now to do this: https://cdathenry.wordpress.com/2013/10/05/modderdojo-week-1-getting-started-with-scriptcraft-and-javascript/

Step 3: Comparing JavaScript to Scratch

Some people criticise Scratch as being “childish”, but I don’t agree. While it is designed so that even 8 year olds can use it, it is still has all of the key features of ‘adult’ programming languages, as listed in the image at the top of this post.

(Technically, any programming language with variables, decision and loops is Turing Complete.)

This means that, if you already know how to write a Scratch programs that use these features, you will be able to apply that knowledge to any other language, such as JavaScript. The syntax of JavaScript is different, but it uses the same computational thinking.

Variables-Operators

Loops

Decisions

Notes:

  • Even though they have basic ideas in common, every programming language has its own specific commands that relate to its purpose: Scratch is focused on 2D games and animations, while ScriptCraft is focused on operating inside Minecraft, and JavaScript generally is used for interactive websites.
  • the echo command that features in these slides is not a standard JavaScript command, it is just used in ScriptCraft to display things on your screen in Minecraft.  Everything else is standard JavaScript.

Scratch Advanced – Week 4 – Cryptography the Caesar Cipther

This week we created on of the most famous ciphers the Caesar Cipher. This cipher is named after the Roman emperor Julius Caesar.

The Caesar cipher works by shifting each letter of the alphabet by a specific number.

In the example of the Caesar Cipher below the letters in the PlainText alphabet have been shifted by three places.

Cipher shift

The letter a becomes D, the letter g becomes J and so on.

Using a Caesar Cipher with an offset of three the words Coder Dojo Athenry would become FRGHU GRMR DWKHQUB

The notes for this session on how to create a Caesar Cipher using Scratch are here: Scratch Encryption project Ceasar Cipher

Scratch Beginners – Week 4, Animation

In this session we improved on our previous Ghostcatcher game by adding animation.

bigideas

We did this by switching between costumes. Rather than using sprites with various costumes already created, we drew our own.

animation

For the first time, we used the broadcast block, to communicate between different parts of the code.

broadcast

A PDF version of the notes from this weeks session can be found here: CDA-S3-Challenge04-BetterGhostCatcher.pdf