natehome 0 Newbie Poster

im trying to write a tron game with python but when ever the tail starts to erase, it erases too much. try running it and you will see what i mean. when you run it drive over your tail and watch it delete too much.

import sys, random, time, pygame
from pygame.locals import *

def print_text(font, x, y, text, color=(255,255,255)):
    imgText = font.render(text, True, color)
    screen.blit(imgText, (x,y))
    

#main program begins
pygame.init()
w = 500
h = 500
screen = pygame.display.set_mode((w,h))
pygame.display.set_caption("Tron")
font1 = pygame.font.Font(None, 24)
pygame.mouse.set_visible(False)
white = 255,255,255
red = 220, 50, 50
yellow = 230,230,50
black = 0,0,0



pos_x = 300
pos_y = 460
p1 = [[300],[460]]
poss = pos_y,pos_x
print p1
screen.fill(black)

vel_y = 0.7
path = 8 # 8=up 6=right 4=left 2=down
#repeating loop
while True:
    for event in pygame.event.get():
        #Keydown
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                pygame.quit()
                sys.exit()
            if event.key == K_UP and path != 2:
                path = 8
            if event.key == K_RIGHT and path != 4:
                path = 6                
            if event.key == K_LEFT and path != 6:
                path = 4
            if event.key == K_DOWN and path != 8:
                path = 2
    
    if path == 8:
        pos_y -= 1
    elif path == 6:
        pos_x += 1
    elif path == 4:
        pos_x -= 1
    elif path == 2:
        pos_y += 1
    p1[0].append(pos_x)
    p1[1].append(pos_y)
    if pos_y <= 0 or pos_y >= h or pos_x <= 0 or pos_x >= w:
        pygame.quit()
        sys.exit()
    pos1 = p1[0][0],p1[1][0],2,2
    pos = pos_x,pos_y,2,2
    cur = [[],[]]
    cur[0].append(pos_x)
    cur[1].append(pos_y)

    if len(p1[0]) >= 500:
        pygame.draw.rect(screen, black, pos1, 0)
        p1[1].pop(0)
        p1[0].pop(0)
        



    
    pygame.time.delay(10) 
    
    #print pos
    
    pygame.draw.rect(screen, white, pos, 0)
    
    
    pygame.display.update()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.