python
1import sys 2from random import randint 3import pygame 4from pygame.locals import QUIT,Rect,KEYDOWN,K_SPACE 5 6pygame.init() 7pygame.key.set_repeat(5,5) 8SURFACE = pygame.display.set_mode((800,600)) 9FPSCLOCK = pygame.time.Clock() 10 11def main(): 12 wall = 80 13 ship_y = 250 14 velocity = 0 15 score = 0 16 slope = randint(1,6) 17 sysfont = pygame.font.SysFont(None,36) 18 ship_image = pygame.image.load("ship.png") 19 bang_image = pygame.image.load("bang.png") 20 holes = [] 21 for xpos in range(walls): 22 holes.append(Rect(xpos * 10,100,10,400)) 23 game_over = False 24 25 while True: 26 is_space_down = False 27 for event in pygame.event.get(): 28 if event.type == QUIT: 29 pygame.quit() 30 sys.exit() 31 elif event.type == KEYDOWN: 32 if event.key == K_SPACE: 33 is_space_down = True 34 35 if not game_over: 36 score += 10 37 velocity = -3 if is_space_down else 3 38 ship_y += velocity 39 edge = holes[-1].copy() 40 test = edge.move(0,slope) 41 if test.top <= 0 or test.bottom >=600: 42 slope = randint(1,6) * (-1 if slope > 0 else 1) 43 edge.inflate_ip(0, ~20) 44 edge.move_ip(10,slope) 45 holes.append(edge) 46 del holes[0] 47 holes = [x.move(-10,0) for x in holes] 48 49 if holes[0].top > ship_y or \ 50 holes[0].bottom < ship_y + 80: 51 game_over = True 52 53 SURFACE.fill((0,255,0)) 54 for hole in holes: 55 pygame.draw.rect(SURFACE,(0,0,0),hole) 56 SURFACE.blit(ship_image,(0,ship_y)) 57 score_image = sysfont.render('score is {}'.format(score),True,(0,0,225)) 58 SURFACE.blit(score_image,(600,200)) 59 60 if game_over: 61 SURFACE.blit(bang_image,(0,ship_y-40)) 62 63 pygame.display.update() 64 FPSCLOCK.tick(15) 65 66 67if __name__ == '__main__': 68 main()
現在使用しているテキストエディタはsublime textで上記のコードをターミナルで実行しようとしたところ,上手くpygameが開きません。これはテキストエディタのもんだいなのでしょうか?
エラーの内容はpygame.error: Couldn't open ship.pngとなっています。
どうすればいいのか分からないです。初心者なので問題点を指摘していただけると嬉しいです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。