pygameで画面に何も表示されないのですが、問題点がありますでしょうか。
python
1import sys 2from random import randint 3import pygame 4from pygame.locals import QUIT,KEYDOWN,KEYUP,K_LEFT,K_RIGHT,K_UP,K_DOWN 5 6pygame.init() 7SURFACE=pygame.display.set_mode((800,800)) 8FPSCLOCK=pygame.time.Clock() 9 10def main(): 11 game_over = False 12 score = 0 13 speed = 25 14 stars = [] 15 keymap = [] 16 ship = [0,0] 17 scope_image = pygame.image.load("scope.jpg") 18 star_image = pygame.image.load("star.jpg") 19 20 scorefont = pygame.font.SysFont(None,36) 21 sysfont = pygame.font.SysFont(None,72) 22 message_over = sysfont.render("GAME OVER!!",True,(0,255,255)) 23 message_rect = message_over.get_rect()#center=(400,400)) 24 message_rect.center = (400,400) 25 26 while len(stars) < 200: 27 stars.append({"pos":[randint(-1600,1600),randint(-1600,1600),randint(0,4095)],"theta":randint(0,360)}) 28 29 while True: 30 for event in pygame.event.get(): 31 if event.type == QUIT: 32 pygame.quit() 33 sys.exit() 34 elif event.type == KEYDOWN: 35 if not event.key in keymap: 36 keymap.append(event.key) 37 elif event.type == KEYUP: 38 keymap.remove(event.key) 39 40 #フレームごとの処理 41 if not game_over: 42 score += 1 43 if score % 10 == 0: 44 speed += 1 45 46 47 if K_LEFT in keymap: 48 ship[0] -= 30 49 elif K_RIGHT in keymap: 50 ship[0]+=30 51 elif K_UP in keymap: 52 ship[1] -= 30 53 elif K_DOWN in keymap: 54 ship[1] += 30 55 56 ship[0] = max(-800,min(800,ship[0])) 57 ship[1] = max(-800,min(800,ship[1])) 58 59 for star in stars: 60 star["pos"][2] -= speed 61 if star["pos"][2] < 64: 62 if abs(star["pos"][0]-ship[0]) <50 and abs(star["pos"][1]-ship[1]) < 50: 63 game_over = True 64 star["pos"] = [randint(-1600,1600),randint(-1600,1600),4095] 65 66 67 #描画 68 SURFACE.fill((0,0,0)) 69 stars = sorted(stars,key = lambda x: x["pos"][2],reverse=True) 70 for star in stars: 71 zpos=star["pos"][2] 72 xpos=((star["pos"][0]-ship[0])<<9)/zpos+400 73 74 ypos=((star["pos"][1]-ship[1])<<9)/zpos+400 75 size=(50<<9)/zpos 76 rotated=pygame.transform.rotozoom(star_image,star["theta"],size/145) 77 SURFACE.bilt(rotated,(xpos,ypos)) 78 79 SURFACE.blit(scope_image,(0,0)) 80 81 if game_over: 82 SURFACE.blit(message_over,message_rect) 83 pygame.mixer.music.stop() 84 85 #スコアの描画 86 score_str = str(score).zfill(6) 87 score_image=scorefont.render(score_str,True,(0,255,0)) 88 SURFACE.blit(score_image,(700,50)) 89 90 pygame.display.update() 91 FPSCLOCK.tick(20) 92 93if __name__ == '__main__': 94 main() 95 96 97 98
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。