randomowy ruch

This commit is contained in:
Bowske 2020-04-03 16:20:20 +02:00
parent a7d4492559
commit 81026b0f6f
2 changed files with 16 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,4 +1,6 @@
import pygame
import random
# This sets the WIDTH and HEIGHT of each grid location
WIDTH = 60
@ -26,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:
self.x -= 1