dodano obsluge smieciarki
This commit is contained in:
parent
4f9977bf5b
commit
8ecd8d3af6
50
game.py
50
game.py
@ -1,7 +1,37 @@
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
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
|
# Define some colors
|
||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
WHITE = (255, 255, 255)
|
WHITE = (255, 255, 255)
|
||||||
@ -46,6 +76,14 @@ done = False
|
|||||||
# Used to manage how fast the screen updates
|
# Used to manage how fast the screen updates
|
||||||
clock = pygame.time.Clock()
|
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 -----------
|
# -------- Main Program Loop -----------
|
||||||
while not done:
|
while not done:
|
||||||
for event in pygame.event.get(): # User did something
|
for event in pygame.event.get(): # User did something
|
||||||
@ -60,6 +98,15 @@ while not done:
|
|||||||
# Set that location to one
|
# Set that location to one
|
||||||
grid[row][column] = 1
|
grid[row][column] = 1
|
||||||
print("Click ", pos, "Grid coordinates: ", row, column)
|
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
|
# Set the screen background
|
||||||
screen.fill(BLACK)
|
screen.fill(BLACK)
|
||||||
@ -76,6 +123,7 @@ while not done:
|
|||||||
(MARGIN + HEIGHT) * row + MARGIN,
|
(MARGIN + HEIGHT) * row + MARGIN,
|
||||||
WIDTH,
|
WIDTH,
|
||||||
HEIGHT])
|
HEIGHT])
|
||||||
|
all_sprites_list.draw(screen)
|
||||||
|
|
||||||
# Limit to 60 frames per second
|
# Limit to 60 frames per second
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
BIN
smieciarka_odwrocona.png
Normal file
BIN
smieciarka_odwrocona.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Loading…
Reference in New Issue
Block a user