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; StaticMesh* mesh;
StaPipOptions* options; StaPipOptions* options;
bool isShooting = false;
void update(); void update();
@@ -45,6 +46,7 @@ class Weapon {
audsrv_adpcm_t* shootAdpcm; audsrv_adpcm_t* shootAdpcm;
void shoot();
void allocateOptions(); void allocateOptions();
u8 getShootChannel(); u8 getShootChannel();
}; };
+20 -15
View File
@@ -66,26 +66,31 @@ void GameState::update() {
} }
skybox->update(player->getPosition()); skybox->update(player->getPosition());
auto cameraInfo = player->getCameraInfo();
engine->renderer.beginFrame(cameraInfo);
dbgObj->setPosition(*cameraInfo.looksAt);
player->update(terrain->heightmap); player->update(terrain->heightmap);
enemyManager->update(terrain->heightmap, player->getPosition()); enemyManager->update(terrain->heightmap, player->getPosition());
renderer.clear(); auto shootAction = player->getShootAction();
{ if (shootAction.isShooting) {
renderer.add(skybox->pair); // First, because of ALLPASS shootAction.ray.value().print();
renderer.add(ship->pair);
renderer.add(dbgObj->pair);
renderer.add(player->pair);
renderer.add(enemyManager->getPairs());
renderer.add(terrain->pair);
} }
renderer.render();
auto cameraInfo = player->getCameraInfo();
dbgObj->setPosition(*cameraInfo.looksAt);
engine->renderer.beginFrame(cameraInfo);
{
renderer.clear();
{
renderer.add(skybox->pair); // First, because of ALLPASS
renderer.add(ship->pair);
renderer.add(dbgObj->pair);
renderer.add(player->pair);
renderer.add(enemyManager->getPairs());
renderer.add(terrain->pair);
}
renderer.render();
}
engine->renderer.endFrame(); engine->renderer.endFrame();
} }
+5
View File
@@ -33,6 +33,11 @@ void Player::update(const Heightmap& heightmap) {
PlayerShootAction Player::getShootAction() const { PlayerShootAction Player::getShootAction() const {
PlayerShootAction action; PlayerShootAction action;
action.isShooting = weapon.isShooting;
if (action.isShooting) {
action.ray = Ray(camera.position, camera.lookAt);
}
return action; return action;
} }
+11 -6
View File
@@ -77,10 +77,10 @@ u8 Weapon::getShootChannel() {
} }
void Weapon::update() { void Weapon::update() {
isShooting = false;
if (!isShootAnimation1 && !isShootAnimation2 && pad->getPressed().Cross) { if (!isShootAnimation1 && !isShootAnimation2 && pad->getPressed().Cross) {
shootTimer.prime(); shoot();
audio->adpcm.tryPlay(shootAdpcm, getShootChannel());
isShootAnimation1 = true;
} }
auto* position = mesh->getPosition(); auto* position = mesh->getPosition();
@@ -105,14 +105,19 @@ void Weapon::update() {
isShootAnimation2 = false; isShootAnimation2 = false;
*position = initialPosition; *position = initialPosition;
if (pad->getPressed().Cross) { if (pad->getPressed().Cross) {
shootTimer.prime(); shoot();
audio->adpcm.tryPlay(shootAdpcm, getShootChannel());
isShootAnimation1 = true;
} }
} }
} }
} }
void Weapon::shoot() {
isShooting = true;
shootTimer.prime();
audio->adpcm.tryPlay(shootAdpcm, getShootChannel());
isShootAnimation1 = true;
}
void Weapon::allocateOptions() { void Weapon::allocateOptions() {
options = new StaPipOptions(); options = new StaPipOptions();
options->textureMappingType = Tyra::TyraNearest; options->textureMappingType = Tyra::TyraNearest;