Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/40919442e595446ba8f5 to your computer and use it in GitHub Desktop.
Save rightfold/40919442e595446ba8f5 to your computer and use it in GitHub Desktop.
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