Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatmap breaks teamvm #4

Open
wants to merge 1 commit into
base: breakout-f
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions core/src/main/scala/com/pluto/box/BreakoutGame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class BreakoutGame extends Game {
.add(new RenderableComponent)
}

lazy val blocks: Seq[Entity] = {
// If you `flatten` or `flatMap` this TeaVM won't compile.
lazy val blocks: Seq[IndexedSeq[Entity]] = {
val blockWidth = 63
val blockHeight = 20
(Gdx.graphics.getWidth / 2 to Gdx.graphics.getHeight by blockHeight + 10).zipWithIndex.flatMap({case (y: Int, colorIndex: Int) =>
(Gdx.graphics.getWidth / 2 to Gdx.graphics.getHeight by blockHeight + 10).zipWithIndex.map({case (y: Int, colorIndex: Int) =>
(0 to Gdx.graphics.getWidth by blockWidth + 10).map(x => {
val positionComponent = new PositionComponent
positionComponent.x = x
Expand All @@ -67,22 +68,20 @@ class BreakoutGame extends Game {

override def create(): Unit = {
// add entities
// ashleyEngine.addEntity(ball)
// ashleyEngine.addEntity(paddle)
// blocks.foreach(println) // line should be blocks.foreach(ashleyEngine.addEntity)
ashleyEngine.addEntity(ball)
ashleyEngine.addEntity(paddle)
blocks.foreach(_.foreach(ashleyEngine.addEntity))

// add systems
// ashleyEngine.addSystem(new MouseXTrackingMovementSystem)
// ashleyEngine.addSystem(new MovementSystem)
// ashleyEngine.addSystem(new RenderingSystem(shapeRenderer))
ashleyEngine.addSystem(new MouseXTrackingMovementSystem)
ashleyEngine.addSystem(new MovementSystem)
ashleyEngine.addSystem(new RenderingSystem(shapeRenderer))
}

override def render(): Unit = {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled)
// ashleyEngine.update(Gdx.graphics.getDeltaTime)
shapeRenderer.setColor(Color.BLUE)
shapeRenderer.circle(50, 50, 50)
ashleyEngine.update(Gdx.graphics.getDeltaTime)
shapeRenderer.end()
}
}