Anonymous avatar Anonymous committed 06df6b3

misc gardening

Comments (0)

Files changed (13)

src/main/scala/com/mojang/ld22/Game.scala

 class Game extends Canvas with Runnable {
 
   var NAME: String = "Manic Rift"
-  var HEIGHT: Int = 120
-  var WIDTH: Int = 160
-  var SCALE: Int = 3
-  private val image: BufferedImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB)
+  var HEIGHT = 120
+  var WIDTH = 160
+  var SCALE = 3
+  private val image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB)
   private val pixels: Array[Int] = (image.getRaster.getDataBuffer.asInstanceOf[DataBufferInt]).getData
-  private var running: Boolean = false
+  private var running = false
   private var screen: Screen = null
   private var lightScreen: Screen = null
-  private val input: InputHandler = new InputHandler(this)
-  private val colors: Array[Int] = new Array[Int](256)
-  private var tickCount: Int = 0
-  var gameTime: Int = 0
+  private val input = new InputHandler(this)
+  private val colors = new Array[Int](256)
+  private var tickCount = 0
+  var gameTime = 0
   private var level: Level = null
-  private var levels: Array[Level] = new Array[Level](5)
-  private var currentLevel: Int = 3
+  private var levels = new Array[Level](5)
+  private var currentLevel = 3
   var player: Player = null
