Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Creative Greenfoot: RAW
  • Table Of Contents Toc
Creative Greenfoot: RAW

Creative Greenfoot: RAW

By : Haungs
4.7 (3)
close
close
Creative Greenfoot: RAW

Creative Greenfoot: RAW

4.7 (3)
By: Haungs

Overview of this book

This book is for coding students and Java programmers of all levels interested in building engaging, interactive applications with Greenfoot. Familiarity with the very basics of Greenfoot is assumed.
Table of Contents (12 chapters)
close
close
11
Index

Avoider Game with Gamepad


We went over how to connect a gamepad to your Greenfoot scenario and how to use the Gamepad API. Now, it is time to code. We are going to add gamepad support to our version of Avoider Game, which we finished creating in Chapter 2, Animation. You can access a copy of that scenario at http://www.packtpub.com/support.

We have two main changes to make to Avoider Game. First, we need to add a reference to a GamePad object associated with our controller and pass that reference between all three worlds in that scenario: AvoiderGameIntroScreen, AvoiderWorld, and AvoiderGameOverWorld. Second, we need to change the Avatar class to be controlled by a gamepad, if present. Otherwise, we default to mouse control.

The entire AvoiderWorld class is not shown in the following code; only the methods that need changing are shown. Here are the changes for AvoiderWorld:

private GamePad pad;

public AvoiderWorld(GamePad p) {
  super(600, 400, 1, false);
  
  bkgMusic = new GreenfootSound...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Creative Greenfoot: RAW
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon