Я пытаюсь создать игру для проекта на основе существующей игры под названием «Самая сложная игра в мире», у меня есть движение, стартовое меню и все такое, но я не знаю, как создать уровень, который выглядит что-то отдаленно похожее на мое вдохновение, тайловые карты используются для создания уровня, но я понятия не имею, как создать тайловую карту, которая бы хорошо выглядела или даже соответствовала моим потребностям. Любая помощь по оптимизации моего кода тоже была бы полезна, так как я уверен, что нарушил многие соглашения.
Я пытался использовать программу под названием «Tiled» для создания карты тайлов, но не могу понять Узнайте, как его правильно использовать.
Весь мой основной блок кода приведен ниже, если он необходим. Я знаю, это беспорядок
import pygame
import button
from players import Player
from pytmx.util_pygame import load_pygame
pygame.init()
#**********************************VARIABLES**********************************
# screen size variables
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 800
clock = pygame.time.Clock()
# defining screen size/name
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Start Menu")
# for player
player = Player(250, 250, 3, (0, 0, 255), 20, screen)
# game states
game_paused = False
menu_state = "main"
# text font
font = pygame.font.SysFont("arialblack", 40)
font2 = pygame.font.SysFont("arialblack", 10)
font_header = pygame.font.SysFont("arialblack", 60)
# text colour
TEXT_COL = (255, 255, 255)
TEXT_COL2 = (0, 0, 0)
# loading / setting buttons
play_btn = pygame.image.load("C:/Users/leeun/OneDrive/Desktop/Python/NEA/Iteration1/images/button_play.png").convert_alpha()
quit_btn = pygame.image.load("C:/Users/leeun/OneDrive/Desktop/Python/NEA/Iteration1/images/button_quit.png").convert_alpha()
leaderboard_btn = pygame.image.load("C:/Users/leeun/OneDrive/Desktop/Python/NEA/Iteration1/images/button_leaderboard.png").convert_alpha()
back_btn = pygame.image.load("C:/Users/leeun/OneDrive/Desktop/Python/NEA/Iteration1/images/button_back.png").convert_alpha()
leaderboard_btn = button.Button(360, 390, leaderboard_btn, 1)
quit_btn = button.Button(400, 500, quit_btn, 1)
play_btn = button.Button(400, 275, play_btn, 1)
back_btn = button.Button(400, 525, back_btn, 1)
# function for displaying text
def draw_text(text, font, text_col, x, y):
img = font.render(text, True, text_col)
screen.blit(img, (x, y))
# runs the game
run = True
game_menu = True
#**********************************MAIN LOOP**********************************
while run:
# fills the screen in with blue
screen.fill((79, 101, 176))
# main screen
if game_menu == True:
# check game state
if menu_state == "main":
# display the game name
draw_text("Worlds Easiest Game", font_header, TEXT_COL, 150, 90)
# draw main menu buttons
if play_btn.draw(screen):
game_menu = False
if leaderboard_btn.draw(screen):
menu_state = "leaderboard"
if quit_btn.draw(screen):
run = False
# check if leaderboard is open
if menu_state == "leaderboard":
# display the leaderboard
draw_text("Leaderboard display", font, TEXT_COL, 160, 250)
# return back to main menu
if back_btn.draw(screen):
menu_state = "main"
# the main game screen, this will include the player, level objects
else:
# sets the game title to Main Game
pygame.display.set_caption("Main Game")
# makes the screen white
screen.fill((255, 255, 255))
# esc to pause top left
draw_text("Press ESC to pause", font2, TEXT_COL2, 25, 25)
# renders the player
player.render()
# movement
key_pressed = pygame.key.get_pressed()
if key_pressed[pygame.K_w]:
player.up()
if key_pressed[pygame.K_a]:
player.left()
if key_pressed[pygame.K_s]:
player.down()
if key_pressed[pygame.K_d]:
player.right()
# border
if player.x < player.size:
player.x = player.size
if player.x > 1000 - player.size-20:
player.x = 1000 - player.size-20
if player.y < player.size:
player.y = player.size
if player.y > 800 - player.size-20:
player.y = 800 - player.size-20
# main loop
for event in pygame.event.get():
# checks if ESC has been pressed to go to main menu
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
game_menu = True
# quits the game
if event.type == pygame.QUIT:
run = False
clock.tick(60)
pygame.display.flip()
pygame.quit()
Подробнее здесь: https://stackoverflow.com/questions/792 ... the-player
Создайте уровень и движущиеся объекты, которые убивают игрока [дубликат] ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение