pygame 文字输入交互_如何与Pygame中的列表项交互?

我开始制作一个游戏,结果我遇到了一个小问题:

*当按下“空格键”时,红色方块会随机显示

问题

我怎样才能把红色方块变成障碍?在

我是个彻头彻尾的乞丐,我很抱歉问这么简单的问题。。:/

代码可能会给你一个想法:import pygame, sys

from random import randint

from pygame.locals import*

"List the Stores the Squares"

red_square_list = []

gameDisplay_width = 800

gameDisplay_height = 600

pygame.init()

gameDisplay = pygame.display.set_mode((gameDisplay_width, gameDisplay_height))

pygame.display.set_caption("Square-it")

clock = pygame.time.Clock()

red_color = pygame.Color("red")

"White Square"

white_x = 400

white_y = 300

white_width = 10

white_height = 10

white_color = pygame.Color("white")

white = pygame.Rect(white_x, white_y, white_width, white_height)

"Red Squares"

def create_red_square(x, y):

red_width = 10

red_height = 10

red = pygame.Rect(x, y, red_width, red_height)

return red

while True:

clock.tick(60)

gameDisplay.fill((0, 20, 5))

gameDisplay.fill(white_color, white)

for event in pygame.event.get():

if event.type == pygame.QUIT:

sys.exit()

for each in red_square_list:

gameDisplay.fill(red_color, each)

pygame.display.update()

'''White Square Movement'''

keys = pygame.key.get_pressed()

if keys[K_LEFT]:

white.left = white.left - 4

if keys[K_RIGHT]:

white.right = white.right + 4

if keys[K_UP]:

white.top = white.top - 4

if keys[K_DOWN]:

white.bottom = white.bottom + 4

"when Space key Pressed, Spawns red Squares"

if keys[K_SPACE]:

x = randint(0, gameDisplay_width)

y = randint(0, gameDisplay_height)

red_square_list.append(create_red_square(x, y))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值