-  private var playerDeadTime: Int = 0
-  private var pendingLevelChange: Int = 0
-  private var wonTimer: Int = 0
-  var hasWon: Boolean = false
+  private var playerDeadTime = 0
+  private var pendingLevelChange = 0
+  private var wonTimer = 0
+  var hasWon = false
 
   var menu: Option[Menu] = None
 
   }
 
   private def init() {
-    var pp: Int = 0
+    var pp = 0
     for (r <- 0 to 5; g <- 0 to 5; b <- 0 to 5) {
       val rr = (r * 255 / 5)
       val gg = (g * 255 / 5)
       val bb = (b * 255 / 5)
       val mid = (rr * 30 + gg * 59 + bb * 11) / 100
-      val r1 = ((rr + mid * 1) / 2) * 230 / 255 + 10
-      val g1 = ((gg + mid * 1) / 2) * 230 / 255 + 10
-      val b1 = ((bb + mid * 1) / 2) * 230 / 255 + 10
+      val r1 = ((rr + mid) / 2) * 230 / 255 + 10
+      val g1 = ((gg + mid) / 2) * 230 / 255 + 10
+      val b1 = ((bb + mid) / 2) * 230 / 255 + 10
       colors(pp) = r1 << 16 | g1 << 8 | b1
       pp += 1
     }
     var lastTime: Long = System.nanoTime
     var unprocessed: Double = 0
     val nsPerTick: Double = 1000000000.0 / 60
-    var frames: Int = 0
-    var ticks: Int = 0
+    var frames = 0
+    var ticks = 0
     var lastTimer1: Long = System.currentTimeMillis
     init()
     while (running) {
   }
 
   def render() {
-    val bs: BufferStrategy = getBufferStrategy
+    val bs = getBufferStrategy
     if (bs == null) {
       createBufferStrategy(3)
       requestFocus()
       return
     }
-    var xScroll: Int = player.x - screen.w / 2
-    var yScroll: Int = player.y - (screen.h - 8) / 2
+    var xScroll = player.x - screen.w / 2
+    var yScroll = player.y - (screen.h - 8) / 2
     if (xScroll < 16) xScroll = 16
     if (yScroll < 16) yScroll = 16
     if (xScroll > level.w * 16 - screen.w - 16) xScroll = level.w * 16 - screen.w - 16
     if (yScroll > level.h * 16 - screen.h - 16) yScroll = level.h * 16 - screen.h - 16
     if (currentLevel > 3) {
-      val col: Int = Color.get(20, 20, 121, 121)
+      val col = Color.get(20, 20, 121, 121)
       for (y <- 0 until 14; x <- 0 until 24) {
         screen.render(x * 8 - ((xScroll / 4) & 7), y * 8 - ((yScroll / 4) & 7), 0, col, 0)
       }
     if (!hasFocus) renderFocusNagger()
 
     for (y <- 0 until screen.h; x <- 0 until screen.w) {
-      val cc: Int = screen.pixels(x + y * screen.w)
+      val cc = screen.pixels(x + y * screen.w)
       if (cc < 255) pixels(x + y * WIDTH) = colors(cc)
     }
 
     val g = bs.getDrawGraphics
     g.fillRect(0, 0, getWidth, getHeight)
-    val ww: Int = WIDTH * 3
-    val hh: Int = HEIGHT * 3
-    val xo: Int = (getWidth - ww) / 2
-    val yo: Int = (getHeight - hh) / 2
+    val ww = WIDTH * 3
+    val hh = HEIGHT * 3
+    val xo = (getWidth - ww) / 2
+    val yo = (getHeight - hh) / 2
     g.drawImage(image, xo, yo, ww, hh, null)
     g.dispose()
     bs.show()
     for (y <- 0 to 1; x <- 0 until 20)
       screen.render(x * 8, screen.h - 16 + y * 8, 0 + 12 * 32, Color.get(000, 000, 000, 000), 0)
 
-
     for (i <- 0 to 9) {
       if (i < player.health) screen.render(i * 8, screen.h - 16, 0 + 12 * 32, Color.get(000, 200, 500, 533), 0)
       else screen.render(i * 8, screen.h - 16, 0 + 12 * 32, Color.get(000, 100, 000, 000), 0)

src/main/scala/com/mojang/ld22/InputHandler.scala

   }
 
   class Key {
-    var presses: Int = 0
-    var absorbs: Int = 0
+    var presses = 0
+    var absorbs = 0
     var down: Boolean = false
     var clicked: Boolean = false
 
 
       if (pressed)
         presses += 1
-
     }
 
     def tick() {

src/main/scala/com/mojang/ld22/level/tile/CactusTile.scala

     level.add(new SmashParticle(x * 16 + 8, y * 16 + 8))
     level.add(new TextParticle("" + dmg, x * 16 + 8, y * 16 + 8, Color.get(-1, 500, 500, 500)))
     if (damage >= 10) {
-      for (i <- 0 until random.nextInt(2) + 1) {
+      for (i <- 0 until random.nextInt(2) + 1)
         level.add(new ItemEntity(new ResourceItem(Resource.cactusFlower), x * 16 + random.nextInt(10) + 3, y * 16 + random.nextInt(10) + 3))
-      }
+
       level.setTile(x, y, Tile.sand, 0)
     }
     else {

src/main/scala/com/mojang/ld22/level/tile/TreeTile.scala

 package level
 package tile
 
-import com.mojang.ld22.entity.Entity
-import com.mojang.ld22.entity.ItemEntity
-import com.mojang.ld22.entity.Mob
-import com.mojang.ld22.entity.Player
-import com.mojang.ld22.entity.particle.SmashParticle
-import com.mojang.ld22.entity.particle.TextParticle
-import com.mojang.ld22.gfx.Color
-import com.mojang.ld22.gfx.Screen
-import com.mojang.ld22.item.Item
-import com.mojang.ld22.item.ResourceItem
-import com.mojang.ld22.item.ToolItem
-import com.mojang.ld22.item.ToolType
-import com.mojang.ld22.item.resource.Resource
-import com.mojang.ld22.level.Level
+import entity.particle.{SmashParticle, TextParticle}
+import entity.{Entity, ItemEntity, Mob, Player}
+import gfx.{Color, Screen}
+import item.{Item, ResourceItem, ToolItem, ToolType}
+import item.resource.Resource
+import level.Level
+import util.Implicits._
 
 class TreeTile(id: Byte) extends Tile(id) {
   connectsToGrass = (true)
     val ur: Boolean = level.getTile(x + 1, y - 1) eq this
     val dl: Boolean = level.getTile(x - 1, y + 1) eq this
     val dr: Boolean = level.getTile(x + 1, y + 1) eq this
-    if (u && ul && l) {
+
+    if (u && ul && l)
       screen.render(x * 16 + 0, y * 16 + 0, 10 + 1 * 32, col, 0)
-    }
-    else {
+    else
       screen.render(x * 16 + 0, y * 16 + 0, 9 + 0 * 32, col, 0)
-    }
-    if (u && ur && r) {
+
+    if (u && ur && r)
       screen.render(x * 16 + 8, y * 16 + 0, 10 + 2 * 32, barkCol2, 0)
-    }
-    else {
+    else
       screen.render(x * 16 + 8, y * 16 + 0, 10 + 0 * 32, col, 0)
-    }
-    if (d && dl && l) {
+
+    if (d && dl && l)
       screen.render(x * 16 + 0, y * 16 + 8, 10 + 2 * 32, barkCol2, 0)
-    }
-    else {
+    else
       screen.render(x * 16 + 0, y * 16 + 8, 9 + 1 * 32, barkCol1, 0)
-    }
-    if (d && dr && r) {
+
+    if (d && dr && r)
       screen.render(x * 16 + 8, y * 16 + 8, 10 + 1 * 32, col, 0)
-    }
-    else {
+    else
       screen.render(x * 16 + 8, y * 16 + 8, 10 + 3 * 32, barkCol2, 0)
-    }
+
   }
 
   override def tick(level: Level, xt: Int, yt: Int) {
   }
 
   private def hurt(level: Level, x: Int, y: Int, dmg: Int) {
-    if (random.nextInt(10) == 0)  // 10% drop rate for apple
-      level.add(new ItemEntity(new ResourceItem(Resource.apple), x * 16 + random.nextInt(10) + 3, y * 16 + random.nextInt(10) + 3))
+    if (rand(0, 10) == 0) // 10% drop rate for apple
+      level.add(new ItemEntity(new ResourceItem(Resource.apple), x * 16 + rand(3, 13), y * 16 + rand(3, 13)))
 
     val damage: Int = level.data(x, y) + dmg
     level.add(new SmashParticle(x * 16 + 8, y * 16 + 8))
     level.add(new TextParticle("" + dmg, x * 16 + 8, y * 16 + 8, Color.get(-1, 500, 500, 500)))
     if (damage >= 20) {
 
-      for (i <- 0 until random.nextInt(2) + 1)
-        level.add(new ItemEntity(new ResourceItem(Resource.wood), x * 16 + random.nextInt(10) + 3, y * 16 + random.nextInt(10) + 3))
+      rand(1, 3) times {
+        level.add(new ItemEntity(new ResourceItem(Resource.wood), x * 16 + rand(3, 13), y * 16 + rand(3, 13)))
+      }
 
-      for (i <- 0 until random.nextInt(random.nextInt(4) + 1))
-        level.add(new ItemEntity(new ResourceItem(Resource.acorn), x * 16 + random.nextInt(10) + 3, y * 16 + random.nextInt(10) + 3))
+      rand(1, 5) times {
+        level.add(new ItemEntity(new ResourceItem(Resource.acorn), x * 16 + rand(3, 13), y * 16 + rand(3, 13)))
+      }
 
       level.setTile(x, y, Tile.grass, 0)
     }

src/main/scala/com/mojang/ld22/package.scala

 import scala.util.Random
 
 package object ld22 {
+
   val random = new Random
+
+  def rand(from: Int, to: Int): Int = random.nextInt(to - from) + from
+
 }

src/main/scala/com/mojang/ld22/screen/AboutMenu.scala

 
 import com.mojang.ld22.gfx.{Color, Font, Screen}
 
-class AboutMenu(parentMenu: Menu) extends Menu {
-  private val parent: Menu = parentMenu
-
+class AboutMenu(val parent: Menu) extends Menu {
   override def tick() {
     if (input.attack.clicked || input.menu.clicked)
       game.setMenu(parent)
-
   }
 
   override def render(screen: Screen) {

src/main/scala/com/mojang/ld22/screen/ContainerMenu.scala

 import com.mojang.ld22.gfx.{Font, Screen}
 
 class ContainerMenu(var player: Player, var title: String, var container: Inventory) extends Menu {
-  private var selected: Int = 0
-  private var oSelected: Int = 0
-  private var window: Int = 0
+  private var selected = 0
+  private var oSelected = 0
+  private var window = 0
 
   override def tick() {
     if (input.menu.clicked) game.setMenu(None)
     if (input.left.clicked) {
       window = 0
-      val tmp: Int = selected
+      val tmp = selected
       selected = oSelected
       oSelected = tmp
     }
     if (input.right.clicked) {
       window = 1
-      val tmp: Int = selected
+      val tmp = selected
       selected = oSelected
       oSelected = tmp
     }
-    val i: Inventory = if (window == 1) player.inventory else container
-    val i2: Inventory = if (window == 0) player.inventory else container
+    val i = if (window == 1) player.inventory else container
+    val i2 = if (window == 0) player.inventory else container
     val len: Int = i.items.size
     if (selected < 0) selected = 0
     if (selected >= len) selected = len - 1

src/main/scala/com/mojang/ld22/screen/CraftingMenu.scala

 import java.util
 
 class CraftingMenu(recips: util.List[Recipe], player: Player) extends Menu {
-  private var selected: Int = 0
+  private var selected = 0
 
   recips.foreach(_.checkCanCraft(player))
   private val recipes: mutable.Seq[Recipe] = recips.sortWith((a, b) => a.canCraft)
     if (input.up.clicked) selected -= 1
     if (input.down.clicked) selected += 1
 
-    val len: Int = recipes.size
+    val len = recipes.size
     if (len == 0) selected = 0
     if (selected < 0) selected += len
     if (selected >= len) selected -= len
 
     if (recipes.size > 0) {
       val recipe: Recipe = recipes(selected)
-      val hasResultItems: Int = player.inventory.count(recipe.resultTemplate)
-      val xo: Int = 13 * 8
+      val hasResultItems = player.inventory.count(recipe.resultTemplate)
+      val xo = 13 * 8
       screen.render(xo, 2 * 8, recipe.resultTemplate.getSprite, recipe.resultTemplate.getColor, 0)
       Font.draw("" + hasResultItems, screen, xo + 8, 2 * 8, Color.get(-1, 555, 555, 555))
       for ((item, i) <- recipe.costs.zipWithIndex) {
-        val yo: Int = (5 + i) * 8
+        val yo = (5 + i) * 8
         screen.render(xo, yo, item.getSprite, item.getColor, 0)
-        var requiredAmt: Int = 1
-        if (item.isInstanceOf[ResourceItem]) {
+        var requiredAmt = 1
+        if (item.isInstanceOf[ResourceItem])
           requiredAmt = (item.asInstanceOf[ResourceItem]).count
-        }
-        var has: Int = player.inventory.count(item)
-        var color: Int = Color.get(-1, 555, 555, 555)
+        var has = player.inventory.count(item)
+        var color = Color.get(-1, 555, 555, 555)
         if (has < requiredAmt) {
           color = Color.get(-1, 222, 222, 222)
         }
       }
     }
   }
-
 }

src/main/scala/com/mojang/ld22/screen/DeadMenu.scala

   override def tick() {
     if (inputDelay > 0)
       inputDelay -= 1
-    else if (input.attack.clicked || input.menu.clicked) {
+    else if (input.attack.clicked || input.menu.clicked)
       game.setMenu(new TitleMenu)
-    }
   }
 
   override def render(screen: Screen) {
     Font.renderFrame(screen, "", 1, 3, 18, 9)
     Font.draw("You died! Aww!", screen, 2 * 8, 4 * 8, Color.get(-1, 555, 555, 555))
-    var seconds: Int = game.gameTime / 60
-    var minutes: Int = seconds / 60
-    val hours: Int = minutes / 60
+    var seconds = game.gameTime / 60
+    var minutes = seconds / 60
+    val hours = minutes / 60
     minutes %= 60
     seconds %= 60
-    var timeString: String = ""
-    if (hours > 0)
-      timeString = hours + "h" + (if (minutes < 10) "0" else "") + minutes + "m"
+
+    val timeString = if (hours > 0)
+      hours + "h" + (if (minutes < 10) "0" else "") + minutes + "m"
     else
-      timeString = minutes + "m " + (if (seconds < 10) "0" else "") + seconds + "s"
+      minutes + "m " + (if (seconds < 10) "0" else "") + seconds + "s"
 
     Font.draw("Time:", screen, 2 * 8, 5 * 8, Color.get(-1, 555, 555, 555))
     Font.draw(timeString, screen, (2 + 5) * 8, 5 * 8, Color.get(-1, 550, 550, 550))
     Font.draw("" + game.player.score, screen, (2 + 6) * 8, 6 * 8, Color.get(-1, 550, 550, 550))
     Font.draw("Press C to lose", screen, 2 * 8, 8 * 8, Color.get(-1, 333, 333, 333))
   }
-
 }

src/main/scala/com/mojang/ld22/screen/InventoryMenu.scala

     renderItemList(screen, 1, 1, 12, 11, player.inventory.items, selected)
   }
 }
-

src/main/scala/com/mojang/ld22/screen/Menu.scala

       selected = -selected - 1
       renderCursor = false
     }
-    val w: Int = x1 - xo
-    val h: Int = y1 - yo - 1
-    val i0: Int = 0
-    var i1: Int = listItems.size
+    val w = x1 - xo
+    val h = y1 - yo - 1
+    val i0 = 0
+    var i1 = listItems.size
     if (i1 > h) i1 = h
-    var io: Int = selected - h / 2
+    var io = selected - h / 2
     if (io > listItems.size - h) io = listItems.size - h
     if (io < 0) io = 0
-    for (i <- i0 until i1) {
+    for (i <- i0 until i1)
       listItems.get(i + io).renderInventory(screen, (1 + xo) * 8, (i + 1 + yo) * 8)
-    }
+
     if (renderCursor) {
       val yy: Int = selected + 1 - io + yo
       Font.draw(">", screen, (xo + 0) * 8, yy * 8, Color.get(5, 555, 555, 555))

src/main/scala/com/mojang/ld22/screen/TitleMenu.scala

 
   override def render(screen: Screen) {
     screen.clear(0)
-    val h: Int = 2
-    val w: Int = 13
-    val titleColor: Int = Color.get(0, 010, 131, 551)
-    val xo: Int = (screen.w - w * 8) / 2
-    val yo: Int = 24
+    val h = 2
+    val w = 13
+    val titleColor = Color.get(0, 010, 131, 551)
+    val xo = (screen.w - w * 8) / 2
+    val yo = 24
     for (y <- 0 until h; x <- 0 until w)
       screen.render(xo + x * 8, yo + y * 8, x + (y + 6) * 32, titleColor, 0)
 
     for (i <- 0 to 2) {
-      var msg: String = options(i)
-      var col: Int = Color.get(0, 222, 222, 222)
+      var msg = options(i)
+      var col = Color.get(0, 222, 222, 222)
       if (i == selected) {
         msg = "> " + msg + " <"
         col = Color.get(0, 555, 555, 555)
     }
     Font.draw("(Arrow keys,X and C)", screen, 0, screen.h - 8, Color.get(0, 111, 111, 111))
   }
-}
+}

src/main/scala/com/mojang/ld22/screen/WonMenu.scala

 package com.mojang.ld22
 package screen
 
-
 import com.mojang.ld22.gfx.{Color, Font, Screen}
 
 class WonMenu extends Menu {
   private var inputDelay: Int = 60
 
   override def tick() {
-    if (inputDelay > 0) inputDelay -= 1
-
-    else if (input.attack.clicked || input.menu.clicked) {
+    if (inputDelay > 0)
+      inputDelay -= 1
+    else if (input.attack.clicked || input.menu.clicked)
       game.setMenu(new TitleMenu)
-    }
   }
 
   override def render(screen: Screen) {
     val hours = minutes / 60
     minutes %= 60
     seconds %= 60
-    var timeString: String = ""
-    if (hours > 0)
-      timeString = hours + "h" + (if (minutes < 10) "0" else "") + minutes + "m"
+    val timeString = if (hours > 0)
+      hours + "h" + (if (minutes < 10) "0" else "") + minutes + "m"
     else
-      timeString = minutes + "m " + (if (seconds < 10) "0" else "") + seconds + "s"
+      minutes + "m " + (if (seconds < 10) "0" else "") + seconds + "s"
 
     Font.draw("Time:", screen, 2 * 8, 5 * 8, Color.get(-1, 555, 555, 555))
     Font.draw(timeString, screen, (2 + 5) * 8, 5 * 8, Color.get(-1, 550, 550, 550))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.