This site requires JavaScript, please enable it in your browser!
Greenfoot back
Roshan123
Roshan123 wrote ...

2020/12/26

help in need

Roshan123 Roshan123

2020/12/26

#
//globally 
Crate crate1=new Crate();
    Crate crate2=new Crate();
//act method
if(solo==1)
            {
            int rand=Greenfoot.getRandomNumber(r.length);
            int rand2=Greenfoot.getRandomNumber(r2.length);
            if(tank>0 && --tank ==0)addObject(new Tank(),r[rand],r2[rand2]);
            if(tank==0 && getObjects(Tank.class).isEmpty())tank =60;
            if(b>0 && --b ==0)addObject(new B(),r[rand],r2[rand2]);
            if(b==0 && getObjects(B.class).isEmpty())b =60;
            if(crate>0 && --crate ==0) {addObject(crate2,30,30); addObject(crate1,770,570);}
            if(crate==0 && getObjects(Crate.class).isEmpty())crate =150;
            if(bottimer>0 && --bottimer ==0) addObject(new EnemyTank(true,3),  695, 495);
            if(bottimer==0 && getObjects(EnemyTank.class).isEmpty())bottimer =100;
            if(bottimer>0 && --bottimer ==0) addObject(new EnemyCannon2(20,125),  695, 495);
            if(bottimer==0 && getObjects(EnemyCannon2.class).isEmpty())bottimer =10;
            if(bottimer1>0 && --bottimer1 ==0) addObject(new EnemyTank1(true,3), 105, 105);
            if(bottimer1==0 && getObjects(EnemyTank1.class).isEmpty())bottimer1 =100;
            if(bottimer1>0 && --bottimer1 ==0) addObject(new EnemyCannon(20,125), 105, 105);
            if(bottimer1==0 && getObjects(EnemyCannon.class).isEmpty())bottimer1 =10;
            }
Roshan123 Roshan123

2020/12/26

#
line 13 & 14 how is it adding crate again and again to the world if its empty i did the same for tank class to add it again to the world but it adds only one time if its empty
//globally 
Crate crate1=new Crate();
    Crate crate2=new Crate();
Tank TSpawn = new Tank();
//act method
if(solo==1)
            {
            int rand=Greenfoot.getRandomNumber(r.length);
            int rand2=Greenfoot.getRandomNumber(r2.length);
            if(tank>0 && --tank ==0)addObject(TSpawn,r[rand],r2[rand2]);
            if(tank==0 && getObjects(Tank.class).isEmpty())tank =60;
            if(b>0 && --b ==0)addObject(new B(),r[rand],r2[rand2]);
            if(b==0 && getObjects(B.class).isEmpty())b =60;
            if(crate>0 && --crate ==0) {addObject(crate2,30,30); addObject(crate1,770,570);}
            if(crate==0 && getObjects(Crate.class).isEmpty())crate =150;
            if(bottimer>0 && --bottimer ==0) addObject(new EnemyTank(true,3),  695, 495);
            if(bottimer==0 && getObjects(EnemyTank.class).isEmpty())bottimer =100;
            if(bottimer>0 && --bottimer ==0) addObject(new EnemyCannon2(20,125),  695, 495);
            if(bottimer==0 && getObjects(EnemyCannon2.class).isEmpty())bottimer =10;
            if(bottimer1>0 && --bottimer1 ==0) addObject(new EnemyTank1(true,3), 105, 105);
            if(bottimer1==0 && getObjects(EnemyTank1.class).isEmpty())bottimer1 =100;
            if(bottimer1>0 && --bottimer1 ==0) addObject(new EnemyCannon(20,125), 105, 105);
            if(bottimer1==0 && getObjects(EnemyCannon.class).isEmpty())bottimer1 =10;
            }
danpost danpost

2020/12/26

#
Maybe you need to restore health to tank when adding it back into the world ??
Roshan123 Roshan123

2020/12/26

#
Ohhh yes I tried this and now its working!!!!
if(tank>0 && --tank ==0)
{
addObject(tank,r[rand],r2[rand2]);
tank.health=3;
}
            if(tank==0 && getObjects(Tank.class).isEmpty())tank =60;
You need to login to post a reply.