1. Invites entrants to write a game in one week from scratch either as an individual or in a team,
2. Is intended to be challenging and fun,
3. Will hopefully increase the public body of game tools, code and expertise,
4. Will let a lot of people actually finish a game, and
5. May inspire new projects (with ready made teams!)
def main():
LEFT = False
RIGHT = False
UP = False
DOWN = False
DIRECTION = "DOWN"
LENGHT = 8
#init pygame and get screen object
pygame.init()
screen = pygame.display.set_mode(screen_rect.size)
#snake block and array
snake_rect = pygame.Surface((10, 10)).convert()
snake_rect.fill((255, 0, 0))
snake_array = [[20, 20], ] #initial position, div by 10
#clear screen before anything else
screen.blit(background, (0, 0))
pygame.display.update()
#get clock for FPS limit
clock = pygame.time.Clock()
while 1:
#get key events and toggle booleans
for event in pygame.event.get():
if event.type == QUIT: return
if (event.type == KEYUP):
if (event.key == K_UP): UP = False
if (event.key == K_LEFT): LEFT = False
if (event.key == K_RIGHT): RIGHT = False
if (event.key == K_DOWN): DOWN = False
if (event.type == KEYDOWN):
if (event.key == K_UP) and ( DIRECTION == "LEFT" or DIRECTION == "RIGHT" ): DIRECTION = "UP"
if (event.key == K_LEFT) and ( DIRECTION == "UP" or DIRECTION == "DOWN" ): DIRECTION = "LEFT"
if (event.key == K_RIGHT) and ( DIRECTION == "UP" or DIRECTION == "DOWN" ): DIRECTION = "RIGHT"
if (event.key == K_DOWN) and ( DIRECTION == "LEFT" or DIRECTION == "RIGHT" ): DIRECTION = "DOWN"
if (event.key == K_c): LENGHT = LENGHT + 1
#clear screen
screen.blit(background, (0, 0))
#update
if DIRECTION == "DOWN":
last_pos = snake_array[-1] #get last position/element
snake_array.append([last_pos[0], last_pos[1]+10]) #append new position
if DIRECTION == "UP":
last_pos = snake_array[-1]
snake_array.append([last_pos[0], last_pos[1]-10])
if DIRECTION == "LEFT":
last_pos = snake_array[-1]
snake_array.append([last_pos[0]-10, last_pos[1]])
if DIRECTION == "RIGHT":
last_pos = snake_array[-1]
snake_array.append([last_pos[0]+10, last_pos[1]])
#snake length logic
if LENGHT > len(snake_array):
#print "LENGHT:" + str(LENGHT) + " ARRAY LEN:" + str(len(snake_array))
pass
else:
snake_array.pop(0) # remove first element
#redraw
#print snake_array
for i in snake_array:
screen.blit(snake_rect, i)
pygame.display.update()