Lesson Plan: Games

The purpose of this lesson is to teach students the basics of building 2D games and animations. Specifically, students will learn about timer events, sprites, and how movement (animation) can be programmed.

Introduce the following concepts:

Events
review of apps and events explored so far: click events, touched, dragged (user-initiated), sms events (external)
Another type of event: timer events -- something occurs on each time interval
Animation
transformation of an object over time (could be move, or rotate, or color change, etc.)
two ways to do it: clock timer or with image sprite properties
we'll look at the clock timer method first
Clock properties
timerInterval -- default is 1000 (ms)
timerEnabled -- default is true, meaning Timer event will trigger every timerInterval
movement
change x or y property of an image sprite
moveto block
events
edgeReached
collidedWith
demo: edgeReached to get ball going back and forth
  1. Demonstrate basics of computer animation. You can use emulator to show these.

    • Drag in a canvas and a ball (or ImageSprite)
    • Drag in a button
    • Show how to move the ball to a particular place on button click using MoveTo operation
    • Show how to do the same thing with set x and set y
    • Drag in a timer event and show the ball movement after 3 seconds.
  2. Question: How do you move a ball horizontally, say 10 pixels a second.

    • Note that there is only a MoveTo, no Move
    • Ask students to work this out, on paper, with another students.
    • Demonstrate solution
    • Explain Ball.X and Ball.Y and why you must moveto (Ball.X+10,y)
  3. Show blocks within Ball component and ask, "how do you make ball appear back on left when it reaches right edge?
        Explain edge reached and MoveTo (1,y)
  4. Give students some problems and partners, and ask them to sketch solutions on paper:

    Ask: How to speed up?

    • by changing offset in moveTo command
    • by changing timer interval
  5. Optional: Show the alternative way of moving a sprite or ball, without using timer event and using the sprite's speed and direction parameters. Note that they should stick with one or the other method.
  6. Animation programming tasks: Write a single app with the following features. Test each feature as you go.

© AppInventor.org 2012