halllp!!! whenever i run my game 2/3 times greenfoot crashes with this error ;c
java.lang.OutOfMemoryError: Java heap space at java.desktop/java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75) at java.desktop/java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.desktop/java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:186) at greenfoot.util.GraphicsUtilities.createCompatibleTranslucentImage(GraphicsUtilities.java:186) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:130) at GifImage.loadImages(GifImage.java:119) at GifImage.<init>(GifImage.java:40) at Player.<init>(Player.java:25) at punk.<init>(punk.java:12) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at greenfoot.core.Simulation.newInstance(Simulation.java:580) at greenfoot.platforms.ide.WorldHandlerDelegateIDE.lambda$instantiateNewWorld$0(WorldHandlerDelegateIDE.java:143) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$$Lambda$85/0x000000080019a440.run(Unknown Source) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:470) at greenfoot.core.Simulation.maybePause(Simulation.java:299) at greenfoot.core.Simulation.runContent(Simulation.java:190) at greenfoot.core.Simulation.run(Simulation.java:183)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; import java.util.ArrayList; /** * Write a description of class Player here. * * @author (your name) * @version (a version number or a date) */ public class Player extends Actor { static int timesDied= 0; static int check1 = 0; static boolean debug = false; static int playerending = 0; //playermovinghitbox checker public ArrayList<String> FaceStorage = new ArrayList<String>(); boolean checklocation =false; int holder; boolean touched = true; //controlls boolean enterdown = false; static boolean playerWalking = false; GifImage LeftWalk = new GifImage("LeftWalk.gif"); GifImage RightWalk = new GifImage("RightWalk.gif"); String direction = "front"; int defVal = 20; //player movement switches //movement boolean stat1 = false; //attack boolean stat2 = false; //punching fistHitbox punch = new fistHitbox(); //front boolean frontpunch = false; boolean FtimerTF = false; int frontpunchtimer = defVal; //back boolean backpunch = false; boolean BtimerTF = false; int backpunchtimer = defVal; //left boolean leftpunch = false; boolean LtimerTF = false; int leftpunchtimer = defVal; //right boolean rightpunch = false; boolean RtimerTF = false; int rightpunchtimer = defVal; //health static int health = 10000; static int boosterhealth = 200; boolean runonce = false; static int currentlv = 1; boolean maingame = true; boolean playercanmove = false; //story stuff boolean justpunch = false; boolean firsts_and_Final_CHoice = false; boolean isdead = false; boolean run = false; /** * Act - do whatever the Player wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(maingame == true){ otherstuff(); } if(playercanmove == true) { playerReqCheck(); stat1= true; stat2= true; if (run == false){ playerMovement(stat1, stat2); } else{playerMovementRun(stat1, stat2);} } if(firsts_and_Final_CHoice == true) { playerPunch(); } } void otherstuff() { start(); health(); cleanup(); } void cleanup() { //actors if(getWorld().getObjects(BossActor.class).size() != 0){ if(getWorld().getObjects(BossActor.class).size() > 1) { getWorld().removeObject(getWorld().getObjects(BossActor.class).get(getWorld().getObjects(BossActor.class).size()-1)); } } if(getWorld().getObjects(GoonActor.class).size() > 1) { getWorld().removeObject(getWorld().getObjects(GoonActor.class).get(getWorld().getObjects(GoonActor.class).size()-1)); if(getWorld().getObjects(GoonActor.class).size() > 4){ getWorld().removeObject(getWorld().getObjects(GoonActor.class).get(getWorld().getObjects(GoonActor.class).size()-2)); } } //suit if(getWorld().getObjects(suit.class).size() > 1) { getWorld().removeObject(getWorld().getObjects(suit.class).get(getWorld().getObjects(suit.class).size()-1)); if(getWorld().getObjects(GoonActor.class).size() > 4){ getWorld().removeObject(getWorld().getObjects(suit.class).get(getWorld().getObjects(suit.class).size()-2)); } } //npcs } void health() { if(isTouching(enemypunch.class)&&runonce == false) { health = health - 5; runonce = true; }else{runonce = false;} if(health<= 0) { health = 100; deathscreen x = new deathscreen(); timesDied++; Greenfoot.setWorld(x); } } void start() { playerMovement(stat1,stat2); if(debug == true){ gamestart(true); }else { stat1= true; stat2 = true; } playerReqCheck(); } void gamestart(boolean start) { if(start == true) { gamestory(); } } void gamestory() { //level one if(currentlv == 1){ BossActor x = new BossActor(); getWorld().addObject(x, 600, getY()); if(getWorld().getObjects(BossActor.class).get(0).check1 == false && getWorld().getObjects(BossActor.class).get(0).runonce2 == false){ x.runact = 1; } } if(currentlv == 2) { playerMovement(stat1,stat2); p_moveLeft(3); if(check1 == 1) { if(getWorld().getObjects(enemySpawner.class).size() > 0){ getWorld().getObjects(enemySpawner.class).get(0).enemys = true; getWorld().getObjects(enemySpawner.class).get(1).enemys = true; } } } if(currentlv == 3) { stat1= true; stat2 = true; p_moveLeft(3); playerMovement(stat1,stat2); } if(currentlv == 5) { stat1= true; stat2 = true; p_moveLeft(3); playerMovement(stat1,stat2); } else { stat1= true; stat2 = true; p_moveLeft(3); playerMovement(stat1,stat2); } } void playerReqCheck() { //checks and spawns in all required items for the player to work if (getWorld().getObjects(playerfeet.class).size() == 0) { getWorld().addObject(new playerfeet(), 0, 0); } if (getWorld().getObjects(playerhitbox.class).size() == 0) { getWorld().addObject(new playerhitbox(), 0, 0); } if (getWorld().getObjects(healthbar.class).size() == 0) { getWorld().addObject(new healthbar(),547,13); } } void playerMovement(boolean movement,boolean fists) { if(movement == true){ p_moveLeft(1); } if(fists == true){ playerPunch(); } } void playerMovementRun(boolean movement,boolean fists) { if(movement == true){ p_moveLeft(2); } if(fists == true){ playerPunch(); } } void playerPunch() { FrontPunch(); LeftPunch(); RightPunch(); BackPunch(); } void FrontPunch(){ if (FtimerTF == false) { frontpunchtimer--; if(frontpunchtimer <= 0) { getWorld().removeObject(punch); FtimerTF = true; frontpunchtimer = defVal; } } if(Greenfoot.isKeyDown("Enter")) { if ("front".equals(direction)&&frontpunch == false && FtimerTF == true ) { getWorld().addObject(punch, getX(), getY()-40); frontpunch = true; FtimerTF = false; } }else{frontpunch = false;} } void BackPunch(){ if (BtimerTF == false) { backpunchtimer--; if(backpunchtimer <= 0) { getWorld().removeObject(punch); BtimerTF = true; backpunchtimer = defVal; } } if(Greenfoot.isKeyDown("Enter")) { if ("back".equals(direction)&&backpunch == false && BtimerTF == true ) { getWorld().addObject(punch, getX(), getY()+40); backpunch = true; BtimerTF = false; } }else{backpunch = false;} } void LeftPunch(){ if (LtimerTF == false) { leftpunchtimer--; if(leftpunchtimer <= 0) { getWorld().removeObject(punch); LtimerTF = true; leftpunchtimer = defVal; } } if(Greenfoot.isKeyDown("Enter")) { if ("left".equals(direction)&&leftpunch == false && LtimerTF == true ) { getWorld().addObject(punch, getX()-30, getY()); leftpunch = true; LtimerTF = false; } }else{leftpunch = false;} } void RightPunch() { if (RtimerTF == false) { rightpunchtimer--; if(rightpunchtimer <= 0) { getWorld().removeObject(punch); RtimerTF = true; rightpunchtimer = defVal; } } if(Greenfoot.isKeyDown("Enter")) { if ("right".equals(direction)&&rightpunch == false && RtimerTF == true ) { getWorld().addObject(punch, getX()+30, getY()); rightpunch = true; RtimerTF = false; } }else{rightpunch = false;} } void p_moveLeft(int speed){ if(getWorld().getObjects(playerfeet.class).size() >= 1){ if(getWorld().getObjects(playerfeet.class).get(0).touchingWalkinglocation() == false&&FaceStorage.size()>=1) { //front if("front".equals(FaceStorage.get( FaceStorage.size()-1))) { setLocation(getX(), getY()+10); } if("front".equals(FaceStorage.get( FaceStorage.size()-2))) { setLocation(getX(), getY()+10); } //back if("back".equals(FaceStorage.get( FaceStorage.size()-1))) { setLocation(getX(), getY()-10); } if("back".equals(FaceStorage.get( FaceStorage.size()-2))) { setLocation(getX(), getY()-10); } //left if("left".equals(FaceStorage.get( FaceStorage.size()-1))) { setLocation(getX()+10, getY()); } if("left".equals(FaceStorage.get( FaceStorage.size()-2))) { setLocation(getX()+10, getY()); } //right if("right".equals(FaceStorage.get( FaceStorage.size()-1))) { setLocation(getX()-10, getY()); } if("right".equals(FaceStorage.get( FaceStorage.size()-2))) { setLocation(getX()-10, getY()); } } } if(playerWalking == true) { if(getWorld().getObjects(playerfeet.class).size() >= 1&&FaceStorage.size()>=1){ if(getWorld().getObjects(playerfeet.class).get(0).touchingWalkinglocation() ==false) { } } if(getWorld().getObjects(playerfeet.class).size() >= 1){ if(getWorld().getObjects(playerfeet.class).get(0).touchingWalkinglocation() == true){ if (Greenfoot.isKeyDown("D") == false && Greenfoot.isKeyDown("A") == false) { if ("front".equals(direction)){ setImage("IdleBack.png"); getImage().scale(100, 140); } if ("back".equals(direction)){ setImage("idleFront.png"); getImage().scale(80, 140); } if ("left".equals(direction)){ setImage("idleL.png"); getImage().scale(50, 140); } if ("right".equals(direction)){ setImage("idleR.png"); getImage().scale(50, 140); } } if(Greenfoot.isKeyDown("W")) { direction = "front"; setLocation(getX(), getY()-speed); FaceStorage.add("front"); //setImage(FrontWalk.getCurrentImage()); //getImage().scale(250, 150); } if(Greenfoot.isKeyDown("D")) { direction = "right"; FaceStorage.add("right"); setLocation(getX()+speed, getY()); setImage(RightWalk.getCurrentImage()); getImage().scale(250, 150); } if(Greenfoot.isKeyDown("A")) { direction = "left"; FaceStorage.add("left"); touched = false; setLocation(getX()-speed, getY()); setImage(LeftWalk.getCurrentImage()); getImage().scale(250, 150); } if(Greenfoot.isKeyDown("S")) { direction = "back"; FaceStorage.add("back"); setLocation(getX(), getY()+speed); //setImage(FrontWalk.getCurrentImage()); //getImage().scale(250, 150); } } } } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class punk here. * * @author (your name) * @version (a version number or a date) */ public class punk extends World { Player player = new Player(); /** * Constructor for objects of class punk. * */ public punk() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); prepare(); } public void act() { } /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. */ private void prepare() { player.maingame = false; player.playercanmove = true; player.playerWalking = true; Walkinglocation walkinglocation = new Walkinglocation(); addObject(walkinglocation,298,197); walkinglocation.getImage().scale(1000, 1000); suit suit = new suit(); addObject(suit,288,163); suit.storyPosition=1; walkinglocation.setLocation(286,358); Player player = new Player(); addObject(player,286,358); walkinglocation.setLocation(283,315); walkinglocation.setLocation(284,399); nextscene nextscene = new nextscene(); addObject(nextscene,284,399); nextscene.currentuse = 1; } }