function - I keep getting syntax error when using def on python -
note: basic game working on practice project syntax error when defining explosions ( near end of code list... new programming yeah... if great stuck because new more appreciated
import pygame, aya, random pygame.locals import * threading import timer #set pygame pygame.init() mainclock = pygame.time.clock() #set window window_width = 400 window_height = 400 windowsurface = pygame.display.set_mode ( (window_width, window_height),0) pygame.display.set_caption("get home!!") #set color constants black = (0,0,0) blue = (0, 0, 255) #set winning text textfont = pygame.font.sysfont ("impact", 60) text = textfont.render ("welcome home!", true, (193, 0, 0)) #set player , breadcrumbs mapcounter = 0 new_ghost = 20 ghost_size = 64 playerimage = pygame.image.load("playerimage.jpg") playerimagetwo = pygame.image.load("playerimage.jpg") ghostimage = pygame.image.load("ghost image.jpg") ghostimagetwo = pygame.image.load("ghost image2.jpg") player = pygame.rect (300, 100,40, 40) ghost = [] in range(20): ghost.append(pygame.rect(random.randint(0, window_width - ghost_size), random.randint(0, window_height - ghost_size), ghost_size, ghost_size)) #movement variables moveleft = false moveright = false movedown = false move_speed = 6 #run game loop startgame = true while startgame == true: #check quit event in pygame.event.get () : if event.type == quit: pygame.quit() sys.exit() if event.type == keydown: #keyboard variables if event.key ++ k_left: moveright = false moveleft = true if event.key ++ k_right: moveright = false moveleft = false if event.key ++ k_up: moveup = true movedown = false if event.key ++ k_down: moveup = false movedown = true if event.type == keyup: if event.key == k_escape: pygame.quit() ays.exit() if event.key == k_left: moveleft = false if event.key == k_right: moveright = false if event.key == k_up: moveup = false if event.key == k_down: movedown = false ghostcounter += 1 if ghostcounter >= new_ghost: #clear ghost array , add new ghost ghostcounter = 0 ghost.append(pygame.rect(random.randint(0, window_width - ghost_size), random.randint(0, window_height - ghost_size), ghost_size, ghost_size)) #draw black background windowsurface.fill(black) #move player if movedown , play.bottom < window_height: player.top += move_speed if moveup , play.top > 0: player.top -= move_speed if moveleft , play.left > 0: player.left -= move_speed if moveright , play.right < window_height: player.right += move_speed windowsurface.blit(playerimage, player) ghost in ghosts: windowsurface.blit(ghostimage, ghost) #check if player has intersected ghost ghost in ghosts[:]: if player.colliderect(ghost): windowsurface.blit(ghostimagetwo,ghost def explosion(): ghost in ghosts: if player.colliderect(ghost) , (moveleft == false , moveright == false , moveup == false , movedown == false): ghosts.remove(ghost) if player.colliderect(ghost) , (moveleft == false , moveright == false , moveup == false , movedown == false): t = timer(3, explosion) t.start() if len(ghost == 0: ghostcounter = 0 windowsurface.blit(text, (90, 104)) startgame = false #draw window pygame.display.update() mainclock.tick(40) while startgame == false event in pygame.event.get(): if event.type == quit: pygame.quit() sys.exit()
as @burhankhalid pointed out, missing )
@ end of line 111 (windowsurface.blit(ghostimagetwo,ghost
), causing error noticed.
additionally, have numerous syntax errors. define variables in different case use them (startgame
being used startgame
, forget close several other )
s (line 124, etc). list goes on.
python forgiving language, not forgiving. find editor , use it, learn how debug code, , stop being sloppy. unable write code works otherwise.
Comments
Post a Comment