PySlither / Slither

A Python module for bridging Scratch and Python
http://pyslither.github.io/
MIT License
14 stars 6 forks source link

Add isTouching() method #61

Closed Tymewalk closed 8 years ago

Tymewalk commented 8 years ago

Works as follows:

Sprite.isTouching(Sprite)

Uses the colliderect method.

BookOwl commented 8 years ago

Looks good. Add a test before you merge it.

Tymewalk commented 8 years ago

Strange... the test only prints "1".

Tymewalk commented 8 years ago

The current test prints this:

Touching!
<rect(0, 0, 200, 169)>
<rect(0, 0, 200, 169)>

So I'm not sure colliderect is working properly. Either that or I messed something up :package:

Tymewalk commented 8 years ago

@BookOwl Some testing later, I find that it keeps returning a value of 1 (or printing it, anyways).

I thought colliderect returned a boolean...?

Tymewalk commented 8 years ago

Never mind that.

I found the problem, it's that the rect in currentCostume never actually gets updated. Sprite.xpos and Sprite.ypos control it all.

Tymewalk commented 8 years ago

I used a method similar to the blit function. The function works as expected now. @BookOwl can you look it over one last time to make sure it looks good?

BookOwl commented 8 years ago

I'm not sure, but doesn't assigning to a rect's properties move it? I haven't gotten pygame set up on my computer, so I can't test it (yet)

Tymewalk commented 8 years ago

@BookOwl I'm not sure, I haven't ever bothered to test. :tongue: However, when checking collisions, I create new rects that get modified with the properties. They're immediately discarded afterwards.

EDIT: By the way, when I run the test everything works fine. It looks exactly the same as when I don't check for touching.

BookOwl commented 8 years ago

The isTouchingTest.py file uses python2 style prints...

BookOwl commented 8 years ago

I fixed the print statements. Other than that, the test looks good. Merging