MCPcopy Create free account
hub / github.com/atraczyk/2d-engine / resolveItemCollisions

Method resolveItemCollisions

engine/src/entity.cpp:1014–1067  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1012}
1013
1014void Player::resolveItemCollisions(TileMap* pmap)
1015{
1016 Point BottomLeft = worldToTile(
1017 position + Vector2(leftPadding, bottomPadding) - pmap->position,
1018 pmap->w_tileSize);
1019 Point TopRight = worldToTile(position - Vector2(rightPadding, topPadding) +
1020 size - pmap->position,
1021 pmap->w_tileSize);
1022
1023 Point min;
1024 Point max;
1025
1026 min.x = std::max(0, BottomLeft.x - 1);
1027 min.y = std::max(0, BottomLeft.y - 1);
1028 max.x = std::min(TopRight.x + 2, pmap->t_mapSize.x);
1029 max.y = std::min(TopRight.y + 2, pmap->t_mapSize.y);
1030
1031 float tx, ty;
1032 float area;
1033 for (int y = min.y; y < max.y; y++)
1034 {
1035 for (int x = min.x; x < max.x; x++)
1036 {
1037 tx = (float)(x * pmap->w_tileSize.x) + pmap->position.x;
1038 ty = (float)(y * pmap->w_tileSize.y) + pmap->position.y;
1039 StaticObject tile =
1040 StaticObject(Vector2(tx, ty),
1041 Vector2(pmap->w_tileSize.x, pmap->w_tileSize.y));
1042 area = intersectionArea(&tile);
1043 if (area)
1044 {
1045 if (pmap->imageLayer[x][y].atileIndex == 241)
1046 {
1047 score++;
1048 for (int i = 0; i < pmap->animatedTiles.size(); i++)
1049 {
1050 if (pmap->animatedTiles[i].position.x == x &&
1051 pmap->animatedTiles[i].position.y == y)
1052 remove(pmap->animatedTiles, i);
1053 }
1054 pmap->imageLayer[x][y].atileIndex = 0;
1055 sound.PlaySfx(SOUND_COIN);
1056 pmap->imageLayer[x][y].tileIndex = -1;
1057 }
1058 else if (position.y < ty + pmap->w_tileSize.y / 4 &&
1059 (pmap->imageLayer[x][y].atileIndex == 246 ||
1060 pmap->imageLayer[x][y].tileIndex == 144)) // water
1061 {
1062 swimming = true;
1063 }
1064 }
1065 }
1066 }
1067}
1068
1069void Entity::landing()
1070{

Callers

nothing calls this directly

Calls 5

worldToTileFunction · 0.85
Vector2Class · 0.85
StaticObjectClass · 0.85
removeFunction · 0.85
PlaySfxMethod · 0.80

Tested by

no test coverage detected