So I'm making this fighting game for my school project, but I am having some trouble with the code. I was able to add all the fighting. but when I added the health bars, I started to get some problems.I have multiple levels, so I made multiple health bars for all the differet worlds, but now my fighting got messed up.
public void checkKey()
{
if (Greenfoot.isKeyDown("a")&& !Greenfoot.isKeyDown("f")&&
!Greenfoot.isKeyDown("w")&&!Greenfoot.isKeyDown("c")&&
!Greenfoot.isKeyDown("g"))
{
move(-9);
walkTimer++;
World world = getWorld();
if (walkTimer==0){
run1.scale(180,180);
setImage(run1);
}
if (walkTimer==4){
run2.scale(180,180);
setImage(run2);
}
if (walkTimer==9){
run3.scale(180,180);
setImage(run3);
}
if (walkTimer==14){
run4.scale(180,180);
setImage(run4);
}
if (walkTimer==18){
run5.scale(180,180);
setImage(run5);
}
if(walkTimer==21){
run6.scale(180,180);
setImage(run6);
}
if (walkTimer==24){
run7.scale(180,180);
setImage(run7);
walkTimer=0;
}
}
else
{
if(!Greenfoot.isKeyDown("w")&&!Greenfoot.isKeyDown("a")&&
!Greenfoot.isKeyDown("f")&& !Greenfoot.isKeyDown("d")&&
!Greenfoot.isKeyDown("g")&& !Greenfoot.isKeyDown("c"))
{
idle=myGif.getCurrentImage();
idle.scale(220, 220);
setImage(idle);
}
}
if (Greenfoot.isKeyDown("d")&&!Greenfoot.isKeyDown("w")&&
!Greenfoot.isKeyDown("f")&& !Greenfoot.isKeyDown("g")&&
!Greenfoot.isKeyDown("c"))
{
move(9);
walkTimer++;
if (walkTimer==0){
runflip1.scale(180,180);
setImage(runflip1);
}
if (walkTimer==4){
runflip2.scale(180,180);
setImage(runflip2);
}
if (walkTimer==9){
runflip3.scale(180,180);
setImage(runflip3);
}
if (walkTimer==14){
runflip4.scale(180,180);
setImage(runflip4);
}
if (walkTimer==18){
runflip5.scale(180,180);
setImage(runflip5);
}
if(walkTimer==21){
runflip6.scale(180,180);
setImage(runflip6);
}
if (walkTimer==24){
runflip7.scale(180,180);
setImage(runflip7);
walkTimer=0;
}
}
if(!isPunching && Greenfoot.isKeyDown("s") && !Greenfoot.isKeyDown("w"))
{
hit1=hit.getCurrentImage();
hit1.scale(250,250);
setImage(hit1);
Actor G = getOneIntersectingObject(Girl.class);
/*if(G !=null)
{
World world = getWorld();
Cave Cave=(Cave)world;
Health health=Cave.getHealth();
health.loseHealth();
}*/
if(G !=null)
{
World world = getWorld();
Forest Forest=(Forest)world;
Health3 health3=Forest.getHealth3();
health3.loseHealth3();
}
/* if(G !=null)
{
World world = getWorld();
Sunset Sunset=(Sunset)world;
Health5 health5=Sunset.getHealth5();
health5.loseHealth5();
}*/
}
if(!isKicking && Greenfoot.isKeyDown("w") && !Greenfoot.isKeyDown("s")){
kick1=kick.getCurrentImage();
kick1.scale(250,250);
setImage(kick.getCurrentImage());
Actor G = getOneIntersectingObject(Girl.class);
if((G !=null)&&(world==(Forest)world))
{
World world = getWorld();
Forest Forest=(Forest)world;
Health3 health3=Forest.getHealth3();
health3.loseHealth3();
}
if((G !=null)&&(world==(Cave)world))
{
Cave Cave=(Cave)getWorld();
Health health=Cave.getHealth();
health.loseHealth();
Score score1=Cave.getScore();
score1.addScore1();
}
if((G !=null)&&(world==(Sunset)world))
{
World world = getWorld();
Sunset Sunset=(Sunset)world;
Health5 health5=Sunset.getHealth5();
health5.loseHealth5();
}
if(Greenfoot.isKeyDown("c") && !Greenfoot.isKeyDown("v"))
{
block.scale(180,180);
setImage(block);
}
}
}
}