微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在pygame中绘制后如何删除形状?

如何解决在pygame中绘制后如何删除形状?

我正在 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 举报,一经查实,本站将立刻删除。