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

Re: [pygame] Sprites false positive collision - newbie alert



Hi Nik,Â

many thanks for your very detailed response. I will go through your amended code to see where I went wrong and correct the issues - all part of the learning curve. ÂI'm also happy to see your completely cleaned-up version if you have time. Currently, I'm interested in where I went wrong with the collision. Onwards and upwards.Â

Thanks again.Â
Adam Â


On 5 May 2014 11:23, Dominik George <nik@xxxxxxxxxxxxx> wrote:
Hi Adam,

> What is the easiest way of detecting the collision between enemy and
> player?
>
> TIA
>
> My whole code is visible at:
> https://github.com/kabads/zoomr/blob/master/zoomr.py

I went through your code and found it to be a bit strange. I guess you started
using PyGame without sprites and have kept some bad habits.

In particular, this means:

Â* A sprite having an iamge attribute, but then using some other atribute
 Â(your il) for drawing it with your own draw method makes no sense.
Â* Always update sprites with their update method
Â* Always keep the sprite's rect in sync with the sprite's position
Â* Always have all sprites in some group (also your player in a player group)
Â* Draw groups as a whole, not every single sprite

Also, please take a look at RenderClear and how to use the clear() method for
clearing the screen surface more efficiently than drawing a solid background.

Find attached your code, amended with the things I said, but leaving its
structure intact. There are also some things about your general Python that
come to mind - if you care, I can send you a completely cleand-up version.

Cheers,
Nik



--
--
You back your data up on the same planet?
http://www.monkeez.org
PGP key: 0x7111B833