2014-03-06 4 views
-1
를 사용하여 오류

이봐 난 파이 게임에 약간의 게임 프로젝트에서 일하고 있어요,하지만 매번 나는 그가 내 스프라이트 사용에 도달 할 때 나는 오류가 내 코드를 실행하려고 여기파이 게임 : 스프라이트

class Sprite: 
    def _init_(self, xposition, yposition, name): 
     self.x = xposition 
     self.y = yposition 
     self.bitmap = image.load(name) 
     self.bitmap.set_colorkey ((0,0,0)) 
    def set_position(self, xposition, yposition): 
     self.x = xposition 
     self.y = yposition 
    def render(self): 
     screen.blit(self.bitmap, (self.x, self.y)) 

과 내가 그것을 호출하는 방법입니다

hero = Sprite(20,400, 'spaceship.bmp') 
herobullet = Sprite(0,480, 'bulete.bmp') 
enemiebullet = Sprite(0,480, 'bulete.bmp') 

업데이트 여기

commad 라인에서 오는 오류 메시지가

Visual Studio \ 2.0 \ visualstudio_py_debugger.py에 대한 C : \ Program Files (x86) \ Microsoft Visual Studio 12.0 \ Common7 \ IDE \ Extensions \ Microsoft \ Python 도구 : 720 : 유니 코드 경고 : 유니 코드 비교가 두 인수를 유니 코드로 변환하지 못했습니다. 파일 이름 == frame.f_code.co_filename 또는 (바운드 및 breakpoint_path_match (파일 이름, frame.f_code.co_filename)) : C : \ Program Files (Microsoft) Visual Studio 12.0 \ Common7 \ IDE 인 경우 불완전한 것으로 해석합니다 ( ). \ Extensions \ Microsoft \ Python Tools for Visual Studio \ 2.0 \ visualstudio_py_util.py : 265 : RuntimeWarning : surfarray 사용 : numpy 또는 Numer라는 모듈이 없음 (ImportError : numpy 또는 Numeric이라는 모듈이 없음) obj_repr = repr (obj) C : \ Program Files (x86) \ Microsoft Visual Studio 12.0 \ Common7 \ IDE \ Extensions \ Microsoft \ Python Tools for Visual Studio \ 2.0 \ visualstudio _py_util.py:265 : RuntimeWarning : sndarray : numpy 또는 Numeric 모듈을 찾지 못했습니다. (ImportError : numpy 또는 Numeric 모듈이 없습니다.) obj_repr = repr (obj) '[6344] python.exe'프로그램이 종료되었습니다. 코드 -1073741510 (0xc000013a). 우리가 어디에서 검색하는 방법 : 그래서 하나의 가능한 오류가

self.bitmap = image.load(name) 

당신이 만약이 될 수 알 수 있도록 여기

모두의
from pygame import * 
import random 
from Space_invader import * 

#create the sprite for both enemy and hero 
class Sprite: 
    def _init_(self, xposition, yposition, name): 
     self.x = xposition 
     self.y = yposition 
     self.bitmap = image.load(name) 
     self.bitmap.set_colorkey ((0,0,0)) 
    def set_position(self, xposition, yposition): 
     self.x = xposition 
     self.y = yposition 
    def render(self): 
     screen.blit(self.bitmap, (self.x, self.y)) 

# colision detection betwee two 32*32 sprite 
def Intersect(o1_x, o1_y, o2_x, o2_y): 
    if (o1_x > o2_x - 32) and (o1_x < o2_x + 32) and (o1_y > o2_y - 32) and (o1_y < o2_y + 32): 
       return 1 
    else: 
       return 0 

#initialise pygame 
init() 
screen = display.set_mode((640,480)) 
key.set_repeat(1,1)  #make sure you can press the same key more then one and that there is a delay between each action 
display.set_caption('UON Invader') #set windows name 
background = image.load('background.png') #load background picture 
hero = Sprite(20,400, 'spaceship.bmp') 
herobullet = Sprite(0,480, 'bulete.bmp') 
enemiebullet = Sprite(0,480, 'bulete.bmp') 
+0

오류가 발생했습니다. – CoryKramer

+0

정확한 오류를 알려 주실 수 있습니까? – evamvid

답변

2

먼저 항상 적절한 오류 메시지를 포함 전체 코드입니다 다음과 같이 파이 게임을 가져 왔습니다 :

import pygame 

이 코드 줄은 다음과 같아야합니다. 변경된 내용 :

self.bitmap = pygame.image.load(name) 

희망 하시겠습니까? Alex

(편집) 런타임 오류를 조금 검색 한 후이 모듈 http://numpy.scipy.org/을 다운로드하여 설치하는 것이 좋습니다.

(edit2) 문제를 검색 한 후 유니 코드 또는 비 asci 문자가 있는지 프로그램을 확인해야한다고 생각합니다. 그들은 "çö"와 같은 것을 보일 것입니다. 실수로 어디서나 이러한 문자를 삽입했는지 확인한 후 수정하십시오.

+0

'import pygame'을'from pygame import *'로 바꾸면됩니다. – evamvid

+0

from 메서드와 같이 가져 오기 –

+1

정확 하겠지만 정통 적이 지 않습니다. –

관련 문제