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] = '%';
			}
		}

	}

}
예제 #2
0
파일: box.c 프로젝트: Clay-Birkett/monetdb
str
BOXrelease(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
	str name;
	Box box;

	(void) cntxt;
	(void) mb;		/*fool compiler */
	OpenBox("release");
	name = *(str *) getArgReference(stk, pci, 2);
	releaseBox(box, name);
	return MAL_SUCCEED;
}
예제 #3
0
void moveCharacter()
{
	if (!keyPressed[K_UP]) {
		keyDownedJump = false;
	}

    // Updating the location of the character based on the key press
	collisionDirection up = Up;
	collisionDirection down = Down;
	collisionDirection left = Left;
	collisionDirection right = Right;

	//Able to jump up.
	if (mummy.onGround == true && charLocation.Y > 0 && keyPressed[K_UP] && playerCollisionDetectionUp() && !keyDownedJump) {
		playMusic(1);
		keyDownedJump = true;
        mummy.jumpHeight = 5;
    }

	//In the process of jumping.
	if (mummy.jumpHeight > 0 && charLocation.Y > 0 && playerCollisionDetectionUp()) {
		playMusic(1);
		--charLocation.Y;
		--mummy.jumpHeight;

	//Falling
	} else if (playerCollisionDetectionDown()) {
		mummy.jumpHeight = 0;
		++charLocation.Y;
	}

	//Is the Mummy still in mid-air?
	if (playerCollisionDetectionDown()) {
		mummy.onGround = false;
	} else {
		mummy.onGround = true;
	}

	//Moving left when NOT holding box.
	if (!mummy.isGrabbing) {

		if (charLocation.X > 0 && keyPressed[K_LEFT] && playerCollisionDetectionLeft()) {
			timeStoodStill = 60;
			--charLocation.X;
			mummy.charDirection = 1;
		} else if (charLocation.X > 0 && keyPressed[K_LEFT] && keyPressed[K_GRAB]) {
			grabBox(left);
		}

	} else {

		if (g_heldBox->beingHeldLeft) {
			if (charLocation.X > 0 && keyPressed[K_LEFT] && boxesCollisionLeft(*g_heldBox)) {
				timeStoodStill = 60;
				--charLocation.X;
				mummy.charDirection = 1;
			}
		} else if (g_heldBox->beingHeldRight) {
			if (charLocation.X > 0 && keyPressed[K_LEFT] && playerCollisionDetectionLeft()) {
				timeStoodStill = 60;
				--charLocation.X;
				mummy.charDirection = 1;
			}
		}

		if (keyPressed[K_DOWN]) {
			releaseBox();
		}

	}

	//Moving right when NOT holding box.
	if (!mummy.isGrabbing) {

		if (charLocation.X < worldSizeX && keyPressed[K_RIGHT] && playerCollisionDetectionRight()) {
			timeStoodStill = 60;
			++charLocation.X;
			mummy.charDirection = 2;
		} else if (charLocation.X < worldSizeX && keyPressed[K_RIGHT] && keyPressed[K_GRAB]) {
			grabBox(right);
		}

	} else { //Moving Right When Holding Box

		if (g_heldBox->beingHeldLeft) {
			if (charLocation.X < worldSizeX && keyPressed[K_RIGHT] && playerCollisionDetectionRight()) {
				timeStoodStill = 60;
				++charLocation.X;
				mummy.charDirection = 2;
			}
		} else if (g_heldBox->beingHeldRight) {
			if (charLocation.X < worldSizeX && keyPressed[K_RIGHT] && boxesCollisionRight(*g_heldBox)) {
				timeStoodStill = 60;
				++charLocation.X;
				mummy.charDirection = 2;
			}
		}

		if (keyPressed[K_DOWN]) {
			releaseBox();
		}

	}

	//Not moving (No detection needed)
	if (keyPressed[K_RIGHT] == false && keyPressed[K_LEFT] == false) {
		mummy.charDirection = 0;
	}

}