Permalink
Browse files

Added summoning sickness to the gates and shepherds.

  • Loading branch information...
fversnel committed May 11, 2012
1 parent e06660a commit 50349a3176bd580884f1e62d50a4811c9a2cfc64
@@ -8,7 +8,7 @@ import org.frankversnel.poortjes.DimensionValue
class Candy(protected val resourceLoader: ResourceLoader) extends DrawableShape with Collidable
with TimeBasedLife {
- protected val maxTimeAliveMillis = 10000
+ protected val maxTimeAliveMillis = 10000L
protected val shape = resourceLoader.addResource("candy.svg")
@@ -12,7 +12,7 @@ class Explosion extends Drawable with Color with Collidable
val color = ColorValue().r(255).a(125)
var dimension = DimensionValue().width(0).height(0)
- protected val maxTimeAliveMillis = 2000
+ protected val maxTimeAliveMillis = 2000L
private val targetRadius = 200f
override def process(update: Update) {
@@ -24,13 +24,15 @@ class GateEnd(protected val resourceLoader: ResourceLoader)
protected val shape = resourceLoader.addResource("gate-end.svg")
}
class GateConnector(protected val resourceLoader: ResourceLoader)
- extends DrawableShape with Collidable {
+ extends DrawableShape with Collidable with SummoningSickness {
+ protected val maxSicknessDurationMillis = 3000L
+
var dimension = DimensionValue().width(2).height(50)
protected val shape = resourceLoader.addResource("gate-connector.svg")
def onCollision(collider: GameObject) {
- if(collider.is[Player]) {
+ if(collider.is[Player] && !hasSummoningSickness) {
val explosion = new Explosion
explosion.translate(matrixStack.translation._1, matrixStack.translation._2)
EntityManager().spawn(explosion)
@@ -3,9 +3,11 @@ package org.frankversnel.poortjes.game.gameobjects
import org.frankversnel.poortjes.GameObject
import org.frankversnel.poortjes.collision.Collidable
-trait PlayerKiller extends Collidable {
+trait PlayerKiller extends Collidable with SummoningSickness {
+ protected val maxSicknessDurationMillis = 3000L
+
def onCollision(collider: GameObject) {
- if(collider.is[Player]) {
+ if(collider.is[Player] && !hasSummoningSickness) {
collider.destroy
}
}
@@ -0,0 +1,15 @@
+package org.frankversnel.poortjes.game.gameobjects
+
+import org.frankversnel.poortjes._
+
+trait SummoningSickness extends Component {
+ protected val maxSicknessDurationMillis: Long
+
+ private var sicknessDurationMillis = 0L
+
+ override def process(update: Update) {
+ sicknessDurationMillis += update.deltaTime.millis
+ }
+
+ def hasSummoningSickness = sicknessDurationMillis < maxSicknessDurationMillis
+}
@@ -8,8 +8,8 @@ import org.frankversnel.poortjes.Update
* the specified maxTimeAliveMillis length.
*/
trait TimeBasedLife extends Component {
- protected val maxTimeAliveMillis: Int
- private var timeAliveMillis = 0
+ protected val maxTimeAliveMillis: Long
+ private var timeAliveMillis = 0L
override def process(update: Update) {
super.process(update)
@@ -1,6 +1,6 @@
package org.frankversnel.poortjes.util
-case class DeltaTime(millis: Int) {
+case class DeltaTime(millis: Long) {
val seconds: Float = millis.toFloat / 1000f
}

0 comments on commit 50349a3

Please sign in to comment.