-
-
Save rightfold/40919442e595446ba8f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Position(x: Double, y: Double) | |
case class Bullet(position: Position, direction: Double) | |
case class Enemy(position: Position, health: Short) | |
var bullets = List[Bullet].empty | |
var enemies = List[Enemy].empty | |
def update() = { | |
bullets = | |
bullets.map(_.copy(position = /* magic to move it in its direction */)) | |
(hittingBullets, nonHittingBullets) = | |
bullets.filter(_.position distanceTo enemy.position < 2) | |
enemies = | |
enemies | |
.map { enemy => enemy.copy(health = enemy.health - hittingBullets.size) } | |
.filter(_.health > 0) | |
bullets = nonHittingBullets | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment