During my quest to learn pygame I came across a tutorial that was really helping me through. However I came across a piece of code that has confused me. Being that this tutorial has a very vague explanation on each of the snippets, I need someone to explain this to me.
#! /usr/bin/env python import pygame y = 0 dir = 1 running = 1 width = 800 height = 600 screen = pygame.display.set_mode((width, height)) linecolor = 255, 0, 0 bgcolor = 0, 0, 0 while running: event = pygame.event.poll() if event.type == pygame.QUIT: running = 0 screen.fill(bgcolor) pygame.draw.line(screen, linecolor, (0, y), (width-1, y)) y += dir if y == 0 or y == height-1: dir *= -1 pygame.display.flip()
I can understand everything above screen.fill(). So pretty much I wanna know what all this is:
pygame.draw.line(screen, linecolor, (0, y), (width-1, y))
whats width-1 do?
y += dir if y == 0 or y == height-1: dir *= -1