Hei freaks
Jeg holder på å lage ett lite spill, litt prøving.
Men jeg får en error som er slik:
jeg finner ikke ut av feilen, men jeg tror at 'c_x' og 'c_y' ikke er "kobla" til ball.
kan dere hjelpe meg?
her er koden
Jeg holder på å lage ett lite spill, litt prøving.
Men jeg får en error som er slik:
Kode
There's an error in your program: *** can't assign to literal (ball2.py,line 64)
kan dere hjelpe meg?
her er koden
Kode
from pygame import * import random ballpic = image.load('ball.png') ballpic.set_colorkey((0,0,0)) fistpic = image.load ('fist.png') fistpic.set_colorkey ((0,0,0)) c_x = 400 c_y = 400 numfists = 15 delay = 10 done = False fists = [] fist = [] for count in range(numfists): fist.append(dict) fists[count] = {'x': 0, 'y': 0, 'e_x': random.randint(1, 2), 'e_y': random.randint(1, 2)} init() screen = display.set_mode((640, 480)) key.set_repeat(1, 1) display.set_caption('Ball game') event.set_grab(1) while done == False: screen.fill(0) for count in range(numfists): screen.blit(fistpic, (fists[count]['x'], fists[count]['y'])) screen.blit(ballpic, (ball['c_x'],ball['c_y'])) display.update() time.delay(delay) for count in range(numballs): balls[count]['x'] = balls[count]['x'] + balls[count]['e_x'] balls[count]['y'] = balls[count]['y'] + balls[count]['e_y'] for count in range(numballs): if balls[count]['x'] > 620: balls[count]['e_x'] = random.randint(-3, 0) if balls[count]['x'] < -10: balls[count]['e_x'] = random.randint(0, 3) if balls[count]['y'] > 470: balls[count]['e_y'] = random.randint(-3, 0) if balls[count]['y'] < -10: balls[count]['e_y'] = random.randint(0, 3) for e in event.get(): if e.type == KEYUP: if e.key == K_ESCAPE: done = True if pressed_keys[K_LEFT]: 'c_x' = 'c_x' + 1 if pressed_keys[K_RIGHT]: 'c_x' = 'c_x' - 1 if pressed_keys[K_UP]: 'c_y' = 'c_y' + 1 if pressed_keys[K_DOWN]: 'c_y' = 'c_y' - 1 def Intersect(c_x, c_y, e_x, e_y): if (c_x > e_x - 32) and (c_x < e_x + 32) and (c_y > e_y - 32) and (c_y < e_y + 32): done = 1 else: done = 0 print "You lasted for", time.get_ticks()/1000, "seconds!"