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.
}
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); } } }
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); } } }