Skip to content

Instantly share code, notes, and snippets.

@litan
Last active June 29, 2022 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save litan/dd15f63a461cc8ce28a0c1cea5e6d203 to your computer and use it in GitHub Desktop.
Save litan/dd15f63a461cc8ce28a0c1cea5e6d203 to your computer and use it in GitHub Desktop.
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()
@CasiaMaryGomes200600
Copy link

HI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment