Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- WIDTH = 800
- HEIGHT = 600
- window = pygame.display.set_mode((WIDTH,HEIGHT))
- pygame.display.set_caption("Why U NO WORK?")
- class throw_coin(object):
- def __init__(self, color, x, y, radius):
- self.color = color
- self.x = x
- self.y = y
- self.radius = radius
- self.hitbox = (self.x-15, self.y-15, self.radius*2, self.radius*2)
- self.vel = 8
- def draw(self, win):
- self.x += self.vel
- pygame.draw.circle(win, self.color, (self.x, self.y), self.radius)
- #update hitbox if coin moves
- self.hitbox = (self.x-15, self.y-15, self.radius*2, self.radius*2)
- # draw the hitbox remove later after debug
- #pygame.draw.rect(win, (white), self.hitbox, 2)
- class player(object):
- def __init__(self, x, y, width, height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.vel = 10
- self.hitbox = (self.x, self.y, 64, 64)
- self.coins = []
- def draw(self, win):
- pygame.draw.rect(window, (255,0,0), [self.x, self.y, self.width,
- self.height])
- # update hitbox if player moves
- self.hitbox = (self.x, self.y, 64, 64)
- # draw the hitbox remove later after debug
- #pygame.draw.rect(win, (white), self.hitbox, 2)
- def move(self):
- # create a variable that is assigned to any keypress
- keys = pygame.key.get_pressed()
- if keys[pygame.K_a] and self.x > self.vel:
- self.x -= self.vel
- if keys[pygame.K_d] and self.x < WIDTH - self.width - self.vel:
- self.x += self.vel
- if keys[pygame.K_w] and self.y > self.vel:
- self.y -= self.vel
- if keys[pygame.K_s] and self.y < HEIGHT - self.height - self.vel:
- self.y += self.vel
- if keys[pygame.K_g]:
- if len(self.coins) < 100:
- self.coins.append(throw_coin((0,255,0), 500, 300, 15))
- for gold in self.coins:
- gold.draw(window)
- user = player(30, 300-32, 64,64)
- run = True
- while run:
- pygame.time.delay(100)
- # exit the program
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- window.fill((0,0,0))
- user.draw(window)
- user.move()
- pygame.display.update()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement