I dont know why the boss crashes the game but he somehow does if anyone could help me I´d apreaciat that, and also therse another thing I need help with at public void spawnBul 1 and 2 I wrote an // before redKnife because it shows me an error when its in use I included the code redKnife too.
}
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Sakuya here. * * @author (your name) * @version (a version number or a date) */ public class Sakuya extends Actor { private int timer = 0 ; int health = 2000 ; private Counter counter; private redShot bulSpawn2, bulSpawn3, bulSpawn4; private Powerup[] pw = new Powerup[ 5 ]; private redKnife[] bul = new redKnife[ 50 ]; private SPortrait portrait; private GreenfootSound sakuyaSnd = new GreenfootSound( "sakuyaBattle.mp3" ); private GreenfootSound stageSnd = new GreenfootSound( "scarletMansion.mp3" ); private GreenfootSound winSnd = new GreenfootSound( "winSound.mp3" ); private GreenfootSound bulfire = new GreenfootSound( "enemybullet.wav" ); private GreenfootSound timerSnd = new GreenfootSound( "countdown.wav" ); private GreenfootSound spellActSnd = new GreenfootSound( "spellactivate.wav" ); private GreenfootSound spellCapSnd = new GreenfootSound( "spellcapture.wav" ); private GreenfootSound bossDeathSnd = new GreenfootSound( "bossDefeat.wav" ); private GreenfootSound deathSnd = new GreenfootSound( "bossDefeat.wav" ); private boolean dead = false ; private int steps = 20 ; private int invulnTimer = 0 ; private int destinX, destinY, distX, distY; private int patternTog = 1 ; private int spawnTog = 1 ; private int bossState = 1 ; private int animTimer = 0 ; private boolean start = false ; private boolean shotsFired = false ; private boolean spellActive = false ; /** * Act - do whatever the Sakuya wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (getY() < 150 ) { setLocation(getX(), getY() + 2 ); } if (invulnTimer <= 150 ) { invulnTimer++; } else { SakuyasWorld sk =(SakuyasWorld)getWorld(); timer = 0 ; invulnTimer = 0 ; counter = new Counter(); sk.addObject(counter, 510 , 40 ); counter.setValue( 30 ); stageSnd.stop(); sakuyaSnd.playLoop(); start = true ; } if (start == true && dead == false ) { if (bossState == 1 ) { if (timer% 25 == 0 ) { //Switch between 2 bullet patterns if (patternTog == 1 ) { bulfire.play(); spawnBul(); } if (patternTog == 2 ) { bulfire.play(); spawnBul2(); } } //Generates new destination target if (timer == 150 ) { gen(); if (patternTog == 1 ) { patternTog = 2 ; } else { patternTog = 1 ; } timer = 0 ; } //Shifts to a new location in 16 moves if (steps < 16 ) { setLocation(getX() + advX(), getY() + advY()); } hitCheck(); hpCheck(); steps++; if (counter.getValue() == 0 ) { health = 1500 ; } if (health <= 1500 ) { bossState = 2 ; counter.setValue( 40 ); bulfire.stop(); } if (timer < 60 ){ move( 1 ); } if (timer >= 60 && timer < 120 ){ setLocation(getX(), getY() + 1 ); } if (timer >= 120 && timer < 180 ){ move(- 1 ); } if (timer >= 180 && timer < 240 ){ setLocation(getX(), getY() - 1 ); } if (timer == 240 ){ timer = 0 ; } hitCheck(); hpCheck(); steps++; } } timer++; if (timer% 50 == 0 ){ counter.setValue(counter.getValue() - 1 ); if (counter.getValue() <= 10 ){ timerSnd.play(); } } if (dead == true ){ if (animTimer == 1 ){ bulfire.stop(); deathSnd.play(); setImage( "explode1.png" ); } if (animTimer == 6 ){ setImage( "explode2.png" ); } if (animTimer == 11 ){ setImage( "explode3.png" ); } if (animTimer == 15 ){ setImage( "explode4.png" ); } if (animTimer == 19 ){ SakuyasWorld sk =(SakuyasWorld)getWorld(); sk.removeObject(counter); sk.removeObject( this ); sk.addScore( 20000 ); bossDeathSnd.play(); WinScreen win = new WinScreen(); sk.addObject(win, 277 , 258 ); sakuyaSnd.stop(); winSnd.play(); Greenfoot.stop(); } animTimer++; } } public void hpCheck() { if (health <= 0 ){ SakuyasWorld sk =(SakuyasWorld)getWorld(); sk.setScore(sk.getScore() + 99999 ); dead = true ; } } public int getHealth() { return health; } public void spellLoc(){ destinX = 277 ; destinY = 166 ; steps = 0 ; } public void spawnBul() { Actor reimu = (Actor)getWorld().getObjects(Reimu. class ).get( 0 ); SakuyasWorld sk =(SakuyasWorld)getWorld(); for ( int i = 0 ; i < 7 ; i++) { // bul[i] = new redKnife(); sk.addObject(bul[i], getX(), getY()); bul[i].setImage( "cherryknife.png" ); bul[i].turnTowards(reimu.getX(), reimu.getY()); } bul[ 0 ].turn( 45 ); bul[ 1 ].turn( 30 ); bul[ 2 ].turn( 15 ); bul[ 4 ].turn(- 15 ); bul[ 5 ].turn(- 30 ); bul[ 6 ].turn(- 45 ); } public void spawnBul2() { SakuyasWorld sk =(SakuyasWorld)getWorld(); for ( int i = 0 ; i < 10 ; i++){ //bul[i] = new redKnife(); sk.addObject(bul[i], getX(), getY()); bul[i].setImage( "cherryknife.png" ); } bul[ 0 ].setRotation( 40 ); bul[ 1 ].setRotation( 80 ); bul[ 2 ].setRotation( 120 ); bul[ 3 ].setRotation( 160 ); bul[ 4 ].setRotation( 200 ); bul[ 5 ].setRotation( 240 ); bul[ 6 ].setRotation( 280 ); bul[ 7 ].setRotation( 320 ); bul[ 8 ].setRotation( 360 ); } public void gen(){ destinX = Greenfoot.getRandomNumber( 250 ) + 50 ; destinY = Greenfoot.getRandomNumber( 100 ) + 50 ; steps = 0 ; } public int advX() { distX = destinX - getX(); return distX/ 15 ; } public int advY() { distY = destinY - getY(); return distY/ 15 ; } public void hitCheck() { Actor Shot = getOneIntersectingObject(Shot. class ); if (Shot != null ) { health = health - 1 ; getWorld().removeObject(Shot); } } } |
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class redKnife here. * * @author (your name) * @version (a version number or a date) */ public class redKnife extends Bullet { int speedy = 3 ; int speedx = 3 ; /** * Act - do whatever the redKnife wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public redKnife( int x , int y) { speedx = x; speedy = y; } public void act() { setLocation(getX()+speedy, getY()+speedy); checkCollission(); } public void setSpeedx( int pSpeedx) { speedx = pSpeedx; } public void checkCollission() { if (isAtEdge()) { getWorld().removeObject( this ); } } } |