![]() ![]() Greenfoot: a live object world for studentsīy Nathan Tippy, OCI Senior Software Engineer Greenfoot, a live object world for students.* Constructor for ScoreBoard to build starting scoreboard. Public static final int SCOREBOARD_HEIGHT = 25 "global" representing the height (bottom to top) of a Private int bombsLeft // number of bombs left Private int sheltersLeft // number of shelters left Private int highScore // high score so far Private int gameScore // current game score If (Greenfoot.isKeyDown("space") & placeShelt.getWorld() = null & placeShelt.hasHealth()) Ok i added both of those but my player doesnt seem to move now #Getworld greenfoot how to#I changed some of it but i need to figure out how to get it in my player class correctly i dont think i did that correctly 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()) #Getworld greenfoot code#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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |