Re: [pygame] Re: p4a development activity?

2011-12-01 Thread Tom Rothamel
Pgs4a development is limited by several factors.

The biggest is that PGS4A is using an unofficial port of SDL to Android.
There's a version of SDL 1.3 for Android, but SDL 1.3 hasn't been released
yet. I also don't know if Pygame runs on SDL 1.3 - I don't think it does. I
don't want to get into a situation where I'm spending a lot of time
modifying SDL, only to have to do it again when the new version comes out.

Right now, my plan is for the next release of pgs4a to sync up with the
next release of Ren'Py. The focus will be on making it easier to set up a
development environment to create packages - that will be an outgrowth of
Ren'Py's new launcher tool.


[pygame] [Pygame] Joystick Inputs

2011-12-01 Thread Andrew Godfroy
Hey,

I have been trying to experiment with Joysticks, hoping that I will be
able to use on in my project. I'm having a little trouble with
actually figuring out how to get stated as the only code I have found
online has been to just get the values for what all the buttons,
axis's, and hats are. I have been kicking myself for the past few
hours just on the internet trying to figure out how to get started
with it all. Considering that I haven't been able to find any
information on how to actually work it; I have decided to take the
last resort and ask everyone here.\

What I want to be able to do is have my players be sprites, and then
have the ability to control them with the joystick. (I'll post the
class at the bottom)

If there is anyone that can help me it will be GREATLY appreciated as
I am completely lost on how to do this.
Thanks

~killerrin


Pygame Version: 1.9.1
Python Version: 3.1.1

- Hide quoted text -


Heres is my Joysticks Information, Class, and Player Image
Image: http://dl.dropbox.com/u/28710254/Photos/Programming/Player.png

ID: js.get_id()
  0
Name: js.get_name()
  Controller (Xbox 360 Wireless Receiver for Windows)

Buttons: js.get_button(button)
  0 == A
  1 == B
  2 == X
  3 == Y
  4 == LB
  5 == RB
  6 == Back
  7 == Start
  8 == LS
  9 == RS

Axis: js.get_axis(axis_num)
  0: LS X Axis
Left: -1.0  Right: 1.0
  1: LS Y Axis
Up: -1.0Down: 1.0
  2: LT, RT
LT: 1.0RT: -1.0
  3: RS Y Axis
Up: -1.0Down: 1.0
  4: RS X Axis
Left: -1.0  Right: 1.0

Hats: js.get_hat(hat_number)
  0: D-Pad
Left-(-1,0) Upleft-(-1,1)
Right-(1,0) Upright-(1,1)
Up-(0,1)Downleft-(-1,-1)
Down-(0,-1) Downright-(1,-1)


class Player(pygame.sprite.Sprite):
  # Set Speed of Player
  speed_x=0
  speed_y=0

  # -- Functions -- #
  def __init__(self,x,y, filename):
  pygame.sprite.Sprite.__init__(self)

  # Import the Player Image
  self.image = pygame.image.load(filename).convert()
  self.image.set_colorkey(BLACK)

  # Make our top-left corner the passed-in location.
  self.rect = self.image.get_rect()
  self.rect.topleft = [x,y]

  def movement(self,x,y): # Change the Speed of the character then
move it
  self.speed_x+=x
  self.speed_y+=y


  def update(self,walls): # Find, and Update the Player location
  # Get the old position, in case we need to go back to it
  old_x=self.rect.left
  new_x=old_x+self.speed_x
  self.rect.left = new_x

  # Check to see if the player is in a wall
  collide = pygame.sprite.spritecollide(self, walls, False)
  if collide:
  self.rect.left=old_x # If it hits a wall, we go back to
before/wont update it.

  old_y=self.rect.top
  new_y=old_y+self.speed_y
  self.rect.top = new_y

  # Check to see if the player is in a wall
  collide = pygame.sprite.spritecollide(self, walls, False)
  if collide: # If it hits a wall, we go back to before/wont
update it.
  self.rect.top=old_y
player = Player( 0,0, Player.png )
player_sprite = pygame.sprite.RenderPlain((player))
player_clicker.add(player)





Once again, If anyone could help me in just trying to figure out what
has to be done, or can atleast point me in the right direction, I will
be forever in debt.

Re: [pygame] [Pygame] Joystick Inputs

2011-12-01 Thread Andrew Godfroy
Alright, I just checked over my question and I noticed I wasn’t exactly clear 
what I was looking for...

What I am asking is how do I work the event handler for checking joystick 
commands such as if the Left Thumbstick-[0] or [1]- moves, or if the A 
button-[0]- is pressed
Does anyone know how that works?

[pygame] Creating a stereo sound from an array doubles frequency

2011-12-01 Thread Marcel Stimberg
Hi list,

I'm having trouble playing sounds (generated from arrays) as stereo
sounds. Creating a sound and copying it to two channels seems to
double the frequency.

The following script (see also here: http://pastebin.com/qqZbJavf )
should make it more clear. It constructs a simple 400Hz sine wave and
plays it as a mono sound (nchannels = 1) or duplicates the array and
plays it as a stereo sound (nchannels = 2). In the second case,
however, the tone that is played is an 800Hz tone instead of a 400Hz
one... This seems not to happen on Windows, I encountered the problem
on ArchLinux and Ubuntu 11.10 (both having pygame 1.9.1).

import numpy as np
import pygame as pg
import time

frequency, samplerate, duration = 400, 44100, 2
nchannels = 1 # change to 2 for stereo
pg.mixer.pre_init(channels=nchannels, frequency=samplerate)
pg.init()

sinusoid = (2**15 - 1) * np.sin(2.0 * np.pi * frequency * \
   np.arange(0, duration) / float(samplerate))
samples = np.array(sinusoid, dtype=np.int16)
if nchannels  1: #copy mono signal to two channels
   samples = np.tile(samples, (nchannels, 1)).T
sound = pg.sndarray.make_sound(samples)
sound.play()

time.sleep(duration/float(samplerate))