Skip to content

Instantly share code, notes, and snippets.

@jaxrtech
Last active August 29, 2015 14:26
Show Gist options
  • Save jaxrtech/e8d91e3d225e0ae1e4e7 to your computer and use it in GitHub Desktop.
Save jaxrtech/e8d91e3d225e0ae1e4e7 to your computer and use it in GitHub Desktop.
class HoverComponent extends Component {
// "Leaked" implementation detail of our `HoverSystem`
var time: Float
}
class PositionComponent extends Component {
var x: Float
var y: Float
}
class Coin extends Entity {
add(new PositionComponent())
add(new HoverComponent())
}
class HoverSystem extends EntitySystem {
/** Allow only entities which required components */
require(classOf[HoverComponent], classOf[PositionComponent])
/** Called each frame with the `entity` to be processed and the
`elapsed` time since the last frame was rendered */
override def process(entity: Entity, elapsed: Float): Unit = {
val position = entity.get[PositionComponent]
val hover = entity.get[HoverComponent]
position.y += 10 * sin(hover.time)
hover.time += elapsed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment