Ahoj!
Mám takový problém, právě dělám hru snake v pythonu za pomoci pygame a vyskytla se mi tu taková chyba a já nevim co s tim. Podle mě je tam všechno dobře.
import pygame as pg
from random import randint
CERNA = (0,0,0)
BILA = (250,250,250)
MODRA = (0,40,250)
ZELENA = (0,255,0)
CERVENA = (250,0,0)
ZLUTA = (255,255,100)
ORANZOVA = (251,155,49)
ZUZOVA = (241,88,226)
sirka_okna = 1280
vyska_okna = 720
hra = True
class snake:
def __init__(self,x,y,s,v,barva,smer,UP,DOWN,LEFT,RIGHT,rychlost,had):
self.x = x
self.y = y
self.s = s
self.rx = s
self.v = v
self.ry = v
self.barva = barva
self.smer = smer
self.UP = UP
self.DOWN = DOWN
self.LEFT = LEFT
self.RIGHT = RIGHT
self.CDP = 60
self.rychlost = rychlost
self.clanku = 3
self.had = had
def nakreslise(self):
pg.draw.rect(okno,self.barva, (self.x,self.y,self.s,self.v))
def pohyb(self):
#POHYB
if self.CDP == 0:
if self.smer == "U":
self.y -= self.v
if self.smer == "D":
self.y += self.v
if self.smer == "L":
self.x -= self.s
if self.smer == "R":
self.x += self.s
self.CDP = self.rychlost
#CLANKY
clanky.append(clanek(self.x,self.y,self.s,self.v,self.barva,1,self.had))
#OKRAJE
if self.x >= sirka_okna:
self.x = 0
if self.x < 0:
self.x = sirka_okna-self.s
if self.y >= vyska_okna:
self.y = 0
if self.y < 0:
self.y = vyska_okna-self.v
#ZMENA SMERU
if u.type == pg.KEYDOWN:
if u.key == self.UP:
self.smer = "U"
if u.key == self.DOWN:
self.smer = "D"
if u.key == self.LEFT:
self.smer = "L"
if u.key == self.RIGHT:
self.smer = "R"
#RYCHLOST A ZPOMALENI
if self.rychlost <= 0:
self.rychlost = 0
self.CDP -= 1
class clanek:
def __init__(self,x,y,s,v,barva,zivoty,had):
self.x = x
self.y = y
self.s = s
self.rx = s
self.v = v
self.ry = v
self.barva = barva
self.zivoty = zivoty
self.had = had
def nakreslise(self):
pg.draw.rect(okno,self.barva, (self.x,self.y,self.s,self.v))
def aPohyb(self):
for had in hadi:
if self.had == had.had:
self.zivoty = had.clanku*had.rychlost
if self.zivoty <= 0:
clanky.remove(self)
pg.init()
okno = pg.display.set_mode((sirka_okna,vyska_okna))
pg.display.set_caption("Tha snake game")
hodiny = pg.time.Clock()
hadi = []
hadi.append(snake(0,0,10,10,ZELENA,"D",pg.K_UP,pg.K_DOWN,pg.K_LEFT,pg.K_RIGHT,15,"zeleny"))
clanky = []
while hra:
for u in pg.event.get():
if u.type == pg.QUIT:
hra = False
okno.fill(CERNA)
for had in hadi:
had.nakreslise()
had.pohyb()
for clanek in clanky:
clanek.nakreslise()
clanek.aPohyb()
pg.display.update()
hodiny.tick(60)
pg.quit()
Když to spustím tak mi to hlásí
Traceback (most recent call last):
File "C:/Users/NB/Desktop/Python/snake.py", line 119, in <module>
had.pohyb()
File "C:/Users/NB/Desktop/Python/snake.py", line 51, in pohyb
clanky.append(clanek(self.x,self.y,self.s,self.v,self.barva,1,self.had))
TypeError: 'clanek' object is not callable
Děkuju za to, že jsi dočetl až sem a doufám, že mi pomůžeš.