i am trying to program Pong and i am so far:
import pygame, sys, time
from pygame.locals import *
pygame.init()
FPS=30
fpsClock=pygame.time.Clock()
size = width, height = 1280, 648
speed = [8, 8]
DISPLAYSURF=pygame.display.set_mode((size),0,32)
background=pygame.image.load('bg.png')
screen = pygame.display.set_mode(size)
UP='up'
DOWN='down'
ball = pygame.image.load("ball.png")
ballrect = ball.get_rect()
player1 = pygame.image.load('player1.png')
player1rect = player1.get_rect()
player1x=14
player1y=323
direction=None
def move(direction, player1, player1x, player1y):
if direction:
if direction == K_UP:
player1y-=5
elif direction == K_DOWN:
player1y+=5
return player1, player1x, player1y
while True:
DISPLAYSURF.blit(background,(0,0))
DISPLAYSURF.blit(player1,(player1x,player1y))
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
direction = event.key
if event.type == KEYUP:
if (event.key == direction):
direction = None
player1, player1x, player1y = move(direction, player1, player1x, player1y)
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.blit(ball, ballrect)
screen.blit(player1, player1rect)
pygame.display.update()
fpsClock.tick(FPS)
but when i am trying to open it in CMD this error appear
File "C:\Users\Gustav\Documents\Pong\Pong.py", line 58
screen.blit(player1, player1rect)
^
TabError: inconsistent use of tabs and spaces in indentation
i do not think that it can load the 'player1rect'. because i wan´t the 'ball' and 'player1' to collide so i did make a rect for them each, but it don´t seems it´s working. so in all i wan´t to get the error disappear.
It is problem with indentation - use tab or 4 spaces, not both. You mixed tabs and spaces near line 58.
I checked your code - it work fine. So test your indentation or use editor which can change tabs to 4 spaces (or 4 spaces to tabs)