i will explain some on the program. i trying to make a snake game. my problem is that the snake always starting in the corner of the screen which mean that he supposed to be dead.. i want to place "image"(image is the name of the photo) in randon locaion on the screen. how i can do it? i tried few times but the progran has been stock.. here is the code..
import sys, pygame,time
FPS=30
fpsClock=pygame.time.Clock()
window_size = ( 819, 460 )
white = ( 255, 255, 255 )
screen = pygame.display.set_mode( window_size )
class Player():
image = pygame.image.load( 'snikebodydraw.png')
image1 = pygame.image.load( 'deadarea.png')
rect = image.get_rect()
player = Player()
move = (0,0) # init movement
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
move = (-10, 0 )
if event.key == pygame.K_RIGHT:
move = ( 10, 0 )
if event.key == pygame.K_UP:
move = ( 0,-10 )
if event.key == pygame.K_DOWN:
move = ( 0, 10 )
player.rect = player.rect.move(move)
screen.blit(player.image1, (0,0))
screen.blit( player.image, player.rect )
pygame.display.flip()
fpsClock.tick(FPS)
Aucun commentaire:
Enregistrer un commentaire