问题描述
我正在 pygame 中制作游戏。我使用“激光”作为玩家射击的射弹。我目前使用一个系统,当某个条件成立时,我将激光的颜色更改为红色。但是,这不适用于 collidirect。当“激光”与实体发生碰撞时,Collidirect 会立即“激活”。 激光是在我代码的最后一行绘制的。
代码如下:
import pygame
import sys
# Creating a loop to keep program running
while True:
# --- Event Processing and controls
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
spaceship_x_change = 10
elif event.key == pygame.K_LEFT:
spaceship_x_change = -10
elif event.key == pygame.K_UP:
red = (255,0)
elif event.type == pygame.KEYUP:
red = (0,0)
spaceship_x_change = 0
spaceship_x += spaceship_x_change
# Preventing the ship from going off the screen
if spaceship_x > display_width - 140:
spaceship_x -= 10
if spaceship_x < 1:
spaceship_x += 10
pygame.draw.rect(game_display,red,[spaceship_x + 69,70,4,310])
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)