Joseph Quigley | 2 Oct 2005 22:30
Picon

Making a character move?

Hi. I'm playing with a Super Mario type game engine that I'm trying to 
write but the MoveIt tutorial doesn't help me.
I can't figure out how to move an image to the left when the Left arrow 
key is pressed. I've looked at
http://pygame.org/docs/ref/pygame_event.html but that didn't help much 
either.
Thanks,
    Joe

Peter Shinners | 3 Oct 2005 01:19
Favicon
Gravatar

Re: Making a character move?

On Sun, 2005-10-02 at 14:30 -0600, Joseph Quigley wrote:
> Hi. I'm playing with a Super Mario type game engine that I'm trying to 
> write but the MoveIt tutorial doesn't help me.
> I can't figure out how to move an image to the left when the Left arrow 
> key is pressed. I've looked at

A full mario type game requires many parts for a moving character. The
hardest parts will involve colliding the character with platforms.

As for starting with left and right, you should look at the "chimp" and
"aliens" example. In the chimp example a monkey zigzags across the
window. The aliens example has a car controlled by the left and right
arrow keys.

Peter Shinners | 3 Oct 2005 01:29
Favicon
Gravatar

Re: Making a character move?

On Sun, 2005-10-02 at 16:19 -0700, Peter Shinners wrote:
> On Sun, 2005-10-02 at 14:30 -0600, Joseph Quigley wrote:
> > I can't figure out how to move an image to the left when the Left arrow 
> > key is pressed. I've looked at
>
> As for starting with left and right, you should look at the "chimp" and
> "aliens" example. 

Ok, figured I might as well throw out a few more details. The only way
to get your object to face both directions is to make two images that
face both directions. 

In both these example programs, you'll see we mirror the character image
with "pygame.transform.flip(surface, True, False)". Then every time the
character is drawn, it picks either the left image or the right image.

Peter Shinners | 3 Oct 2005 09:04
Favicon
Gravatar

updating the docs

I've updated the pygame documentation with a new version of things. This
should be a good thing, but it likely needs a round or two of proofing
and fixes.

I've gone through every function, method, and object and redone the
docs. Things are reorganized a bit, and things should be a bit clearer.
Unfortunately it's been a long span of time between me starting and
finishing the revisions. I haven't gone back myself to check for grammar
and sanity much yet.

The biggest difference is that the reference is no longer generated from
the docstrings. It is now pulled into separate simple text-like files.
I'm hoping this makes it easier to get cleanups and submissions. It also
makes languages translations more of an option.

http://www.pygame.org/docs/

If you want to start editing the docs, grab this archive and send me the
changed files. http://www.pygame.org/ftp/contrib/pygamedoc.zip

andrew baker | 3 Oct 2005 09:36
Picon

Re: updating the docs

Three cheers for Petey.

try:
    for i in range(3):
         print "Hip!"
finally:
   print "Hooray!"

On 10/3/05, Peter Shinners <pete-eNbnrwMA38Zg9hUCZPvPmw@public.gmane.org> wrote:
I've updated the pygame documentation with a new version of things. This
should be a good thing, but it likely needs a round or two of proofing
and fixes.

I've gone through every function, method, and object and redone the
docs. Things are reorganized a bit, and things should be a bit clearer.
Unfortunately it's been a long span of time between me starting and
finishing the revisions. I haven't gone back myself to check for grammar
and sanity much yet.

The biggest difference is that the reference is no longer generated from
the docstrings. It is now pulled into separate simple text-like files.
I'm hoping this makes it easier to get cleanups and submissions. It also
makes languages translations more of an option.

http://www.pygame.org/docs/

If you want to start editing the docs, grab this archive and send me the
changed files. http://www.pygame.org/ftp/contrib/pygamedoc.zip





--
Andrew Ulysses Baker
"failrate"
Jack Nutting | 3 Oct 2005 11:35
Picon

reserving an audio channel?

Hi gang,

Most of the sounds I've used in my games so far are short, fire'n'forget thingies.  I manually grab a channel (so I can do stereo effects) with pygame.mixer.find_channel(True) so that if there are no available channels, it will grab the longest-running busy one.

Now I've got a sound effect that I want to continue looping under certain conditions.  Unfortunately, since this quickly ends up being the longest-running busy channel, it always ends up getting appropriated by another sound.

What I'd like to do is essentially "lock" this one channel where I'm playing the long-running sample.  I see pygame.mixer.set_reserved(), but that just takes a number of channels to reserve;  How do I specify that I want to lock just *this* channel?  Do I need to first grab my channel and then call set_reserved(1) before any other sound stuff?  That seems sort of convoluted...  Also, the documentation says that "calling Sound.play() will not use the reserved channels."  Does that apply to find_channel() as well?

TIA,

--
// jack
// http://www.nuthole.com

Peter Shinners | 3 Oct 2005 18:29
Favicon
Gravatar

Re: reserving an audio channel?

On Mon, 2005-10-03 at 11:35 +0200, Jack Nutting wrote:
> Most of the sounds I've used in my games so far are short,
> fire'n'forget thingies.  I manually grab a channel (so I can do stereo
> effects) with pygame.mixer.find_channel(True) so that if there are no
> available channels, it will grab the longest-running busy one.

This is exactly what reserving channels is for. Now that you mention it,
I'm not sure if the find_channel() call respects the reserved channels.
It all happens inside SDL_mixer. I'm pretty sure it does work with
reserved channels, but I would recommend testing.

First call pygame.mixer.set_reserved(1) to give you one reserved
channel. These are always the first 'n' channels in the system. Play
your longer lasting effects like this,
pygame.mixer.Channel(0).play(long_sound)

If you are noticing your short effects getting cut, it's also easy to
bump up the number of mixing channels in play.
pygame.mixer.set_num_channels(20). The default is 8.

One last note, you can use stereo effects using the Sound.play() method.
This returns the channel object that is playing the sound. So a
mysound.play().set_volume(0, 1) will do the trick.

Jason | 3 Oct 2005 21:08
Picon

RLEACCEL error.

Hi,

Been playing about and trying ot get my first PyGame routine sorted. 
I've hit some hurdles, manged to scramble my way over them but this one 
has got me totally stumped!

When I run my program I'm getting the following error...

NameError: global name 'RLEACCEL' is not defined

I can't seem to see any reference to this anywhere, my code is...

import os,sys
import pygame
import random

def load_image(name, colorkey=None):
     fullname = os.path.join('', name)
     try:
         image = pygame.image.load(fullname)
     except pygame.error, message:
         print 'Cannot load image:', name
         raise SystemExit, message
     image = image.convert()
     if colorkey is not None:
         if colorkey is -1:
             colorkey = image.get_at((0,0))
         image.set_colorkey(colorkey, RLEACCEL)
     return image, image.get_rect()

class block(pygame.sprite.Sprite):
     blockImage=None

     def __init__(self):
         pygame.sprite.Sprite.__init__(self)

         if block.blockImage is None:
             block.image, block.rect=load_image("block2.jpg",-1)

     def update(self):
         self.rect.move(1,1)

def main():
     pygame.init()
     screen=pygame.display.set_mode((640,480))
     background=pygame.Surface(screen.get_size()).convert_alpha()

     a=block()
     allsprites=pygame.sprite.RenderPlain((block))

     while True:
         allsprites.update()
         screen.blit(background,(0,0))
         allsprites.draw(screen)
         pygame.display.flip()

if __name__=="__main__":
     main()

IF there are any other bugs in there, please don't tell me as I'm trying 
to learn from my mistakes, but the RLEACCEL has had me baffled for hours 
now.

TIA

Jason Massey | 3 Oct 2005 21:50
Picon

Re: RLEACCEL error.

Just off the top of my head it looks like you need either:

1) replace the plain RLEACCEL with pygame.RLEACCEL

or, even better, at the top after import pygame

from pygame.locals import *

On 10/3/05, Jason <jason@...> wrote:
> Hi,
>
> Been playing about and trying ot get my first PyGame routine sorted.
> I've hit some hurdles, manged to scramble my way over them but this one
> has got me totally stumped!
>
> When I run my program I'm getting the following error...
>
> NameError: global name 'RLEACCEL' is not defined
>
> I can't seem to see any reference to this anywhere, my code is...
>
> import os,sys
> import pygame
> import random
>
> def load_image(name, colorkey=None):
>      fullname = os.path.join('', name)
>      try:
>          image = pygame.image.load(fullname)
>      except pygame.error, message:
>          print 'Cannot load image:', name
>          raise SystemExit, message
>      image = image.convert()
>      if colorkey is not None:
>          if colorkey is -1:
>              colorkey = image.get_at((0,0))
>          image.set_colorkey(colorkey, RLEACCEL)
>      return image, image.get_rect()
>
>
> class block(pygame.sprite.Sprite):
>      blockImage=None
>
>      def __init__(self):
>          pygame.sprite.Sprite.__init__(self)
>
>          if block.blockImage is None:
>              block.image, block.rect=load_image("block2.jpg",-1)
>
>      def update(self):
>          self.rect.move(1,1)
>
>
> def main():
>      pygame.init()
>      screen=pygame.display.set_mode((640,480))
>      background=pygame.Surface(screen.get_size()).convert_alpha()
>
>      a=block()
>      allsprites=pygame.sprite.RenderPlain((block))
>
>
>
>      while True:
>          allsprites.update()
>          screen.blit(background,(0,0))
>          allsprites.draw(screen)
>          pygame.display.flip()
>
>
> if __name__=="__main__":
>      main()
>
>
> IF there are any other bugs in there, please don't tell me as I'm trying
> to learn from my mistakes, but the RLEACCEL has had me baffled for hours
> now.
>
> TIA
>
>

Jason Massey | 3 Oct 2005 21:57
Picon

Re: RLEACCEL error.

Actually it seems that RLEACCEL is stored in the pygame.constants...doh!

So you could still use option #1 or

from pygame.constants import RLEACCEL

On 10/3/05, Jason Massey <jason.massey@...> wrote:
> Just off the top of my head it looks like you need either:
>
> 1) replace the plain RLEACCEL with pygame.RLEACCEL
>
> or, even better, at the top after import pygame
>
> from pygame.locals import *
>
>
>
> On 10/3/05, Jason <jason@...> wrote:
> > Hi,
> >
> > Been playing about and trying ot get my first PyGame routine sorted.
> > I've hit some hurdles, manged to scramble my way over them but this one
> > has got me totally stumped!
> >
> > When I run my program I'm getting the following error...
> >
> > NameError: global name 'RLEACCEL' is not defined
> >
> > I can't seem to see any reference to this anywhere, my code is...
> >
> > import os,sys
> > import pygame
> > import random
> >
> > def load_image(name, colorkey=None):
> >      fullname = os.path.join('', name)
> >      try:
> >          image = pygame.image.load(fullname)
> >      except pygame.error, message:
> >          print 'Cannot load image:', name
> >          raise SystemExit, message
> >      image = image.convert()
> >      if colorkey is not None:
> >          if colorkey is -1:
> >              colorkey = image.get_at((0,0))
> >          image.set_colorkey(colorkey, RLEACCEL)
> >      return image, image.get_rect()
> >
> >
> > class block(pygame.sprite.Sprite):
> >      blockImage=None
> >
> >      def __init__(self):
> >          pygame.sprite.Sprite.__init__(self)
> >
> >          if block.blockImage is None:
> >              block.image, block.rect=load_image("block2.jpg",-1)
> >
> >      def update(self):
> >          self.rect.move(1,1)
> >
> >
> > def main():
> >      pygame.init()
> >      screen=pygame.display.set_mode((640,480))
> >      background=pygame.Surface(screen.get_size()).convert_alpha()
> >
> >      a=block()
> >      allsprites=pygame.sprite.RenderPlain((block))
> >
> >
> >
> >      while True:
> >          allsprites.update()
> >          screen.blit(background,(0,0))
> >          allsprites.draw(screen)
> >          pygame.display.flip()
> >
> >
> > if __name__=="__main__":
> >      main()
> >
> >
> > IF there are any other bugs in there, please don't tell me as I'm trying
> > to learn from my mistakes, but the RLEACCEL has had me baffled for hours
> > now.
> >
> > TIA
> >
> >
>


Gmane