Advertisement
Guest User

Untitled

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