space.basic 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Sternenfänger
  2. # Links/Rechts bewegen, Sterne sammeln, Meteoriten vermeiden.
  3. # Nach Game Over mit START/X neu starten.
  4. initWindow(720, 480)
  5. function box(x, y, w, h, c)
  6. for ax = 0 to w - 1
  7. for ay = 0 to h - 1
  8. setPixel(x + ax, y + ay, c)
  9. end
  10. end
  11. end
  12. function star(x, y, c)
  13. setPixel(x + 2, y, c)
  14. setPixel(x + 2, y + 1, c)
  15. setPixel(x, y + 2, c)
  16. setPixel(x + 1, y + 2, c)
  17. setPixel(x + 2, y + 2, c)
  18. setPixel(x + 3, y + 2, c)
  19. setPixel(x + 4, y + 2, c)
  20. setPixel(x + 2, y + 3, c)
  21. setPixel(x + 2, y + 4, c)
  22. end
  23. function rock(x, y, c)
  24. box(x + 1, y, 4, 1, c)
  25. box(x, y + 1, 6, 4, c)
  26. box(x + 1, y + 5, 4, 1, c)
  27. end
  28. function ship(x, y, c)
  29. box(x + 7, y, 4, 2, c)
  30. box(x + 4, y + 2, 10, 2, c)
  31. box(x, y + 4, 18, 3, c)
  32. setPixel(x + 2, y + 7, c)
  33. setPixel(x + 15, y + 7, c)
  34. end
  35. bg = color(0, 0, 4)
  36. white = color(31, 31, 31)
  37. yellow = color(31, 31, 0)
  38. red = color(31, 5, 0)
  39. cyan = color(0, 31, 31)
  40. green = color(0, 31, 8)
  41. playerX = 111
  42. playerY = 148
  43. starX = random(4, 235)
  44. starY = 0
  45. rockX = random(4, 235)
  46. rockY = 0
  47. score = 0
  48. lives = 3
  49. speed = 1
  50. nextLevel = 5
  51. gameOver = 0
  52. while !shouldClose()
  53. nextFrame()
  54. clearWindow(bg)
  55. if gameOver == 0
  56. if isButtonDown(BT_LEFT)
  57. playerX = playerX - 2
  58. end
  59. if isButtonDown(BT_RIGHT)
  60. playerX = playerX + 2
  61. end
  62. if playerX < 0
  63. playerX = 0
  64. end
  65. if playerX > 222
  66. playerX = 222
  67. end
  68. starY = starY + speed
  69. rockY = rockY + speed + 1
  70. hitStar = 0
  71. if starY >= playerY - 5
  72. if starY <= playerY + 8
  73. if starX >= playerX
  74. if starX <= playerX + 18
  75. hitStar = 1
  76. end
  77. end
  78. end
  79. end
  80. if hitStar == 1
  81. score = score + 1
  82. starX = random(4, 235)
  83. starY = 0
  84. end
  85. if starY > 159
  86. starX = random(4, 235)
  87. starY = 0
  88. end
  89. hitRock = 0
  90. if rockY >= playerY - 6
  91. if rockY <= playerY + 8
  92. if rockX + 6 >= playerX
  93. if rockX <= playerX + 18
  94. hitRock = 1
  95. end
  96. end
  97. end
  98. end
  99. if hitRock == 1
  100. lives = lives - 1
  101. rockX = random(4, 235)
  102. rockY = 0
  103. end
  104. if rockY > 159
  105. rockX = random(4, 235)
  106. rockY = 0
  107. end
  108. if score >= nextLevel
  109. speed = speed + 1
  110. nextLevel = nextLevel + 5
  111. end
  112. if lives <= 0
  113. gameOver = 1
  114. end
  115. render(0, 0, white, "Score: ", score)
  116. render(96, 0, white, "Lives: ", lives)
  117. render(176, 0, white, "Speed: ", speed)
  118. star(starX, starY, yellow)
  119. rock(rockX, rockY, red)
  120. ship(playerX, playerY, cyan)
  121. end
  122. if gameOver != 0
  123. render(64, 48, red, "GAME OVER")
  124. render(48, 68, white, "Score: ", score)
  125. render(24, 96, green, "Press START / X")
  126. if getButtonDownTime(BT_START) == 1
  127. playerX = 111
  128. starX = random(4, 235)
  129. starY = 0
  130. rockX = random(4, 235)
  131. rockY = 0
  132. score = 0
  133. lives = 3
  134. speed = 1
  135. nextLevel = 5
  136. gameOver = 0
  137. end
  138. end
  139. end
  140. printLine("stop")