Getworld greenfoot3/16/2023 ![]() ![]() SetLocation(Greenfoot.getRandomNumber(800)+1, Greenfoot.getRandomNumber(240)+40) GetWorld().addObject(new Lobstrosity(),Greenfoot.getRandomNumber(800)+1, * Act - do whatever the Lostrosity wants to do. GetWorld().addObject(placeShelt, getX(), getY()-50) GetWorld().addObject(poisonbomb, getX(), getY()) PoisonBomb poisonbomb = new PoisonBomb() If ("space".equals(Greenfoot.getKey())& getWorld().getObjects(Shelter.class).isEmpty()) GetWorld().removeObjects(getWorld().getObjects(null)) If(isTouching(Lobstrosity.class) || getWorld().getObjects(Lobstrosity.class).isEmpty()) * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the Player wants to do. Private ScoreBoard score = new ScoreBoard() Private Shelter placeShelt= new Shelter(10) Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) GetWorld().removeObject(this) // remove this shelter Įlse // shelter not strong enough to function if shelter is still strong enough to function. StrengthLeft-=byVal // reduce the strength * byVal is the amount to reduce this shelter's strength * reduceStrength reduces the strength of the shelter by a ReduceStrength(1) // use the other reduceStrength method * reduceStrngth reduces this shelter's strength by 1 unit Img.drawString(""+ strengthLeft, SHELTER_WIDTH/2-10, SHELTER_HEIGHT-8) add text repressenting the strength left in black Img = new GreenfootImage(SHELTER_WIDTH, SHELTER_HEIGHT) note that methods outside this class should not call redraw simply rebuilds the image for the shelter. StrengthLeft = initialStrength // remember initial strength * initialStrength is the starting strength of Private static final int SHELTER_HEIGHT = 25 Private static final int SHELTER_WIDTH = 225 private as there is no reason to utiize these outside Private int strengthLeft // remaining strength Return getObjects(Lobstrosity.class).size() * the number of lobstrosities in the world * lobstrosit圜ount tells us how man lobstrosities are Return (!getObjects(PoisonBomb.class).isEmpty()) but avoids the need for code elsewhere. fairly inelegant and inefficient way to code this * containsBomb tells us whether or not a bomb * true if there is a shelter, false if not * containsShelter tells us whether or not a shelter Lobstrosity lobstrosity = new Lobstrosity() ĪddObject(lobstrosity,400,Greenfoot.getRandomNumber(240)+40) If (Greenfoot.isKeyDown("n") & getObjects(Lobstrosity.class).isEmpty()) * the ScoreBoard object seen in the world * getScoreBoard gives us the Scoreboard found in the world ScoreBoard scoreboard = new ScoreBoard() ĪddObject(new Lobstrosity(),400,Greenfoot.getRandomNumber(240)+40) Create a new world with 600x400 cells with a cell size of 1x1 pixels. * Constructor for objects of class MyWorld. ive gotten the shelter to appear but i cant seem to figuer out how to make the life decrease. Right now, the character shoots bomb at lobsters falling from the sky and they disappear and also is supposed to press space and make a "shelter" that can only be hit by 10 lobsters then disappear. addObject(sideways, rand.nextInt(), rand.Im trying to make a game for greenfoot. If (getObjects(Character.class).size() = 0) Ground topedge = new Ground('topedge1.png') If(isTouching(pionBlanc.class)||isTouching(roiBlanc.class)||isTouching(tourBlanc.class)||isTouching(fouBlanc.class)||isTouching(reineBlanc.class)||isTouching(chevalBlanc.class)) GreenfootImage image = new GreenfootImage('carreVert.jpg') * Act - do whatever the carreVert wants to do. * Write a description of class carreVert here. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |