Search code examples
pythonpython-3.xpygamelinedraw

I can't draw lines in Pygame


I made a Pygame program and I tried to draw a line. But every time I'm running the program, it shows me this:

  File "/Documents/game.py", line 47
    pygame.draw.line(win, (255,255,255), (0,375), (500,375))
    ^
SyntaxError: invalid syntax

My code:

#!/usr/bin/env python
import pygame
from pygame.locals import *
import sys
import threading
import random
import os
base_path = os.path.dirname(__file__)
bg_path = os.path.join(base_path, "imports/bg.png")
bgimg = pygame.image.load(bg_path)
cannon_path = os.path.join(base_path, "imports/cannon.png")
cannonimg = pygame.image.load(cannon_path)
bullet_path = os.path.join(base_path, "imports/bullet.png")
bulletimg = pygame.image.load(bullet_path)
target_path = os.path.join(base_path, "imports/target.png")
targetimg = pygame.image.load(target_path)
icon_path = os.path.join(base_path, "imports/icon.png")
iconimg = pygame.image.load(icon_path)
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("ShootIt!")
pygame.display.set_icon(iconimg)
while True:
    pygame.time.delay(25)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:           
            pygame.quit()
            sys.exit()     
    keys = pygame.key.get_pressed()
    bg = win.blit(bgimg, (0,0))
    cannon = win.blit(cannonimg, (225,225)
    pygame.draw.line(win, (255,255,255), (0,375), (500,375))
    pygame.display.update()

By the way, I'm using Mac OS X, Python 3.8.3 and Pygame 2.0.0.


Solution

  • In the line before the line in which the error is displayed, a ) is missing:

    cannon = win.blit(cannonimg, (225,225)