void boxesUpdate() { for (unsigned int i = 0; i < boxes.size(); ++i) { //This is an array which stores the coordinates of the box(which takes up 9 spaces) unsigned int * boxCoords[9] = { &g_worldGrid[boxes[i].boxLocationX][boxes[i].boxLocationY], &g_worldGrid[boxes[i].boxLocationX - 1][boxes[i].boxLocationY], &g_worldGrid[boxes[i].boxLocationX + 1][boxes[i].boxLocationY], &g_worldGrid[boxes[i].boxLocationX][boxes[i].boxLocationY - 1], &g_worldGrid[boxes[i].boxLocationX - 1][boxes[i].boxLocationY - 1], &g_worldGrid[boxes[i].boxLocationX + 1][boxes[i].boxLocationY - 1], &g_worldGrid[boxes[i].boxLocationX][boxes[i].boxLocationY - 2], &g_worldGrid[boxes[i].boxLocationX - 1][boxes[i].boxLocationY - 2], &g_worldGrid[boxes[i].boxLocationX + 1][boxes[i].boxLocationY - 2] }; //This is to delete everything that the box is overlaping with, such as lava. for (unsigned int h = 0; h < 9; ++h) { if (canDestroy(*boxCoords[h])) { *boxCoords[h] = ' '; } } //This makes the box fall down if there is no ground underneath it. boxesGravity(boxes[i]); //This is to move the box if a player is pushing/pulling it. moveBox(boxes[i]); //If the box is no longer the same Y coordinates as the player, the box is released if the player was holding it. if (mummy.isGrabbing && g_heldBox->boxLocationY != charLocation.Y) { releaseBox(*g_heldBox); } //A new array to get the new coordinates of the box as the box has been moved. unsigned int * boxCoordsNew[9] = { &g_worldGrid[boxes[i].boxLocationX][boxes[i].boxLocationY], &g_worldGrid[boxes[i].boxLocationX - 1][boxes[i].boxLocationY], &g_worldGrid[boxes[i].boxLocationX + 1][boxes[i].boxLocationY], &g_worldGrid[boxes[i].boxLocationX][boxes[i].boxLocationY - 1], &g_worldGrid[boxes[i].boxLocationX - 1][boxes[i].boxLocationY - 1], &g_worldGrid[boxes[i].boxLocationX + 1][boxes[i].boxLocationY - 1], &g_worldGrid[boxes[i].boxLocationX][boxes[i].boxLocationY - 2], &g_worldGrid[boxes[i].boxLocationX - 1][boxes[i].boxLocationY - 2], &g_worldGrid[boxes[i].boxLocationX + 1][boxes[i].boxLocationY - 2] }; //This is to 'solidify' the box so that the player and other boxes cannot pass through it. for (unsigned int h = 0; h < 9; ++h) { if (canDestroy(*boxCoordsNew[h])) { *boxCoordsNew[h] = '%'; } } } }
void Mine::collideWith(Entity *ent) { if(((ent->getPosition().positionVector() - position.positionVector()).getMagnitude() <= coreRadius+ent->getRadius()) && canDestroy(ent)) { detonate(); } else if (canDetonate(ent)) { isArmed = true; detonateTime = mineDelay; radius = 1; } }