import pygame
import random
import os
class Play(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = player_img
self.image.set_colorkey(BLACK)
self.rect = self.image.get_rect()
self.rect.center = (WIDTH / 2, HEIGHT / 2)
def update(self):
self.rect.x += 5
if self.rect.left > WIDTH:
self.rect.right = 0
player = Play()
Traceback (most recent call last):
File "C:\Users\sobol\OneDrive\Рабочий стол\python\game\pl.py", line 20, in <module>
player = Play()
File "C:\Users\sobol\OneDrive\Рабочий стол\python\game\pl.py", line 10, in __init__
self.image = player_img
NameError: name 'player_img' is not defined
class Play(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = player_img
self.image.set_colorkey(BLACK)
self.rect = self.image.get_rect()
self.rect.center = (WIDTH / 2, HEIGHT / 2)
def update(self):
self.rect.x += 5
if self.rect.left > WIDTH:
self.rect.right = 0
player = Play()
import pygame
import random
import os
from player import *
# настройка папки ассетов
game_folder = os.path.dirname(__file__)
img_folder = os.path.join(game_folder, 'img')
WIDTH = 800
HEIGHT = 650
FPS = 30
# Задаем цвета
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Создаем игру и окно
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()
all_sprites = pygame.sprite.Group()
all_sprites.add(player)
player_img = pygame.image.load(os.path.join(img_folder, 'p1_jump.png')).convert()
# Цикл игры
running = True
while running:
# Держим цикл на правильной скорости
clock.tick(FPS)
# Ввод процесса (события)
for event in pygame.event.get():
# check for closing window
if event.type == pygame.QUIT:
running = False
# Обновление
all_sprites.update()
# Рендеринг
screen.fill(BLACK)
all_sprites.draw(screen)
# После отрисовки всего, переворачиваем экран
pygame.display.flip()
pygame.quit()
import pygame
import random
import os
player = Player()
class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = player_img
self.image.set_colorkey(BLACK)
self.rect = self.image.get_rect()
self.rect.center = (WIDTH / 2, HEIGHT / 2)
def update(self):
self.rect.x += 5
if self.rect.left > WIDTH:
self.rect.right = 0
Traceback (most recent call last):
File "C:\Users\sobol\OneDrive\Рабочий стол\python\game\main.py", line 5, in <module>
from player import *
File "C:\Users\sobol\OneDrive\Рабочий стол\python\game\player.py", line 5, in <module>
player = Player()
NameError: name 'Player' is not defined
import pygame
import random
import os
# настройка папки ассетов
game_folder = os.getcwd()
img_folder = os.path.join(game_folder, 'img')
WIDTH = 800
HEIGHT = 650
FPS = 30
# Задаем цвета
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Создаем игру и окно
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()
all_sprites = pygame.sprite.Group()
player = Player()
all_sprites.add(player)
player_img = pygame.image.load(os.path.join(img_folder, 'p1_jump.png')).convert()
# Цикл игры
running = True
while running:
# Держим цикл на правильной скорости
clock.tick(FPS)
# Ввод процесса (события)
for event in pygame.event.get():
# check for closing window
if event.type == pygame.QUIT:
running = False
class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = player_img
self.image.set_colorkey(BLACK)
self.rect = self.image.get_rect()
self.rect.center = (WIDTH / 2, HEIGHT / 2)
def update(self):
self.rect.x += 5
if self.rect.left > WIDTH:
self.rect.right = 0
# Обновление
all_sprites.update()
# Рендеринг
screen.fill(BLACK)
all_sprites.draw(screen)
# После отрисовки всего, переворачиваем экран
pygame.display.flip()
pygame.quit()
Traceback (most recent call last):
File "C:\Users\sobol\OneDrive\Рабочий стол\python\game\main.py", line 33, in <module>
player = Player()
NameError: name 'Player' is not defined
[Finished in 1.1s]
Traceback (most recent call last):
File "C:\Users\sobol\OneDrive\Рабочий стол\python\game\main.py", line 45, in <module>
player = Player()
File "C:\Users\sobol\OneDrive\Рабочий стол\python\game\main.py", line 26, in __init__
self.image = player_img
NameError: name 'player_img' is not defined
[Finished in 8.1s]