Anonymous avatar Anonymous committed a130da3

misc

Comments (0)

Files changed (6)

src/main/scala/com/mojang/ld22/entity/Entity.scala

 package com.mojang.ld22
 package entity
 
-import java.util.Random
 import com.mojang.ld22.gfx.Screen
 import com.mojang.ld22.item.Item
 import com.mojang.ld22.level.Level
 
 abstract class Entity {
 
-
-  var x: Int = 0
-  var y: Int = 0
-  var xr: Int = 6
-  var yr: Int = 6
-  var removed: Boolean = false
+  var x = 0
+  var y = 0
+  var xr = 6
+  var yr = 6
+  var removed = false
   var level: Level = null
 
   def render(screen: Screen)  //abstract

src/main/scala/com/mojang/ld22/entity/Inventory.scala

 package com.mojang.ld22
 package entity
 
-import java.util.ArrayList
-import java.util.List
+import collection.mutable
 import com.mojang.ld22.item.Item
 import com.mojang.ld22.item.ResourceItem
 import com.mojang.ld22.item.resource.Resource
-import collection.mutable
 
 class Inventory {
   var items: mutable.Buffer[Item] = mutable.Buffer.empty  // XXX not ideal

src/main/scala/com/mojang/ld22/item/ToolItem.scala

 package com.mojang.ld22
 package item
 
-import java.util.Random
 import com.mojang.ld22.entity.Entity
 import com.mojang.ld22.entity.ItemEntity
 import com.mojang.ld22.gfx.Color
 class ToolItem(val toolType: ToolType, val level: Int) extends Item {
   import ToolItem._
 
-  override def getColor: Int = {
-    return LEVEL_COLORS(level)
-  }
+  override def getColor: Int = LEVEL_COLORS(level)
 
-  override def getSprite: Int = {
-    return toolType.sprite + 5 * 32
-  }
+  override def getSprite: Int = toolType.sprite + 5 * 32
 
   override def renderIcon(screen: Screen, x: Int, y: Int) {
     screen.render(x, y, getSprite, getColor, 0)
     Font.draw(getName, screen, x + 8, y, Color.get(-1, 555, 555, 555))
   }
 
-  override def getName: String = {
-    return LEVEL_NAMES(level) + " " + toolType.name
-  }
+  override def getName: String = "%s %s".format(LEVEL_NAMES(level), toolType.name)
 
-  override def onTake(itemEntity: ItemEntity) {
-  }
+  override def onTake(itemEntity: ItemEntity) {}
 
-  override def canAttack: Boolean = {
-    return true
-  }
+  override def canAttack: Boolean = true
 
   override def getAttackDamageBonus(e: Entity): Int = {
     if (toolType eq ToolType.axe) {
     if (toolType eq ToolType.sword) {
       return (level + 1) * 3 + random.nextInt(2 + level * level * 2)
     }
-    return 1
+    1
   }
 
   override def matches(item: Item): Boolean = {
       if (other.level != level) return false
       return true
     }
-    return false
+    false
   }
-
 }

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

 package level
 package tile
 
-import java.util.Random
 import com.mojang.ld22.entity.Entity
 import com.mojang.ld22.gfx.Color
 import com.mojang.ld22.gfx.Screen
 import com.mojang.ld22.level.Level
+import scala.util.Random
 
 class LavaTile(id: Byte) extends Tile(id) {
   private val wRandom: Random = new Random
   connectsToLava = (true)
 
   override def render(screen: Screen, level: Level, x: Int, y: Int) {
+    // Cause the lava tiles to oscillate pleasingly
     wRandom.setSeed((Tile.getTickCount + (x / 2 - y) * 4311) / 10 * 54687121l + x * 3271612l + y * 3412987161l)
     val col: Int = Color.get(500, 500, 520, 550)
-    val transitionColor1: Int = Color.get(3, 500, level.dirtColor - 111, level.dirtColor)
-    val transitionColor2: Int = Color.get(3, 500, level.sandColor - 110, level.sandColor)
-    val u: Boolean = !level.getTile(x, y - 1).connectsToLava
-    val d: Boolean = !level.getTile(x, y + 1).connectsToLava
-    val l: Boolean = !level.getTile(x - 1, y).connectsToLava
-    val r: Boolean = !level.getTile(x + 1, y).connectsToLava
-    val su: Boolean = u && level.getTile(x, y - 1).connectsToSand
-    val sd: Boolean = d && level.getTile(x, y + 1).connectsToSand
-    val sl: Boolean = l && level.getTile(x - 1, y).connectsToSand
-    val sr: Boolean = r && level.getTile(x + 1, y).connectsToSand
-    if (!u && !l) {
+    val transitionColor1 = Color.get(3, 500, level.dirtColor - 111, level.dirtColor)
+    val transitionColor2 = Color.get(3, 500, level.sandColor - 110, level.sandColor)
+    val u = !level.getTile(x, y - 1).connectsToLava
+    val d = !level.getTile(x, y + 1).connectsToLava
+    val l = !level.getTile(x - 1, y).connectsToLava
+    val r = !level.getTile(x + 1, y).connectsToLava
+    val su = u && level.getTile(x, y - 1).connectsToSand
+    val sd = d && level.getTile(x, y + 1).connectsToSand
+    val sl = l && level.getTile(x - 1, y).connectsToSand
+    val sr = r && level.getTile(x + 1, y).connectsToSand
+    if (!u && !l)
       screen.render(x * 16 + 0, y * 16 + 0, wRandom.nextInt(4), col, wRandom.nextInt(4))
-    }
-    else screen.render(x * 16 + 0, y * 16 + 0, (if (l) 14 else 15) + (if (u) 0 else 1) * 32, if ((su || sl)) transitionColor2 else transitionColor1, 0)
-    if (!u && !r) {
+    else
+      screen.render(x * 16 + 0, y * 16 + 0, (if (l) 14 else 15) + (if (u) 0 else 1) * 32, if ((su || sl)) transitionColor2 else transitionColor1, 0)
+
+    if (!u && !r)
       screen.render(x * 16 + 8, y * 16 + 0, wRandom.nextInt(4), col, wRandom.nextInt(4))
-    }
-    else screen.render(x * 16 + 8, y * 16 + 0, (if (r) 16 else 15) + (if (u) 0 else 1) * 32, if ((su || sr)) transitionColor2 else transitionColor1, 0)
-    if (!d && !l) {
+    else
+      screen.render(x * 16 + 8, y * 16 + 0, (if (r) 16 else 15) + (if (u) 0 else 1) * 32, if ((su || sr)) transitionColor2 else transitionColor1, 0)
+
+    if (!d && !l)
       screen.render(x * 16 + 0, y * 16 + 8, wRandom.nextInt(4), col, wRandom.nextInt(4))
-    }
-    else screen.render(x * 16 + 0, y * 16 + 8, (if (l) 14 else 15) + (if (d) 2 else 1) * 32, if ((sd || sl)) transitionColor2 else transitionColor1, 0)
-    if (!d && !r) {
+    else
+      screen.render(x * 16 + 0, y * 16 + 8, (if (l) 14 else 15) + (if (d) 2 else 1) * 32, if ((sd || sl)) transitionColor2 else transitionColor1, 0)
+
+    if (!d && !r)
       screen.render(x * 16 + 8, y * 16 + 8, wRandom.nextInt(4), col, wRandom.nextInt(4))
-    }
-    else screen.render(x * 16 + 8, y * 16 + 8, (if (r) 16 else 15) + (if (d) 2 else 1) * 32, if ((sd || sr)) transitionColor2 else transitionColor1, 0)
+    else
+      screen.render(x * 16 + 8, y * 16 + 8, (if (r) 16 else 15) + (if (d) 2 else 1) * 32, if ((sd || sr)) transitionColor2 else transitionColor1, 0)
   }
 
   override def mayPass(level: Level, x: Int, y: Int, e: Entity): Boolean = e.canSwim
 
   override def tick(level: Level, xt: Int, yt: Int) {
-    var xn: Int = xt
-    var yn: Int = yt
-    if (random.nextBoolean) xn += random.nextInt(2) * 2 - 1
-    else yn += random.nextInt(2) * 2 - 1
+    var xn = xt
+    var yn = yt
+    if (random.nextBoolean())
+      xn += random.nextInt(2) * 2 - 1
+    else
+      yn += random.nextInt(2) * 2 - 1
     if (level.getTile(xn, yn) eq Tile.hole) {
       level.setTile(xn, yn, this, 0)
     }

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

 package level
 package tile
 
-import java.util.Random
 import com.mojang.ld22.entity.Entity
 import com.mojang.ld22.gfx.Color
 import com.mojang.ld22.gfx.Screen
 import com.mojang.ld22.level.Level
+import scala.util.Random
 
 class WaterTile(id: Byte) extends Tile(id) {
+  private val wRandom = new Random
 
-    connectsToSand = (true)
-    connectsToWater = (true)
-
+  connectsToSand = (true)
+  connectsToWater = (true)
 
   override def render(screen: Screen, level: Level, x: Int, y: Int) {
+    // Make the water oscillate in some aesthetically pleasing way
     wRandom.setSeed((Tile.getTickCount + (x / 2 - y) * 4311) / 10 * 54687121l + x * 3271612l + y * 3412987161l)
-    val col: Int = Color.get(005, 005, 115, 115)
-    val transitionColor1: Int = Color.get(3, 005, level.dirtColor - 111, level.dirtColor)
-    val transitionColor2: Int = Color.get(3, 005, level.sandColor - 110, level.sandColor)
-    val u: Boolean = !level.getTile(x, y - 1).connectsToWater
-    val d: Boolean = !level.getTile(x, y + 1).connectsToWater
-    val l: Boolean = !level.getTile(x - 1, y).connectsToWater
-    val r: Boolean = !level.getTile(x + 1, y).connectsToWater
-    val su: Boolean = u && level.getTile(x, y - 1).connectsToSand
-    val sd: Boolean = d && level.getTile(x, y + 1).connectsToSand
-    val sl: Boolean = l && level.getTile(x - 1, y).connectsToSand
-    val sr: Boolean = r && level.getTile(x + 1, y).connectsToSand
-    if (!u && !l) {
+    val col = Color.get(005, 005, 115, 115)
+    val transitionColor1 = Color.get(3, 005, level.dirtColor - 111, level.dirtColor)
+    val transitionColor2 = Color.get(3, 005, level.sandColor - 110, level.sandColor)
+    val u = !level.getTile(x, y - 1).connectsToWater
+    val d = !level.getTile(x, y + 1).connectsToWater
+    val l = !level.getTile(x - 1, y).connectsToWater
+    val r = !level.getTile(x + 1, y).connectsToWater
+    val su = u && level.getTile(x, y - 1).connectsToSand
+    val sd = d && level.getTile(x, y + 1).connectsToSand
+    val sl = l && level.getTile(x - 1, y).connectsToSand
+    val sr = r && level.getTile(x + 1, y).connectsToSand
+
+    if (!u && !l)
       screen.render(x * 16 + 0, y * 16 + 0, wRandom.nextInt(4), col, wRandom.nextInt(4))
-    }
-    else screen.render(x * 16 + 0, y * 16 + 0, (if (l) 14 else 15) + (if (u) 0 else 1) * 32, if ((su || sl)) transitionColor2 else transitionColor1, 0)
-    if (!u && !r) {
+    else
+      screen.render(x * 16 + 0, y * 16 + 0, (if (l) 14 else 15) + (if (u) 0 else 1) * 32, if ((su || sl)) transitionColor2 else transitionColor1, 0)
+
+    if (!u && !r)
       screen.render(x * 16 + 8, y * 16 + 0, wRandom.nextInt(4), col, wRandom.nextInt(4))
-    }
-    else screen.render(x * 16 + 8, y * 16 + 0, (if (r) 16 else 15) + (if (u) 0 else 1) * 32, if ((su || sr)) transitionColor2 else transitionColor1, 0)
-    if (!d && !l) {
+    else
+      screen.render(x * 16 + 8, y * 16 + 0, (if (r) 16 else 15) + (if (u) 0 else 1) * 32, if ((su || sr)) transitionColor2 else transitionColor1, 0)
+
+    if (!d && !l)
       screen.render(x * 16 + 0, y * 16 + 8, wRandom.nextInt(4), col, wRandom.nextInt(4))
-    }
-    else screen.render(x * 16 + 0, y * 16 + 8, (if (l) 14 else 15) + (if (d) 2 else 1) * 32, if ((sd || sl)) transitionColor2 else transitionColor1, 0)
-    if (!d && !r) {
+    else
+      screen.render(x * 16 + 0, y * 16 + 8, (if (l) 14 else 15) + (if (d) 2 else 1) * 32, if ((sd || sl)) transitionColor2 else transitionColor1, 0)
+
+    if (!d && !r)
       screen.render(x * 16 + 8, y * 16 + 8, wRandom.nextInt(4), col, wRandom.nextInt(4))
-    }
-    else screen.render(x * 16 + 8, y * 16 + 8, (if (r) 16 else 15) + (if (d) 2 else 1) * 32, if ((sd || sr)) transitionColor2 else transitionColor1, 0)
+    else
+      screen.render(x * 16 + 8, y * 16 + 8, (if (r) 16 else 15) + (if (d) 2 else 1) * 32, if ((sd || sr)) transitionColor2 else transitionColor1, 0)
   }
 
   override def mayPass(level: Level, x: Int, y: Int, e: Entity): Boolean = e.canSwim
 
   override def tick(level: Level, xt: Int, yt: Int) {
-    var xn: Int = xt
-    var yn: Int = yt
-    if (random.nextBoolean) xn += random.nextInt(2) * 2 - 1
-    else yn += random.nextInt(2) * 2 - 1
+    var xn = xt
+    var yn = yt
+    if (random.nextBoolean())
+      xn += random.nextInt(2) * 2 - 1
+    else
+      yn += random.nextInt(2) * 2 - 1
+
     if (level.getTile(xn, yn) eq Tile.hole) {
       level.setTile(xn, yn, this, 0)
     }
   }
 
-  private var wRandom: Random = new Random
 }
 

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

 
 import com.mojang.ld22.crafting.Recipe
 import com.mojang.ld22.entity.Player
-import com.mojang.ld22.sound.Sound
 import com.mojang.ld22.gfx.{Color, Font, Screen}
 import com.mojang.ld22.item.ResourceItem
-import scala.collection.JavaConversions.{asScalaBuffer, mutableSeqAsJavaList}
-import scala.collection.mutable
-import java.util
+import com.mojang.ld22.sound.Sound
 
 class CraftingMenu(recips: Seq[Recipe], player: Player) extends Menu {
   private var selected = 0
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.