shoot action in demo

This commit is contained in:
h4570
2022-08-14 20:20:56 +02:00
parent 6e5b75e39b
commit 65f40091db
4 changed files with 38 additions and 21 deletions
+2
View File
@@ -31,6 +31,7 @@ class Weapon {
StaticMesh* mesh;
StaPipOptions* options;
bool isShooting = false;
void update();
@@ -45,6 +46,7 @@ class Weapon {
audsrv_adpcm_t* shootAdpcm;
void shoot();
void allocateOptions();
u8 getShootChannel();
};
+11 -6
View File
@@ -66,14 +66,19 @@ void GameState::update() {
}
skybox->update(player->getPosition());
auto cameraInfo = player->getCameraInfo();
engine->renderer.beginFrame(cameraInfo);
dbgObj->setPosition(*cameraInfo.looksAt);
player->update(terrain->heightmap);
enemyManager->update(terrain->heightmap, player->getPosition());
auto shootAction = player->getShootAction();
if (shootAction.isShooting) {
shootAction.ray.value().print();
}
auto cameraInfo = player->getCameraInfo();
dbgObj->setPosition(*cameraInfo.looksAt);
engine->renderer.beginFrame(cameraInfo);
{
renderer.clear();
{
renderer.add(skybox->pair); // First, because of ALLPASS
@@ -85,7 +90,7 @@ void GameState::update() {
renderer.add(terrain->pair);
}
renderer.render();
}
engine->renderer.endFrame();
}
+5
View File
@@ -33,6 +33,11 @@ void Player::update(const Heightmap& heightmap) {
PlayerShootAction Player::getShootAction() const {
PlayerShootAction action;
action.isShooting = weapon.isShooting;
if (action.isShooting) {
action.ray = Ray(camera.position, camera.lookAt);
}
return action;
}
+11 -6
View File
@@ -77,10 +77,10 @@ u8 Weapon::getShootChannel() {
}
void Weapon::update() {
isShooting = false;
if (!isShootAnimation1 && !isShootAnimation2 && pad->getPressed().Cross) {
shootTimer.prime();
audio->adpcm.tryPlay(shootAdpcm, getShootChannel());
isShootAnimation1 = true;
shoot();
}
auto* position = mesh->getPosition();
@@ -105,13 +105,18 @@ void Weapon::update() {
isShootAnimation2 = false;
*position = initialPosition;
if (pad->getPressed().Cross) {
shoot();
}
}
}
}
void Weapon::shoot() {
isShooting = true;
shootTimer.prime();
audio->adpcm.tryPlay(shootAdpcm, getShootChannel());
isShootAnimation1 = true;
}
}
}
}
void Weapon::allocateOptions() {
options = new StaPipOptions();