16 feb 2010

BPM - Space Invaders con Drools

Usando Drools en los juegos.

Space-Invaders-Enterprise-Edition-FPS_-89-500x398.png
 

rule "Reverse aliens if one reachs the edge of the screen"
    when
        $alien : AlienEntity()
        exists (AlienEntity(x < 10) or AlienEntity(x > 750))
    then
        $alien.setHorizontalMovement(-$alien.getHorizontalMovement());
        $alien.setY($alien.getY() + 10);
end
 
rule "Process bullets hitting aliens"
    when
        $shot : ShotEntity()
        $alien : AlienEntity(this != $shot, eval($shot.collidesWith($alien)))
        $otherAlien : AlienEntity()
    then
        game.getEntities().remove($shot);
        game.getEntities().remove($alien);
        $otherAlien.setHorizontalMovement($otherAlien.getHorizontalMovement() * 1.04);
end
 
rule "End the game when all aliens are killed"
    salience 1
    when
        not AlienEntity()
        exists ShipEntity()
    then
        game.notifyWin();
        game.getEntities().clear();
end
 
rule "End the game when an alien reaches the bottom"
    when
        exists AlienEntity(y > 570)
    then
        game.notifyDeath();
        game.getEntities().clear();
end


ref:

No hay comentarios:

FeedCount

analytics

 
sfrede