Re: [pygame] Delay Between iterations
Hey Nate I applied your solution and it worked for me :) Thanks a lot :) Thanks to everybody else too :) Regards Ankur Aggarwal On Fri, Jan 13, 2012 at 2:15 AM, Zack Baker zbaker1...@gmail.com wrote: Sorry nevermind. Saw your next email On Jan 12, 2012, at 12:35 PM, ANKUR AGGARWAL wrote: In the last code provided I messed up the Bullet Class Code. Apologies for that. Below is my code : import pygame from pygame.locals import * import random import time pygame.init() screen=pygame.display.set_mode((640,480),0,24) pygame.display.set_caption(Hit The Stone) background=pygame.Surface(screen.get_size()) background=background.convert() screen.blit(background,(0,0)) class Plane(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image=pygame.image.load('plane.gif').convert() self.rect=self.image.get_rect() self.rect.centerx=random.randint(0,screen.get_width()) self.distancefromcenter=30 self.rect.centery=screen.get_height()-self.distancefromcenter self.dx=2 self.dy=2 def update(self): self.pressed=pygame.key.get_pressed() if self.pressed[K_DOWN]: self.rect.centery+=self.dy elif self.pressed[K_UP]: self.rect.centery-=self.dy elif self.pressed[K_LEFT]: self.rect.centerx-=self.dx elif self.pressed[K_RIGHT]: self.rect.centerx+=self.dx if self.rect.bottom=screen.get_height(): self.rect.bottom=screen.get_height() elif self.rect.top=0: self.rect.top=0 if self.rect.centerx=screen.get_width()-self.distancefromcenter: self.rect.centerx=screen.get_width()-self.distancefromcenter elif self.rect.centerx=self.distancefromcenter: self.rect.centerx=self.distancefromcenter class Bullet(pygame.sprite.Sprite): def __init__(self,posx,posy,image): pygame.sprite.Sprite.__init__(self) self.image=image self.rect=self.image.get_rect() self.rect.center=(posx,posy-30) self.dy=5 def update(self): self.rect.centery-=self.dy self.rect.center=(self.rect.centerx,self.rect.centery) if self.rect.top=0: self.kill() class Blank(pygame.sprite.Sprite): def __init__(self,posx,posy): pygame.sprite.Sprite.__init__(self) self.image=pygame.Surface((10,20)) self.image.fill((0,0,0)) self.rect=self.image.get_rect() self.rect.center=(posx,posy-30) self.dy=5 def update(self): self.rect.centery-=self.dy self.rect.center=(self.rect.centerx,self.rect.centery) if self.rect.top=0: self.kill() def main(): image=pygame.image.load('geometrybullet.png').convert() plane=Plane() allSprites=pygame.sprite.Group(plane) clock=pygame.time.Clock() while 1: pressed=pygame.key.get_pressed() for i in pygame.event.get(): if i.type==QUIT or pressed[K_q]: exit() if pressed[K_SPACE]: bullet=Bullet(plane.rect.centerx,plane.rect.centery,image) bullet.shootCount=0 allSprites.add(bullet) allSprites.clear(screen,background) allSprites.update() allSprites.draw(screen) pygame.display.flip() if __name__=='__main__': main() On Thu, Jan 12, 2012 at 11:01 PM, ANKUR AGGARWAL coolankur2...@gmail.comwrote: import pygame from pygame.locals import * import random pygame.init() screen=pygame.display.set_mode((640,480),0,24) pygame.display.set_caption(Hit The Stone) background=pygame.Surface(screen.get_size()) background=background.convert() screen.blit(background,(0,0)) class Plane(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image=pygame.image.load('plane.gif').convert() self.rect=self.image.get_rect() self.rect.centerx=random.randint(0,screen.get_width()) self.distancefromcenter=30 self.rect.centery=screen.get_height()-self.distancefromcenter self.dx=2 self.dy=2 def update(self): self.pressed=pygame.key.get_pressed() if self.pressed[K_DOWN]: self.rect.centery+=self.dy elif self.pressed[K_UP]: self.rect.centery-=self.dy elif self.pressed[K_LEFT]: self.rect.centerx-=self.dx elif self.pressed[K_RIGHT]: self.rect.centerx+=self.dx if self.rect.bottom=screen.get_height(): self.rect.bottom=screen.get_height() elif self.rect.top=0: self.rect.top=0 if self.rect.centerx=screen.get_width()-self.distancefromcenter: self.rect.centerx=screen.get_width()-self.distancefromcenter elif
Re: [pygame] Continuous Shooting
Yeah.. I applied the counter logic and it worked for me :) Thanks a lot :) Regards Ankur Aggarwal On Fri, Jan 13, 2012 at 12:02 AM, Julian Marchant onp...@yahoo.com wrote: First off, you need some sort of time management. As it is now, it'll run at variable speeds depending on how fast the processor is. Use pygame.time.Clock to limit the frame rate and/or use delta timing. As for your problem, all you need is a counter variable. Have the counter variable start at 0 and decrease it by 1 (or the amount of time passed if you're using delta timing) each time the loop happens. When the shoot key is pressed, create a bullet and set the counter to the amount of time you want to wait for the next bullet. Then, if the shoot key is held down while the loop variable is 0, create another bullet and reset the counter to the wait time. --- On *Thu, 1/12/12, ANKUR AGGARWAL coolankur2...@gmail.com* wrote: From: ANKUR AGGARWAL coolankur2...@gmail.com Subject: [pygame] Continuous Shooting To: pygame-users@seul.org, tu...@python.org Date: Thursday, January 12, 2012, 12:39 PM Hey I was making a demo shooting game and problem is that I want a continuous stream of bullets. As of now on pressing the space key only one bullet comes out of the plane (I want this to be continuous stream). On pressing space key again bullet starts from its initial point. My problem in the code is that I am able to make a single object of Bullet only (thats why it is throwing single bullet) and unable to find the another logic. Please help me out. Attaching the files along with this mail. import pygame from pygame.locals import * import random pygame.init() screen=pygame.display.set_mode((640,480),0,24) pygame.display.set_caption(Hit The Stone) class Plane(pygame.sprite.Sprite): def __init__(self,bullet): self.bullet=bullet pygame.sprite.Sprite.__init__(self) self.image=pygame.image.load('plane.gif').convert() self.rect=self.image.get_rect() self.rect.centerx=random.randint(0,screen.get_width()) self.distancefromcenter=30 self.rect.centery=screen.get_height()-self.distancefromcenter self.dx=2 self.dy=2 def update(self): pressed=pygame.key.get_pressed() if pressed[K_DOWN]: self.rect.centery+=self.dy elif pressed[K_UP]: self.rect.centery-=self.dy elif pressed[K_LEFT]: self.rect.centerx-=self.dx elif pressed[K_RIGHT]: self.rect.centerx+=self.dx if self.rect.bottom=screen.get_height(): self.rect.bottom=screen.get_height() elif self.rect.top=0: self.rect.top=0 if self.rect.centerx=screen.get_width()-self.distancefromcenter: self.rect.centerx=screen.get_width()-self.distancefromcenter elif self.rect.centerx=self.distancefromcenter: self.rect.centerx=self.distancefromcenter if pressed[K_SPACE]: self.bullet.x=self.rect.centerx self.bullet.y=self.rect.centery class Bullet(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image=pygame.image.load('geometrybullet.png').convert_alpha() self.rect=self.image.get_rect() self.rect.center=(-100,-100) self.x=-100 self.y=-100 self.dy=5 def update(self): self.y-=self.dy self.rect.center=(self.x,self.y) if self.rect.top0: self.x=-100 self.y=-100 def main(): background=pygame.Surface(screen.get_size()) background=background.convert() screen.blit(background,(0,0)) bullet=Bullet() plane=Plane(bullet) allSprites=pygame.sprite.Group(plane,bullet) while 1: for i in pygame.event.get(): quitPressed=pygame.key.get_pressed() if i.type==QUIT or quitPressed[K_q]: exit() allSprites.clear(screen,background) allSprites.update() allSprites.draw(screen) pygame.display.flip() if __name__=='__main__': main() Thanks in advance :) Regards Ankur Aggarwal
Re: [pygame] Capabilities of Pygame
On Thu, Jan 12, 2012 at 9:04 PM, Ryan Strunk ryan.str...@gmail.com wrote: If you're working on a game that you could conceivably write by yourself or with a small team, python will probably be up for the job. That’s good to know. With as much as critics of Python harp on the speed, I was worried that resulting software was going to crawl along at a snail’s pace. Are there any situations that come to mind where Python wouldn’t work? It's a little complicated. If you write everything in pure python only using the pygame library, then yes I can easily think of some examples where it wouldn't work at all, or not have good performance. However, some (maybe all?) of these can be solved by finding another library written specifically for that purpose to help you. And, as Sean Wolfe said, there are people working on speeding up python, and don't forget that computers are getting faster all the time. So it might not even be the case in a few years. Given that, if I were making a game that relied heavily one of the following things, I would reconsider python: - 3D - I've only used pyopengl and, I admit, it's kind of slow. When I ported a pyopengl game I wrote into C++, I got something like a 10x speedup. pyglet might perform better. - Huge numbers of sprites, like in the thousands or tens of thousands. - Collision detection and physics between more than ~100 objects. There are certainly libraries for this, but I'm not sure how they perform compared to their C++ counterparts. - Pixel-level manipulation of images, although this has gotten much better with the surfarray module. - Running on a mobile device. - Running in a browser. This has some similarities with Silver's list, which is also good. -Christopher
Re: [pygame] Capabilities of Pygame
On 12/01/12 06:04 PM, Ryan Strunk wrote: *From:*owner-pygame-us...@seul.org [mailto:owner-pygame-us...@seul.org] *On Behalf Of *Christopher Night *Sent:* Thursday, January 12, 2012 7:54 PM *To:* pygame-users@seul.org *Subject:* Re: [pygame] Capabilities of Pygame Seriously, what kind of game do you want to make? I have a couple in mind: an internet multi-player side scroller based on the rules to Sparkle, a sandbox-type world combining missions and social situations, various sports titles. All of the games will take place solely in an audio medium. If I understand correctly, these games will be sound only. If so, Pygame may not be the best choice. The SDL library, on which Pygame is built, plays background music fine. However, sound effects are another issue. Anything but short sound snippets can show a noticeable delay between when the sound is initiated and when it is heard. SDL does not store sound samples in audio memory. They are fed to the sound card each time. This copy time leads to the delay. Also, though SDL does support streaming, Pygame does not. Everything must be loaded before played. If you're working on a game that you could conceivably write by yourself or with a small team, python will probably be up for the job. In neither case is performance going to be the main consideration of you personally. That’s good to know. With as much as critics of Python harp on the speed, I was worried that resulting software was going to crawl along at a snail’s pace. Are there any situations that come to mind where Python wouldn’t work? Thanks a lot for all your help. Best, Ryan That said, Python/Pygame is still a good way to become familiar with game development. It is a good framework for developing a project, which can be rewritten to performance later. Lenard Lindstrom
Re: [pygame] p4a animation lag
On Fri, Dec 30, 2011 at 6:09 PM, Sean Wolfe ether@gmail.com wrote: Good info, I'll move the clock tick to the main loop and see what that gets me. Thanks for the tip. Hey guys, just wanted to check in with my p4a work. So after a few weeks mucking about with Java I went back to my phone and ran a 'top' while running my game. Turns out I had some HTC Sync software also running that was really sucking up cpu time. I killed that, then watched the output while running the animation. pygame.renpy.org:python was between 60-80% cpu, and the animation was running much faster. So, I have new hope for doing this in python! I mean, this is a two-year-old HTC Sprint Hero I'm running on, so by the time I actually am looking to beta a game... the technology will be that much better. Good cause the coding overhead trying to do this in Java makes it a whole lot of not fun ... Onwards!
[pygame] No available video device
Hello, I created a game, and its windows installer. One of my friends installed it, but when he runs the exe file, he gets the following message: pygame.error: No available video device Does anyone who nows what's the problem? I don't understand exactly, because he installed the video and sound device drivers. And of course, on other computers the game works well. Thanks for your help! Cheers, Aron
Re: [pygame] Capabilities of Pygame
--- On Fri, 1/13/12, Lenard Lindstrom le...@telus.net wrote: Also, though SDL does support streaming, Pygame does not. Everything must be loaded before played. Um... that's not true. pygame.mixer.music is Pygame's streaming module.
Re: [pygame] Capabilities of Pygame
On 13/01/12 01:43 PM, Julian Marchant wrote: --- On Fri, 1/13/12, Lenard Lindstromle...@telus.net wrote: Also, though SDL does support streaming, Pygame does not. Everything must be loaded before played. Um... that's not true. pygame.mixer.music is Pygame's streaming module. Oh right, I forgot about file like objects. Has anyone managed to use the music module to play streaming audio? Lenard Lindstrom
Re: [pygame] Capabilities of Pygame
I use it for my 'soundtracks' in the games. The only problem I run into with it is it takes a 'loop' argument, which is how many times the song should loop, I wish you could set this too infinite but I usually set it too 500 and that seems to work. Assuming no one will play my game for mor than 26 hours in a row... -Zack On Jan 13, 2012, at 9:22 PM, Christopher Night cosmologi...@gmail.com wrote: On Fri, Jan 13, 2012 at 9:15 PM, Lenard Lindstrom le...@telus.net wrote: On 13/01/12 01:43 PM, Julian Marchant wrote: --- On Fri, 1/13/12, Lenard Lindstromle...@telus.net wrote: Also, though SDL does support streaming, Pygame does not. Everything must be loaded before played. Um... that's not true. pygame.mixer.music is Pygame's streaming module. Oh right, I forgot about file like objects. Has anyone managed to use the music module to play streaming audio? I feel like I'm misunderstanding you, but yes I use pygame.mixer.music to stream audio from an OGG file all the time. I've never had a problem with it. Is that what you're asking? -Christopher
Re: [pygame] Capabilities of Pygame
Or just set it to -1? (Docs are wonderful: http://www.pygame.org/docs/ref/music.html#pygame.mixer.music.play ) On Fri, Jan 13, 2012 at 7:36 PM, Zack Baker zbaker1...@gmail.com wrote: I use it for my 'soundtracks' in the games. The only problem I run into with it is it takes a 'loop' argument, which is how many times the song should loop, I wish you could set this too infinite but I usually set it too 500 and that seems to work. Assuming no one will play my game for mor than 26 hours in a row... -Zack On Jan 13, 2012, at 9:22 PM, Christopher Night cosmologi...@gmail.com wrote: On Fri, Jan 13, 2012 at 9:15 PM, Lenard Lindstrom le...@telus.net wrote: On 13/01/12 01:43 PM, Julian Marchant wrote: --- On Fri, 1/13/12, Lenard Lindstromle...@telus.net wrote: Also, though SDL does support streaming, Pygame does not. Everything must be loaded before played. Um... that's not true. pygame.mixer.music is Pygame's streaming module. Oh right, I forgot about file like objects. Has anyone managed to use the music module to play streaming audio? I feel like I'm misunderstanding you, but yes I use pygame.mixer.music to stream audio from an OGG file all the time. I've never had a problem with it. Is that what you're asking? -Christopher
Re: [pygame] Capabilities of Pygame
Thanks guys!! -Zack On Jan 13, 2012, at 10:45 PM, Ian Mallett geometr...@gmail.com wrote: On Fri, Jan 13, 2012 at 7:36 PM, Zack Baker zbaker1...@gmail.com wrote: I use it for my 'soundtracks' in the games. The only problem I run into with it is it takes a 'loop' argument, which is how many times the song should loop, I wish you could set this too infinite but I usually set it too 500 and that seems to work. Assuming no one will play my game for mor than 26 hours in a row... -Zack If I recall, try -1