• Unit 10: Platform Game Programming

    Key unit competence

    to be able to use complex expressions, operators and controls to design platforms.

    10.1 Concepts of platform and its usage

    A platform sprite is an immobile sprite usually a stage background and can interact with other sprites on stage. Most platforms are located at the bottom of the stage and appear as either ground, wall, grass field, brick pavement, etc. A game where there is no platform, the player cannot jump, swing, or bounce; the actions that are characteristics of a game.

    the platform sprite is the avatar controlled by the player. Its appearance can affect game play slightly, depending on the angles and size of its costume(s).

    An avatar is usually a picture representing a particular person or something in a game or forum.

    10.1.1 Create platform sprites

    Before you create a platform sprite, you must know what type of the game you want the platform to work for, the level of the game, etc. Learn more about creating platform sprites in section 10.2.

    10.1.2 Interact with platform sprites

    two or more sprites may interact with each other when they touch each other, or touches certain specified colors, moves in certain direction, etc. the scratch player can interact with platform depending on the type of game and sprites therein designed. Most platforms are designed immobile, the main sprite-player must be given commands that limits or allows movements and in any form of interaction. the scratch window below is showing two sprites. one is Lion and another is a parrot. Whenever the lion touches the parrot, the parrot runs away. the accompanying sprites are given below. try using these scripts and see how sprites interact. Assume all the white space (background) is your area of interaction.

    Activity 10.1 (a)

    (i) Introduce the two sprites as shown in the screen below. You can use paint to draw them or at this stage just import them into scratch. For more information on how to use scratch paint tools, see Activity 10.1 (b).

    (ii) Place these scripts in the scripts area for the lion and for the parrot and watch how these sprites interact.

    The way sprites interact with others and the platform is covered within the games we have developed in this unit.

    10.1.3 Role of platforms in scratch

    In a platform, objects i.e. sprites can fall, move, slide, jump, and bounce. the platform acts as an area of sprite interactions. the platform associates those properties identified into the game in which one controls a character to typically move towards a given goal.

    10.2 Creating a platform sprite

    We need to create a platform and so we think of a game for which to create and a suitable platform to use.

    Activity 10.1 (b)

    Create a platform sprite for a game named Hard Journey in which a sprite named John is to walk to the end in order to win. In this platform, John should find items that give him a challenge to pass on.

    Use the steps given below to create the platform sprite

    Step 1: Create a platform sprite as a walk way for John using scratch tools. First open scratch (I am using scratch 2.0 the newer software) and then click on stage1 Backdrop. see picture below.

    10.2.1 Pick a color

    scratch editor has very many colors to choose from. After you have clicked on 1 and 2 as shown in picture 10.2 above, you can then make a choice of the color (s) you want using the mouse and design a needed item. see picture 10.3.

    10.2.2 Design a needed item

    Step 2:Use scratch Paint tools to design a needed item (platform- journey where John is to walk). It’s better we use two colors. one color (green) for free movement in the journey and another color (red) indicating enemy.

    10.2.3 To edit or copy a sprite or an item

    to edit a backdrop name, click on it and type a new name. see picture above.

    to copy a backdrop, right-click on it and select duplicate.

    to delete a backdrop, right-click on it and select delete.

    to edit a sprite’s name, click on default name and type the new name in the name box.

    to copy a sprite; right-click on the sprite; select duplicate.

    to delete a sprite; right-click on the sprite; select delete.

    Designing a needed item (Player)

    If you had deleted the cat sprite you can now draw a new item (John) using scratch paint tools.

    Duplicate John1 costume and then click Flip left-right.

    Do this by right clicking on the John1 costume then select duplicate. Afterwards click “Flip left-right” button as shown in the picture below.

    10.2.4 Build a Combo block

    A combo block is a combination of scripts that can make a sprite to move, jump, walk, make sound, etc. and can also affect the behavior of the background platform.

    Activity 10.2

    Create combo blocks that will make John to appear in a specific position when the game starts, ready to move and jump.

    Solution

    to create combo blocks, you must know what each block does and we already have this knowledge. now you give John-sprite the following scripts (combo block) to take his initial position, show up and get set each time the green flag is clicked.

    to give John the ability to move forward or backward. Use the following scripts below.

    Give John-sprite some movement limits by using the scripts below.

    With the scripts below, John will be able to jump

    Activity 10.3

    1. In groups, discuss how you can associate scratch tools and produce a planned platform. Just think of a game and look at the tools you may need.

    2. Discuss the role of platforms in scratch programming language.

    3. Modify the platform (Stage1 backdrop) we made in Activity 10.1(b) to appear as shown in the following pictures using scratch paint tools.

    4. Create the Stage2 backdrop and make it terrain2 to appear as shown below.

    Use the following steps to create backdrop2

    ·select stage1 Backdrop and then click on the Backdrops tab.

    ·Right click on Terrain1 backdrop and select duplicate. this will create Terrain2 backdrop.

    ·Make changes to the backdrop using scratch paint tools to appear as shown in picture 10.8.

    5. Create stage3 backdrop to appear similar to the following as shown in picture 10.9 and call it terrain3.

    to all level backgrounds add the following scripts to enable a player move back to level 1 faster if it is required.

    10.3 Add Level of a game

    You can use colors in a platform to detect the end of a level or determine the end using edge of a platform. You can also use an object which sends one back to the beginning of the level.

    the character sprite is named John. Green is the color of the walking ground. edge has been used such that if one reaches to it; qualifies for next level platform.

    Activity 10.4

    Using the designed backdrops (platform) in Activity 10.3, add levels of the game enabling a player to move from one level to another. Create a winning costume that will produce a sound and a winning message at level 3.

    Follow the following steps

    Step 1:Let us add more scripts to block 4 enabling the sprite to move from one platform or backdrop to another. see block 8 below (as a result).

    Step 2:In this game, RED objects are used to send the player back to the beginning of the level. We can now modify block 5 by adding in more scripts as shown below in block 9 below (as a result).

    Step 3:Let us add more scripts to block 6 and determine where the game ends. see block 10 below as a result

    Step 4: Create a winning costume for John sprite by giving him a different facial color.

    Step 5:Let’s us add more scripts to make John produce sound and a winning message. see block 11 below.


    Activity 10.5

    1. Using the Hard Journey game in the previous activity, design two more challenging backdrops (add 2 levels) to work for level 4 and level 5 of the game. Let the backdrops be placed in-between backdrop 2 and 3.

    2. Make a variable called Jump and use it to test how John-sprite works with gravity while jumping. Use the following scripts.

    3. Use appropriate scripts that could make the blue color to hide John (disappear automatically) such that a player must show him in order to play again.

    Suggested answers for Activity 5

    1. new backdrop3 may appear as this one shown in the following pictures (a) and (b) but you are free to design a different one. this level can later be renamed Terrain3.

    the new backdrop4 which can later be renamed Terrain4 may appear as this one below.

    2. steps for making a variable are:

    ·on the Scripts tab click Data block.

    ·Click Make a Variable. In the New Variable dialog box type in Jump. select “For this sprite only” and click OK.

    ·the resulting blocks appear as shown in picture 10.13 from which you can pick what you want.

    3. the scripts that can make John-sprite hide when touching blue color are in block 13.

    10.4 Commands for sprite manipulations

    there are a number of commands in scratch, which you can use to make your game interesting. Most of the commands below have been used in our activities. You should learn more of what they exactly do. Also practice on locating them quickly when needed.

    1. Color () is Touching ()?: this is a condition for checking if a color (represented by first brackets) on the sprite is touching a specific color (represented by the second brackets).

    2. Repeat Unit l:this is a loop that will stop once the condition is true.

    3. Change () by (): this script changes the specified variable by the amount.

    4. Key () Pressed?: this is a condition for checking if the specified key (represented by brackets) is being pressed.

    5. Touching ()?: this is a condition for checking if the sprite is touching the mouse-pointer or another sprite (represented by the brackets).

    6. Touching Color ()?: this is a condition for checking if the sprite is touching a specific color represented by brackets.

    7. Switch Costume to ():this block changes the sprite’s costume to the specified one (represented by brackets).

    8. Switch Backdrop to (): this changes the stage’s costume/backdrop to the specified one (represented by brackets).

    9. Switch Backdrop to () and wait: this block is for stage only, it waits until all of the hat blocks triggered by this have completed.

    10. Next Costume: this block changes the sprite’s costume to the next one in the costume list.

    11. Next Backdrop:this changes the stage’s costume/backdrop to the next one in the costume list.

    10.5 Sample controls

    there are a number of controls in scratch and some of them include the following:

    1. Repeat (): this is a loop that repeats the specified amount of times.

    2. Forever: this is a loop that will never end.

    3. If () Then:this block checks the condition so that if the condition is true, the blocks inside it (represented by brackets) will activate.

    4. If () Then, Else: this block checks the condition so that if the condition is true, the blocks inside the first C will activate and if the condition is false, the blocks inside the second C will activate.

    5. Move () Steps: this block moves the sprite forward the amount of steps (represented by brackets) in the direction the sprite is facing.

    6. Turn () Degrees (Clockwise): this block turns the sprite (clockwise) the specified amount (represented by brackets).

    7. Turn () Degrees (Counter-clockwise): this block turns the sprite (counter-clockwise) the specified amount (typed in brackets).

    8. Point in Direction (): this block points the sprite in the direction you specify.

    9. Point Towards (): this block points the sprite towards the mouse-pointer or another sprite.

    10. Go to X: () Y: (): this sprite moves the sprite to the specified X and Y position.

    11. Go to (): this block moves the sprite to the mouse-pointer or another sprite.

    12. Touching ()?: this is a condition for checking if the sprite is touching the mouse-pointer or another sprite.

    13. Show: shows the sprite.

    14. Hide: Hides the sprite.

    15. Set () to (): sets the specified variable to the amount.

    16. Change () by (): Changes the specified variable by the amount.

    17. Show Variable (): shows the variable’s stage Monitor.

    18. Hide Variable (): Hides the variable’s stage Monitor.

    Note: Try to use most of these block sprites in your games.

    End of Unit 10 Assessment

    1. Use Internet facility and explore millions of scratch projects that other scratch users have shared. Look inside and see how they work and then learn from them.

    Note: Since playing scratch games is fun, make sure you know how the codes used in those projects work and try them. Remix projects or borrow scripts and graphics from them but ensure to include credits on the projects page if you are to use other people’s material.

    2. a) Design a platform stage (background) similar to the one shown below as lake waters and sky. In the waters there is a shark that eats small fish that you will introduce in the water. name the game file as Danger shark.


    b) Introduce in a big fish (shark) with two costumes. Costume1 is biting and costume2 is opening mouth.

    c) Apply necessary scripts to make the shark, move up, down, left and right in the waters so as to catch pray but must not move beyond waters upwards.

    d) Introduce in 2 small (can be similar or different) fish as prey for the shark. Use similar scripts on each of them. set score variable and time variable. set time at 20 such that if it elapses, the game is over and the player just counts the scores achieved in that time.

    e) Design a platform where the game ends (Game over) and show its sprite commands.

    f) Apply sound in your scripts such that each time the shark eats a fish it makes sounds.

    Glossary

    Ad blocking: this is a software technology, which allows for blocking ads before they are loaded by the web browser. that means that you are saving bandwidth and the page is rendered faster within your browser.

    Add ons: these are apps that Internet explorer uses to interact with web content like videos and games. toolbars and extensions are also types of add-ons.

    App:A program written mainly for mobile operating system like iOS or Android. Apps are usually games, utilities, or suites.

    Application:A program that turns your computer into a specific tool, such as a word processor, photo editor, or browser.

    Axis Title:this is text that identifies plotted data on x or y- axis.

    Browser extension:software that modifies the interface and/or behavior of web browser e.g. add-on.

    Chart Title:this is text that identifies the purpose of the chart.

    Content-control software (content filtering):this is computer software designed to restrict or control the content a reader is authorized to access, especially when utilized to restrict material delivered over the Internet via the Web, e-mail, or other means e.g. ad blocker.

    Data point:this is a value in data series.

    Data range:this is a block of cells that provides data to be used to create a chart/graph.

    Data series:this is a range of data that comprises of a bar, column, line or pie slice.

    Data source: this is a named source of data usually a DBMS file.

    Document Protection: this is to safeguard or preserve a document from damage or misuse.

    Download:this means copying files from a remote computer to your computer using a modem or network connection. For example, you can download files from the web to your hard disk.

    Downloading:this is a process of transferring information (copying) from a remote computer to your computer.

    File system:this is the overall arrangement in which files are named, stored and organized by the operating system, for example, Windows 8 uses NTFS file system.

    Grid lines:these are horizontal and vertical lines that help the reader to determine data values in a chart.

    Install:this is to copy a program on to your computer for use. e.g. you can install operating system on your computer and Microsoft office applications after and then use them do perform tasks.

    Legend:this is a feature that connects colors and patterns in a chart with the data they represent. the legend acts as the key that explains what each color or pattern in the chart means.

    Open source operating system: this is an operating system that anybody is freely licensed to use, copy, study and change e.g. Linux is a Free and open source software (Foss); this means, anybody can use Linux operating system in any way he/she wants. the source code is openly shared such that people are encouraged to voluntarily improve its design. Chrome OS is also open source.

    Photography: this is the method of producing procedures with camera. It is a profession or hobby of taking photographs, developing and printing/processing the images.

    Plug-in (or Add-on) and Add-in:these are simple extensions that extend the usability of the program such as Internet explorer or Mozilla Firefox.

    Printing:this is the action of producing text or graphics on paper or another medium by a Printing machine.

    Source code:this is a computer code used by programmers to write a program and it is human readable.

    Suite:A collection of applications or utilities sold for a single price, and having a single or similar user interface. these include both application suites (Microsoft office), and utility suites (Norton Internet security).

    Typography:this is the art and craft of designing typefaces and organizing for display.

    Uploading: this is the process of sending or transferring data or programs, usually from a peripheral computer to a central often remote computer.

    Utility:A program that either protects the computer or makes it faster, more reliable, or easier to use.

    Video game accessory:this is a piece of hardware used in conjunction with a video game console for playing video games.

    Unit 9: Network SecurityASSESSMENT