Re: [pygame] Need names and nationalities for AI playes in new sport-game
Excellent! My name, as I guess it says in the from field, is Ben Collier, and I'm from England / Britain / UK. 2009/11/12 John Eriksson j...@arainyday.se Hi fellow pygame developers! I'm developing a sports game. It's a fictive sport played one-on-one, on ice against another human player or against a rather advanced AI. As part of the game it is possible to create a career in the World Series against 40 (or so) AI controlled players. I started to search the net to find inspiration for names and nationalities to the AI-players. But then I thought it would be much nicer to use the names and nationalities of pygame developers instead of just using fictive names. All AI-players will have different skill levels wich is randomly set in the begining of a new World Series career. In one career your named character will be the best in the world, and in another it might be a rookie in Division 4. The game will be released as Freeware for both Linux and Windows. The source code will (as allways for my projects) be available once the game is done. If you wan't your name to apear as a AI-player in the game, please send me your name (first + last) and your nationality. Best Regards /John Eriksson http://arainyday.se
[pygame] Creating large numbers of sprites in array or other structure
Hi, I'm fairly new to pygame, certainly haven't used it much, and up until now have been creating sprites by defining an extension to the sprite class and then instantiating each sprite by assigning it as, for example: newsprite = NewSprite(250,250) ...with the arguments that the init method uses in brackets. If I want to create, say, 150 sprites, and simply add each one to a group rather than having to have a distinct reference for each one, how do I do it? I can't seem to find an example online and I've not had much luck adding them to an array. Thanks in advance, Ben Collier
Re: [pygame] Creating large numbers of sprites in array or other structure
Hi Luke, Thanks for that. From the code you've got there it looks like a list should work fine. I haven't got the code I'd been trying to hand (essentially assigning a new sprite to the list, but it sounds as though it was a python problem, not pygame) I shouldn't have any problems with this from now on. Thanks very much. Fingers crossed! From your code, you could reference sprites[5] to get the sixth sprite, right? Thanks Ben 2009/10/26 Luke Paireepinart rabidpoob...@gmail.com On Mon, Oct 26, 2009 at 4:43 AM, Ben Collier bmcoll...@gmail.com wrote: Hi, I'm fairly new to pygame, certainly haven't used it much, and up until now have been creating sprites by defining an extension to the sprite class and then instantiating each sprite by assigning it as, for example: newsprite = NewSprite(250,250) ...with the arguments that the init method uses in brackets. If I want to create, say, 150 sprites, and simply add each one to a group rather than having to have a distinct reference for each one, how do I do it? I can't seem to find an example online and I've not had much luck adding them to an array. Why have you not been able to add them to a list? (by the way, we call them lists not arrays in Python) Can you not just say locations = [(250, 250), (100,100), (300, 300)] sprites = [NewSprite(location) for location in locations] spritegroup = NewSpriteGroup() for sprite in sprites: spritegroup.add(sprite) Note this is pseudocode as I don't remember the exact syntax to initialize sprites, etc. but you should get the idea. Is there a problem doing it this way? (In the future, it would be better to say I have tried it this way, and it did not work because or i have tried it this way and I am not sure why it did not work but here is what it did or something like this, so we have some indication of what you have tried, and why it didn't work. See http://catb.org/~esr/faqs/smart-questions.htmlhttp://catb.org/%7Eesr/faqs/smart-questions.html) -Luke
Re: [pygame] Creating large numbers of sprites in array or other structure
Thanks Luke, Will do. 2009/10/26 Luke Paireepinart rabidpoob...@gmail.com On Mon, Oct 26, 2009 at 6:07 AM, Ben Collier bmcoll...@gmail.com wrote: Hi Luke, Thanks for that. From the code you've got there it looks like a list should work fine. I haven't got the code I'd been trying to hand (essentially assigning a new sprite to the list, but it sounds as though it was a python problem, not pygame) If you want to add a new sprite to a list, you can simply use the append method of the list. a = [1,2,3,4,5] a.append(6) print a results in [1,2,3,4,5,6] Also look at extend, a = [1,2,3,4,5] b = [6,7,8] print a.append(b) [1,2,3,4,5,[6,7,8]] print a.extend(b) [1,2,3,4,5,6,7,8] So extend is for tacking a list to the end of a list, and append is for adding an element (which can be a list if you want.) I shouldn't have any problems with this from now on. Thanks very much. Fingers crossed! From your code, you could reference sprites[5] to get the sixth sprite, right? Yep, exactly. If you have names for your sprites, you can throw them in a dictionary instead, so you would be able to reference them as: sprites['spaceship'].x = 15 or whatever, but if they're just 150 bullets, for example, and you want to move them to the right on the screen, it'd be easier just to use a list and say for bullet in bullets: bullet.x += 5 And of course there's nothing keeping you from having a dictionary of lists, so you could do sprites['spaceship'].x = 15 for bullet in sprites['bullets']: bullet.x += 5 Or whatever. (I'm not sure if this is how you control sprite's positions, I don't use Sprite very much and I mostly use Pyglet these days (but that will change again soon.)) Hope that helps, -Luke P.S. if you're not too familiar with Python or just starting out, come join the Python Tutor mailing list, I'm a contributor over there and we talk about a lot of general Python stuff (and not just really low-level stuff either, some of the stuff they get into I don't even understand!) If you need some great, free materials to learn, just ask over there and everyone will be happy to direct you to the best resources available for starting out! Thanks Ben 2009/10/26 Luke Paireepinart rabidpoob...@gmail.com On Mon, Oct 26, 2009 at 4:43 AM, Ben Collier bmcoll...@gmail.comwrote: Hi, I'm fairly new to pygame, certainly haven't used it much, and up until now have been creating sprites by defining an extension to the sprite class and then instantiating each sprite by assigning it as, for example: newsprite = NewSprite(250,250) ...with the arguments that the init method uses in brackets. If I want to create, say, 150 sprites, and simply add each one to a group rather than having to have a distinct reference for each one, how do I do it? I can't seem to find an example online and I've not had much luck adding them to an array. Why have you not been able to add them to a list? (by the way, we call them lists not arrays in Python) Can you not just say locations = [(250, 250), (100,100), (300, 300)] sprites = [NewSprite(location) for location in locations] spritegroup = NewSpriteGroup() for sprite in sprites: spritegroup.add(sprite) Note this is pseudocode as I don't remember the exact syntax to initialize sprites, etc. but you should get the idea. Is there a problem doing it this way? (In the future, it would be better to say I have tried it this way, and it did not work because or i have tried it this way and I am not sure why it did not work but here is what it did or something like this, so we have some indication of what you have tried, and why it didn't work. See http://catb.org/~esr/faqs/smart-questions.htmlhttp://catb.org/%7Eesr/faqs/smart-questions.html) -Luke