关于不互动的重影问题,大佬指点一下

我认为问题出现在这里:

import sys,random,time,pygame,math
from pygame.locals import *

def print_text(font,x,y,text,color=(100,225,225)):
    imgText = font.render(text,True,color)
    screen.blit(imgText,(x,y))

pygame.init()
screen = pygame.display.set_mode((1600,850))
pygame.display.set_caption('接球')
font1 = pygame.font.Font(None,24)
pygame.mouse.set_visible(False)

white = 255,255,255
red = 220,50,50
yellow = 230,230,230
black = 0,0,0

lives = 5
score = 0
game_over = True
mouse_x = mouse_y = 0
pos_x = 300
pos_y = 460
bomb_x = random.randint(0,1600)
bomb_y = 850
vel_y = 10
clock = pygame.time.Clock()


while True:
    clock.tick(40)
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
        elif event.type == MOUSEMOTION:
            mouse_x,mouse_y = event.pos
            move_x,move_y = event.rel
        elif event.type == MOUSEBUTTONUP:
            if game_over:
                game_over = False
                lives = 5
                score = 0


        keys = pygame.key.get_pressed()
        if keys[K_ESCAPE]:
            sys.exit()

        screen.fill((0,0,100))

    else:

        bomb_y += vel_y


        if bomb_y < 850:
            bomb_x = random.randint(0,850)
            bomb_y = -50
            lives -= 1
        if lives == 0:
            game_over = True
        elif bomb_y >pos_y:
            if bomb_x >pos_x and bomb_x < pos_x +120:
                score += 10
                bomb_x = random.randint(0,1600)
                bomb_y = -20

    pygame.draw.circle(screen,black,(```python
import sys,random,time,pygame,math
from pygame.locals import *

def print_text(font,x,y,text,color=(100,225,225)):
    imgText = font.render(text,True,color)
    screen.blit(imgText,(x,y))

pygame.init()
screen = pygame.display.set_mode((600,500))
pygame.display.set_caption('接球')
font1 = pygame.font.Font(None,24)
pygame.mouse.set_visible(False)

white = 255,255,255
red = 220,50,50
yellow = 230,230,230
black = 0,0,0

lives = 5
score = 0
game_over = True
mouse_x = mouse_y = 0
pos_x = 300
pos_y = 460
bomb_x = random.randint(0,1600)
bomb_y = 850
vel_y = 10
clock = pygame.time.Clock()


while True:
    clock.tick(40)
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
        elif event.type == MOUSEMOTION:
            mouse_x,mouse_y = event.pos
            move_x,move_y = event.rel
        elif event.type == MOUSEBUTTONUP:
            if game_over:
                game_over = False
                lives = 5
                score = 0


        keys = pygame.key.get_pressed()
        if keys[K_ESCAPE]:
            sys.exit()

        screen.fill((0,0,100))

    else:

        bomb_y += vel_y


        if bomb_y < 500:
            bomb_x = random.randint(0,600)
            bomb_y = -50
            lives -= 1
        if lives == 0:
            game_over = True
        elif bomb_y >pos_y:
            if bomb_x >pos_x and bomb_x < pos_x +120:
                score += 10
                bomb_x = random.randint(0,1600)
                bomb_y = -20

    pygame.draw.circle(screen,black,(bomb_x-4,int(bomb_y)-4),30,0)
    pygame.draw.circle(screen,yellow,(bomb_x,int(bomb_y)),30,0)

    pos_x = mouse_x
    if pos_x <0:
        pos_x =0
    elif pos_x > 1600:
        pos_x = 1600
    pygame.draw.rect(screen,black,(pos_x-4,pos_y-4,120,40),0)
    pygame.draw.rect(screen,red,(pos_x,pos_y,120,40),0)

    print_text(font1,0,0,'lives:'+str(lives))
    print_text(font1,500,0,'score:'+str(score))
    pygame.display.update()

    bomb_x-4,int(bomb_y)-4),30,0)
    pygame.draw.circle(screen,yellow,(bomb_x,int(bomb_y)),30,0)

    pos_x = mouse_x
    if pos_x <0:
        pos_x =0
    elif pos_x > 1600:
        pos_x = 1600
    pygame.draw.rect(screen,black,(pos_x-4,pos_y-4,120,40),0)
    pygame.draw.rect(screen,red,(pos_x,pos_y,120,40),0)

    print_text(font1,0,0,'lives:'+str(lives))
    print_text(font1,500,0,'score:'+str(score))
    pygame.display.update()
讨论数量: 1

小白路过 :joy: :joy:

6天前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!