When the shieldEnergyBlue class is added to the world through the selection menu, it functions normally. However when it is added through my shipblue class it skips frames and energy and doesn't work, I have no idea what's wrong.
Here's the code for my shipblue.class.
Here's the code for my energy powerup class (makes shieldBlue = true)
Heres the code for the shieldEnergyBlue
When the energy bar is added from the shipblue class when shieldBlue == true it sort of bugs out.
If you wish to see exactly what I mean, go to my scenario and add the power up somewhere on the screen when the game starts, then make blue collect the power up(control blue with "8,4,and 6" on the num pad.)
http://www.greenfoot.org/scenarios/16251
P.S. yes I made 100 different images for all 100 phases of the shield energy.
P.S.S Also there are some sound problems that have been created since i've switched from wav to mp3.
Any help is appreciated
import greenfoot.*;
/**
* Write a description of class shipred here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class shipblue extends Actor
{
private GreenfootImage blueMoving = new GreenfootImage("shipbluemoving.png");
private GreenfootImage shipblue = new GreenfootImage("shipblue.png");
private int shotTimer = 0;
private int rotate = 0;
private int onspawn = 0;
public static int bluewin = 0;
private int winframes = 0;
public static GreenfootSound laser = new GreenfootSound("laser.wav");
private GreenfootSound engine = new GreenfootSound("engine.wav");
private GreenfootSound winSFX = new GreenfootSound("victory.wav");
public static boolean shieldBlue = false;
public boolean ShieldBlue(){
return shieldBlue;
}
public GreenfootSound laser(){
return laser;
}
public int BlueWin(){
return bluewin;
}
/**
* Act - do whatever the shipred wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (shotTimer < 30){
shotTimer++;
}
spawn();
movement();
destroy();
win();
shield();
}
public void movement()
{
if (countdown.begin == 1){
if (Greenfoot.isKeyDown("8"))
{
move(3);
setImage(blueMoving);
engine.setVolume(55);
engine.play();
}
else {
setImage(shipblue);
engine.stop();
}
if (Greenfoot.isKeyDown("4"))
{
turn(-3);
}
if (Greenfoot.isKeyDown("6"))
{
turn(3);
}
if (shotTimer == 30){
if (Greenfoot.isKeyDown("enter"))
{
shooting();
}
}
}
}
public void shooting(){
getWorld().addObject(new blueBullet(getRotation()),getX(), getY());
laser.setVolume(75);
laser.play();
shotTimer = 0;
}
private void spawn(){
if (onspawn == 0){
setRotation(180);
onspawn++;
}
}
private void destroy(){
if (blueHealth.blueHP == 0){
Actor explosion = new explosion();
shipred.redwin++;
getWorld().addObject(new explosion(), getX(), getY());
getWorld().removeObject(this);
}
}
private void win(){
if (bluewin == 1){
winframes++;
winSFX.setVolume(45);
winSFX.play();
if (winframes == 30){
blueWin bluewin = new blueWin();
playAgain playagain = new playAgain();
menu menu = new menu();
getWorld().addObject(bluewin,300,200);
getWorld().addObject(playagain,300,320);
getWorld().addObject(menu,300,370);
getWorld().removeObject(this);
}
}
}
private void shield(){
if(shieldBlue == true){
Actor shield = new shieldEnergyBlue();
getWorld().addObject(new shieldEnergyBlue(),540,55);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class shieldPowerup here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class shieldPowerup extends Actor
{
/**
* Act - do whatever the shieldPowerup wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
GreenfootImage image = new GreenfootImage("shieldPowerup.png");
image.scale(25,25);
setImage(image);
if(isTouching(shipblue.class)){
shipblue.shieldBlue = true;
shieldEnergyBlue.energy = 100;
shieldEnergyBlue.drain = 0;
getWorld().removeObject(this);
}
}
}
import greenfoot.*;
import java.util.*;
import java.awt.*;
/**
* Write a description of class shieldEnergy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class shieldEnergyBlue extends Actor
{
public static int energy = 100;
public static int drain = 0;
private int frame = 0;
public int Energy(){
return energy;
}
public int Drain(){
return drain;
}
public void act()
{
shield();
}
public void shield(){
drain++;
if(energy >= 0 && drain%10 == 0){
String nmbr= "" + energy;
setImage("shieldEnergy/" + nmbr + ".png");
energy--;
}
if(energy == 0){
getWorld().removeObject(this);
shipblue.shieldBlue = false;
}
}
}

