Last active
August 29, 2015 14:26
-
-
Save jaxrtech/e8d91e3d225e0ae1e4e7 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
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