giganciprogramowania

kulka.py (Arkanoid cz2)

Feb 2nd, 2026
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import pygame
  2. import random
  3.  
  4. SZEROKOSC_EKRANU = 1024
  5. WYSOKOSC_EKRANU = 800
  6. vec = pygame.math.Vector2
  7.  
  8. class Kulka(pygame.sprite.Sprite):
  9. def __init__(self):
  10. super(Kulka, self).__init__()
  11. self.obraz = pygame.image.load("images/ball.png")
  12. self.zresetuj_pozycje()
  13. self.r = 16
  14. self.przegrana = False
  15.  
  16. #resetowanie pozycji
  17. def zresetuj_pozycje(self):
  18. self.wspolrzedne = vec(SZEROKOSC_EKRANU/2, WYSOKOSC_EKRANU-140)
  19. self.rect = self.obraz.get_rect(center=self.wspolrzedne)
  20. self.wektor = vec(0, -10)
  21. self.kat_nachylenia = random.randrange(-30, 30)
  22. self.wektor.rotate_ip(self.kat_nachylenia)
  23. self.przegrana = False
  24.  
  25. #aktualizacja
  26. def aktualizuj(self, platforma):
  27. self.wspolrzedne += self.wektor
  28. self.rect.center = self.wspolrzedne
  29. self.sprawdz_kolizje(platforma)
  30.  
  31. #sprawdz wszystkie mozliwe kolizje
  32. def sprawdz_kolizje(self, platforma):
  33. #krawędzie ekranu
  34. if self.rect.x <= 0:
  35. self.wektor.x *= -1
  36. if self.rect.right >= SZEROKOSC_EKRANU:
  37. self.wektor.x *= -1
  38. if self.rect.top <= 0:
  39. self.wektor.y *= -1
  40. if self.rect.bottom >= WYSOKOSC_EKRANU:
  41. self.przegrana = True
  42.  
  43. #kolizja z platformą
  44. if self.rect.colliderect(platforma.rect):
  45. self.wektor.y *= -1
  46. self.wektor.x += platforma.porusza_sie*5
  47. if self.wektor.x < -10: self.wektor.x = -10
  48. if self.wektor.x > 10: self.wektor.x = 10
Add Comment
Please, Sign In to add comment