Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import pygame
  2. pygame.init()
  3.  
  4. WIDTH = 800
  5. HEIGHT = 600
  6.  
  7. window = pygame.display.set_mode((WIDTH,HEIGHT))
  8. pygame.display.set_caption("Why U NO WORK?")
  9.  
  10. class throw_coin(object):
  11.  
  12. def __init__(self, color, x, y, radius):
  13. self.color = color
  14. self.x = x
  15. self.y = y
  16. self.radius = radius
  17. self.hitbox = (self.x-15, self.y-15, self.radius*2, self.radius*2)
  18. self.vel = 8
  19.  
  20. def draw(self, win):
  21. self.x += self.vel
  22. pygame.draw.circle(win, self.color, (self.x, self.y), self.radius)
  23. #update hitbox if coin moves
  24. self.hitbox = (self.x-15, self.y-15, self.radius*2, self.radius*2)
  25. # draw the hitbox remove later after debug
  26. #pygame.draw.rect(win, (white), self.hitbox, 2)
  27.  
  28. class player(object):
  29.  
  30. def __init__(self, x, y, width, height):
  31. self.x = x
  32. self.y = y
  33. self.width = width
  34. self.height = height
  35. self.vel = 10
  36. self.hitbox = (self.x, self.y, 64, 64)
  37. self.coins = []
  38.  
  39. def draw(self, win):
  40. pygame.draw.rect(window, (255,0,0), [self.x, self.y, self.width,
  41. self.height])
  42. # update hitbox if player moves
  43. self.hitbox = (self.x, self.y, 64, 64)
  44. # draw the hitbox remove later after debug
  45. #pygame.draw.rect(win, (white), self.hitbox, 2)
  46.  
  47. def move(self):
  48.  
  49. # create a variable that is assigned to any keypress
  50. keys = pygame.key.get_pressed()
  51. if keys[pygame.K_a] and self.x > self.vel:
  52. self.x -= self.vel
  53. if keys[pygame.K_d] and self.x < WIDTH - self.width - self.vel:
  54. self.x += self.vel
  55. if keys[pygame.K_w] and self.y > self.vel:
  56. self.y -= self.vel
  57. if keys[pygame.K_s] and self.y < HEIGHT - self.height - self.vel:
  58. self.y += self.vel
  59. if keys[pygame.K_g]:
  60. if len(self.coins) < 100:
  61. self.coins.append(throw_coin((0,255,0), 500, 300, 15))
  62. for gold in self.coins:
  63. gold.draw(window)
  64.  
  65. user = player(30, 300-32, 64,64)
  66. run = True
  67. while run:
  68. pygame.time.delay(100)
  69. # exit the program
  70. for event in pygame.event.get():
  71. if event.type == pygame.QUIT:
  72. run = False
  73. window.fill((0,0,0))
  74. user.draw(window)
  75. user.move()
  76. pygame.display.update()
  77.  
  78. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement