Creators – Week 6

This week we started a new project, a top-down game where we’ll be feeding food to hungry animals who are rushing at us.

We had another asset bundle to download to get the assets we will be using for this project. It’s available on our Teams site.

Upon importing the asset bundle, we start with a basic scene which has three planes, two black ones flanking one with a grass texture. The asset bundle contains a total of four suitable textures for the ground and we had a look at those, and saw how to use them.

The asset pack also contains prefabs, these are pre-made combinations of Unity objects, ready to use. We had a look at some these prefabs by clicking once on them and viewing the preview at the bottom of the inspector. We also saw how double-clicking on them opens the prefab in the game view for editing and how using the back arrow at the upper-left returns us to the scene.

We brought in three animals, a human and a slice of pizza (scaled up by 3 or 4 to make it visible), laid out roughly as shown below:

Making the Player Move

We made a Scripts folder and added a new C# script called PlayerController.cs. At the top, we added two properties:

    public float horizontalInput;
    public float speed = 10.0f;

And Update() we changed to the following:

    void Update()
    {
        horizontalInput = Input.GetAxis("Horizontal");
        transform.Translate(Vector3.right * horizontalInput * Time.deltaTime * speed);
    }

Now, when testing, we see the player can go side-to-side, but it can also go completely off screen! How do we limit this? We do that by adding an if statement; this allows us to check if something is true, and then do something only when it is true.

First we added a new property to the top of the class:

    public float xRange = 10.0f;

This represents the range (between -10 and +10) that we want to confine the player’s position to.

In Update(), after the transform.Translate(), we add the following code:

       if (transform.position.x < -xRange)
        {
            transform.position = new Vector3(-xRange,  transform.position.y,  transform.position.z);
        }

What does this say? If the x part of the players position gets smaller than -xRange (-10) (meaning it goes too far to the left), then we change the player’s position so that the x part is exactly -xRange (-10).

When we test now, we’ll find that we can move as far right as we want, but when we move left, once the player’s x position gets to -10, we can’t move any further.

It’s easy now to add in the same check for the right-hand-side. We can copy-paste the last block of code and make a few small changes to the copy:

        if (transform.position.x > xRange)
        {
            transform.position = new Vector3(xRange, transform.position.y, transform.position.z);
        }

So, the less-than (<) changes to greater-than (>) and -xRange (-10) changes to xRange (+10) in two places.

Now the player is constricted in two directions.

Making a Moving Pizza Prefab

To make the pizza move we make a new C# script called MoveForward.cs and attach it to our pizza slice. In this script we have one property:

    public float speed = 40.0f;

And a single line in Update():

        transform.Translate(Vector3.forward * Time.deltaTime * speed); 

We make a new folder called Prefabs and then just drag our pizza slice from the Heirarchy into it. We now have a prefab of the moving pizza slice. We can delete the instance of the pizza slice in the scene; we’ll be spawning them automatically later.

And Finally…

We looked into spawning the prefab on a regular interval from the player’s position. That’s not part of the final game, but it was just to illustrate making an instance of a prefab from code.

The code for this week’s project is on our GitHub, as always. There is also small additional project there called “ScriptableObjects for a Recipe System” which is demonstrating a way to define ingredients and recipes and was in response one if our ninja’s queries. To download our stuff from GitHub, you can just click on the green button and choose “Download ZIP”

Note that this ZIP file will contain all our projects for the year!

Explorers Week 5&6 – Pacman

For the last two weeks (with a break for a Red Weather Warning!) we worked on a Pacman type game. We tried to put in all the code we have learned over this year and all the games were brilliant and all so different.

 

We designed our own sprites rather than take them from the library.

 

Here are the notes in PDF CDA-S9-Week_05_Pacman.pdf

Here is a link to the game if you want to check it out. https://scratch.mit.edu/projects/375094277

See you two weeks time, keep yourselves safe and healthy.

Martha

Julie, Ruaidhrí, Iseult and Eoin

Explorers Week 6 – Guessing Game!

Hello Everyone,

Great to see you all on Saturday and welcome to our new members.

We made a slight departure from the games we have done in previous weeks. This weeks game was a mathematical Guessing Game.

DUCK

We only had one sprite and one large block of code. We had to create variables and figure out all the possible situations that could occur when a guess was made.

guess

Here are the notes in PDF form from our Week 6 Session. CDA-S7-Week_06-GuessNumbers.pdf

I have also uploaded the game to the Scratch Website in our Explorers Account so you can see the full working game.

Explorers – Week 6 – Halloween Scene

Hi everyone,

Hope you enjoyed this weeks session and remember we are off for the mid-term and so our next session is on the 11th of November.

To get ready for the spooky season we created a Halloween Scene, lots of scary sounds and switching of costumes to create the effect of movement.

