Also, da ich nicht genau weiß wie ich das testen soll, machst du das einfach. Du musst folgende Änderungen vornehmen:
1.) MarioWorld muss jetzt so aussehen:
Meine Änderungen habe ich kommentiert. Sie befinden sich nur in den Variablen und im Konstruktor.
2.) Dementsprechend muss die explode()-Methode in der Shoot1-Klasse jetzt so aussehen:
3.) Und bei Mario muss die act()-Methode so sein:
Alle Änderungen kommentiert. Einfach Copy&Paste bzw. Altes ersetzen. Sag Bescheid, ob alles funktioniert.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | import greenfoot.*; /** * Write a description of class Mario here. * * @author (your name) * @version (a version number or a date) */ public class MarioWorld extends World // David { GreenfootSound backgroundMusic = new GreenfootSound( "SuperMario.mp3" ); //diese variable ist wichtig. sie speichert die map World map; //wenn du eine MarioWorld erzeugst musst du nun eine Welt mit übergeben. In diesem Fall eine Map public MarioWorld(World world) { super ( 800 , 600 , 1 ); backgroundMusic.playLoop(); prepare(); //hier speicherst du die übergebene Welt in der map-variable map=world; } public void stopped() // Konstantin Keinert, Robert Windel { backgroundMusic.setVolume( 0 ); } public void started() // Konstantin Keinert, Robert Windel { backgroundMusic.setVolume( 80 ); } public void act() { } private void prepare() { Bottom bottom = new Bottom(); addObject(bottom, 400 , 570 ); Block block5 = new Block(); addObject(block5, 30 , 350 ); Block block6 = new Block(); addObject(block6, 80 , 350 ); Block block7 = new Block(); addObject(block7, 130 , 350 ); //Block block8 = new Block(); //addObject(block8, 180, 350); Block block9 = new Block(); addObject(block9, 230 , 350 ); Smallbottom bottom1 = new Smallbottom(); addObject(bottom1, 130 , 350 ); Mario mario = new Mario(); addObject(mario, 60 , 450 ); Block block = new Block(); addObject(block, 775 , 450 ); Block block1 = new Block(); addObject(block1, 735 , 450 ); Block block2 = new Block(); addObject(block2, 695 , 450 ); Block block3 = new Block(); addObject(block3, 675 , 450 ); Block block4 = new Block(); addObject(block4, 467 , 370 ); Block block10 = new Block(); //Block oben ganz links addObject(block10, 100 , 220 ); //Block block11 = new Block(); //addObject(block11, 170, 130); //Block block12 = new Block(); //addObject(block12, 210, 130); //Block block13 = new Block(); //addObject(block13, 250, 130); Block block14 = new Block(); addObject(block14, 300 , 130 ); Block block15 = new Block(); addObject(block15, 330 , 130 ); Block block16 = new Block(); addObject(block16, 370 , 130 ); Block block17 = new Block(); addObject(block17, 410 , 130 ); Block block18 = new Block(); addObject(block17, 500 , 130 ); Block block19 = new Block(); addObject(block19, 540 , 130 ); Block block20 = new Block(); addObject(block20, 590 , 130 ); Ziel ziel = new Ziel(); addObject(ziel, 590 , 79 ); return ; } } |
1 2 3 4 5 6 7 8 9 | private void explode() // Konsti { List car = getWorld().getObjects(Car. class ); //hier übergibst du die welt an die neue marioWorld Greenfoot.setWorld( new MarioWorld(getWorld())); getWorld().addObject( new Explosion(), getX(), getY()); getWorld().removeObject( this ); return ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public void act() { isAlive = true ; int moveSize = 300 ; movement(); if (Enemydie() == true ) { return ; } gravity(); if (getY()+ 30 > getWorld().getHeight()) { die(); } debug(); if (getOneIntersectingObject(Ziel. class ) != null ) { backgroundMusic.setVolume( 0 ); //das ist neu //getWorld() kennst du ja schon. hier teilst du greenfoot nur mit, dass es sich bei der //Welt um eine MarioWorld handelt und speicherst diese dann in einer passenden variable MarioWorld welt = (MarioWorld) getWorld(); //jetzt rufst du die in der MarioWorld gespeicherte map auf und setzt diese als neue //Welt Greenfoot.setWorld(welt.map); } } |