7/28/2023 0 Comments Greenfoot world end gameI don't want to make this answer too long, but hopefully that gives the general idea: have a shared parent world class which both level classes inherit from (using extends), and then both level classes can call methods from the shared parent.Įdit: sorry, I think I just understood more clearly that you also want to transfer the actors between the worlds when switching level. Then you have two level classes, each of which extends DoggieWorld (not just plain World), allowing you to call the spawnClovers method from each: class Level1 extends DoggieWorld If (Greenfoot.getRandomNumber(1000) < speed)ĪddObject(new Clover(), Greenfoot.getRandomNumber(getWidth()), 0) So you might have: class DoggieWorld extends World they both spawn clovers) then you probably want a shared parent class. If you want to share code between your levels (e.g. They will both appear directly beneath World in the class diagram. So you might have: class Level1 extends World In Greenfoot, levels are usually implemented by having different worlds. SetLocation (getX() + animationSpeed, getY()) SetLocation (getX() - animationSpeed, getY()) Integers that help control the speed of movement and animationįor (int imageCounter = 0 imageCounter runningRight.length - 1)Ĭ = (Clover)getOneIntersectingObject(Clover.class) Ĭ1 = (SpecialTreat1)getOneIntersectingObject(SpecialTreat1.class) Ĭ2 = (SpecialTreat2)getOneIntersectingObject(SpecialTreat2.class) Declare Greenfoot images for standing still facing left and right Declare arrays of Greenfoot images for animation import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) How am I supposed to do that? In other words, I can't seem to transfer the same things from GameWorld to Level1, which includes the clovers, candies, and score board, when a certain condition is met (i.e., a specific number of points is reached)? FYI: I've used a separate actor for the score board (hope this helps.). However, the thing is that I want to create multiple levels, and that I kind of want what I have for the first world (named GameWorld) to appear in level 1, which is in a different world. What this game basically does is that the actor, Doggie, will try his best to catch the clovers and special treats that seems to be falling from the trees by running back and forth across the screen (through the user's left and right arrow keyboard input, of course). For a Greenfoot final class project, I decided to make a game called "Doggie the Super Catcher".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |