Pen Collision

brantsmith

  • Posts: 151
Here is the Link: http://www.stencyl.com/game/play/3121

I am really excited to say that I think I have found a way to find when an actor is colliding with a pen drawn color. This will help the Quaint Brush project, and also hopefully help others. You can use whatever you want to draw on the screen, Not just the drawing tools. So this engine does not tax your Fps.


This of course is just the bare code right now. I will try to see how I can incorporate this into a more practical use. I also hope to release a demo where you can draw the lines. This of course incorporates as3 code, so It cant be used by non-coders. But I am working on making it workable for everyone.

I am sorry their is not gravity. At the moment, the gravity on stencyl will not work with this design. There will have to be a custom made behavior for this. (which should not be hard. Just editing the On Ground behavior to accept the calls from my behavior.

If You have any questions regarding the project, please let me know.

I just released a new demo where you can draw your own wall or shape, and watch as the actor collides with the shape.

The behavior is a very new Idea, But I hope to have a demo out soon that showcases its ability to by used in a platform game.

EDIT: Demo is released on the stencylforge. This is not the platform demo, but my previous drawing demo.

For those guys out there who are looking for good ways to draw lines. I worked on a way to make smooth lines in drawing. It is in the new demo I uploaded, and is available for download in stencylForge.

!IMPORTANT!

EDIT: As I was working on the engine, I decided it was going to take to much time, That i dont have. (since I do have a summer job.) So I decided I would put up an explanation on here of how the engine works, and also release the last demo on stencylforge.


How it works:


The way this works is to set up individual pixels points around the actor that record what color they are over. So when the pixel hovers over a certain color, you can use that info to change a boolean. (then You can use this boolean to tell your actor to move or stop) So, say that you position a pixel on the side of your actor. When that pixel detects a different color, you can now discern that, that specific side is hitting a different color. That is what I did for the demos. I told it that when the pixels around the square touched anything other than black (the background color) stop the actor. Or you can work it that when the pixels detects a specific color, Do something. This can be used for QuaintBrush. I will explain how to do both things.

I will start out explaining the easiest one. When the pixel detects any color other than the background color.

so, first you will need 2 variables.
PixelColor (Color) this is what the color of the pixel that is directly underneath it is.
can move (Boolean) this is the boolean that can be changed to discern if your character moves, or gains new powers.

First off you will need the code that goes in the code block. This is what detects the color.
Code: [Select]
_PixelColor = FlxG.buffer.getPixel32(actor.getX(), actor.getY());_PixelColor = Internal name of the color atribute. (mentioned above)
actor = actor the behavior is attached to.

You must understand though that this will not work as it is right now. Because of the fact the getX and GetY function gets the farthest pixel to the upper left of the actor. So right now it is going to register the color of the pixel(at the upper most left) of the actor. Not the screen around it. So what you have to do is this.

Code: [Select]
_PixelColor = FlxG.buffer.getPixel32(actor.getX() - 1, actor.getY() - 1);what this does is it displaces the pixel by one pixel to the left and one pixel up. You will have to work with those numbers yourself. This is why you need skills in programming. So once you do this we can move on to the boolean part.

if you look driectly below, you will see this code.

there are 2 things in the equation.
PixelColor and  a big #.
PixelColor is the color of the pixel that the engine is looking at.
the big # is actually a color in number form.

the color that is there now is 4294967295. it is the # for white.
4278190080 is the # for black.
you will have to find the #'s by yourself.

So in this example, It asks the question: is the color of the pixel the it is looking at the color white?
If so, you set the boolean to yes. So you can move, because now you know your actor is not touching anything. But otherwise, set the boolean to false. You can now use these responses to allow or disallow movement.

You will need to repeat this step many times, positioning the different sensors all around the actor. Then you will have to arrange the data to be used in a useful way. I think in my demo that I had about 12 sensors on the square. 

The other way would be that (if {PixelColor = Special Color} set double jump to true. Else false). In this case you are looking for a certain color, When it detects that color, it enables something.

Of course in this situation you could set a timer that when you touch that certain color, you have double jump for about 2 or 3 seconds.

I know this is a lot of stuff. And it is quite hard and tedious to do. But I was able to do it, so it is possible. If someone out there would like to simplify this engine into a block. Please do.

I will soon release a video tutorial showing in more detail how to do this. If you want a video tutorial, just request it, because i do not want to go to the trouble of making a video, and nobody wants it.

If you guys have any questions, Just ask me. I will try to answer them.

And finally, I just want to thank Jon and the team of stencyl for creating something that is just revolutionary in its own field. I hope that this will be able to aid in this project.









« Last Edit: June 11, 2011, 07:43:08 pm by brantsmith »
Coding is Awesome.
Stencyl is Better.

Greg

  • *
  • Posts: 1260
Nice work, looking good so far - and performance is good as well. 

brantsmith

  • Posts: 151
Coding is Awesome.
Stencyl is Better.

Darkhog

  • Posts: 1243
brantsmith, I wonder if you could make custom blocks interface to use it by non-programmers.

There are no impossible things. There is only lack of skills.
Don't click this if your computer has less than 641 kilobytes of RAM.
Stencyl stencyling stencylish stencylers :D

brantsmith

  • Posts: 151
Yes, its possible That I could. And then those who know how to code more could advance the behavior for their own game.
Coding is Awesome.
Stencyl is Better.

brantsmith

  • Posts: 151
I just released a better demo. Now you can draw your own walls.
Coding is Awesome.
Stencyl is Better.

Epic428

  • Posts: 1118
Great work on this! The performance so far is excellent, though the collision bounds, and pen smoothness can be tweaked some more. I look forward to seeing more progress on this!
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

brantsmith

  • Posts: 151
Well, actually the pen drawing is not part of the engine. It is actually modeled from some code I saw Someone put up on the forum. It is just there to show what the engine can do. Yes, I did notice that the collision bounds need some more help, But that is not too hard. I am actually going to work on a demo that can more showcase the ability for it to be used in platform games.

Could you specify on what you mean by the collision bounds need tweaking?

« Last Edit: June 10, 2011, 05:05:33 am by brantsmith »
Coding is Awesome.
Stencyl is Better.

Rhys

  • Posts: 1046
Cool, I might mess around with this to implement some of my old scratch engines to make this more usable for platformers, not-real physics etc.

edit: wait is this even on stencylforge

Darkhog

  • Posts: 1243
Drawing line is faulty, when you moving your mouse too fast. But I think I have solution. Instead of making points when mouse is down, how about drawing line from last point to current? Then drawing will look normal.

There are no impossible things. There is only lack of skills.
Don't click this if your computer has less than 641 kilobytes of RAM.
Stencyl stencyling stencylish stencylers :D

brantsmith

  • Posts: 151
Drawing line is faulty, when you moving your mouse too fast. But I think I have solution. Instead of making points when mouse is down, how about drawing line from last point to current? Then drawing will look normal.

Actually, The drawing lines program was not coded by me. I just pulled it off the forum, so that it could show the strength of the collision engine. I wanted to put up a demo that could show that The collision engine could do this, and I did not have a lot of time to spend working on the drawing behavior. I will soon be releasing a demo that shows how this can be used in a platform type game. That was what I was thinking of doing (regarding the drawing idea), so I guess that confirms that I should do that.
Coding is Awesome.
Stencyl is Better.

brantsmith

  • Posts: 151
edit: wait is this even on stencylforge

No this is not on stencylforge. And the reason is that the way the engine is set up, Everything is very cluttered (from trying to see if the idea worked). I will be trying to clean up the behavior and make it more usable. Because right now, I would have to right out a long explanation on how to get it to work. Once it gets more cleaned up, i will put it on stencyl forge.

« Last Edit: April 24, 2013, 05:02:33 pm by brantsmith »
Coding is Awesome.
Stencyl is Better.

sharpleaf

  • Posts: 90
There are at least 2 forum posts (one of them being mine) recently that have been trying to figure out how to draw to the screen without performance hits.
I know you said that you just pulled the code for that off of the forums, bout could you please either point me in the direction of the code you found for the pen part or post hit here?
Or post it here? http://community.stencyl.com/index.php/topic,1137.0.html

brantsmith

  • Posts: 151
There are at least 2 forum posts (one of them being mine) recently that have been trying to figure out how to draw to the screen without performance hits.
I know you said that you just pulled the code for that off of the forums, bout could you please either point me in the direction of the code you found for the pen part or post hit here?
Or post it here? http://community.stencyl.com/index.php/topic,1137.0.html

it is the one on your forum that greg posted.
Coding is Awesome.
Stencyl is Better.

sharpleaf

  • Posts: 90
.....really? Did you modify it at all?

I ask because I tried Greg's solution and it ran fine until you added too many points. Then it slooooowwwweeedddd down.
With your little tech demo, I can draw much much more to the screen before I even notice a performance hit.