Advertisement
Guest User

collision problem

a guest
Mar 27th, 2025
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. import pygame
  2. screen = pygame.display.set_mode((810,810))
  3. (width,height) = (359,255)
  4. (wallwidth,wallheight) = 50,50
  5. x = 0
  6. y = 0
  7. wx = 700
  8. wy = 700
  9. color = (0,0,0)
  10. pygame.display.set_caption( 'da biggest BALLER!waw' )
  11. dontfaqwiththeshaq = pygame.image.load('shaq_fu.webp').convert()
  12. shaqcraq = pygame.image.load('the biggest bird.jpg').convert()
  13.  
  14. class Sprite(pygame.sprite.Sprite):
  15.  
  16. def __init__(self,image,x,y):
  17. super().__init__()
  18. self.image = pygame.Surface([width,height])
  19. self.x = x
  20. self.y = y
  21. pygame.draw.rect(self.image, color, pygame.Rect(0, 0, width,height))
  22. self.rect = self.image.get_rect()
  23. def render(self,image):
  24. pygame.draw.rect(screen,color,(x,y,width,height))
  25.  
  26.  
  27.  
  28. object_ = Sprite(dontfaqwiththeshaq, x, y)
  29. object_.rect.x = x
  30. object_.rect.y = y
  31. all_sprites_list = pygame.sprite.Group()
  32. all_sprites_list.add(object_)
  33.  
  34. class Wall(pygame.sprite.Sprite):
  35. def __init__(self,wimage,wx,wy):
  36. super().__init__()
  37. self.wimage = pygame.Surface([wallwidth,wallheight])
  38. self.wx = wx
  39. self.wy = wy
  40. pygame.draw.rect(self.wimage,color,pygame.Rect(0,0,wallwidth,wallheight))
  41. self.rect = self.wimage.get_rect()
  42.  
  43. def render(self,wimage):
  44. pygame.draw.rect(screen,color,(wx,wy,wallwidth,wallheight))
  45.  
  46. wallblock = Wall(shaqcraq,wx,wy)
  47. wallblock.rect.x = wx
  48. wallblock.rect.y = wy
  49. all_sprites_list.add(wallblock)
  50.  
  51. wrect = wallblock.rect
  52. rect = object_.rect
  53. collidelist = pygame.sprite.spritecollide(object_,all_sprites_list,False)
  54.  
  55. running = True
  56. delta_time = 0.1
  57. x += 50 * delta_time
  58. y += 50 * delta_time
  59. clock = pygame.time.Clock()
  60. while running:
  61.  
  62. all_sprites_list.update()
  63. screen.blit(shaqcraq,(0,0))
  64. object_.render(screen)
  65. wallblock.render(screen)
  66. screen.blit(dontfaqwiththeshaq,(x,y))
  67. keys = pygame.key.get_pressed()
  68. if keys[pygame.K_LEFT]:
  69. x -=30
  70. if keys[pygame.K_RIGHT]:
  71. x +=30
  72. if keys[pygame.K_DOWN]:
  73. y +=30
  74. if keys[pygame.K_UP]:
  75. y -=30
  76. for sprite in collidelist:
  77. color = (0,255,255)
  78.  
  79. for event in pygame.event.get():
  80. if event.type == pygame.QUIT:
  81. running = False
  82. pygame.display.flip()
  83. delta_time = clock.tick(60) / 1000
  84. delta_time = max(0.001, min(0.1, delta_time))
  85.  
  86. pygame.quit()
  87.  
  88.  
  89.  
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement