Advertisement
otorp2

MC draw grid

Apr 27th, 2020
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. https://makecode.com/_WHWfz91Lc5eR
  2. https://sites.google.com/site/akulcsarsite/makecode/makecode-arcade
  3.  
  4. enum SpriteKindLegacy {
  5.     Player,
  6.     Projectile,
  7.     Food,
  8.     Enemy
  9. }
  10. controller.left.onEvent(ControllerButtonEvent.Pressed, function () {
  11.     grid.moveLeft(mySprite)
  12. })
  13. controller.down.onEvent(ControllerButtonEvent.Pressed, function () {
  14.     grid.moveDown(mySprite, false)
  15. })
  16. controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
  17.     rows += 1
  18.     setGridSize()
  19.     drawGrid()
  20. })
  21. function drawGrid () {
  22.     grid.drawGrid(bg, 7)
  23. }
  24. controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
  25.     columns += 1
  26.     setGridSize()
  27.     drawGrid()
  28. })
  29. controller.right.onEvent(ControllerButtonEvent.Pressed, function () {
  30.     grid.moveRight(mySprite, false)
  31. })
  32. function setGridSize () {
  33.     grid.setSize(rows, columns)
  34.     grid.setSpriteLocation(mySprite, 0, 0)
  35. }
  36. controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
  37.     grid.moveUp(mySprite)
  38. })
  39. let rows = 0
  40. let columns = 0
  41. let bg: Image = null
  42. let mySprite: Sprite = null
  43. mySprite = sprites.create(img`
  44.     . . . . . . . e e e e . . . . .
  45.     . . . . . e e 4 5 5 5 e e . . .
  46.     . . . . e 4 5 6 2 2 7 6 6 e . .
  47.     . . . e 5 6 6 7 2 2 6 4 4 4 e .
  48.     . . e 5 2 2 7 6 6 4 5 5 5 5 4 .
  49.     . e 5 6 2 2 8 8 5 5 5 5 5 4 5 4
  50.     . e 5 6 7 7 8 5 4 5 4 5 5 5 5 4
  51.     e 4 5 8 6 6 5 5 5 5 5 5 4 5 5 4
  52.     e 5 c e 8 5 5 5 4 5 5 5 5 5 5 4
  53.     e 5 c c e 5 4 5 5 5 4 5 5 5 e .
  54.     e 5 c c 5 5 5 5 5 5 5 5 4 e . .
  55.     e 5 e c 5 4 5 4 5 5 5 e e . . .
  56.     e 5 e e 5 5 5 5 5 4 e . . . . .
  57.     4 5 4 e 5 5 5 5 e e . . . . . .
  58.     . 4 5 4 5 5 4 e . . . . . . . .
  59.     . . 4 4 e e e . . . . . . . . .
  60. `, SpriteKindLegacy.Player)
  61. bg = image.create(scene.screenWidth(), scene.screenHeight())
  62. columns = 4
  63. rows = 3
  64. scene.setBackgroundImage(bg)
  65. grid.allowWrap(true)
  66. grid.setSpriteVelocity(150)
  67. setGridSize()
  68. drawGrid()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement