Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from random import randrange, choice
- WIDTH = 600
- HEIGHT = 400
- pygame.init()
- win = pygame.display.set_mode((WIDTH, HEIGHT))
- pygame.display.set_caption('Game Developer(clown)')
- walkLeft = [pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/left1.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/left2.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/left1.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/left0.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/left4.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/left3.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/left4.png')]
- walkRight = [pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/right1.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/right2.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/right1.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/right0.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/right4.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/right3.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/right4.png')]
- walkUp = [pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/up_1.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/up_2.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/up_1.png'),
- pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/up_3.png')] # TODO
- playerStand = pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/stay.png')
- bg = pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/bg.jpg')
- coin = pygame.image.load('C:/Users/User/Desktop/PYTHON/pygame/dudar/sprites/coin.png')
- clock = pygame.time.Clock()
- width = 60
- height = 71
- x = randrange(10, WIDTH-10-width)
- y = HEIGHT - 5 - height
- speed = 5
- colors = [(122, 28, 255), (124, 255, 207), (127, 0, 0), (255, 106, 0), (35, 255, 15)]
- left, right = False, False
- up, down = False, False
- animCount = 0
- lastMove = 'left'
- class Bullet:
- """ create new bullet for attack """
- def __init__(self, x, y, R, facing, color=choice(colors)):
- self.x = x
- self.y = y
- self.R = R
- self.facing = facing
- self.color = color
- self.speed = 8 * self.facing
- def draw(self, win):
- pygame.draw.circle(win, self.color, (self.x, self.y), self.R)
- coinX = randrange(5, WIDTH-25)
- coinY = randrange(36, HEIGHT-100)
- def draw_on_win():
- global animCount
- win.blit(bg, (0, 0))
- win.blit(coin, (coinX, coinY))
- if animCount+1 >= 56:
- animCount = 0
- if left:
- win.blit(walkLeft[animCount//8], (x, y))
- animCount += 2
- elif right:
- win.blit(walkRight[animCount//8], (x, y))
- animCount += 2
- elif up:
- win.blit(walkUp[animCount//14], (x, y))
- animCount += 2
- elif down:
- win.blit(walkUp[animCount//14], (x, y))
- animCount += 2
- else:
- win.blit(playerStand, (x, y))
- # draw bullet
- for bullet in bullets:
- bullet.draw(win)
- pygame.display.update()
- bullets = []
- run = True
- while run:
- clock.tick(30)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- for bullet in bullets:
- if (bullet.x - bullet.R) < 600 and (bullet.x + bullet.R) > 0:
- bullet.x += bullet.speed
- else:
- bullets.remove(bullet)
- ''' Тут создаю совпадение монетки с пулькой'''
- if bullet.x+5 >= coinX and bullet.x <= coinX+25:
- if bullet.y+5 >= coinY and bullet.y <= coinY+25:
- coinX = randrange(5, WIDTH-25)
- coinY = randrange(36, HEIGHT-36)
- if event.type == pygame.MOUSEBUTTONDOWN:
- if event.button == 1:
- if lastMove == 'right':
- facing = 1
- elif lastMove == 'left': # TODO: lastMove for Y
- facing = -1
- if len(bullets) < 10:
- bullets.append(Bullet(round(x + width//2), round(y + height//2),
- 5, facing))
- keys = pygame.key.get_pressed()
- if (keys[pygame.K_LEFT] or keys[pygame.K_a]) and x > speed:
- x -= speed
- right, up = False, False
- left = True
- lastMove = 'left'
- elif (keys[pygame.K_RIGHT] or keys[pygame.K_d]) and x+speed+width+13 < WIDTH:
- x += speed
- left, up = False, False
- right = True
- lastMove = 'right'
- elif (keys[pygame.K_UP] or keys[pygame.K_w]) and y > speed:
- y -= speed//1.5
- left, right = False, False
- up = True
- elif (keys[pygame.K_DOWN] or keys[pygame.K_s]) and y+speed+height < HEIGHT:
- y += speed//1.5
- left, right = False, False
- up = True
- else:
- left, right, up, down = False, False, False, False
- animCount = 0
- win.fill((0, 0, 0))
- draw_on_win()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement