Most texure work

This commit is contained in:
2025-06-10 21:59:51 +02:00
parent a17e3abbff
commit 39c31f0042
103 changed files with 666 additions and 246 deletions

View File

@@ -8,7 +8,14 @@
#include "../entity/entity.h"
const uint16_t AmmoDamages[ITEMREGISTRY_SIZE] = {
[IRON_INGOT] = 1
[IRON_INGOT] = 2,
[GOLD_INGOT] = 1,
[SILVER_INGOT] = 3,
[PLATINUM_INGOT] = 5,
[IRON_BULLET] = 20,
[GOLD_BULLET] = 10,
[SILVER_BULLET] = 30,
[PLATINUM_BULLET] = 50,
};
void updateTurret(Tile *tile) {
@@ -17,45 +24,77 @@ void updateTurret(Tile *tile) {
uint16_t damage = AmmoDamages[inItem->type];
if (damage > 0) {
bool foundEnt = false;
// Reduce cooldown (miscVal) if above 0
if (tile->miscVal > 0) {
tile->miscVal--;
}
for (int i = 0; i < entities.activeCount; i++) {
Entity *ent = &entities.entities[i];
int dx = abs(ent->renderRect.x - (tile->rect.x * TILE_SIZE));
int dy = abs(ent->renderRect.y - (tile->rect.y * TILE_SIZE));
int d = sqrt(pow(dx, 2) + pow(dy, 2));
if (d <= (TILE_SIZE * 8)) {
ent->health -= damage;
inItem->type = 0;
tile->audioCh = getAvailableChannel();
if (tile->audioCh < NUM_SYNTH_VOICES) {
audioData.synthVoices[tile->audioCh].volume = 255;
audioData.synthVoices[tile->audioCh].phase = 0;
audioData.synthVoices[tile->audioCh].sourceRect.x = TILE_SIZE * tile->rect.x;
audioData.synthVoices[tile->audioCh].sourceRect.y = TILE_SIZE * tile->rect.y;
audioData.synthVoices[tile->audioCh].waveform = WAVE_TRIANGLE;
audioData.synthVoices[tile->audioCh].frequency = 400;
}
tile->fixedFrame = 0;
foundEnt = true;
break;
}
}
if (!foundEnt) {
audioData.synthVoices[tile->audioCh].volume = 0;
tile->fixedFrame = 1;
}
} else {
// If there's no ammo or it's invalid, stop the sound and return
if (damage == 0) {
if (tile->audioCh < NUM_SYNTH_VOICES) {
audioData.synthVoices[tile->audioCh].volume = 0;
}
tile->fixedFrame = 1;
if (animationStep % (TileRegistry[tile->type].animation.frameCount - 1) == 0) {
tile->fixedFrame = 1;
}
return;
}
if (audioData.synthVoices[tile->audioCh].frequency > 80) {
audioData.synthVoices[tile->audioCh].frequency--;
// Search for a target entity
bool foundEnt = false;
for (int i = 0; i < entities.activeCount; i++) {
Entity *ent = &entities.entities[i];
int dx = abs(ent->renderRect.x - (tile->rect.x * TILE_SIZE));
int dy = abs(ent->renderRect.y - (tile->rect.y * TILE_SIZE));
int d = sqrt(dx * dx + dy * dy);
if (d <= (TILE_SIZE * 8)) {
foundEnt = true;
if (tile->miscVal == 0) {
// Do damage and consume ammo
ent->health -= damage;
inItem->type = 0;
// Get or reuse audio channel
if (tile->audioCh >= NUM_SYNTH_VOICES) {
tile->audioCh = getAvailableChannel();
}
if (tile->audioCh < NUM_SYNTH_VOICES) {
SynthVoice *voice = &audioData.synthVoices[tile->audioCh];
voice->volume = 255;
voice->phase = 0;
voice->sourceRect.x = tile->rect.x * TILE_SIZE;
voice->sourceRect.y = tile->rect.y * TILE_SIZE;
voice->waveform = WAVE_TRIANGLE;
voice->frequency = 400;
}
tile->fixedFrame = 0;
tile->miscVal = 20; // Cooldown (ticks) until next fire
}
break; // Only shoot one entity
}
}
}
// No entity found? Fade sound out
if (!foundEnt && tile->audioCh < NUM_SYNTH_VOICES) {
SynthVoice *voice = &audioData.synthVoices[tile->audioCh];
if (voice->volume > 0) {
voice->volume--;
}
if (animationStep % (TileRegistry[tile->type].animation.frameCount - 1) == 0) {
tile->fixedFrame = 1;
}
}
// Lower frequency for pitch effect if it's still playing
if (tile->audioCh < NUM_SYNTH_VOICES) {
SynthVoice *voice = &audioData.synthVoices[tile->audioCh];
if (voice->frequency > 80) {
voice->frequency--;
}
}
}