for teachers of ics3u/4u teaching with greenfoot

19
FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

Upload: summer-amis

Post on 14-Dec-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

F O R T E AC H E R S O F I C S 3 U / 4 U

TEACHING WITH GREENFOOT

Page 2: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

NOTE TO TEACHERS

• Everything you see here (these slides, code samples, programs) are on your complimentary USB drive.

Page 3: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

AGENDA

• Intro – What is Greenfoot (5 minutes)• Greenfoot Basics – (15 minutes)• First look at Greenfoot – Creating a World and Actors• Basic Concept Demo• Important Elements of a good scenario

• Hands On Part 1 (20 minutes)• Create your World, your Actor and create movement

• Collision Detection Tutorial (10 minutes)• Detect Objects colliding and triggering events• Adding Sound

• Hands On Part 2 (remaining time…)

Page 4: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

WHAT IS GREENFOOT?

• Greenfoot is:• A simple yet useful Java IDE similar to BlueJ• An easy-to-use 2D graphics engine• An object based programming tool that allows for easy

demonstration and instruction of object oriented programming through visual examples

• Easy to learn for any experienced Java programmer

Page 5: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

WHY GREENFOOT?

• Java is a great academic language – it’s strict structure and object oriented nature makes it ideal for UCS3U/4U• However, Java has an antiquated, tedious set of

graphics commands.• Students quickly tire of text-only programming in

Java, and often struggle with Java’s built in graphics• Greenfoot provides an easier approach to

creating games and visual simulations

Page 6: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

GETTING STARTED

• Greenfoot is available for Mac OSX, Windows and Linux – (Java must be installed)• Can easily be installed by your TST• If it is not possible to have it installed, there is a

Windows-only “Greenfoot on a Stick” version that can be run from a USB key – which is what we will be working with today

Page 7: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

PROS AND CONS

PROS

• Easy to start programming games and simulations complete with 2D graphics and sound

• Mouse support• Extensible with the full

Java programming language

• Makes for fun tasks and assignments

• Effective way to teach and demonstrate OOP

CONS

• Poor support for text(although you can use the System console)• No 3D• Ultimately limited to

games of moderate complexity• Must use included IDE

Page 8: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

SOME ADDITIONAL BENEFITS

• Good for teaching Linked Lists – some Greenfoot methods return a linked list of objects• Useful for teaching inheritance – all sub-classes

of Actors can be further inherited from, leaving the potential to create and use different super classes to good effect• Grade 11 students can usually have basic

functionality of some sort working within 1 period• Module available for XBox360 Kinect module – It

is possible to use Greenfoot to program for body motion capture! (although I haven’t tried…)

Page 9: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

GREENFOOT RESOURCES

• The development staff of Greenfoot is active in creating a plethora of resources on an on-going basis, including:• The Greenroom – Discussion forum and resources for

teachers, requires registration from teacher email address - http://greenroom.greenfoot.org/

• Numerous online resources for learning Greenfoot - http://www.greenfoot.org/doc

• Scenario (and code) sharing - http://www.greenfoot.org/scenarios

• Discussion Forum for students – http://www.greenfoot.org/topics

• And more…

Page 10: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

FIRST LOOK AT GREENFOOTIDE, ACTOR AND WORLD CREATION TUTORIAL

Page 11: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

ACTOR

• All objects that will move within the game world should be sub-classes of Actor

• (It is possible to create non-Actor classes within Greenfoot – useful for advanced projects)

• You can declare abstract sub-classes of Actor and then create sub-sub-classes – useful for creating related types of objects (I.e. different enemies in a game)

Page 12: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

WORLD

• Your program begins by you creating a sub-class of World – defining your own game world

• Typically, the World will own the Actors.

• Includes a number of global variables – world size, act() order, state of execution (is the game currently running), etc.

Page 13: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

PERSISTENT ACTORS

• In many programs, you will want to keep a permanent reference to your Actors

• This is best accomplished by defining your Actors within the constructor of your World class

• Your World can contain methods that allow Actors to communicate

Page 14: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

PERSISTENT ACTORDEMO

Page 15: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

THE “MAIN” METHOD

• No main() method in Greenfoot

• The scenarios are run in “acts” where the act() method of every class gets called once per frame

• Use your World (the class you created which inherits from World, not World itself) as you would a main method.

• You can add an act() method to your World (and you should!)

Page 16: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

BUILDING YOUR WORLD

• Some things that you should consider for your World:• setPaintOrder() – allows you to control which Actors are

displayed on top and which will appear behind

• setActOrder() – set the order in which classes’ act() methods get called in each act.

• Store permanent references to Actors which you will need to manage later

• Instance variables for your data and for program flow

Page 17: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

YOUR FIRST GAME!

• Frogger Game!

• Little Frogger must cross the road without getting smushed

• Example solutions (basic and advanced) on your USB key

Page 18: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

PROCESS

• Part 1 – Create the basic objects• A World with a background image• A little Frogger Actor that takes input from the keyboard• Cars (or other Enemies) (Actors) that cross the road and

threaten to kill our poor frog!

• Part 2 – Add collision detection and associated actions

• Part 3 – Finishing Touches, polish, as time allows• Sounds• Displaying Text (score, level, etc)

Page 19: FOR TEACHERS OF ICS3U/4U TEACHING WITH GREENFOOT

VARIOUS RESOURCES

• Greenfoot on a Stick – Greenfoot and all associated Java libraries, runnable off of a USB key

• Paint.net – best free paint program I’ve been able to find. Does transparency.

• Frogger! (my 3-4 hours of coding version)

• A few other scenarios