Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup.

Added framerate counter.
  • Loading branch information...
commit 67426e2c846db46d28346aaed211ea6a9cef7ca5 1 parent 1485b22
@fversnel authored
View
4 src/main/scala/org/frankversnel/poortjes/common/update.scala
@@ -2,4 +2,6 @@ package org.frankversnel.poortjes
import org.frankversnel.poortjes.util.DeltaTime
-case class Update(deltaTime: DeltaTime, gameObjects: List[GameObject])
+case class Update(deltaTime: DeltaTime, gameObjects: List[GameObject]) {
+ val framerate = 1000 / deltaTime.millis
+}
View
4 src/main/scala/org/frankversnel/poortjes/game/poortjes.scala
@@ -14,8 +14,8 @@ import org.frankversnel.poortjes.util._
import org.frankversnel.poortjes.game.gameobjects._
class Poortjes extends PApplet with Logging {
- private val screenWidthPx = 400;
- private val screenHeightPx = 300;
+ private val screenWidthPx = 800;
+ private val screenHeightPx = 500;
private val backgroundClr = 0;
override def setup = {
View
21 src/main/scala/org/frankversnel/poortjes/rendering/processing_2d_renderer.scala
@@ -12,25 +12,28 @@ class Processing2DRenderer(
private val backgroundColor: Int) extends Renderer {
def drawText(transform: Transform, text: String, color: Color) {
- draw(transform, color) {
+ draw(transform) {
+ fill(color)
graphics.text(text, 0, 0)
}
}
def drawRectangle(transform: Transform, color: Color) {
- draw(transform, color) {
+ draw(transform) {
+ fill(color)
graphics.rect(0, 0, transform.dimension.width, transform.dimension.height)
}
}
def drawCircle(transform: Transform, color: Color) {
- draw(transform, color) {
+ draw(transform) {
+ fill(color)
graphics.ellipse(0, 0, transform.dimension.width, transform.dimension.height)
}
}
def drawShape(transform: Transform, resourceId: ResourceId) {
- drawTransform(transform) {
+ draw(transform) {
graphics.shape(shapeLoader.getResource(resourceId),
0, 0, transform.dimension.width, transform.dimension.height)
}
@@ -38,19 +41,13 @@ class Processing2DRenderer(
def clearScreen = graphics.background(backgroundColor)
- private def draw(transform: Transform, color: Color) (drawFunction: => Unit) {
- fill(color)
- drawTransform(transform)(drawFunction)
- }
-
- private def drawTransform(transform: Transform) (drawFunction: => Unit) {
- graphics.setMatrix(Transform.processingMatrix(transform))
+ private def draw(transform: Transform) (drawFunction: => Unit) {
graphics.pushMatrix
+ graphics.setMatrix(Transform.processingMatrix(transform))
drawFunction
graphics.popMatrix
- graphics.resetMatrix
}
private def fill(color: Color) {
View
12 src/main/scala/org/frankversnel/poortjes/rendering/rendering_manager.scala
@@ -1,13 +1,23 @@
package org.frankversnel.poortjes.rendering
+import org.slf4j.scala.Logging;
+
import org.frankversnel.poortjes._
-class RenderingManager(private val renderer: Renderer) extends ComponentManager {
+class RenderingManager(private val renderer: Renderer) extends ComponentManager with Logging {
type T = Drawable
def processComponents(update: Update) {
renderer.clearScreen
allComponents.foreach(_.draw(renderer))
+
+ //logger.info(update.framerate + "fps")
+
+ // Draw framerate
+ renderer.drawText(new Transform {
+ var dimension = DimensionValue()
+ translate(200, 10)},
+ update.framerate + "fps", Color.white)
}
protected def isCorrectType(component: Component) = component.isInstanceOf[Drawable]
View
2  src/main/scala/org/frankversnel/poortjes/rendering/slick_2d_renderer.scala
@@ -12,7 +12,7 @@ class Slick2DRenderer(
private val graphics: Graphics,
private val shapeLoader: SlickImageLoader) extends Renderer {
- def drawText(component: Transform, text: String, color: Color) {
+ def drawText(transform: Transform, text: String, color: Color) {
throw new RuntimeException("TODO Implement this method")
}
Please sign in to comment.
Something went wrong with that request. Please try again.