danpost wrote...
It actually works, but I have 3 class of aliens and I want that when there is none of the aliens, then it ends completely, because it stops when I only kill one kind of class alien if you can explain me
if (getObjects(Alien.class).isEmpty() && getObjects(Alien2.class).isEmpty() && ...)
Greenfoot.setWorld(new GameOver());
Greenfoot.setWorld(new GameOver());
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Alien here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Alien extends Actor
{
private int timer = 2+Greenfoot.getRandomNumber(500);
public Alien()
{
setRotation(0);
}
/**
* Act - do whatever the Alien wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
Actor bullet = getOneIntersectingObject(Bullet.class); //variable qui retourne la classe bullet
if(bullet!= null) {
World world = getWorld();
MyWorld myWorld = (MyWorld)world;
Counter counter = myWorld.getCounter();
counter.addScore();
getWorld().removeObject(this);
}
if (--timer==0){
shoot();
timer = 2+Greenfoot.getRandomNumber(500);
}
setLocation(getX()+1, getY());
}
public void shoot()
{
getWorld().addObject(new AlienBullet(), getX(), getY());
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
private int IntervalBetweenShots = Integer.MAX_VALUE; //Donne la valeur maximale de l'intervalle de temps entre les tirs.
public Player()
{
setRotation(0);
}
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
boolean isLeftKeyDown = Greenfoot.isKeyDown("left");
if(isLeftKeyDown) {
int x = getX();
int y = getY();
x = x - 5;
setLocation(x,y);
}
boolean isRightKeyDown = Greenfoot.isKeyDown("right");
if(isRightKeyDown) {
int x = getX();
int y = getY();
x = x + 5;
setLocation(x,y);
}
boolean isSpaceKeyDown = Greenfoot.isKeyDown("space");
if(isSpaceKeyDown){
if(IntervalBetweenShots > 30){
getWorld().addObject(new Bullet(), getX(), getY());
IntervalBetweenShots = 0;
}
IntervalBetweenShots++;
}
Actor bullet = getOneIntersectingObject(AlienBullet.class);
if(bullet!= null) {
World world = getWorld();
GameOver gameover = new GameOver(); //GameOver est un type de variable (l'objet game over) et new game over crée un acteur game over à placer sur le jeu
getWorld().addObject(gameover, 450, 300);
getWorld().removeObject(this);
Greenfoot.stop();
}
}
}
private boolean alienHitsShooter()
{
if (getOneIntersectingObject(Alien.class) != null) return true;
if (getOneIntersectingObject(Alien2.class) != null) return true;
...
return false;
}if (alienHitsShooter())