Skip to content

Instantly share code, notes, and snippets.

@cflewis
Created February 13, 2010 09:50
Show Gist options
  • Save cflewis/303365 to your computer and use it in GitHub Desktop.
Save cflewis/303365 to your computer and use it in GitHub Desktop.
rule "Reverse aliens if one reaches 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment