Skip to content

Commit 4fa885d

Browse files
committed
Added comment for clarity in pixel perfect collision detection
1 parent 33253b0 commit 4fa885d

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

dynamic_listings/C++/default/collisiondetection/pixel_perfect.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ bool pixel_perfect_collision(Sprite A, Sprite B){
3030
int y1 = std::max(A.y, B.y);
3131
int y2 = std::min((A.y + A.height), (B.y + B.height));
3232

33-
// For each pixes in the intersecting rectangle, let's check
33+
// For each pixel in the intersecting rectangle, let's check
3434
for (int y=y1; y < y2; y++){
3535
for (int x=x1; x < x2; x++){
36+
// We're working in the intersecting triangle, so we'll need to
37+
// rework our coordinates
3638
Color a = A.bitmask.getColor(x - A.x, y - A.y);
3739
Color b = B.bitmask.getColor(x - B.x, y - B.y);
3840
if (a.isWhite() && b.isWhite()){

dynamic_listings/javascript/default/collisiondetection/pixel_perfect.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ function pixel_perfect_collision(A, B){
3636
let y1 = max(A.y, B.y);
3737
let y2 = min((A.y + A.height), (B.y + B.height));
3838

39-
// For each pixes in the intersecting rectangle, let's check
39+
// For each pixel in the intersecting rectangle, let's check
4040
for (let y = y1; y <= y2; y++){
4141
for (let x = x1; x <= x2; x++){
42+
// We're working in the intersecting triangle, so we'll need to
43+
// rework our coordinates
4244
let a = A.bitmask.getColor(x - A.x, y - A.y);
4345
let b = B.bitmask.getColor(x - B.x, y - B.y);
4446

dynamic_listings/lua/default/collisiondetection/pixel_perfect.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ local function pixel_perfect_collision(A, B)
5050
local y1 = math.max(A.y, B.y)
5151
local y2 = math.min((A.y + A.height), (B.y + B.height))
5252

53-
-- For each pixes in the intersecting rectangle, let's check
53+
-- For each pixel in the intersecting rectangle, let's check
5454
for y = y1, y2 do
5555
for x = x1, x2 do
56+
-- We're working in the intersecting triangle, so we'll need to
57+
-- rework our coordinates
5658
local a = A.bitmask.getColor(x - A.x, y - A.y)
5759
local b = B.bitmask.getColor(x - B.x, y - B.y)
5860

dynamic_listings/pseudocode/default/collisiondetection/pixel_perfect.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ function pixel_perfect_collision(Sprite A, Sprite B) -> bool{
2424
int y1 = max(A.y, B.y);
2525
int y2 = min((A.y + A.height), (B.y + B.height));
2626

27-
// For each pixes in the intersecting rectangle, let's check
27+
// For each pixel in the intersecting rectangle, let's check
2828
for (each y from y1 to y2){
2929
for (each x from x1 to x2){
30+
// We're working in the intersecting rectangle, so we'll need to
31+
// rework our coordinates
3032
a = A.bitmask.getColor(x - A.x, y - A.y);
3133
b = B.bitmask.getColor(x - B.x, y - B.y);
3234

dynamic_listings/python/default/collisiondetection/pixel_perfect.py

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def pixel_perfect_collision(A: Sprite, B: Sprite) -> bool:
6262
# For each pixel in the intersecting rectangle, let's check
6363
for y in range(y1, y2):
6464
for x in range(x1, x2):
65+
# We're working in the intersecting rectangle, so we'll need to
66+
# rework our coordinates
6567
a: Color = A.bitmask.get_color(x - A.x, y - A.y)
6668
b: Color = B.bitmask.get_color(x - B.x, y - B.y)
6769

0 commit comments

Comments
 (0)