correction, the '@win.event' decorator on function 'update' is not
needed.


On Sep 25, 1:40 pm, Tartley <[EMAIL PROTECTED]> wrote:
> Hey Dany0,
>
> It's easier for people to help you out if you can break your problem
> down into small, specific questions, rather than just asking 'why
> doesn't my code work?'. Then people can help you without having to
> spend lots of time figuring out what you mean. For example, you could
> ask 'Why do I see no bullets on screen?'
>
> My first suggestion is you spend some time reading up on Python. As
> noted, you are using some things like classes in ways they are not
> usually used. A brilliant place to start on this is the book 'dive
> into python', which is available for free online.
>
> Regardless of all the above, the pyglet users list has been very good
> to me, and I want to give something back, so here's a 'fixed' version
> of your code, that does what I *think* you want it to do:
>
> from pyglet import app, clock, image, window
>
> background_image = image.load('background.png')
> bullet_image = image.load('bullet.png')
> gun_image = image.load('gun.gif')
>
> win = window.Window(fullscreen=True)
> win.set_mouse_visible(False)
>
> class Gun:
>     def __init__(self):
>         # the gun remembers its own x,y position
>         self.x = 0
>         self.y = 0
>
> gun = Gun()
> bullets = []
>
> class Bullet:
>     def __init__(self, x, y):
>         # each bullet remembers its own x,y position
>         self.x = x
>         self.y = y
>
> @win.event
> def on_mouse_motion(x, y, dx, dy):
>      # put the gun 22 pix below where the mouse is
>      gun.x = x
>      gun.y = y-22
>
> @win.event
> def on_mouse_release(x, y, button, modifiers):
>     # create a new bullet, add it to our list of bullets
>     bullets.append(Bullet(gun.x, gun.y))
>
> @win.event
> def on_draw():
>     # draw everything: background, gun, bullets
>     background_image.blit(1,1)
>     gun_image.blit(gun.x, gun.y)
>     for bullet in bullets:
>         bullet_image.blit(bullet.x, bullet.y)
>
> @win.event
> def update(dt):
>     # move every bullet upwards
>     for bullet in bullets:
>         bullet.y += 100 * dt
>
> # ask pyglet to call 'update' every frame
> clock.schedule(update)
>
> # it is recommended to call app.run() instead of writing your own
> event loop
> app.run()
>
> On Sep 23, 5:20 pm, Dany0 <[EMAIL PROTECTED]> wrote:
>
> > this is da images:http://www.wikiupload.com/download_page.php?id=61430
> > this is da code:
>
> > from pyglet import window
> > from pyglet import image
>
> > win = window.Window()
>
> > win.set_mouse_visible(False)
>
> > @win.event
> > def set_fullscreen(self, fullscreen=True, screen=None):
> >        pass
>
> > class background:
> >     img = image.load('background.bmp')
>
> > class gun:
> >     gun_img = image.load('gun.bmp')
> >     x = 0
> >     y = 0
>
> > class bullet:
> >     img = image.load('bullet.bmp')
> >     x = gun.x+10
> >     y = gun.y
>
> > @win.event
> > def on_mouse_motion(x, y, dx, dy):
> >      gun.x = x
> >      gun.y = y-22
>
> > @win.event
> > def on_mouse_release(x, y, button, modifiers):
> >     bullet.img.blit(bullet.x, bullet.y)
>
> > while not win.has_exit:
> >     win.dispatch_events()
> >     win.clear()
> >     background.img.blit(1,1)
> >     gun.gun_img.blit(gun.x, gun.y)
> >     win.flip()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to