alcemirfernandes / pynguin

Automatically exported from code.google.com/p/pynguin
GNU General Public License v3.0
0 stars 0 forks source link

A way for one penguin to know when it has run into the drawn path of another penguin? #35

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
e.g. to enable the creation of things like mazes.

Original issue reported on code.google.com by aresnick...@gmail.com on 15 Jul 2010 at 4:51

GoogleCodeExporter commented 9 years ago
I've been thinking about this. It's certainly useful, but it's going to be 
tricky.

Things don't actually get drawn when commands are executed. They get pushed on 
to a stack of draw commands that are executed at a later time.

So, when one pynguin says collides(x) it needs to return an answer right now, 
but the answer now may be different from the answer when things actually get 
around to getting drawn.

So, this would need to introduce some kind of a synchronization to work 
reliably.

That said, a simple version should not be too difficult. It would probably work 
for your maze example. You would draw your maze completely, and only after it 
was finished send in a pynguin to explore the maze.

If you want to give it a try, look at something around here:
http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qgraphicsscene.html#ite
mAt

Original comment by miss...@hotmail.com on 15 Jul 2010 at 5:49

GoogleCodeExporter commented 9 years ago
http://code.google.com/r/aresnickety-pynguin/source/detail?r=57f601ab1d21f4a8bfe
310785a85e799e9f0a27e is a start; amazingly, I couldn't figure out how to 
request a code review directly.

Original comment by aresnick...@gmail.com on 18 Jul 2010 at 2:12

GoogleCodeExporter commented 9 years ago
The way I did it is terrible and fragile, it turns out =)  I think instead I 
want an event for intersection, and also to be able to choose whether or not to 
pay attention to the path the turtle is drawing (as part of the intersection 
code).  Also, there are weird artifacts with choosing resolution and step size 
that mean that it doesn't always perform as expected.

Original comment by aresnick...@gmail.com on 18 Jul 2010 at 1:56

GoogleCodeExporter commented 9 years ago
> I didn't see an easy way to check if an Element was drawn yet

If it has not been drawn yet, then it just won't be there at all.

> choosing resolution and step size

When looking for an intersection, you'd definitely need to use a
small forward() step for each move.

If you're willing to wait for things to get drawn, maybe you could
draw, check for intersections, and then back up to the point where
the intersection actually occurred.

Thinking about it some more, I wonder if you might also run in to 
trouble because you will be running GUI code from the non-GUI thread.

It's an interesting puzzle. It would be nice to get it working right.

Original comment by miss...@hotmail.com on 18 Jul 2010 at 7:25

GoogleCodeExporter commented 9 years ago
Try after Revision d60de268743f

There is a new pynguin method colorat() that should return the color at the 
spot where the pynguin is currently.

It is not pulled in to the default functions yet, so you will need to use:

p.colorat()

If you are checking this function repeatedly, it also slows down progress 
greatly. It works, but there may be a better way to do this...

Original comment by miss...@hotmail.com on 16 Aug 2011 at 4:19