I am trying to build the border for my pygame (by following a youtube tutorial) and I've encountered an error that I need help to understand. I've tried to fix it but the error remains. Here is my code:
import pygame, sys, time, random, colorsys, math
from pygame.math import Vector2
from pygame.locals import *
def main():
x = 100
y = 100
velocity = 0
acceleration = 0.1
# Initialize the pygame
pygame.init()
# Create the screen
DISPLAY = pygame.display.set_mode((500, 400), 0, 32)
# Title and Icon
pygame.display.set_caption('Dragon')
icon = pygame.image.load('dragon.png')
pygame.display.set_icon(icon)
velocity = pygame.Vector2()
velocity.xy = 3, 0
WHITE=(255, 255, 255)
BLUE=(0, 0, 255)
DISPLAY.fill(WHITE)
while True:
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
DISPLAY.fill((255, 255, 255))
pygame.draw.rect(DISPLAY, BLUE, (x, y, 50, 50))
x += velocity.x
if x + 50 > DISPLAY.get_width():
velocity.x = -3
if x < 0:
velocity.x = 3
y += velocity
velocity += acceleration
if keys[pygame.K_a]:
velocity = -3
pygame.display.update()
pygame.time.delay(10)
main()
And when I click run, the error is:
line 51, in <module>
main()
line 45, in main
y += velocity
TypeError: unsupported operand type(s) for +=: 'int' and 'pygame.math.Vector2'
