Merge pull request 'fixing blinking grid' (#3) from s473577_fix_blinking_grid into master

Reviewed-on: #3
This commit is contained in:
Mateusz Kantorski 2023-03-11 13:29:09 +01:00
commit 517b60b7a7

26
main.py
View File

@ -5,13 +5,21 @@ pygame.init()
screen = pygame.display.set_mode((1280, 720)) screen = pygame.display.set_mode((1280, 720))
c = (0, 150, 0) c = (0, 150, 0)
def draw_grid():
for y in range(80, 720, 80): # horizontal lines
pygame.draw.line(screen, c, (80, y), (1280 - 80, y), 1)
for x in range(80, 1280, 80): # vertical lines
pygame.draw.line(screen, c, (x, 80), (x, 720 - 80), 1)
class Wozek: class Wozek:
def __init__(self): def __init__(self):
self.x = 55 self.x = 55
self.y = 55 self.y = 55
self.height = 64 self.height = 64
self.width = 64 self.width = 64
self.image = pygame.image.load("wozek.png") self.image = pygame.image.load("wozek.png")
# Credit: Forklift icons created by Smashicons - Flaticon # Credit: Forklift icons created by Smashicons - Flaticon
# https://www.flaticon.com/free-icons/forklift # https://www.flaticon.com/free-icons/forklift
@ -29,7 +37,7 @@ def main():
sys.exit(0) sys.exit(0)
elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
if wozek.y <= 600: if wozek.y <= 600:
wozek.y += 80 wozek.y += 80
elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
if wozek.y >= 100: if wozek.y >= 100:
wozek.y -= 80 wozek.y -= 80
@ -40,17 +48,11 @@ def main():
if wozek.x >= 100: if wozek.x >= 100:
wozek.x -= 80 wozek.x -= 80
# Drawing
for x in range(0, 1280, 80): screen.fill((0, 0, 0)) # removes object trail
pygame.draw.line(screen, c, (1, x), (1280, x), 2) draw_grid()
pygame.draw.line(screen, c, (x, 1), (x, 720), 2)
pygame.display.update()
#Drawing
screen.fill((0,0,0)) #removes object trail
pygame.display.flip() #updating frames
wozek.draw() wozek.draw()
pygame.display.flip() # updating frames
if __name__ == "__main__": if __name__ == "__main__":