[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] A bunch of newbie questions



On 11/26/07, Miguel Sicart <mundial82@xxxxxxxxx> wrote:
> Hi all,
Hi
> First of all - this email has a collection of basic, newbie questions. I
> hope this doesn't break etiquette or it's too annoying - if these are too
> many questions, or too basic (and there is somewhere else I could find
> answers), please let me know :)
It looks like everything here is Pygame stuff, so you're OK!
> On to the questions.
> I am not a programmer, and only recently I took up Python/Pygame. While
> Object Orientation does not seem conceptually quite hard, I think the
> implementation puzzles. So here's the question:
> I have a class that defines the main object with a keyboard method (among
> others) that controls player input
> class Hero(pygame.sprite.Sprite)
>  def keyboard(self)
> I have another object called companion, which just moves around the Hero
>
> What I want is that, when the player presses space, a new object companion
> is created, up to for. So, how do I do that? Sprites are in groups in the
> main loop, but how do I append/add an instance to a group from the class.
> In other words: how do I access the main loop from an object's method? (if
> that is possible).
>
>
> Another question:
> I am making a Every Extend clone to learn the magic of pygame. I have some
> trouble with two things:
> 1. The chain reaction - I am using rect.inflate, but it seems to be quite
> unprecise. Is it just better to load a new image, a "explosion", with a
> different rect, instead of inflating the original's rect?
If you're sizing something repeatedly, then the image quality will go
down.  (Try doubling and then halving an image in photoshop).  Better
to make a different surface.  I'm not sure that's your question
though.
> 2. Dying: as someone said, dying is easy, comedy is hard. OK, so when the
> hero dies, I need to kill the sprite, make a timer, and then instantiate it
> again. And I have no clue how to do any of these things (well, except
> self.(kill)). I am not fishing for code here, but for how to think about how
> to solve this problem.
>
> I hope I have been at least a bit clear. Thanks to those who reach here and
> have read the text :) and thanks in advance for the help!
For class instances, add them to lists:

whatevers = []
class whatever:
    def __init__(self):
        self.something = something
whatevers.append(whatever())

Sorry I don't have time for anything more detailed.
> cheers,
>
> Naranjito the Newbie
Bye!
Ian