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

2024/11/21

something not working

Alizee Alizee

2024/11/21

#
my code doesn't repeat like i code it to if (attaqueChoisi == 3){ while(repAttaque3 < 10){ prochaineAttaque = System.currentTimeMillis(); if(prochaineAttaque >= derniereAttaque + 300){ derniereAttaque = prochaineAttaque; getWorld().addObject(new ProjectileBoss1(),getX(), getY()); repAttaque3++; } } }
danpost danpost

2024/11/21

#
Alizee wrote...
my code doesn't repeat like i code it to << Code Omitted >>
You are using a while loop, which must complete within a single act cycle. Therefore, it's a cover-up -- it does repeat !!! (probably) I believe that all ProjectileBoss1 instances happen to be exactly on top of each other (covering each other up). It might be easier to just use a counter to count act steps instead of the system timer:
private int repAttaque3;

public void act() {
    //  starting attack
    if (attaqueChoisi == 3) {
        int delay = 300;
        int reps = 10
        repAttaque3 = delay*(reps-1)+1;
    }
    
    // continuing attack
    if (repAttaque3 > 0 && --repAttaque3%300 == 0) {
        getWorld().addObject(new ProjectileBoss1(), getX(), getY());
    }
}
The repAttaque3 counter will hit a multiple of 300 ten times while counting down to zero.
Alizee Alizee

2024/11/22

#
I tryed the code you send me but the delay doesn't work they appen all at the same time;
Alizee Alizee

2024/11/22

#
it might be because attaqueChoisi doesn't change so it start the attack every frame
danpost danpost

2024/11/22

#
Alizee wrote...
it might be because attaqueChoisi doesn't change so it start the attack every frame
Please provide the complete class codes to your world and this characters class.
Alizee Alizee

2024/11/25

#
characters. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Calamitas here. * * @author (your name) * @version (a version number or a date) */ public class Calamitas extends Boss { /** * Act - do whatever the Calamitas wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ long tempAttaque = System.currentTimeMillis(); long derniereAttaque = System.currentTimeMillis(); int tourAttaque2 = 1; int repAttaque1 = 0; int repAttaque2 = 0; int repAttaque3 = 0; int attaqueChoisi = 1; long prochaineAttaque = System.currentTimeMillis(); int delai = 0; int rep = 0; public void act() { if (attaqueChoisi == 1){ delai = 350; rep = 10; repAttaque1 = delai*(rep-1)+1; } if(repAttaque1 > 0 && --repAttaque1%delai == 0){ for(int j = 0; j<20; j++){ getWorld().addObject(new ProjectileBoss3(), getX(), getY()); } } if (attaqueChoisi == 2){ prochaineAttaque = System.currentTimeMillis(); if(tourAttaque2 == 1){ if(prochaineAttaque >= derniereAttaque + 350){ derniereAttaque = prochaineAttaque; for(int j = 0; j<10; j++){ int PositionX=j*100; getWorld().addObject(new ProjectileBoss2(), PositionX, 800); } tourAttaque2 = 2; } } if(tourAttaque2 == 2){ if(tourAttaque2 == 3){ derniereAttaque = prochaineAttaque; for(int j = 0; j<20; j++){ int PositionX=j*100 + 50; getWorld().addObject(new ProjectileBoss2(), PositionX, 800); } tourAttaque2 = 1; } } } if (attaqueChoisi == 3){ delai = 3000; rep = 10; repAttaque3= delai*(rep-1)+1; } if(repAttaque3 > 0 && --repAttaque3%3000 == 0){ getWorld().addObject(new ProjectileBoss1(),getX(), getY()); rep--; repAttaque3= delai*(rep-1)+1; attaqueChoisi = 0; } attaqueChoisi++; } } myworld import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class MyWorld extends World { Blahaj joueur; /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(800, 800, 1, false); int niveau1 = new NiveauBD().getTableauAIndice(0); GenerateurNiveaux gn = new GenerateurNiveaux(40,40,niveau1); gn.genererNiveau(this); joueur = new Blahaj(); addObject(joueur, 400, 700); } }
danpost danpost

2024/11/26

#
Alizee wrote...
characters. << Code Omitted >>
Change from this:
if(repAttaque1 > 0 && --repAttaque1%delai == 0){
for(int j = 0; j<20; j++){
    getWorld().addObject(new ProjectileBoss3(), getX(), getY());
}
to this:
if(repAttaque1 > 0 && --repAttaque1%delai == 0){
    getWorld().addObject(new ProjectileBoss3(), getX(), getY());
}
The for loop works pretty much like the while loop -- in that it also must complete its execution (complete looping) in one act step. Removing the loop (without removing what is inside it) will have only one ProjectileBoss3 instance put in the world at any time. The int counter, repAttaque1, will take care of the repeat spawning.
You need to login to post a reply.