Public class CupcakeWorld extends World else if( getY() > getWorld().Transcribed image text: Exercise 9.69 Fix the score counting.
The following is the code for this class: import greenfoot.* It is also responsible for generating periodic enemies, generating rewards, and increasing the difficulty of the game over time. This subclass of World sets up all the actors associated with the scenario, including a score.
Implementing Cupcake CounterĬreate a scenario called Cupcake Counter and add each class to it as they are discussed. The game requires good jumping and avoiding skills. The game will increase in difficulty as your cupcake count goes up. Balls will be fired from the turret at the top of the screen and fountains will appear periodically. After touching a cupcake, it will disappear and reappear randomly on another platform. You can also use the space bar key to jump. The left and right arrow keys move your character left and right and the up arrow key makes your character jump. The goal of Cupcake Counter is to collect as many cupcakes as you can before being hit by either a ball or a fountain.
We will first look at a majority of the code for the World and Actor classes in this game without showing the code implementing the topic of this article, that is, the different forms of projectile-based movement.įigure 1: This is a screenshot of Cupcake Counter How to play In this article, we will build a simple platform game called Cupcake Counter (shown in Figure 1). Doing this forces us to handle issues that might be elided in smaller, one-off examples. It is beneficial to the learning process to discuss topics in the context of complete scenarios. (For more resources related to this topic, see here.) Cupcake Counter It’s not as simple as Douglas Adams makes it sound in his quote, but nothing worth learning ever is. We will apply what you learn to a small platform game that we will build up over the course of this article.Ĭreating realistic flying objects is not simple, but we will cover this topic in a methodical, step-by-step approach, and when we are done, you will be able to populate your creative scenarios with a wide variety of flying, jumping, and launched objects. In this article, you will learn about the basics of projectiles, how to make an object bounce, and a little about particle effects. There are often simple heuristics we can use to approximate realistic motion. However, this course of action is complex and often overkill. Some refer to this as creating a physics engine for your game or simulation. One common method of implementing this type of movement is to create a set of classes that model real-world physical properties (mass, velocity, acceleration, friction, and so on) and have game or simulation actors inherit from these classes. For example, a soccer ball, bullet, laser, light ray, baseball, and firework are examples of this type of object. In this article by Michael Haungs, author of the book Creative Greenfoot, we will create a simple game using basic movements in Greenfoot.Īctors in creative Greenfoot applications, such as games and animations, often have movement that can best be described as being launched. “Flying is learning how to throw yourself at the ground and miss.”