Code Sketch
KojoLite upload test - A simple game
By: Lalit Pant
Category: Programming
0


0




def p = Picture { val pos = position right() forward(50) left() arc(50, 45) moveTo(pos) } val gg = fillColor(green) -> p val bg1 = trans(200, 0) * fillColor(black) -> p val bg2 = trans(-200, 0) * fillColor(black) -> p clear() invisible() draw(gg, bg1, bg2) drawStage(pink) def badBehavior(me: Picture, bvec: Vector2D) { bvec.rotate(randomDouble(10)-5) me.transv(bvec) if (me.collidesWith(stage)) { bounceVecOffStage(bvec, me) me.transv(bvec) } } val speed = 1.5 val sf = 1.5 val bg1vec = Vector2D(0, speed) bg1.act { me => badBehavior(me, bg1vec) } val bg2vec = Vector2D(speed, 0) bg2.act { me => badBehavior(me, bg2vec) } gg.act { me => if (isKeyPressed(Kc.VK_RIGHT)) { me.translate(speed * sf, 0) } if (isKeyPressed(Kc.VK_LEFT)) { me.translate(-speed * sf, 0) } if (isKeyPressed(Kc.VK_UP)) { me.translate(0, speed * sf) } if (isKeyPressed(Kc.VK_DOWN)) { me.translate(0, -speed * sf) } } val baddys = List(bg1, bg2) gg.act { me => if (me.collision(baddys).isDefined) { stopAnimation() me.setFillColor(red) write("You Lost") } } activateCanvas()



Lalit Pant [2] said:

This no longer works with Kojo 2.x, where vectors are immutable. See the Hunted sample bundled with Kojo for ideas on how to get this to work.



Your Comment:





Login to post a comment