I have the following code:
global mousepos
class SpaceGameWindow(window.Window):
...
def __init__(self, *args, **kwargs):
self.max_monsters = 20
mousepos =[0,0]
...
def on_mouse_motion(self, x, y, dx, dy):
mousepos = [x,y]
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
mousepos = [x,y]
def on_mouse_press(self, x, y, button, modifiers):
if (button == 1):
self.bullets.append(Bullet(mousepos,self.ship
, self.bullet_image
, self.height
, x=self.ship.x + (self.ship.image.width / 2) - (self.bullet_image.width / 2)
, y=self.ship.y))
but it gives me the following error on the line where I create the bullet object:
... in on_mouse_press
self.bullets.append(Bullet(mousepos,self.ship
NameError: global name 'mousepos' is not defined
I'm using python 2.5.1
Anyone have any ideas as to how I can solve my problem?