I am making a python program that reads an image and creates a level according to every pixel's color. Although , when i run it, I'm getting this error "inconsistent use of tabs and spaces in indentation" at line 139. It's quite frustrating because I can't figure out why it is wrong.
I've already tried changing the indentation size to 2, 4 and 8 but it fixed nothing
Here's my code
#Libraries
import Image
from os import system
from random import randint
#Object class
class object:
def __init__(self, x , y, facing, image, type):
self.x = x
self.y = y
self.facing = facing
self.image = image
self.type = type
#Game variables
entities = []
score = 0
pixels = []
#Read image
pic = Image.open("level1.png", mode="r")
#Get image size
width = pic.size[0]
height = pic.size[1]
picload = pic.load()
#Create pixel array
for y in range(height):
for x in range(width):
pixels.append(picload[x, y])
#Read all pixels
x = 0
y = 0
for i in range(len(pixels)):
#Change x y coordinates
x += 1
if x % height == 0:
x = 0
y += 1
pixel = pixels[i]
r = pixel[0]
g = pixel[1]
b = pixel[2]
a = pixel[3]
#Create object based on pixel info
#If pixel is black
if r >= 200 and g >= 200 and b >= 200: entities.append(x, y, "r", "■", "wall")
#If pixel is red
elif r >= 200 and g <= 50 and b <= 50: entities.append(x, y, "r", "•", "food")
#if pixel is blue
elif r <= 50 and g <= 50 and b >= 200: entities.append(x, y, "r", "☺", "player")
#Running the level
while True:
#output
print("Output:", output)
output = ""
print("Score:", score)
for y in range(height):
print("")
for x in range(width):
drawed = False
for i in range(len(entities)):
entity = entities[i]
if entity.x == x and entity.y == y and drawed == False:
drawed = True
print(entity.image, end = "")
if not drawed: print(".", end="")
#input
dir = input("\n\n####################\nWASD: ").lower()
#processing
#movement
for i in range(len(entities)):
entity = entities[i]
ii = i
if entity.type == "player":
if dir == "w":
entity.y -= 1
entity.facing = "u"
elif dir == "s":
entity.y += 1
entity.facing = "d"
elif dir == "a":
entity.x -= 1
entity.facing = "l"
elif dir == "d":
entity.x += 1
entity.facing = "r"
for h in range(len(entities)):
centity = entities[h]
if entity.x == centity.x and entity.y == centity.y and not ii == h:
if dir == "w":entity.y += 1
elif dir == "s":entity.y -= 1
elif dir == "a":entity.x += 1
elif dir == "d": entity.x -=1
#colisions
for h in range(len(entities)):
entity = entities[h]
f = entity.facing
cx = entity.x
cy = entity.y
if f == "r": cx += 1
elif f == "l": cx -= 1
elif f == "u": cy -= 1
elif f == "d": cy += 1
for i in range(len(entities)):
centity = entities[i]
if centity.x == cx and centity.y == cy:
print("a")
#Clear terminal
system("clear")