Spielend programmieren lernen

Programmierkurse für Kinder, Jugendliche und Erwachsene

User Tools

Site Tools


en:blog:2016:0818_planethunter

teaching to code a PocketCode game in 4 hours

Summary: a fully playable PocketCode app was created by an student of my courses in exactly 4 hours

During a programming course at spielend-programmieren a student of mine, Benjamin Kaut coded his first ever android app uing PocketCode in exactly 4 hours. The course was originally planned to focus on coding with Python but PocketCode turned out to be very popular.

Benjamin had seen Scratch once but had no real coding experience with visual programming languages. As i timed the Pocket-Code Sessions very exact, i can report that the whole app was coded (and teached) in 4 hours, split over 3 days.

I focused more on the “how to” because the “why” was already teached when coding with Python. I think that others can repeat the process possibly much faster. Benjamin used a Samsung Galaxy S6 Android smartphone to code. His app is optimized to make use of the 4k resolution. I still have to wrap my head around the fact that my students tiny smartphone has more screen resolution than my big pc monitor.

Here is what a description of the code, broken down into 4 parts. Please note that the parts are not equally long, the duration of each part depends on the skill and previous knowledge of the student.

part 1

  • Download and install [PocketCode and Pocket Paint on the Android Smartphone of the student, using Google Play Store
  • create a new game, select “vertical” when asked for smartphone orientation
  • create a new background object using the smartphone camera
  • create a new opject (sprite), using PocketPaint.
  • Give this new object the name “player”
  • code script for “player” object:
[control] when program is started:
[movement] set position to 0,0
[movement] set set size to 60%
[control] repeat
    [control] if abs( inclination_x ) > 5:
         [movement] change x by (inclination_x * -1) 
    [control] if abs( inclination_y ) > 5:
         [movement] change y by (inclination_y * -1)
  • test the game: tilting the smartphone should move the player

part 2

  • improve the game so that the player can not “leave” the screen. For that you need to know your screen resolution. Those can be displayed while running the game, clicking the “back” button of the smartphone once and clicking on the “axis” icon that become visible at the bootom of the screen. I assume here the screen resolution is x:1440 and y:2560
  • inside the script of the “player” object, add this code into the reapeat loop:
[control] if x_position  < -720:
    [movement] set x_position to -720
[control] if x_position  > 720:
     [movement] set x_position to 720
[control] if y_position < -1280:
    [movement] set y_position to -1280
[control] if y_position > 1280:
     [movement] set y_position to 1280
  • test the game: player can no longer leave the screen

part 3

  • create additional backgrounds: for start/help, credit screen and “game over” screen.
  • rename the background pictures into “play”, “start”, “credit”, “gameover”
  • create two buttons as new (sprite) objects: one “start” button and one “credit” button. Name them “start” and “credit”. The buttons should be not bigger than 10% of the background picture
  • edit the script of the “start” button:
[control] when program is started:
[movement] set postion to ( choose a good position )
[look] make visible

[control] when object is clicked (touched):
[control] send message "game start"
  • edit the script of the “credits” button:
[control] when program is started:
[movement] set position to ( choose a good position )
[look] make visible

[control] when object is clicked (touched):
[control] send message "credits"
[look] hide
  • edit the script of the background:
[control] when program is started:
[look] show "start"
[control] when i recive message "credits":
    [look] show "credits"
    [control] wait 3 seconds
    [look] show "start"
  • inside the script of the player sprite, create to new entries for global variables. Do this right after “when program is started”:
[data] set value of "lifes" to 100
[data] set value of "points" to 0
[data] display both values at the top edge of the screen
  • also inside the script of the player sprite, inside the repeat loop, create those two entries to update global variables:
[data] set value of "player_x" to x-position (of object)
[data] set value of "player_y" to y-position (of object)
  
* create a new object, called "hunter", using Pocket Paint. While painting, make sure the sprite is pointing with it's nose to the right side
* create script for hunter sprite:
[control] when program is started
[look] set size to 60%
[look] set position to 0, -500 (depending on smartphone resolution)
[control] repeat
   [control] if random( 1, 100) < 5:
        [movement] glide 1 seconds to "player_x", "player_y" (change the value for "seconds" to change the difficulty of the game)
   [control] else
        [movement] point to "player"
        
       
[control] when program is started
[control] if abs(x-position (of object) - "player_x") < 50:
    [control] if abs(y-position (of object) - "player_y") < 50:
          [control] send message to all: "player_hit"
          

First PagePrevious PageBack to overviewNext PageLast Page

/var/www/horst/spielend-programmieren.at/data/pages/en/blog/2016/0818_planethunter.txt · Last modified: 2017/11/03 21:14 by horstjens@gmail.com