Esempio n. 1
0
void ItemTortoise::move(float dt)
{
	if (isFarAwayFromMario())
	{
		removeFromParent();
		return;
	}
	if (_status == SLEEP || _status ==DEAD || !isLeftInWindow())
	{
		return ;
	}

	// 根据方向,再具体确定
	if (_dir == Common::LEFT)
	{
		if (canMoveLeft(dt))
		{
			moveLeft(dt);
		}
		else
		{
			_dir = Common::RIGHT;
			if (_status == NORMAL)
			{
				stopAllActions();
				runAnimation("TortoiseMoveLeft");
			}
		}
	}
	else
	{
		if (canMoveRight(dt))
		{
			moveRight(dt);
		}
		else
		{
			_dir = Common::LEFT;
			if (_status == NORMAL)
			{
				stopAllActions();
				runAnimation("TortoiseMoveRight");
			}
		}
	}

	if (canMoveDown(dt))
	{
		moveDown(dt);
	}
	else
	{
		_speedDown = 10;
	}

}
Esempio n. 2
0
/**
    Searches for solution
*/
int solveFifteen()
{
    struct GameState *queue;
    int i;
    
    while (notEmptyPQ())
    {
        queue = getQueueTop();
        
        if (queue->manhattanDistance == 0)
        {
            printSolution(queue);
            
            for (i = 0; i < rows; i++)
            {
                free(queue->tilesPosition[i]);
            }
            free(queue->tilesPosition);
            free(queue->prev);
            queue->prev = NULL;
            
            /* deallocate memory */
            int pocet = 0;
            while (notEmptyPQ())
            {
                pocet++;
                free(queue);
                queue = NULL;
                queue = getQueueTop();
                for (i = 0; i < rows; i++)
                {
                    free(queue->tilesPosition[i]);
                }
                free(queue->tilesPosition);
                free(queue->prev);
                queue->prev = NULL;
            }
            printf("Ve fronte bylo %d\n", pocet);
            system("PAUSE");
            return 0;
        }
        else
        {
            int lastMove = getLastMove(queue);
            if (canMoveLeft(queue) && lastMove != MOVE_RIGHT)
            {
                struct GameState *s = createNewState(queue);
                if (s == NULL)
                {
                    return OUT_OF_MEMORY;    
                }
                moveLeft(s);
                s->manhattanDistance = getManhattanDistance(*s);
                insertPQ(s);
            }
            if (canMoveRight(queue) && lastMove != MOVE_LEFT)
            {
                struct GameState *s = createNewState(queue);
                if (s == NULL)
                {
                    return OUT_OF_MEMORY;    
                }
                moveRight(s);
                s->manhattanDistance = getManhattanDistance(*s);
                insertPQ(s);
            }
            if (canMoveUp(queue) && lastMove != MOVE_DOWN)
            {
                struct GameState *s = createNewState(queue);
                if (s == NULL)
                {
                    return OUT_OF_MEMORY;    
                }
                moveUp(s);
                s->manhattanDistance = getManhattanDistance(*s);
                insertPQ(s);
            }
            if (canMoveDown(queue) && lastMove != MOVE_UP)
            {
                struct GameState *s = createNewState(queue);
                if (s == NULL)
                {
                    return OUT_OF_MEMORY;    
                }
                moveDown(s);
                s->manhattanDistance = getManhattanDistance(*s);
                insertPQ(s);
            }
        }
        
    }
    return 1;
}
Esempio n. 3
0
void ItemTortoiseFly::move(float dt)
{
	if (_status == NORMAL)
	{
		if (_dir == Common::LEFT)
		{
			moveLeft(dt);
			if (getPositionX() <= _left)
			{
				_dir = Common::RIGHT;
				updateStatus();
			}
		}
		else
		{
			moveRight(dt);
			if (getPositionX() >= _right)
			{
				_dir = Common::LEFT;
				updateStatus();
			}
		}
	}
	else if (_status == DROPPING)
	{
		if (canMoveDown(dt))
		{
			moveDown(dt);
		}
		else
		{
			_speedDown = _speedAcc;
			_status = ONLAND;
			updateStatus();
		}
	}
	else if (_status == ONLAND || _status == CRAZY)
	{
		if (canMoveDown(dt))
		{
			moveDown(dt);
		}
		else
		{
			_speedDown = _speedAcc;
		}

		if (_dir == Common::LEFT)
		{
			if (canMoveLeft(dt))
			{
				moveLeft(dt);
			}
			else
			{
				_dir = Common::RIGHT;
			}
		}
		else
		{
			if (canMoveRight(dt))
			{
				moveRight(dt);
			}
			else
			{
				_dir = Common::LEFT;
			}
		}
	}
}
Esempio n. 4
0
void Player::update(float frameTime, LevelController* lc) {
	// 1-Press NoClip
	if (noClipButtonReleased && input->isKeyDown(VK_F2)) {
		noClip = !noClip;
		noClipButtonReleased = false;
	} else {
		noClipButtonReleased = true;
	}
	velocityX = getVelocity().x;
	velocityY = getVelocity().y;
	// Handle NoClip
	if (noClip) {
		if (input->isKeyDown(PLAYER_RIGHT)) {
			velocityX = playerNS::NOCLIP_SPEED * frameTime;
			orientation = Right;
		} else if (input->isKeyDown(PLAYER_LEFT)) {
			velocityX = -playerNS::NOCLIP_SPEED * frameTime;
			orientation = Left;
		} else {
			velocityX = 0;
		}
		if (input->isKeyDown(PLAYER_UP)) {
			velocityY = -playerNS::NOCLIP_SPEED * frameTime;
			orientation = Up;
		} else if (input->isKeyDown(PLAYER_DOWN)) {
			velocityY = playerNS::NOCLIP_SPEED * frameTime;
			orientation = Down;
		} else {
			velocityY = 0;
		}
		velocity = VECTOR2(velocityX, velocityY);
		frameDelay = 1000000;
		Item* activeItem = inventory->getActiveItem()->getItem();
		if (inventory->getActiveItem()->getItem()->getItemType() == Item::Equipable) {
			Gun* gun = dynamic_cast<Gun*>(activeItem);
			if (gun != 0) {
				gun->update(frameTime, orientation, getX(), getY(), input, lc);
			}
		}
		Entity::update(frameTime);
		return;
	}
	// Set Obj Vars
	levelController = lc;
	// Debug Messages
	OSD::instance()->addLine("Jump Distance: " + std::to_string(jumpdistance) + " / " + std::to_string(playerNS::JUMP_HEIGHT));
	OSD::instance()->addLine("Can | Left: " + std::to_string(canMoveLeft(true)) + " | Right: " + std::to_string(canMoveRight(true)) + " | Up: " + std::to_string(canMoveUp(true)) + " | Down: " + std::to_string(canMoveDown(true)));
	// Stuck Hotfix
	if (!canMoveLeft() && !canMoveRight() && !canMoveUp() && !canMoveDown()) {
		setX(spawnPos.x);
		setY(spawnPos.y);
	}
	// Update Guns
	inventory->update(frameTime, input);
	// Boss Audio
	if (lc->getMapX() * -1.0 > 1900) {
		audio->stopCue(BK_MUSIC);
		audio->playCue(BOSS_MUSIC);
	}

	// Start of Player Movement
	if (healthStatus != Dead) {
		if (!canMoveDown()) {
			if (!input->isKeyDown(PLAYER_UP) && !input->isKeyDown(PLAYER_JUMP))
				canJump = true;
			canFall = false;
			falling = false;
		} else {
			canFall = true;
			falling = true;
		}
		// Move Left and Right
		if (input->isKeyDown(PLAYER_RIGHT) && canMoveRight()) {
			velocityX = playerNS::SPEED * frameTime;
			while (!canMoveRight()) {
				spriteData.x -= 0.1;
				velocityX = 0;
			}
			orientation = Right;
		} else if (input->isKeyDown(PLAYER_LEFT) && canMoveLeft()) {
			velocityX = -playerNS::SPEED * frameTime;
			while (!canMoveLeft()) {
				spriteData.x += 0.1;
				velocityX = 0;
			}
			orientation = Left;
		} else {
			velocityX = 0;
			if (input->isKeyDown(PLAYER_UP)) {
				orientation = Up;
			}

			if (input->isKeyDown(PLAYER_DOWN)) {
				orientation = Down;
			}
		}
		// Handle Jumping
		if (jumping || (((input->isKeyDown(PLAYER_JUMP) || input->isKeyDown(PLAYER_UP)) && canMoveUp() && canJump))) {
			jumpdistance = jumpOriginY - getY();
			if (canJump && !jumping)
				jumpOriginY = getY();
			if (jumpdistance > playerNS::JUMP_HEIGHT || !canMoveUp()) {
				jumping = false;
				canJump = false;
				falling = true;
			} else {
				if (!jumping)
					velocityY = -playerNS::JUMP_SPEED * frameTime;
				else
					velocityY += 0.5 * frameTime;
				jumping = true;
				canJump = false;
			}
		}
		if (!jumping)
			jumpOriginY = getY();
		if (falling && !jumping) {
			if (canMoveDown()) {
				velocityY = playerNS::FALLING_SPEED * frameTime;
			} else {
				velocityY = 0;
			}
		}
		// Handle Stuck
		while (canMoveUp() && !canMoveDown() && !canMoveLeft() && !canMoveRight()) {
			spriteData.y -= 0.1;
		}
		while (!canMoveUp() && !canMoveDown() && !canMoveLeft() && canMoveRight()) {
			spriteData.x += 0.1;
		}
		while (!canMoveUp() && !canMoveDown() && canMoveLeft() && !canMoveRight()) {
			spriteData.x -= 0.1;
		}
		// Final Sanity Check
		if (!canMoveLeft() && velocityX < 0 || !canMoveRight() && velocityX > 0)
			velocityX = 0;
		if (!canMoveUp() && velocityY < 0 || !canMoveDown() && velocityY > 0)
			velocityY = 0;
		setVelocity(VECTOR2(velocityX, velocityY));

		// Handle Orientations
		if (input->isKeyDown(PLAYER_UP))
			orientation = Up;
		else if (input->isKeyDown(PLAYER_DOWN))
			orientation = Down;
		switch (orientation) {
		case Right:
			currentFrame = 953;
			spriteData.flipHorizontal = true;
			break;
		case Down:
			currentFrame = 954;
			break;
		case Left:
			currentFrame = 953;
			spriteData.flipHorizontal = false;
			break;
		case Up:
			currentFrame = 952;
			break;
		}

		// Draw Items
		Item* activeItem = inventory->getActiveItem()->getItem();
		if (inventory->getActiveItem()->getItem()->getItemType() == Item::Equipable) {
			Gun* gun = dynamic_cast<Gun*>(activeItem);
			if (gun != 0) {
				gun->update(frameTime, orientation, getX(), getY(), input, lc);
			}
		}
		// Crate Collision
		if (lc->collidedWithCrate() == 1 && lc->getCrateItem() != -1) {
			audio->playCue(RELOAD);
			if (lc->collidedWithCrate() == 1 && lc->getCrateItem() != -1) {
				int itemid = lc->getCrateItem();
				InventoryItem *invItem;
				std::vector<InventoryItem*>* itemList = inventory->getItems();
				switch (itemid) {
				case playerNS::ItemType::shotGun:
					shotgun = new Shotgun();
					shotgun->initialize(gameptr, 136, 41, 2, gunTexture);
					shotgun->setCurrentFrame(6);
					invItem = new InventoryItem(shotgun);
					break;
				case playerNS::ItemType::machineGun:
					machineGun = new MachineGun();
					machineGun->initialize(gameptr, 136, 41, 2, gunTexture);
					machineGun->setCurrentFrame(0);
					invItem = new InventoryItem(machineGun);
					break;
				case 3:
					break;
				}
				for (int i = 0; i < itemList->size(); i++) {
					InventoryItem *iItem = itemList->at(i);
					Item* item = iItem->getItem();
					Item* newItem = invItem->getItem();
					if (item->getItemType() == Item::Equipable && newItem->getItemType() == Item::Equipable) {
						Gun* gunInvItem = dynamic_cast<Gun*>(item);
						Gun* gunNewItem = dynamic_cast<Gun*>(newItem);
						if (gunInvItem->getGunId() == gunNewItem->getGunId()) {
							gunInvItem->addAmmo();
							lc->setCrateCollided(0);
							return; // Should this be return or break?
						}
					} else if (item->getItemType() == Item::Usable && newItem->getItemType() == Item::Usable) {
						lc->setCrateCollided(0);
						return;
					} // Should this be return or break?
				}
				inventory->addItem(invItem);
				lc->setCrateCollided(0);
				lc->setCrateItem(-1);
			}
		}
		Entity::update(frameTime);
	}
}
Esempio n. 5
0
void Jack::ai(float frameTime, Entity & ent, float mapX, LevelController* lc) {
	OSD::instance()->addLine("AI Can | Left: " + std::to_string(canMoveLeft()) + " | Right: " + std::to_string(canMoveRight()) + " | Up: " + std::to_string(canMoveUp()) + " | Down: " + std::to_string(canMoveDown()));
	switch (aiState) {
	case Patrol:
		if (currDest != VECTOR2(-1, -1)) {
			derivedDest = VECTOR2(currDest.x + offsetOld.x, currDest.y + offsetOld.y);
		}
		if (!canMoveLeft() && !canMoveRight() && !canMoveUp() && !canMoveDown()) {
			setX(derivedDest.x);
			setY(derivedDest.y);
		}
		if (pathList.size() == 0)
			return;
		if (currDest == VECTOR2(-1, -1) || spriteData.x == derivedDest.x) {
			pathCount++;
			if (pathCount >= pathList.size())
				pathCount = 0;
			currDest = pathList.at(pathCount);
		}
		if (spriteData.x > derivedDest.x) {
			if (velocity.x > 0 && spriteData.x - derivedDest.x < 1 && canMoveLeft()) {
				velocity.x = 0;
				setX(derivedDest.x);
			} else {
				orientation = Left;
				if (!moveLeft(frameTime)) {
					currDest = VECTOR2(-1, -1);
				}
			}
		} else if (spriteData.x < derivedDest.x) {
			if (velocity.x < 0 && derivedDest.x - spriteData.x < 1 && canMoveRight()) {
				velocity.x = 0;
				setX(derivedDest.x);
			} else {
				orientation = Right;
				if (!moveRight(frameTime)) {
					currDest = VECTOR2(-1, -1);
				}
			}
		} else {
			velocity.x = 0;
		}
		chatString = "SAVE ME PLEASE!";
		break;
	case Chase:
		if (currDest != VECTOR2(-1, -1)) {
			derivedDest = VECTOR2(gameptr->getPlayer()->getX(), gameptr->getPlayer()->getY());
		}
		if (pathList.size() == 0)
			return;
		if (currDest == VECTOR2(-1, -1) || spriteData.x == derivedDest.x) {
			pathCount++;
			if (pathCount >= pathList.size())
				pathCount = 0;
			currDest = pathList.at(pathCount);
		}
		if (spriteData.x > derivedDest.x) {
			if (velocity.x > 0 && spriteData.x - derivedDest.x < 1) {
				velocity.x = 0;
				setX(derivedDest.x);
			} else {
				orientation = Left;
				if (!moveLeft(frameTime)) {
					currDest = VECTOR2(-1, -1);
				}
			}
		} else if (spriteData.x < derivedDest.x) {
			if (velocity.x < 0 && derivedDest.x - spriteData.x < 1) {
				velocity.x = 0;
				setX(derivedDest.x);
			} else {
				orientation = Right;
				if (!moveRight(frameTime)) {
					currDest = VECTOR2(-1, -1);
				}
			}
		} else {
			velocity.x = 0;
		}
		chatString = "THANK YOU AGENT FOR SAVING ME! <3";
		break;
	case Attack:
		velocity = VECTOR2(0, 0);
		if (currDest != VECTOR2(-1, -1)) {
			derivedDest = VECTOR2(currDest.x, currDest.y);
		}
		//OSD::instance()->addLine("NPC Shoot Orientation: " + std::to_string(derivedDest.x - getX()) + " (" + std::to_string((int)(derivedDest.x)) + " - " + std::to_string((int)getX()) + ")");
		VECTOR2 delta = VECTOR2(derivedDest.x - getX(), 0);
		if (delta.x < 0)
			orientation = Left;
		else if (delta.x > 0)
			orientation = Right;
		else
			orientation = Up;
		break;
	}
	//OSD::instance()->addLine("MapX: " + std::to_string(mapX));
	//OSD::instance()->addLine("NPC AI (" + std::to_string(aiState) + ") at (" + std::to_string(spriteData.x) + ", " + std::to_string(spriteData.y) + ") going to (" + std::to_string((derivedDest.x)) + ", " + std::to_string(derivedDest.y) + ") Moving at: (" + std::to_string((velocity.x)) + ", " + std::to_string(velocity.y) + ") ");
}