diff --git a/.cache-main b/.cache-main index 80650a3..4ee569f 100644 Binary files a/.cache-main and b/.cache-main differ diff --git a/src/exemplo/CatchTheStars.scala b/src/exemplo/CatchTheStars.scala index 250135d..e8b01fb 100644 --- a/src/exemplo/CatchTheStars.scala +++ b/src/exemplo/CatchTheStars.scala @@ -10,13 +10,13 @@ import com.sun.org.apache.bcel.internal.generic.Select object CatchTheStars extends App { case class Player(var x: Double, var y: Double) { - val image = Image("Nave.png") + val img = Image("Spacecraft.png") var score = 0 var vel_x, vel_y = 0.0 var angle = 0.0 def draw() = { - image.centralized_draw(x, y, 3, angle) + img.centralized_draw(x, y, 3, angle) } def rotate_right() = { @@ -42,7 +42,7 @@ object CatchTheStars extends App { } def catch_the_stars(stars: List[Star]) = { - val caught = Select.stars { + val caught = stars.filter{ star => Game.distance(x, y, star.x, star.y) >= 35 } val n = stars.size - caught.size @@ -56,14 +56,14 @@ object CatchTheStars extends App { val x = r.nextInt(game.width) val y = r.nextInt(game.height) val color = ColorF(r.nextInt(216) + 40, r.nextInt(216) + 40, r.nextInt(216) + 40) - val images = Image.fatie("Estrela.png", 25, 25) + val images = Image.fatie("Star.png", 25, 25) val i = r.nextInt(images.size) def draw() = { val image = images((Clock.milisegundos / 100 + i) % images.size) - image.centralized_draw(x, y, 1) + image.centralized_draw(x, y, 1) //PROBLEMA N IDENTIFICADO } } @@ -92,54 +92,55 @@ object CatchTheStars extends App { } } - // Estado Inicio + // State start def update_start() = { if (Keyboard.KEY_I) state = "PLAYING" } def draw_start() = { - val msg = "PRESSIONE [ I ] PARA COMEƇAR" + val msg = "PRESS [I] TO GET STARTED" font.draw_centered(msg, game.width / 2, game.height / 2, 3, ColorF.YELLOW) } - // Estado Jogando + // State Player def update_playing() = { val r = scala.util.Random // eventos if (Keyboard.RIGHT) spacecraft.rotate_right if (Keyboard.LEFT) spacecraft.rotate_left if (Keyboard.UP) spacecraft.accelerate - // inserir novas estrelas estrelas se necessario + // insert new stars if necessary if (r.nextInt(100) < 4 && stars.size < 25) { stars = Star() :: stars } - stars = spacecraft.catch_the_stars(stars) // catar estrelas - spacecraft.move // atualizar a posicao do jogador - time = time + 1.0 / 60.0 // incrementar o tempo + stars = spacecraft.catch_the_stars(stars) // Catch the stars //PROBLEMA N IDENTIFICADO + spacecraft.move // update player position + time = time + 1.0 / 60.0 // increase time if (time.intValue() >= 30) { - state = "END" // terminar o jogo depois de 30 segundos + state = "END" // finish the game after 30 seconds } } def draw_player() = { spacecraft.draw for (star <- stars) { - star.draw + star.draw //PROBLEMA N IDENTIFICADO + } font.draw(s"Placar: ${spacecraft.score}", 10, 20, 3, ColorF.YELLOW) font.draw(s"Time: ${time.toInt}s", 10, 40, 3, ColorF.YELLOW) } - // Estado: fim do jogo + // state: Game over def draw_end() = { - val msg = s"GAME OVER, VOCE FEZ ${spacecraft.score} PONTOS" + val msg = s"GAME OVER, YOU SCORED ${spacecraft.score} POINTS" font.draw_centered(msg, game.width / 2, game.height / 2, 3, ColorF.YELLOW) } def update_end() = {} - game.start("Cata Estrelas", 640, 480, update, draw) + game.start("Catch the Stars", 640, 480, update, draw) } diff --git a/src/jerimum/Animation.scala b/src/jerimum/Animation.scala index 55b32bb..653b71b 100644 --- a/src/jerimum/Animation.scala +++ b/src/jerimum/Animation.scala @@ -6,8 +6,8 @@ case class Animation(speed: Int, images: List[Image]) { private[this] val start = System.currentTimeMillis() private[this] val size = images.length - def imagem(): Image = { - val indice = ((System.currentTimeMillis() - start) / speed % size).toInt - images(indice) + def image(): Image = { + val index = ((System.currentTimeMillis() - start) / speed % size).toInt + images(index) } } \ No newline at end of file diff --git a/src/jerimum/Game.scala b/src/jerimum/Game.scala index e89aab3..94a9af2 100644 --- a/src/jerimum/Game.scala +++ b/src/jerimum/Game.scala @@ -6,7 +6,7 @@ import scala.util.{ Failure, Try } object Game extends Runnable { - var title: String = "Sem Nome" + var title: String = "Unnamed" var width: Int = 640 var height: Int = 480 var fps: Int = 60 @@ -64,7 +64,7 @@ object Game extends Runnable { time = 0 } } - parar() + stop() } def start(title: String = "Potigol com Jerimum", width: Int = 640, @@ -84,7 +84,7 @@ object Game extends Runnable { } } - private[this] def parar() = synchronized { + private[this] def stop() = synchronized { if (running) { running = false Try(thread.join()) match { diff --git a/src/jerimum/Image.scala b/src/jerimum/Image.scala index c83483a..5b7e1c4 100644 --- a/src/jerimum/Image.scala +++ b/src/jerimum/Image.scala @@ -65,7 +65,7 @@ class Image(val buffer: BufferedImage, val road: String = "") { List(l) } - private[this] def girar(g: Graphics2D, angle: Double, x: Double, y: Double, scalaX: Double, scalaY: Double)(draw: => Unit): Unit = { + private[this] def spin(g: Graphics2D, angle: Double, x: Double, y: Double, scalaX: Double, scalaY: Double)(draw: => Unit): Unit = { val old = g.getTransform() if (angle != 0.0) g.rotate(Math.toRadians(angle), x + buffer.getWidth / 2, y + buffer.getHeight / 2) draw @@ -74,7 +74,7 @@ class Image(val buffer: BufferedImage, val road: String = "") { def draw(x: Double, y: Double, z: Int, angle: Double = 0.0, scalaX: Double = 1.0, scalaY: Double = 1.0): Unit = { Draw.include(z, g => { - girar(g, angle, x, y, scalaX, scalaY) { + spin(g, angle, x, y, scalaX, scalaY) { val width = (buffer.getWidth * scalaX).toInt val height = (buffer.getHeight * scalaY).toInt val deltaX = if (width < 0) -width else 0