I am trying to create a game, but I keep getting an the error 'Unindent does not match any outer indentation level' , preventing my code from being able to run.
I tried changing the order and looking for mistakes, but am unable to spot any
import pygame, sys from pygame.locals import *
#Initialize Package
pygame.init()
win = pygame.display.set_mode ((640,600))
pygame.display.set_caption("EduCAUTION")
#Colours init
crushed = (142, 71, 71)
white = (250, 250, 250)
#Text init
pygame.font.init()
myfont = pygame.font.SysFont('Arial', 50)
subtitle = pygame.font.SysFont('Arial', 25)
normal = pygame.font.SysFont('comicsans', 20)
#Hardware Game Text
hardtitle = myfont.render('Beware Hardware', False, (crushed))
hardrules = subtitle.render('Walk the character to the right answer to clear the path.', False, (75,75,75))
hardQ1 = myfont.render('RAM stands for...', False, (crushed))
Hopt1 = subtitle.render('Random Access Memory', False, (75,75,75))
Hopt2 = subtitle.render('Rotten Apple Monkey', False, (75,75,75))
#Images Init
hardBG = pygame.image.load('comsciBG.jpg')
#Animation
walkRight = [pygame.image.load('R1.png'), pygame.image.load('R2.png'), pygame.image.load('R3.png'), pygame.image.load('R4.png'), pygame.image.load('R5.png'), pygame.image.load('R6.png'), pygame.image.load('R7.png'), pygame.image.load('R8.png'), pygame.image.load('R9.png')]
walkLeft = [pygame.image.load('L1.png'), pygame.image.load('L2.png'), pygame.image.load('L3.png'), pygame.image.load('L4.png'), pygame.image.load('L5.png'), pygame.image.load('L6.png'), pygame.image.load('L7.png'), pygame.image.load('L8.png'), pygame.image.load('L9.png')]
left = False
right = False
walkCount = 0
#Constants
x = 60
y = 300
width = 50
height = 50
vel = 25
end = 540
#Variables
game3 = 0
def comSci():
global game3
global walkCount
if walkCount + 1 >= 27:
walkCount = 0
win.blit(hardBG, (-5,-20))
win.blit(hardtitle, (160, 15))
win.blit(hardrules, (60,80))
if game3 == 0:
win.blit(hardQ1, (200, 200))
pygame.draw.rect(win, white,(15,290,250,50))
pygame.draw.rect(win, white,(405, 290, 220, 50))
win.blit(Hopt1, (30, 300))
win.blit(Hopt2, (420, 300))
# If facing left
if left:
gameWindow.blit(walkLeft[walkCount//3], (x,y))
walkCount += 1
# If facing right
if right:
gameWindow.blit(walkRight[walkCount//3], (x,y))
walkCount += 1
pygame.display.update()
run = True
while run:
#Quit game
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if keys[pygame.K_LEFT] and x > 15:
x -= vel
left = True
right = False
elif keys[pygame.K_RIGHT] and x < 590 - vel - width:
x += vel
left = False
right = True
elif keys[pygame.K_UP] :
if x >= 200 and y>=40:
y -= vel
left = False
right = False
elif keys[pygame.K_DOWN] and y < 404 - vel - width:
y += vel
left = False
right = False
else:
left = False
right = False
walkCount = 0
comSci()
#End Game
pygame.quit()
The code is suppose to allow an animation to move based on mouse clicks. (Yes, I am aware that the variables are a little innacurate, it is a work in progress). How can I fix this error?