Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. import pygame
  2. pygame.init()
  3.  
  4. #Graphics
  5. win = pygame.display.set_mode((1800, 700))
  6. pygame.display.set_caption("Jotaro's revenge")
  7. bg = pygame.image.load('bg.png')
  8. char = pygame.image.load('ora.png')
  9.  
  10. #Sound
  11. music = pygame.mixer.music.load('jotaro.mp3')
  12. pygame.mixer.music.play(-1)
  13. pygame.mixer.music.set_volume(0.2)
  14.  
  15. class player(object):
  16. def __init__(self, x, y, width, height):
  17. self.x = x
  18. self.y = y
  19. self.width = width
  20. self.height = height
  21. self.vel = 15
  22. self.hitbox = (137, self.y, self.width, self.height)
  23.  
  24. def draw(self, win):
  25. win.blit(char, (self.x,self.y))
  26. self.hitbox = (137, self.y, self.width, self.height)
  27. pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  28.  
  29. def hit(self):
  30. print('hit')
  31.  
  32. class textbox(object):
  33. def __init__(self,x,y,width,height):
  34. self.x = x
  35. self.y = y
  36. self.width = width
  37. self.height = height
  38. self.vel = 10
  39. self.hitbox = (self.x, self.y, self.width, self.height)
  40.  
  41. def draw(self, win):
  42. self.hitbox = (self.x, self.y, self.width, self.height)
  43. pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  44.  
  45. def drawgamewindow():
  46. win.blit(bg,(0,0))
  47. article1.draw(win)
  48. article2.draw(win)
  49. article3.draw(win)
  50. article4.draw(win)
  51. man.draw(win)
  52. pygame.display.update()
  53.  
  54. #mainloop
  55. run = True
  56. article1 = textbox(2000, 100, 100, 50)
  57. article2 = textbox(2000, 250, 100, 50)
  58. article3 = textbox(2000, 400, 100, 50)
  59. article4 = textbox(2000, 550, 100, 50)
  60. man = player(100, 100, 70, 125)
  61. while run:
  62. pygame.time.delay(20)
  63.  
  64. #player movement
  65. for event in pygame.event.get():
  66. if event.type == pygame.QUIT:
  67. run = False
  68.  
  69. #artiklite liikumine
  70. article1.x -= article1.vel
  71. article2.x -= article2.vel
  72. article3.x -= article2.vel
  73. article4.x -= article2.vel
  74.  
  75. if article1.y - article1.height < man.hitbox[1] + man.hitbox[3] and article1.y + article1.height > man.hitbox[1]:
  76. if article1.x + article1.width > man.hitbox[0] and article1.x < man.hitbox[0] + man.hitbox[2]:
  77. man.hit()
  78. print('1')
  79.  
  80. if article2.y - article2.height < man.hitbox[1] + man.hitbox[3] and article2.y + article2.height > man.hitbox[1]:
  81. if article2.x + article2.width > man.hitbox[0] and article2.x < man.hitbox[0] + man.hitbox[2]:
  82. man.hit()
  83. print('2')
  84.  
  85. if article3.y - article3.height < man.hitbox[1] + man.hitbox[3] and article3.y + article3.height > man.hitbox[1]:
  86. if article3.x + article3.width > man.hitbox[0] and article3.x < man.hitbox[0] + man.hitbox[2]:
  87. man.hit()
  88. print('3')
  89.  
  90. if article4.y - article4.height < man.hitbox[1] + man.hitbox[3] and article4.y + article4.height > man.hitbox[1]:
  91. if article4.x + article4.width > man.hitbox[0] and article4.x < man.hitbox[0] + man.hitbox[2]:
  92. man.hit()
  93. print('4')
  94.  
  95.  
  96. keys = pygame.key.get_pressed()
  97.  
  98. if keys[pygame.K_w] and man.y > man.vel :
  99. man.y -= man.vel
  100.  
  101. if keys[pygame.K_s] and man.y < 700 - man.height - man.vel:
  102. man.y += man.vel
  103.  
  104.  
  105. drawgamewindow()
  106.  
  107.  
  108.  
  109.  
  110. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement