Re: [pygame] A bunch of newbie questions

2007-11-29 Thread Mundial 82

Hi there,

Thanks a bunch - it works (and sorry for my poor explanatory powers :)

cheers!

Naranjito


On Nov 28, 2007, at 8:55 PM, Michael George wrote:


I'm not sure exactly what you want, but

for x in object:
 deadStar.grav(x)

will call deadStar.grav on each sprite in the sprite group object.

--Mike

Miguel Sicart wrote:

hi all,

thanks a bunch for the answers - I have learnt much, and  
everything seems to work.

I have an extra question, though. Albeit much more simple:
I have an object with a gravitational method that should affect  
all objects of one type in the game.  How do I pass that method to  
a sprite group?
(like deadStar.grav(object), being object a group of sprites -  
Python does not like it since the objects lack self.x, self.y  
before they are instantiated).


Cheers, and thanks for the help,

Naranjito

On 11/27/07, *Dmitrii 'Mamut' Dimandt* [EMAIL PROTECTED]  
mailto:[EMAIL PROTECTED] wrote:



 if game_mode == player_alive:
 handle_input()
 move_player()
 if player.is_killed():
 if number_of_lives == 0:
I'd change it to, possibly, if player.number_of_lives , but that
depends
on the actual game design









Re: [pygame] A bunch of newbie questions

2007-11-28 Thread Miguel Sicart
hi all,
thanks a bunch for the answers - I have learnt much, and everything seems to
work.
I have an extra question, though. Albeit much more simple:
I have an object with a gravitational method that should affect all objects
of one type in the game.  How do I pass that method to a sprite group?
(like deadStar.grav(object), being object a group of sprites - Python does
not like it since the objects lack self.x, self.y before they are
instantiated).

Cheers, and thanks for the help,

Naranjito

On 11/27/07, Dmitrii 'Mamut' Dimandt [EMAIL PROTECTED] wrote:


  if game_mode == player_alive:
  handle_input()
  move_player()
  if player.is_killed():
  if number_of_lives == 0:
 I'd change it to, possibly, if player.number_of_lives, but that depends
 on the actual game design



Re: [pygame] A bunch of newbie questions

2007-11-28 Thread Michael George

I'm not sure exactly what you want, but

for x in object:
 deadStar.grav(x)

will call deadStar.grav on each sprite in the sprite group object.

--Mike

Miguel Sicart wrote:

hi all,

thanks a bunch for the answers - I have learnt much, and everything 
seems to work.

I have an extra question, though. Albeit much more simple:
I have an object with a gravitational method that should affect all 
objects of one type in the game.  How do I pass that method to a 
sprite group?
(like deadStar.grav(object), being object a group of sprites - Python 
does not like it since the objects lack self.x, self.y before they are 
instantiated).


Cheers, and thanks for the help,

Naranjito

On 11/27/07, *Dmitrii 'Mamut' Dimandt* [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:



 if game_mode == player_alive:
 handle_input()
 move_player()
 if player.is_killed():
 if number_of_lives == 0:
I'd change it to, possibly, if player.number_of_lives , but that
depends
on the actual game design


 




Re: [pygame] A bunch of newbie questions

2007-11-27 Thread Dmitrii 'Mamut' Dimandt

 if game_mode == player_alive:
 handle_input()
 move_player()
 if player.is_killed():
 if number_of_lives == 0:
I'd change it to, possibly, if player.number_of_lives, but that depends
on the actual game design


[pygame] A bunch of newbie questions

2007-11-26 Thread Miguel Sicart
Hi all,
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 :)
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?
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!

cheers,

Naranjito the Newbie


Re: [pygame] A bunch of newbie questions

2007-11-26 Thread Ian Mallett
On 11/26/07, Miguel Sicart [EMAIL PROTECTED] 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


Re: [pygame] A bunch of newbie questions

2007-11-26 Thread Pete Shinners

Miguel Sicart wrote:
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).


Welcome, hopefully you can get all the answers you need here.
When I'm making games, the game objects themselves are not responsible 
for directly handling input, this is usually a good idea. You would some 
part of the main loop check for the spacebar, and create and track the 
created helpers.


If the design is that the player object should really own the helper 
objects, then make a list or a set on the player class. The player 
object can create the helpers and keep track of them for itself.


For a game object to talk to the main loop, you need to set up some way 
to access the loop. Typically a game only has one main loop. Keep a 
reference to this main loop in a common module your game shared. Then 
anyone can reference the current main loop through the module.



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?


It kind of depends on the number of effects that will be going on. The 
easiest will be for each explosion in the chain reaction to create a new 
game object with its own image and rect.


If you are going to have many overlapping objects in a rectangle. You 
may want to keep track of only the bounding rectangle of all of them. 
Then you can use this single rectangle for calls to 
pygame.display.update().


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.


Your game main loop will work with something usually called a state 
machine. This mainly means some kind of class or global variables that 
tell the game what mode it is in. The job of the state machine is to 
track what is going on, and figure out when to switch to some other 
mode. A simplistic method would use a set of strings with the main loop.


if game_mode == player_alive:
handle_input()
move_player()
if player.is_killed():
if number_of_lives == 0:
game_mode == game_over
else:
game_mode == player_dead
killed_time = current_time()
elif game_mode == player_dead:
if current_time() - killed_time  3seconds():
player.restart()
game_mode == player_alive