Hi i'm trying to make a basic snake game. However i cannot seem to be able to display any food. I have tried numerous different ways but i just can't get anything to show :@. I simply want a red rectangle that will display in random places everytime the snake hits it. Any help would be very much appreciated.
# -*- coding: cp1252 -*-
import pygame , pygame .mixer , random, sys
from pygame.locals import *
ballimg = 'c:/Python/images/segment.png'
caption = 'Snake Game using PyGame .'
screen_size = width , height = 800 , 600
speed = [0 , 1]
black = (0, 0, 0)
applepos = (random.randint (0, 590), random.randint(0, 590))
pygame . init ()
screen = pygame . display . set_mode ( screen_size )
pygame . display . set_caption ( caption )
appleimage = Surface.fill(color, rect=20, 20, special_flags=0): return rect
appleimage.fill((255, 0, 0))
ball = pygame . image . load ( ballimg ). convert ()
ballrect = ball . get_rect ()
finished = False
paused = False
while not finished :
for event in pygame . event . get ():
if event . type == KEYDOWN:
if event.key == K_DOWN:
speed = [0 , 1]
elif event.key == K_UP:
speed = [0 , -1]
elif event.key == K_LEFT:
speed = [-1 , 0]
elif event.key == K_RIGHT:
speed = [1 , 0]
elif event.key == K_ESCAPE:
finished = True
elif event.key == K_PAUSE:
paused = not paused
if event . type == pygame . QUIT :
sys . exit ()
pygame.time.delay (10)
if paused == False:
ballrect = ballrect . move ( speed )
screen . fill ( black )
screen . blit (ball , ballrect )
pygame . display . flip ()
#check to see if its hit the wall
print ballrect.left, ballrect.right
if ballrect .left <0 or ballrect .right > width or ballrect .top <0 or ballrect . bottom > height :
f=pygame.font.SysFont('Arial', 30)
t=f.render('YOU DIED! Your score was: ', True, (255, 255, 255))
paused = True
print "Finished"