Skip to content

Instantly share code, notes, and snippets.

@Orpheon
Last active December 19, 2015 12:39
Show Gist options
  • Select an option

  • Save Orpheon/5956802 to your computer and use it in GitHub Desktop.

Select an option

Save Orpheon/5956802 to your computer and use it in GitHub Desktop.
bool collides_with_wallmask(Character *character, Bitmask *map)
{
bool collided = false;
for (int w=0; w<character->width; w++)
{
for (int h=0; h<character->height; h++)
{
printf("\nRound:\n%i, %i", (int)character->x + w, (int)character->y - h);
printf("\n%i, %i", w, h);
printf("\n%i, %i\n", map->width, map->height);
fflush(stdout);
// Check for every pixel in character, is there wallmask there?
if (map->mask[(int)character->x + w][(int)character->y - h])
{
collided = true;
break;
}
}
if (collided)
{
break;
}
}
return collided;
}
------------------
Output:
------------------
Round:
1589, 227
0, 0
4146, 1200
Round:
1590, 227
1, 0
4146, 1200
Round:
0, 0
0, 0
0, 1083757568
9056 Segmentation fault (core dumped) ./bin/executable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment