Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CollideCheck.hx #1095

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 4 additions & 30 deletions samples/CollideCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,6 @@ class CollideCheck extends hxd.App {
line.drawRect(0, -0.5, 100, 1);
line.endFill();

//var r = new h2d.col.RoundRect(rrect.x, rrect.y, RW, RH, rrect.rotation);
//mapCol( function(pt) return r.distance(pt) );
}

function mapCol( dist : h2d.col.Point -> Float, scale = 1. ) {
var pt = new h2d.col.Point();
var bmp = hxd.Pixels.alloc(s2d.width, s2d.height, BGRA);
for( x in 0...bmp.width )
for( y in 0...bmp.height ) {
pt.x = x + 0.5;
pt.y = y + 0.5;
var d = dist(pt);
if( d < 0 ) {
var c = Std.int( -d * scale * 4 + 0x20 );
if( c > 0xFF ) c = 0xFF;
bmp.setPixel(x, y, 0xFF000000 | (c << 16));
} else {
var c = Std.int( d * scale );
if( c > 0xFF ) c = 0xFF;
bmp.setPixel(x, y, 0xFF000000 | c);
}
}
var view = new h2d.Bitmap(h2d.Tile.fromPixels(bmp));
view.alpha = 0.5;
s2d.add(view, 0);
bmp.dispose();
}

override function update(dt:Float) {
Expand All @@ -66,21 +40,21 @@ class CollideCheck extends hxd.App {
var r = new h2d.col.RoundRect(rrect.x, rrect.y, RW * 2, RH * 2, rrect.rotation);
var pt = new h2d.col.Point(px, py);

rrect.rotation += 0.002;
rrect.color.set(0, 0, 1);
var n = r.getNormalAt(pt);

rrect.color.set(0, 0, 1);
line.x = px;
line.y = py;
var n = r.getNormalAt(pt);
line.rotation = Math.atan2(n.y, n.x);

if( r.inside(pt) )
rrect.color.set(0, 1, 0);

rrect.rotation += 0.002;
}

static function main() {
new CollideCheck();
}

}