Pygame: error using sprite

-1

Hey i'm working on a little game project on pygame, but everytime i try to run my code i get an error when he gets to using my sprite:

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))

and here is how i call it

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

Update

here is the error message that comes up in the commad line

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_debugger.py:720: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal if filename == frame.f_code.co_filename or (not bound and breakpoint_path_match(filename, frame.f_code.co_filename)): 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: use surfarray: no module named numpy or Numeric found (ImportError: no module named numpy or Numeric found) 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: use sndarray: no module named numpy or Numeric found (ImportError: no module named numpy or Numeric found) obj_repr = repr(obj) The program '[6344] python.exe' has exited with code -1073741510 (0xc000013a).

here is the full code

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')
python
pygame
sprite
asked on Stack Overflow Mar 6, 2014 by Fellow Rémi • edited Mar 7, 2014 by Fellow Rémi

1 Answer

2

First of all always include your adequate error message so we know where to search :) So one possible error could be the

self.bitmap = image.load(name)

If you have imported pygame like this:

import pygame

This line of code should be changed to :

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

Hope that helps! Alex

(edit) after searching a bit for your runtime error, a probable solution would be to download and install this module http://numpy.scipy.org/.

(edit2) After searching for you issue I think that you need to check your program for any unicode or non-asci characters. They would look something like this "çö". See if you have inserted any of these characters anywhere by mistake and try to fix it :)

answered on Stack Overflow Mar 7, 2014 by Alex Koukoulas • edited Mar 7, 2014 by Alex Koukoulas

User contributions licensed under CC BY-SA 3.0