Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- #Настройки окна
- WIDTH = 500
- HEIGHT = 500
- FPS = 60
- #Настройка цвета
- BLACK = (0,0,0)
- WHITE = (255,255,255)
- RED = (255,0,0)
- BLUE = (0,0,255)
- #Инициализация
- pygame.init()
- screen = pygame.display.set_mode((WIDTH,HEIGHT))
- clock = pygame.time.Clock()
- #Время
- lastTime = 0
- currentTime = 0
- # Персонаж
- x = WIDTH // 2
- y = HEIGHT // 2
- hero = pygame.Rect(x, y, 60, 50)
- heroImg = pygame.image.load('razorinv.png')
- # Пули
- # Ширина пули для Rect
- wb = 2
- # Высота пули для Rect
- hb = 5
- # Изображение пули
- bulletImg = pygame.image.load("bullet.png")
- # Список, где будут хранится пули ввиде объектов Rect
- bullets = []
- # Переменная, которая будет меняться, когда игрок будет нажмить пробел
- isShot = False
- moving = ''
- running = True
- while running:
- screen.fill(BLACK)
- for i in pygame.event.get():
- if i.type == pygame.QUIT:
- running = False
- if i.type == pygame.KEYDOWN:
- if i.key == pygame.K_LEFT:
- moving = 'LEFT'
- if i.key == pygame.K_RIGHT:
- moving = 'RIGHT'
- if i.key == pygame.K_UP:
- moving = 'UP'
- if i.key == pygame.K_DOWN:
- moving = 'DOWN'
- if i.key == pygame.K_DOWN:
- isShot = True
- if i.type == pygame.KEYUP:
- if i.key == pygame.K_LEFT or i.key == pygame.K_RIGHT or i.key == pygame.K_UP or i.key == pygame.K_DOWN:
- moving = 'STOP'
- # Передвижение персонажа
- if moving == 'LEFT' and hero.left > 0:
- hero.left -= 5
- if moving == 'RIGHT' and hero.right < WIDTH:
- hero.left += 5
- if moving == 'UP' and hero.top > 100:
- hero.top -= 5
- if moving == 'DOWN' and hero.bottom < HEIGHT:
- hero.top += 5
- if isShot:
- bullets.append(pygame.Rect(hero.left + 33, hero.top + 5, wb, hb))
- #Отрисовка персонажа
- screen.blit(heroImg, (hero.left, hero.top))
- pygame.display.update()
- clock.tick(FPS)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement