Re: [pygame] main game object using singleton/global/static?

2009-07-22 Thread Daniel Jo
There's not alot you can do about 'self' in general, but if you reference a
particular attribute or function many times you can avoid self by creating a
local reference to the attribute or function.  In your example could replace
the last two lines with:

game = self.game
game.playsound ("boom")
game.spawn ("item")

Of course, this would be a much more useful optimisation in cases with many
more references to 'self.game' within a single function or in cases where
'self.game' appears in a loop.

What it really sounds like you are looking for is something like Pascal's
'with' statement, which basically treats a record or object's attributes as
locals.  Python's 'with' statement has an entirely different function and
purpose, of course. . .

On Wed, Jul 22, 2009 at 4:01 PM, Jake b  wrote:

> Is there a shortcut or easier way than what I am doing? Because having to
> use the same reference in every object seems redundant?
> I am using a
>
> I feel I am spamming "self." A lot of my classes have a lot of "self."
> lines Example of random code:
>
> class Unit():
>  def onCollide(self, other):
>   if self.modifiedHP() - other.damage() < 0:
>   self.die()
>   self.game.playsound("boom")
>   self.game.spawn("item")
>
> So I'm looking for advice on if this is normal? Or bad code?
> --
> Jake
>



-- 
--Ostsol

http://cheesesun.blogspot.com/


Re: [pygame] main game object using singleton/global/static?

2009-07-22 Thread Jake b
Is there a shortcut or easier way than what I am doing? Because having to
use the same reference in every object seems redundant?
I am using a

I feel I am spamming "self." A lot of my classes have a lot of "self." lines
Example of random code:

class Unit():
 def onCollide(self, other):
  if self.modifiedHP() - other.damage() < 0:
  self.die()
  self.game.playsound("boom")
  self.game.spawn("item")

So I'm looking for advice on if this is normal? Or bad code?
-- 
Jake


Re: [pygame] noob questions about creating and playing sounds

2009-07-22 Thread Jerzy Jalocha N
On Wed, Jul 22, 2009 at 1:53 PM, Ian Mallett wrote:
> Curiously, I once made a sound synthesizer using Numeric and sndarray, here:
> http://geometrian.com/Programs/Waves2Source.zip.  It doesn't have any
> problems.  It looks like it computes the sine wave point by point with a
> list, then changes it into a Numeric array.  The sample rate is also half
> the sample rates here, which might have something to do with it.
>

:) Very cool!
This sounds OK here. There are two minor noise sources I can identify,
but they are really small, and I can perfectly live with that. I'll
take a closer look into the code.

I don't think sample rate is the issue here, because I tested
everything from 8000 up to 96000.

Thanks, Ian!


Re: [pygame] noob questions about creating and playing sounds

2009-07-22 Thread Ian Mallett
Curiously, I once made a sound synthesizer using Numeric and sndarray, here:
http://geometrian.com/Programs/Waves2Source.zip.  It doesn't have any
problems.  It looks like it computes the sine wave point by point with a
list, then changes it into a Numeric array.  The sample rate is also half
the sample rates here, which might have something to do with it.


Re: [pygame] noob questions about creating and playing sounds

2009-07-22 Thread Ian Mallett
On Wed, Jul 22, 2009 at 10:25 AM, Jerzy Jalocha N wrote:

> I am using:
>  * Pygame 1.8.1
>  * Python 2.6.2
>  * Xubuntu 9.04 Jaunty Jackalope
>  * Linux 2.6.28-13.45
>  * ALSA 1.0.18

I am using
PyGame 1.8.1
Python 2.5.4
Vista (Win32)


Re: [pygame] noob questions about creating and playing sounds

2009-07-22 Thread Jerzy Jalocha N
On Wed, Jul 22, 2009 at 12:46 PM, Jake b wrote:
> For the crackle, are you using the latest version of pygame? I know a
> certain version had problems on win32.

I am using:
 * Pygame 1.8.1
 * Python 2.6.2
 * Xubuntu 9.04 Jaunty Jackalope
 * Linux 2.6.28-13.45
 * ALSA 1.0.18

It would be interesting to know, if the posted code examples produce
that noise on your machine :)


Re: [pygame] noob questions about creating and playing sounds

2009-07-22 Thread Jake b
For the crackle, are you using the latest version of pygame? I know a
certain version had problems on win32.

On Wed, Jul 22, 2009 at 12:32 AM, Ian Mallett  wrote:

> Hi again,
>
> Hmmm, the note of your original approach is the same, but the timbre is
> different.  Mine matches a sine wave made with Audacity for tone.  I notice
> mine has less crackle than the original--but it's still there.
>
> The issue then is that crackle...
>
> I thought the issue might be the buffer size.  (the buffer size default for
> pre_init is 0, while for init it 3072.  I don't know if the pre_init changes
> anything that way.  Changing it didn't work, however.
>
> As an aside, pygame.sndarray.samples(...) doesn't seem to work unless the
> mixer is intitialized in stereo...
>
> I looked at the array manually, but didn't notice anything weird--although
> there's A LOT of values...
>
> It's good you got a solution though.
>
> Ian
>



-- 
Jake