44 lines
1.6 KiB
C
44 lines
1.6 KiB
C
//
|
|
// Created by bruno on 2.6.2025.
|
|
//
|
|
|
|
#include "miner.h"
|
|
#include "tile.h"
|
|
#include "../util/audio.h"
|
|
|
|
const ItemType MinerRecipes[TILEREGISTRY_SIZE] = {
|
|
[BGType_IRON_ORE] = IRON_ORE,
|
|
[BGType_SILVER_ORE] = SILVER_ORE,
|
|
[BGType_GOLD_ORE] = GOLD_ORE,
|
|
[BGType_PLATINUM_ORE] = PLATINUM_ORE
|
|
};
|
|
|
|
|
|
void updateMiner(Tile *tile) {
|
|
ItemOnBelt *outItem = &tile->items[MINER_OUTPUT_SLOT];
|
|
BackgroundType bgt = backgroundMap[tile->rect.y][tile->rect.x].type;
|
|
ItemType targetOutItemType = MinerRecipes[bgt];
|
|
Item targetOutItem = ItemRegistry[targetOutItemType];
|
|
|
|
if (targetOutItemType != TYPE_AIR && outItem->type == 0) {
|
|
if (tile->miscVal == 0) {
|
|
tile->audioCh = getAvailableChannel();
|
|
if (tile->audioCh < NUM_SYNTH_VOICES) {
|
|
audioData.synthVoices[tile->audioCh].volume = 64;
|
|
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_NOISE;
|
|
audioData.synthVoices[tile->audioCh].frequency = 400;
|
|
}
|
|
}
|
|
if (outItem->type == 0 && ++tile->miscVal >= targetOutItem.miscVal) {
|
|
if (tile->audioCh < NUM_SYNTH_VOICES) {
|
|
audioData.synthVoices[tile->audioCh].volume = 0;
|
|
}
|
|
tile->miscVal = 0;
|
|
outItem->type = targetOutItemType;
|
|
outItem->offset = -0.5f;
|
|
}
|
|
}
|
|
} |