我想在特定的层级[y]上画出草,下面只显示土地。这几乎是我所有的代码,只删除了无关的内容。
import pygame
from pygame import *
pygame.init()
width, height = 640, 480
screen = pygame.display.set_mode((width, height))
height_of_grass = 150
run = True
speed_of_player = 1
player = pygame.image.load("images/steve.png")
grass = pygame.image.load("images/grass_block.jpg")
dirt = pygame.image.load("images/dirt_block.jpg")
sky = pygame.image.load("images/sky.png")
clouds = pygame.image.load("images/cloud.png")
oak_wood_log = pygame.image.load("images/oak_wood_log.png")
oak_leaves = pygame.image.load("images/oak_leaves.png")
keys = [False, False, False, False]
player_position = [100, 100]
while run:
screen.fill((50, 168, 158))
screen.blit(player, player_position)
for x in range(int(width/grass.get_width()) + 1):
screen.blit(grass, (x*grass.get_width(), height_of_grass))
x = 0
for x in range(int(width/dirt.get_width()) + 1):
for y in range(height_of_grass, int(height / grass.get_height()) + 1):
screen.blit(dirt, (x*dirt.get_width, y*dirt.get_height))
pygame.display.flip()
for event in pygame.event.get():
if event == pygame.QUIT:
run = False
if player_position[0] < -16 or player_position[0] > (width + 16) or player_position[1] < -16 or player_position[1] > (height + 16):
print("You´ve broke the game! Congratilations")
exit(-1)
这只是我遇到问题的部分代码。我的Pygame窗口没有显示下面的泥土。
if event.type == pygame.QUIT
而不是if event == pygame.QUIT
。 - Rabbid76