The concept behind Stringy Flash game: determine if a Sprite is inside a lasso

Do you remember my Flash game called Stringy?

I blogged about it about a month ago and some people asked me some hints about the way used to catch the stars drawing a lasso around it.

There are a lot of mathematical formulas to solve this task, and range from “more than complicate” to “you must be joking”.

I decided to post a prototype of the code I used starting from the post Develop a Flash game like String Avoider – AS3 version – and more!, without any comment, and it will be up to you to guess how I solved the problem in a ridiculously easy way.

This is what you will get:

Catch the circle with a lasso to make it move in a random spot.

And this is the code:

No need to download anything, you can replace the code contained in the original prototype with this one.

Did you figure out how I made it possible with no formulas?

  • Chris

    Uh finally. Have been waiting for that one :D

    I’m gonne turn that into a functional Corona App later and share it with you guys. :)

  • I was in a similar type situation just a few weeks back. I wrote a game (unpublished) similar to this where circling objects was included. The first test I used was complete display object and used math like this. I also wrote a second test using blitting and was able to do collision checking by getPixel().

    Furthermore, you didn’t attribute your lineIntersection algorithm to Keith Hair (or whomever he got his from). Not sure if he cares, but a link is usually nice.

    http://keith-hair.net/blog/2008/08/04/find-intersection-point-of-two-lines-in-as3/

  • Alberto

    A little explanation of the code would be great. Or at least som comments on the functions. I don’t understand the maths that you are using ;)

  • Emanuele Feronato

    @UnknownGuardian: the function has been coded starting from the Wikipedia page http://en.wikipedia.org/wiki/Line-line_intersection, I don’t remember if I went to Keith’s page too, probably we got inspired from the same sources.

    @Alberto: ok, I’ll be posting some more hints during next posts.

  • Very creative and inspiring ! I love the way you introduce a concept (like mouse trail) and then introduce yet a concept built on the previous one (like lasso). I think exploring the potential is the real lesson here.

    As to your implementation of lineIntersection, I notice you have to check for NaN:

    var p:Point=lineIntersection(p1,p2,p3,p4);
    if ((p!=null && !isNaN(p.x)))….

    This is not optimal, I think. Should we also check for isNaN(p.y) ?
    But this is down to geometry, there are plenty of line intersection implementations out there. The important thing is concepts and how one mastery may lead to another. Thanks!

  • Chris

    After some time fiddling around, I think I might have to redo the Code, since Corona has neither the ability to make polygons nor a hitTest… Gnah!