import pygame, time from Raspberry import Raspberry from Block import PygameBlock #test Raspberry pygame.init() playSurface = pygame.display.set_mode((640, 480)) pygame.display.set_caption('Block test') redColour = pygame.Color(255, 0, 0) redBlock = PygameBlock(20, redColour, playSurface) raspberry = Raspberry(redBlock) #...first the backdrop blackColour = pygame.Color(0, 0, 0) playSurface.fill(blackColour) raspberry.draw() # ...finally activte the update of the screen pygame.display.flip() raspberry.spawn() print "raspberry.position = ", raspberry.position time.sleep(5) pygame.quit()
if snake.checkPosition(): gameOver() snake.checkIntersect(snakeList) if snake.position == raspberry.position: # snake eats raspberry, spawn a new. raspberry.spawn() speed += 0.5 else: # remove the tail - a new head has already been added - the snake will only grow longer when it takes a raspberry snake.segments.pop() #"pop" without an argument removes the last item of the list #put everything in position for redrawing... #...first the backdrop playSurface.fill(blackColour) # ...then draw snake for snake in snakeList: snake.draw(playSurface) # ...then draw raspberry raspberry.draw(playSurface) # ...finally activte the update of the screen pygame.display.flip() # advance fpsClock.tick(speed)