Created
October 30, 2018 19:34
-
-
Save playdeezgames/f76256275e8c4e7a0d7e2ff8fd062b75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cellWidth = 8 | |
cellHeight = 8 | |
cellColumns = 40 | |
cellRows = 30 | |
screenWidth = cellWidth * cellColumns | |
screenHeight = cellHeight * cellRows | |
blocks = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] | |
tail=[20,20,20,20,20,20] | |
direction = 1 | |
playing = False | |
tailLength = 6 | |
def plotX(column): | |
return column * cellWidth | |
def setupGame(): | |
blocks=[] | |
while len(blocks)<cellRows: | |
blocks.append(0) | |
tail=[] | |
while len(tail)<tailLength: | |
tail.append(floor(cellColumns/2)) | |
def setup(): | |
frameRate(10) | |
size(screenWidth, screenHeight) | |
def drawBlocks(): | |
fill(255) | |
noStroke() | |
row = 0 | |
for column in blocks: | |
x = column * cellWidth | |
y = row * cellHeight | |
rect(x,y,cellWidth,cellHeight) | |
row = row + 1 | |
def drawWalls(): | |
fill(0,0,255) | |
#draw left wall | |
rect(0,0,cellWidth,screenHeight) | |
#draw right wall | |
rect(screenWidth - cellWidth,0,cellWidth,screenHeight) | |
def keyPressed(): | |
global playing | |
global direction | |
if playing: | |
if keyCode==LEFT: | |
direction = -1 | |
elif keyCode==RIGHT: | |
direction = 1 | |
else: | |
if key==" ": | |
setupGame() | |
playing = True | |
def drawTail(): | |
row = 0 | |
for column in tail: | |
x = column * cellWidth | |
y = row * cellHeight | |
if row<(tailLength-1): | |
fill(255,255,0) | |
else: | |
fill(255,0,0) | |
rect(x,y,cellWidth,cellHeight) | |
row = row + 1 | |
def draw(): | |
global playing | |
global tail | |
global direction | |
global blocks | |
#clear background | |
background(0) | |
#draw blocks | |
drawBlocks() | |
#draw walls | |
drawWalls() | |
#draw | |
drawTail() | |
if playing: | |
head = tail[tailLength-1] + direction | |
del tail[0] | |
tail.append(head) | |
del blocks[0] | |
blocks.append(floor(random(1,cellColumns-1))) | |
if head==blocks[tailLength-1]: | |
playing = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment