Skip to content

Commit

Permalink
Mutable point
Browse files Browse the repository at this point in the history
  • Loading branch information
reynders committed May 13, 2012
1 parent ea0f9ba commit c686ad5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/main/scala/grambers/Observer.scala
@@ -1,9 +1,7 @@
package grambers

import java.lang.System._
import javax.swing._
import java.awt._
import java.awt.image._
import Util.log

class Camera {
Expand Down Expand Up @@ -66,6 +64,8 @@ class Observer (var w: Int, var h: Int, val universe : Universe, var thingInFocu
}
}

var centerPoint = new Point(0, 0)

def drawUniverse(g2 : Graphics2D) {

if (Config.limitFps)
Expand All @@ -77,8 +77,14 @@ class Observer (var w: Int, var h: Int, val universe : Universe, var thingInFocu
log.warn("bgImage width " + bgImage.image.getWidth + " is not window width " + w)

g2.drawImage(bgImage.image, 0, 0, null)
universe.staticThings.foreach(thing => thing.draw(g2, thing.center + Point(xViewTranslation, yViewTranslation)))
universe.movingThings.foreach(thing => thing.draw(g2, thing.center + Point(xViewTranslation, yViewTranslation)))

universe.staticThings.foreach{ thing =>
thing.draw(g2, centerPoint.set(thing.center.x + xViewTranslation, thing.center.y + yViewTranslation))
}

universe.movingThings.foreach{ thing =>
thing.draw(g2, centerPoint.set(thing.center.x + xViewTranslation, thing.center.y + yViewTranslation))
}

Config.fps += 1
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/scala/grambers/Shape.scala
Expand Up @@ -12,7 +12,7 @@ abstract class Shape(val center : Point) {
def this(x : Int, y : Int) = this(new Point(x, y))
}

class Point(val x : Int, val y : Int) {
class Point(var x : Int, var y : Int) {

def +(i : Int) : Point = {
return(Point(x + i, y + i))
Expand All @@ -30,7 +30,11 @@ class Point(val x : Int, val y : Int) {
return(Point(x - other.x, y - other.y))
}

implicit def IntToPoint(i:Int) : Point = new Point(i, i)
def set(fromX : Int, fromY : Int) : Point = {
this.x = fromX;
this.y = fromY;
this
}

override def equals(that : Any) = that match {
case point : Point => (this.x == point.x && this.y == point.y)
Expand Down

0 comments on commit c686ad5

Please sign in to comment.