Conditional or if statements ask questions about the program state to choose from a set of different sequences of commands (Basically if something is true then a chosen set of commands will execute, and if not, a different set of commands will execute or nothing will happen). Examples of if statements can be seen in almost all game and software applications. To find specific examples, we can look at the programming behind Crossy Road.
In Crossy Road, you have to tap the screen in order to move forward. An if statements would have been used by the programmer so that if screen is touched then move forward by 1.
Similarly, if the screen is swiped sideways or backwards, the game will automatically move the character sideways or backwards by 1 every time the screen is swiped in the desire direction. The basic code for this would sound like if screen swiped from left to right then move right by 1 OR if screen swiped from right to left then move left by 1. The same thing happens for moving backwards except the screen would need to be swiped downwards and the character would move down or backwards by 1.
Watch out though! If you get hit my a car or a train, or even if you fall in water, then game stops and you temporarily 'die'. Don't worry though! Like in any video game you can try again and come back to life. The if statement to simulate this would be something like if character touches car then stop everything. The actual code for the game is much more complicated because after you 'die' different screens and options are brought up however, the main code for the whole action of 'dying' is probably similar.
One of the really cool things about Crossy Road that keeps players interested is you can win different characters. If you have 100 coins then you can go to the prize machine to win a character. One of the codes for this would be if coins = <100 then show 'win a prize' button. If you wanted to go further you'd need a code that said if the button was pressed then show a different background, bring up a different script or 'character' etc. You would need a whole new set of codes to program the actual prize machine.
One of the other cool things about Crossy Road is that if you have a certain character, the 'map' or 'roads' will be specified to that certain characters habitat or theme. To do this there would need to be an if code that said if '_______' character is selected then change background to '________'. Examples of this are desert areas for desert animals and winter areas for winter animals. There is also a map that turns black and white for Frankenstein and the main grassy one for all the basic characters.
Friday, 20 February 2015
Thursday, 12 February 2015
Variables, Programming and Video Games: It's not Chemistry But There Is Definitely a Connection
What is a variable? Well basically (in math at least) it's a letter that replaces an unknown number. Variables can be used in programming as numbers, but they can also be used as text values such as "true" or "false" for example.
So now that you know what a variable is your probably wondering to yourself "Well... what can be stored as a variable...". Well, I'll tell you that almost anything can be stored as a variable and they can be used to do hundreds of different things. You could create a variable called "store" that could store the information about the number of points you get during a game.
.
("How Do Computer Programs Use Variable?" BBC News. BBC Bitesize, n.d. Web. 12 Feb. 2015.)
Now your probably wondering "Well... how could the word 'store' automatically know what I want it to do and store the number of points I have?" well that part is simple actually. When your avatar or character touches or "collects" a coin or piece of treasure for example, you could tell the program to increase the variable 'score' by 1. As you keep touching or 'collecting' points, the variable 'score' will keep changing.
Variables are needed to run almost everything except the simplest of simple computer programs. Programs need variables to store information as it runs. Whether it needs to store numbers, or answers to a question, variables allow us as programmers to change and access thing information as the program is running.

Here's a simple example of variable used in scratch programming:
1. Make the character as for your name
2. Make a variable called 'name' and set the variable to the answer
3. Make the character join the words 'Hello' and the variable 'name' and say "Hello (your name)".
GOOD LUCK!
So now that you know what a variable is your probably wondering to yourself "Well... what can be stored as a variable...". Well, I'll tell you that almost anything can be stored as a variable and they can be used to do hundreds of different things. You could create a variable called "store" that could store the information about the number of points you get during a game.
.
("How Do Computer Programs Use Variable?" BBC News. BBC Bitesize, n.d. Web. 12 Feb. 2015.)
Now your probably wondering "Well... how could the word 'store' automatically know what I want it to do and store the number of points I have?" well that part is simple actually. When your avatar or character touches or "collects" a coin or piece of treasure for example, you could tell the program to increase the variable 'score' by 1. As you keep touching or 'collecting' points, the variable 'score' will keep changing.
Variables are needed to run almost everything except the simplest of simple computer programs. Programs need variables to store information as it runs. Whether it needs to store numbers, or answers to a question, variables allow us as programmers to change and access thing information as the program is running.

Here's a simple example of variable used in scratch programming:
1. Make the character as for your name
2. Make a variable called 'name' and set the variable to the answer
3. Make the character join the words 'Hello' and the variable 'name' and say "Hello (your name)".
GOOD LUCK!
Sunday, 8 February 2015
A Small Introduction to Scratch Programming

(FLAPPY BIRD SCRATCH!)

Subscribe to:
Posts (Atom)