Submitted by leut on Thu, 06/26/2008 - 12:50pm
Attached here are a few example scenarios.
We suggest you go through them in this order:
- BackForth_1.zip: Demos simple back and for actor movement with hard coded boundaries.
- BackForth_2.zip: Adds methods "CanMoveLeft() and CanMoveRight() which checkthe boundaries using getWorld().getWidth() instead of hardcoding a specific value.
- BackForth_3.zip: Add the instance variable "jumpDistance" to allow easy changing of the distance a Bee moves.
- RandomMotionBee.zip: Used the method Greenfoot.getRandomNumber( ) to generate a random direction for the Bee to move.
- RandomMotionBeeWithConstructor: Uses constructors to set the jump distance for randomly moving bees.
- KeyControlledBee.zip: Uses Greenfoot.isKeyDown() method to create a keyboard controlled Bee.
- KeyControlledBeeWithFlowers: Uses getOneIntersectionObject() to detect collisions and then remove one of the colliding sprites with getWorld().removeObject() ;
- ForLoops1: make a horizontal line of objects using a for loop
- ForLoops2: spell the word "HI" with objects using for loops
- ForLoops3: Place objects randomly on the screen using a for loop
- Game1: A first example game. The bee has to get all the flowers before the time runs out. Uses class variables in aWorld for numFlowers and numSoFar (number of flowers you have gotten so far). Win/lose codition is conveyed to the player via System.out.println
- Game2: Same as game 1 but now the flowers are stationary until you hit them and then they start moving. Goald is to visit (pollinate) all the flowers. The start vibrating after the Bee visits them.
- Game3: Same as game 2 but add in win/lose screens by: changing the background and removing the current game objects.
- Game4: Same as game 3 but added dragonflies that exhibit a patrolling behavior. If the bee is caught by a dragonfly the lose screen is different from the one for running out of time. Also, tweaked the art compared to game3. Check out the patrolling behavior. The dragonfly class has keeps track of its current direction and number of steps taken in that direction. Once a dragonfly has gone 10 steps in a direction it choses a new direction with equal probability.
- Game5: Same as game 4 but changed the dragonflies to chase down the bee once the bee is within a threshold distance. The code requires calculating the distance between two points. Check out the closeToBee() and moveTowardsBee() methods.
- chips: an example of using arrays. The ants objects are stored in a an array. The ant class specify no movement methods yet the ants move! This is because inside the chips class code the ants are moved. In the chips class code we loop through the array of ants and move each ant one x and one y coordinate closer to the chips.
- Game6: store the dragonflies in an array. Give the player a "magic wand". When the player hits "W", all dragonflies within a certain distance of the Bee are splatted (the image is changed and they stop moving). Demos the use of arrays within the game.
- Game7: Uses the world act() method to drive game state changes (play, lose, win, etc). In addition this game version introduces sound. Just put a .wav file in the Sound directory and call Greenfoot.playSound("filename.wav") ;
- MouseExample: An example of using the mouse. The class pointer holds and image that we want to move around with the mouse. When the player moves over an apple and clicks the apple disappears.
- MazeExample: An example of how to create barrier walls that can then be used to construct mazes that an actor object must navigate. The walls are made up of squares. The actual code for the "barrier" functionality is found in the player controlled actor (the ant), where the tryMove() method moves the actor to the desired location, test to see if it intersecting a wall cube, and if so moves it back.
- Animate: An animation example. To get this to work you need a sequence of .png files that share a common base name and differ only by consecutive numbers for each frame. For example, if you have a 6 frame walk cycle you should name the .png files walk1.png, walk2.png, ... walk6.png. These image files should be placed in the Images directory. Next, the programmer needs to copy the file "Animation.java" from this scenario into the scenario in which they intend to use an animated actor. After copying the file close greenfoot and then re-open Greenfoot. You should see "Animation" listed under "Other classes" in the bottom right. Finally, you should copy the Animated Actor and then bird (or some other name) class hierarchy as in this example.
- Projectile: This scenario demonstrates the usage of the projectile class. In the "shooter" actor code check out the method "tryShoot()". In here you will see the interface to the projectile class. Notice the code in the "Target" and "Projectile" classes. Also notice the Vector auxillary class. Again, as in Animate, you need to copy over the "Vector.java" file to the scenario within which you want to use projectiles. And again, close and then re-open greenfoot to have the Vector class show up in the class list.
- TextExample: This scenario shows how to use our TextObject class. The class is used to print strings (a sequence of characters) to the screen.
- TalkingSprite: This scenario shows how to use our TalkingSprite class. To run the scenario create a JoeSpeaker object in the world, then press run and hit the "t" key.