Hi,
I am working on a project in which Mario must collect coins.
He can die from goombas and can shoot fireballs.
BUT I got a problem...
I want to add a Boss (Bowser) after a time to the game!!!
HOW can I make this?
This is my code for the World:
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * The bloodstream is the setting for our White Blood Cell scenario. * It's a place where blood cells, bacteria and viruses float around. * * @author Brennan Eppinger * @version 10/30/2017 */ public class Bloodstream extends World { private int score; private int time; private static final String bgImageName = "background.png" ; private static final double scrollSpeed = 2.5 ; private static final int picWidth = ( new GreenfootImage(bgImageName)).getWidth(); private GreenfootImage bgImage, bgBase; private int scrollPosition = 0 ; GreenfootSound bgMusic = new GreenfootSound( "ground-music.mp3" ); /** * Constructor: Set up the staring objects. */ public Bloodstream() { super ( 780 , 360 , 1 ); prepare(); score = 0 ; time = 7000 ; showScore(); showTime(); setBackground(bgImageName); bgImage = new GreenfootImage(getBackground()); bgBase = new GreenfootImage(picWidth, getHeight()); bgBase.drawImage(bgImage, 0 , 0 ); } public void started() { bgMusic.playLoop(); } public void stopped() { bgMusic.pause(); } public void act() { if (Greenfoot.getRandomNumber( 100 ) < 1 ) { addObject( new Coin(), 779 , Greenfoot.getRandomNumber( 360 )); } if (Greenfoot.getRandomNumber( 1000 ) < 6 ) { addObject( new Virus(), 779 , Greenfoot.getRandomNumber( 360 )); } started(); countTime (); scrollPosition -= scrollSpeed; while (scrollSpeed > 0 && scrollPosition < -picWidth) scrollPosition += picWidth; while (scrollSpeed < 0 && scrollPosition > 0 ) scrollPosition -= picWidth; paint(scrollPosition); } private void paint( int position) { GreenfootImage bg = getBackground(); bg.drawImage(bgBase, position, 0 ); bg.drawImage(bgImage, position + picWidth, 0 ); } public void addScore( int points) { score = score + points; showScore(); if (score < 0 ) { Greenfoot.playSound( "game-over.wav" ); Greenfoot.stop(); } } private void showScore() { showText( "Score: " + score, 80 , 25 ); score = score + 20 ; } private void countTime() { time--; showTime(); if (time == 0 ) { showEndMessage(); Greenfoot.stop(); } showText( "Zeit: " + time, 700 , 25 ); } private void showTime() { showText( "Zeit: " + time, 700 , 25 ); } private void showEndMessage() { Greenfoot.playSound( "win.mp3" ); showText( "Die Zeit ist um!" , 390 , 150 ); showText( "Dein Score: " + score + " points" , 390 , 170 ); } private void prepare() { Mario mario = new Mario(); addObject(mario, 97 , 179 ); } } |