I chose a Witch with a wolf howl but I saw lots of great ideas as I was going around the room. Some had Ghouls, others Vampires, its was all pretty scary.

We also learnt a nice trick for giving the allusion of movement. We had a bat change both its size and Costume and it worked very well to give the effect of the bat flying towards us with the moon behind it.

Here are the notes in PDF from this weeks sessions CDA-S6-Week_06-Halloween

Also if you want the completed Scratch Code you can download it by going on to the Scratch.mit.edu website login to the CoderDojo Account (details are in the notes) and search for CDA_Martha_Week06.

Hope you have a great Halloween, be safe when you are out Trick or Treating but have lots of Fun!!

 

 

Explorers – Guessing Game

Hi everyone,

Good to see you back after the Halloween break.

Last Saturday we did a slightly different game to usual., There was no movement, no sensing when something happened. It was a Maths Game, a guessing game where the computer picks a random number and we had to guess the number.

GuessNumbers

We had to first make sure that a random number was picked using an Operator. Previously we have used a Variable to store a Score or Lives, but this time it was storing the random number and our guesses. Leaving them on screen as we were testing allowed us to understand more about the variable and what it does…it also made the testing a little easier.

Depending how any guesses we were given we repeated our code that number of times. As well as having to make decisions, i.e If_then, we also had to do a comparison before making the decision, to determine whether the guess was correct, too low or too high.

5guesess

Some of you tried to add a timer and below is the code you will need if you didn’t get it to work. Take a look and add it to your own game/games.

timer

 

Here is a link to last weeks notes. cda-s6-week_06-guessnumbers.pdf

 

See you next week!

Martha

 

 

 

Beginners scratch week 6 – Pen Commands

Since we had a terrific guest speaker today, there wasn’t enough time to rework our paddle ball game to the famous breakout game, so I picked out the quick (but really neat) drawing game! The .pdf of the slides can be found here:CDA-S5-Challenge_08-Pen Command-CDA-S5-Pen Commands CDA-S5-Pen Commands-code

In order to make it easier to change the values that control the angles of the drawing and the length of the sides, we created variables that we could change via sliders on the STAGE (right click on the variable on the stage after you create it and a menu pops up giving you some options, including a slider option). CDA-S5-Pen Commands-slider variablesReplace the handwritten numbers in the TURN and the MOVE motion commands with the variables for speed and degrees. When you touch the green flag and start the movement of your sprite, you can slide the sliders to get the perfect (or craziest) drawing! Duplicate your sprite and get several sprites drawing at once.

One extra bit that we didn’t get to is to use buttons to start and stop our drawing. Create two new button sprites and script them to send a broadcast when clicked. CDA-S5-Pen Commands-buttons

Just edit the script in the drawing sprite by putting the WHEN I RECEIVE event command at the top of the drawing script and select the START broadcast. Add another bit to the drawing sprite to STOP ALL when it receives the STOP broadcast from the Stop button.

 

Next week we will do the breakout game and we will plan the animation project for the following week.

Don’t forget to upload your projects to the website: scratch.mit.edu! Put it on your own login and share it or put it on ours: cdathenry1516.

All the best,

Julie

 

 

 

 

Week 6 – Scratch Beginners – Guessing Game

Hi everyone,

Last Saturday we did a slightly different game to usual., There was no movement, no sensing when something happened. It was a Maths Game, a guessing game where the computer picks a random number and we had to guess the number.

GuessNumbers

We had to first make sure that a random number was picked using an Operator. Previously we have used a Variable to store a Score or Lives, but this time it was storing the random number and our guesses. Leaving them on screen as we were testing allowed us to understand more about the variable and what it does…it also made the testing a little easier.

Depending how any guesses we were given we repeated our code that number of times. As well as having to make decisions, i.e If_then, we also had to do a comparison before making the decision, to determine whether the guess was correct, too low or too high.

5guesess

I hope you all enjoyed the difference this week and we are going try something else different next week. We  (You)  are going to create a Animated Christmas Scene. Get your Thinking Hats On!

Here are this weeks notes in PDF: CDA-S4-Week_06-GuessNumbers.pdf

 

Python Games – Weeks 5-6: Getting started with Pygame

Last week we relocated to NUIG for a Massive Open Dojo Session. There was lots going on to enjoy and it was great to see such a large turn out. Well done to our own Michael Madden and to Karl Sweeney from CoderDojo Galway City for organizing it all. Thanks also to Martha for the t-shirts.

The ninjas from the Python Games group who attended didn’t do any new coding but they enjoyed personalizing the Bunnies And Badgers game with their own images. We were set a challenge to create a game to highlight the environmental issues facing the oceans. We started working on that today and we will continue with that for a few weeks. Ocean Cleaner

Before we started working on that today we had a look at some basic Python concepts contained in this demo program. Next week we will look at using lists and for loops in Pygame and at collision detection.

Here are my slides from today python session_6