我想在屏幕上的草上画一个特定的水平[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窗口只是没有显示污垢咆哮。你知道吗
污垢不显示,因为内环的范围错误,并且污垢瓷砖的y位置计算不正确。你知道吗
计算污垢开始的y水平面和必须被污垢覆盖的区域的高度:
在吸引污垢的嵌套循环中使用
dirt_start_height
和all_dirt_height
:在“污垢绘制循环”中,您看到的是
grass.get_height()
我想你是想把
dirt.get_height
放在那里。你知道吗相关问题 更多 >
编程相关推荐