陈尚涵 发表于 2020-4-4 14:12:07

即是展示又是询问

我刚刚用pygame做了个超简单超简单的打砖块游戏(一共才40多行),可是这里面的球与砖块的碰撞检测我还是不是太清楚。目前暂时用了X,Y分别进行匹配的方法。可是有时候侦测的有点慢,显现出我的球是有白色背景的(无奈),甚至少时候会穿过球,减一分...求大神帮助。代码如下(test1是砖块,test2是球,自己找素材):
"""用pygame开发一款打砖块的游戏"""
# 初始化
import pygame, sys, random, pygame.freetype

# 开始运行
if __name__ == "__main__":
    pygame.init()
    screen = pygame.display.set_mode((600, 400))
    test1 = pygame.image.load("test1.png")
    test2 = pygame.image.load("test2.png")
    t1_location = (190, 280)
    t2_location = (240, 25)
    speed = speed = random.randint(0, 3) * 2 + -3
    clock = pygame.time.Clock()
    file = pygame.freetype.Font("C://windows//Fonts//msyh.ttc", 36)
    score = 0
    note = file.render_to(screen, (260, 30), "Your score is:" + str(score), fgcolor=pygame.Color("black"), size=36)
    while True:
      t1_location = (pygame.mouse.get_pos(), t1_location)
      if not t2_location < 0 and not t2_location > 580:
            t2_location = (t2_location+speed, t2_location+1)
      else:
            speed = -speed
            t2_location = (t2_location+speed, t2_location+1)
      if t2_location >= 260:
            if t2_location >= 390:
                t2_location = (t1_location, 25)
                speed = random.randint(0, 3) * 2 + -3
                score -= 1
            elif t1_location < t2_location+30 and t1_location > t2_location-30:
                score += 1
                t2_location = (t1_location, 25)
                speed = random.randint(0, 3) * 2 + -3
      for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
      screen.fill(pygame.Color("white"))
      screen.blit(test1, t1_location)
      screen.blit(test2, t2_location)
      note = file.render_to(screen, (200, 30), "Your score is:" + str(score), fgcolor=pygame.Color("black"), size=36)
      pygame.display.update()
      clock.tick(160)

乘号 发表于 2020-4-4 14:27:29

墙裂要求素材

一个账号 发表于 2020-4-5 11:10:17

乘号 发表于 2020-4-4 14:27
墙裂要求素材

自己去找!!!!

陈尚涵 发表于 2020-4-8 12:29:17

你们不会画???画图一画就OK了。你们告诉我pygame怎么进行碰撞侦测就OK了
页: [1]
查看完整版本: 即是展示又是询问