sprawdzanie przeszkody

This commit is contained in:
s444349 2020-04-03 16:42:18 +02:00
commit 240cbba695
2 changed files with 15 additions and 2 deletions

View File

@ -105,7 +105,7 @@ def game():
print("Click ", pozycja_myszki,
"Grid coordinates: ", wiersz, kolumna)
plansza[wiersz, kolumna].setKolor(BLUE)
# plansza[wiersz, kolumna].setKolor(BLUE)
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
@ -118,7 +118,8 @@ def game():
smieciarka.w_dol()
# Limit to 60 frames per second
clock.tick(60)
smieciarka.rand_move()
clock.tick(5)
# czarny kolor w tle
obraz.fill(BLACK)

View File

@ -1,5 +1,6 @@
import pygame
import game
import random
# This sets the WIDTH and HEIGHT of each grid location
WIDTH = 60
@ -27,6 +28,17 @@ class Smieciarka(pygame.sprite.Sprite):
self.rect = pygame.Rect(self.x * WIDTH + MARGIN * self.x + MARGIN, self.y * HEIGHT + MARGIN * self.y, WIDTH,
HEIGHT)
def rand_move(self):
rand_int = random.randint(0, 20)
if (rand_int >= 0 and rand_int < 5):
self.w_lewo()
elif (rand_int >= 5 and rand_int < 10):
self.w_prawo()
elif (rand_int >= 10 and rand_int < 15):
self.w_gore()
elif (rand_int >= 15 and rand_int < 20):
self.w_dol()
def w_lewo(self):
if self.x > 0 or game.plansza[self.x - 1, self.y].jestPrzeszkoda is not True:
self.x -= 1