diff --git a/.gitignore b/.gitignore index d1879c6..e5eb40b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ venv/ .vscode/ .ideagit -.idea/ \ No newline at end of file +.idea \ No newline at end of file diff --git a/game.py b/game.py index 90b80f6..8efef09 100644 --- a/game.py +++ b/game.py @@ -1,11 +1,37 @@ - import pygame -# test2 -# testujemy -# test3 -# test AdamO -# test AdamB + +class Smieciarka(pygame.sprite.Sprite): + def __init__(self, x, y): + self.x = x + self.y = y + self.image = pygame.image.load('smieciarka.png') + pygame.sprite.Sprite.__init__(self) + self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + + MARGIN, self.y * HEIGHT + MARGIN * self.y, WIDTH, HEIGHT) + + def w_lewo(self): + if self.x > 0: + self.x -= 1 + self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN + self.image = pygame.image.load('smieciarka.png') + + def w_prawo(self): + if self.x < 14: + self.x += 1 + self.rect.x = MARGIN + self.x * WIDTH + self.x * MARGIN + self.image = pygame.image.load('smieciarka_odwrocona.png') + + def w_gore(self): + if self.y > 0: + self.y -= 1 + self.rect.y = self.y * HEIGHT + self.y * MARGIN + + def w_dol(self): + if self.y < 14: + self.y += 1 + self.rect.y = self.y * HEIGHT + self.y * MARGIN + # Define some colors BLACK = (0, 0, 0) @@ -51,6 +77,14 @@ done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() +smieciarka = Smieciarka(10, 10) + +smieciarka_list = pygame.sprite.Group() +all_sprites_list = pygame.sprite.Group() + +smieciarka_list.add(smieciarka) +all_sprites_list.add(smieciarka) + # -------- Main Program Loop ----------- while not done: for event in pygame.event.get(): # User did something @@ -65,6 +99,15 @@ while not done: # Set that location to one grid[row][column] = 1 print("Click ", pos, "Grid coordinates: ", row, column) + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + smieciarka.w_lewo() + if event.key == pygame.K_RIGHT: + smieciarka.w_prawo() + if event.key == pygame.K_UP: + smieciarka.w_gore() + if event.key == pygame.K_DOWN: + smieciarka.w_dol() # Set the screen background screen.fill(BLACK) @@ -81,6 +124,7 @@ while not done: (MARGIN + HEIGHT) * row + MARGIN, WIDTH, HEIGHT]) + all_sprites_list.draw(screen) # Limit to 60 frames per second clock.tick(60) diff --git a/smieciarka_odwrocona.png b/smieciarka_odwrocona.png new file mode 100644 index 0000000..ac4a734 Binary files /dev/null and b/smieciarka_odwrocona.png differ