こんにちは。
コマンドラインでpygameをインストールして、画面を表示させようとしているのですが、いつまでも読み込みをしていて画面が表示されません。どのようにすれば、画面をすぐに表示することができるでしょうか?
開発環境:IDLE
import sys from random import randint import pygame from pygame.locals import QUIT,Rect,KEYDOWN,K_SPACE pygame.init() pygame.key.set_repeat(5,5) SURFACE = pygame.display.set_mode((800,600)) FSPCLOCK = pygame.time.Clock() def main(): walls = 80 ship_y = 250 velocity = 0 score = 0 slope = randint(1,6) sysfont = pygame.font.SysFont(None,36) ship_image = pygame.image.load('ship.png') bang_image = pygame.image.load('bang.png') holes = [] for xpos in range(walls): holes.append(Rect(xpos*10,100,10,400)) game_over = False while(1): is_space_down = False for event in pygame.event.get(): if event.type ==QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN: if event.key == K_SPACE: is_space_down = True if not game_over: score += 10 velocity += -3 if is_space_down else 3 ship_y += velocity edge = holes[-1].copy() test = edge.move(0,slope) if test.top <= 0 or test.bottom >=600: slope = randint(1,6)*(-1 if slope >0 else 1) edge.inflate_ip(0,-20) edge.move_ip(10,slope) holes.append(edge) del holes[0] holes = [x.move(-10,0) for x in holes] if holes[0].top > ship_y or \ holes[0].bottom < ship_y + 80: game_over = True SURFACE.fill((0,255,0)) for hole in holes: pygame.draw.rect(SURFACE,(0,0,0),hole) SURFACE.blit(ship_image,(0,ship_y)) score_image = sysfont.render('score is {}'.format(score),True,(0,0,225)) SURFACE.blit(score_image,(600,20)) if game_over: SURFACE.blit(bang_image,(0,ship_y-40)) pygame.display.update() FSPCLOCK.tick(15) if __name__ == '__main__': main()
そして、実行すると
Traceback (most recent call last): File "a.py", line 68, in <module> main() File "a.py", line 18, in main ship_image = pygame.image.load('ship.png') pygame.error: Couldn't open ship.png
となり、ずっと読み込み中が続きます。
作成中のスクリプトをcodeタグで囲って質問文に追記してくださいな。