collision-handling is tighter (I want to take the current rotation into account and the math is tedious :/ )
// pixel-perfect collision checker: var max = Math.max, min = Math.min; function Check(a, b) { if (a == b) return false; // images: var s1 = a.surface, s2 = b.surface; // positions: var top = max(a.pos.y, b.pos.y), var left = max(a.pos.x, b.pos.x), var right = min(a.pos.x + s1.width, b.pos.x + s2.width), var bottom = min(a.pos.y + s1.height, b.pos.y + s2.height); // collisions: for (var y = top; y < bottom; ++y) { for (var x = left; x < right; ++x) { var c1 = s1.getPixel(x - a.pos.x, y - a.pos.y); var c2 = s2.getPixel(x - b.pos.x, y - b.pos.y); if (c1.alpha > 0 && c2.alpha > 0) return true; } } return false; }