def update(): global gameOver if stage[shooterPosition][0] != 0: gameOver = True kit.clear() renderStage() kit.setPixel(0, shooterPosition, colors[currentColor]) kit.render()
def update(): global gameOver if stage[shooterPosition][0] == 1: gameOver = True if (t % 240 - score) == 0: shift() kit.clear() renderStage() kit.setPixel(0, shooterPosition, [8, 8, 8]) kit.render()
def renderStage(): global stage global score sum = 0 for i, row in enumerate(stage): for j, value in enumerate(row): sum = sum + value color = [10 * value] * 3 kit.setPixel(j, i, color) if sum == 0: score = score + 1 restart()
def renderMainShipBullets(): for i, bullet in enumerate(mainShip.bullets): if t % 2 == 0: bullet.move() if bullet.life > 20: del mainShip.bullets[i] else: for j, enemy in enumerate(enemies): if enemy.getX() == bullet.getX() and enemy.getY( ) == bullet.getY(): del enemies[j] del mainShip.bullets[i] kit.setPixel(bullet.getX(), bullet.getY(), colors[4])
def renderEnemies(): for enemy in enemies: if t % 96 == 0: enemy.turnRight() elif t % 48 == 0: enemy.turnLeft() if t % 24 == 0: enemy.moveForward() for y, row in enumerate(enemy.getSprite()): for x, c in enumerate(row): if c != 0: kit.setPixel((enemy.getX() + x - 1) % 16, (enemy.getY() + y - 1) % 8, colors[(c + 2) % len(colors)])
def loop(): global t t = t + 1 kit.checkControls() if not gameOver: if t % int(level) == 0: updateBall() kit.clear() renderFrame() kit.render() else: kit.setBackground([10, 10, 0]) for i in range(0, score): kit.setPixel(i % 16, int(i / 16), [10, 0, 0]) kit.render()
def loop(): if not gameOver: moveObstacle() renderObstacle() jump() checkCollision() renderFloor() renderSky() renderCharacter() if gameOver: for i in range(0, int(level * 2)): kit.setPixel(i % 16, int(i / 16), colors[4]) if kit.isPressingB: reset()
def renderSky(): i = int(t / 2) for y, line in enumerate(sky): for x, pixel in enumerate(line): kit.setPixel(x, y, colors[sky[y][(x + i) % 16]])
def renderObstacle(): n = int(obstaclePosition) kit.setPixel(n, 6, colors[6]) kit.setPixel(n, 5, colors[6]) kit.setPixel(n + 1, 6, colors[6]) kit.setPixel(n + 1, 5, colors[6])
def line(x1, y1, x2, y2, color): for pixel in bresenham(x1, y1, x2, y2): kit.setPixel(pixel[0], pixel[1], color) kit.render()
def renderFloor(): for x in range(0, 16): kit.setPixel(x, 7, colors[5])
def renderPixel(): if pixelVisible and inStage(cursor[0], cursor[1]): kit.setPixel(cursor[0], cursor[1], color)
def renderPixelHeading(): vector = headings[heading] nx = cursor[0]+vector[0] ny = cursor[1]+vector[1] if pixelHeadingVisible and inStage(nx, ny): kit.setPixel(nx, ny, headingColor)
def renderStage(): for i, row in enumerate(stage): for j, value in enumerate(row): kit.setPixel(j, i, colors[value])
def renderRightPad(): for i in range(0, padSize): kit.setPixel(15, int(padPosition + i), [0, 10, 0])
def renderBall(): kit.setPixel(ballPosition[0], ballPosition[1], colors[4])
def clearScreen(): for i in range(0, 16): for j in range(0, 8): kit.setPixel(15 - i, j, [10, 10, 10]) kit.render() sleep(0.2)
def renderStage(): for y, line in enumerate(stage): for x, pixel in enumerate(line): kit.setPixel(x, y, colors[pixel])
def renderMainShip(): for y, row in enumerate(mainShip.getSprite()): for x, c in enumerate(row): kit.setPixel((mainShip.getX() + x - 1) % 16, (mainShip.getY() + y - 1) % 8, colors[c])
def renderBall(): kit.setPixel(ballPosition[0], ballPosition[1], [20, 20, 20])
def renderCharacter(): i = int(t / 4) % len(charSprite) for y, line in enumerate(charSprite): for x, pixel in enumerate(line): ny = int(charPosition) + y kit.setPixel(x, ny, colors[charSprite[i][y][x]])
def renderStage(): for y, row in enumerate(stage): for x, col in enumerate(row): kit.setPixel(x, y, stage[y][x])
def renderPad(): for x in range(padPosition, padPosition+padSize): kit.setPixel(x, 7, colors[7])
def renderLeftPad(): for i in range(0, padSize): kit.setPixel(0, int(padPosition + i), [0, 0, 10])