Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A simple game
// a simple game - you need to keep the rectangle within the canvas
// the rectangle moves and grows in size; its speed goes up as its size increases
// you can rotate it by pressing the 'P' key; you can make it smaller by clicking on it
cleari()
drawStage(black)
val rect = fillColor(lightGray) * penColor(lightGray) -> PicShape.rect(40, 60)
draw(rect)
animate {
rect.translate(1, 0)
rect.scale(1.001)
if (isKeyPressed(Kc.VK_P)) {
rect.rotate(1)
}
if (rect.collidesWith(stageBorder)) {
rect.setFillColor(red)
stopAnimation()
}
}
rect.onMouseClick { (x, y) =>
rect.scale(0.9)
}
activateCanvas()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment