TEACHING WITH GREENFOOT FOR TEACHERS OF ICS3U/4U NOTE TO TEACHERS • Everything you see here (these slides, code samples, programs) are on your complimentary USB drive. AGENDA • Intro – What is Greenfoot • Greenfoot Basics – (5 minutes) (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…) 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 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 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 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 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…) 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… FIRST LOOK AT GREENFOOT I D E , A C T O R A N D WO R L D C R E A T I O N T U T O R I A L 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) 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. 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 PERSISTENT ACTOR DEMO 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!) 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 YOUR FIRST GAME! • Frogger Game! • Little Frogger must cross the road without getting smushed • Example solutions (basic and advanced) on your USB key 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) 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