void Player::update(float dt) { int a = global->multiBtn->getDirValue(); float angle = a; this->setBarrelAngle(a); //发射大炮 rotation = calAngle(); if (global->multiBtn->getIsFired()) { Bomb *bomb = Bomb::create(); Physics3DRigidBodyDes rbDes; rbDes.mass = 1.f; rbDes.shape = Physics3DShape::createSphere(0.5f); Vec3 start = _tank->getPosition3D(); bomb->set3DParams("model/box.c3t", "Icon.png", &rbDes, start, 0.5f); bomb->setRigidParams(Vec3::ONE, Vec3::ZERO, 0.5f, 0.4f); float l = 6.0f; float x0 = 0.0f, y0 = 0.0f, z0 = 0.0f; y0 = l * std::sin(angle * PI / 180); float l0 = l * std::cos(angle * PI / 180); x0 = start.x + l0 * std::sin(rotation * PI / 180); z0 = start.z + l0 * std::cos(rotation * PI / 180); Vec3 dir(x0, y0, z0);//方向向量 dir = dir - start; float power = 100; //power bomb->setDirAndPower(dir, power); bomb->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(bomb); global->multiBtn->setIsFired(false); } }
void Player::update(float dt) { Global *global = Global::getInstance(); if (global->getInstance()->_playerObj != this) { return; } int a = global->multiBtn->getDirValue(); float angle = a; // log("----->%f %f %f", global->hitPosition.x, global->hitPosition.y, global->hitPosition.z); float rotation = calAngle(); this->setPlayerAngle(a); // log("-------> %f", rotation); // log("-----------> %f %f %f", barrelV.x, barrelV.y, barrelV.z); // rotation = rotation + 180 -90; if (global->multiBtn->getIsFired()) { this->setIsFired(global->multiBtn->getIsFired());////////////////////////////////////////// Bomb *bomb = Bomb::create(); m_curBomb = bomb; Physics3DRigidBodyDes rbDes; // rbDes.originalTransform.translate(global->_camera->getPosition3D()); rbDes.mass = 1.f; rbDes.shape = Physics3DShape::createSphere(0.5f); Vec3 start = m_tank->getPosition3D(); bomb->set3DParams("model/box.c3t", "Icon.png", &rbDes, start, 0.5f); bomb->setRigidParams(Vec3::ONE, Vec3::ZERO, 0.5f, 0.4f); float l = 6.0f; float x0 = 0.0f, y0 = 0.0f, z0 = 0.0f; y0 = l * std::sin(angle * PI / 180); float l0 = l * std::cos(angle * PI / 180); x0 = start.x + l0 * std::sin(rotation * PI / 180); z0 = start.z + l0 * std::cos(rotation * PI / 180); Vec3 dir(x0, y0, z0);//方向向量 dir = dir - start; float power = 100; //power bomb->setDirAndPower(dir, power); bomb->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(bomb); ////////////////////////////////////////// global->multiBtn->setIsFired(false); } if (m_curBomb == nullptr) { return; } if (m_curBomb->getBombIsDead()) { setIsBombDidLanded(1); m_curBomb->setBombIsDead(0); // this->removeFromParent(); } }