const int SFX_WHACKAMOLE_HIT = 25;//Sound to play when hitting mole with positive score
const int SFX_WHACKAMOLE_PENALTY1 = 3;//Sound to play when hitting mole with negative score
const int SFX_WHACKAMOLE_PENALTY2 = 14;//Sound to play when hitting mole that ends the game witn score zeroed out.
const int SFX_WHACKAMOLE_GAME_OVER = 29;//Sound to play when the game ends via time out.
const int FONT_WHACKAMOLE = 0;//Font used to render HUD
const int CSET_WHACKAMOLE_MOLE1 = 7;//CSets used by different kinds of moles
const int CSET_WHACKAMOLE_MOLE2 = 8;
const int CSET_WHACKAMOLE_MOLE3 = 5;
const int CSET_WHACKAMOLE_MOLE4 = 1;
//Whack-A-Mole minigame
//You have a couple of holes. Moles of different kinds pop out at random intervals and after some time, hide back. Your goal is to hit moles that grant positive score, while avoiding hitting moles with negative score. Amass target score within time limit to win.
//1. Set up 6 consecutive combos: 1 - empty hole. 2 - "Mole popping out" animation, must have cycle to next combo, 3 - revealed mole, ready to be hit (Pound combo type needed), 4 - "Mole being hit" animation, must cycle into empty hole, 5 - "mole hiding in" , must cycle into empty hole, 6- "mole hiding in on game over", must cycle into empty hole.
//2. Build gameplay area using 1st combo from step 1. Its recommended so no two hole combos are adjacent. Max 16 holes.
//3. Place combo with combo and CSet of 1st combo from step 1.
// D0 - Total game time, in seconds.
// D1 - #####.____ - Time before mole hides into hole, in frames
// D1 - _____.#### - Maximum time before new mole pops out from hole, in frames.
// D2 - Target score.
// D3 - #####.____ - ABS - String to display at the game startup.
// D3 - _____.#### - ABS - String to display at the game end.
// If D3 <0 - allow whacking moles by standing on them and pressing Ex1.
// D4-D7 Score values of different mole types. Can be negative. -1000 - Instant game over with score zeroed out.
ffc script WhackAMole{
void run (int time, int moletime, int target, int str, int mole1, int mole2, int mole3, int mole4){
int holes[16];
int timer[16];
int moletype[16];
int scets[16];
for (int i=0;i<16;i++){
holes[i]=-1;
timer[i]= 0;
moletype[i]=-1;
scets[i]=-1;
}
int poptime = GetHighFloat(moletime);
int cooldown = GetLowFloat(moletime);
int molescore[4] = {mole1, mole2, mole3, mole4};
int molecsets[4] = {CSET_WHACKAMOLE_MOLE1,CSET_WHACKAMOLE_MOLE2,CSET_WHACKAMOLE_MOLE3,CSET_WHACKAMOLE_MOLE4};
int molepos=0;
time*=60;
int curhole = -1;
int curtype = -1;
bool hammer = str<0;
int score=0;
int cmb=-1;
int str1 = Abs(GetHighFloat(str));
int str2 = Abs(GetLowFloat(str));
int strui1[] = "SCORE";
int strui2[] = "TIME";
Screen->Message(str1);
for (int i=0;i<176;i++){
if (Screen->ComboD[i]==this->Data){
holes[molepos]=i;
timer[molepos]=-Rand(cooldown)-1;
moletype[molepos]=-1;
molepos++;
if (molepos>=16)break;
}
}
while(true){
for (int i=0;i<16;i++){
if (time<=0)break;
if (holes[i]<0)continue;
curhole = holes[i];
// Screen->DrawInteger(3, ComboX(curhole), ComboY(curhole)+16, FONT_BATTLESHIP,1,0, -1, -1, timer[i], 0, OP_OPAQUE);
// Screen->DrawInteger(3, ComboX(curhole), ComboY(curhole)+24, FONT_BATTLESHIP,1,0, -1, -1, moletype[i], 0, OP_OPAQUE);
if (timer[i]<0){
timer[i]++;
if (timer[i]==0){
moletype[i] = Rand(5);
if (moletype[i]==4)moletype[i]=0;
curtype = moletype[i];
Screen->ComboD[curhole] = this->Data+1;
Screen->ComboC[curhole] = molecsets[curtype];
scets[i]=molecsets[curtype];
timer[i]=poptime;
}
}
else{
Screen->ComboC[curhole] = scets[i];
if (hammer){
cmb = ComboAt (CenterLinkX(), CenterLinkY()-2);
if (cmb==curhole && Link->PressEx1) Screen->ComboD[curhole]=this->Data+3;
}
if (Screen->ComboD[curhole]==this->Data+3){
Game->PlaySound(SFX_WHACKAMOLE_HIT);
int curscore = moletype[i];
curscore = molescore[curscore];
if (curscore<0){
if (curscore<-999){
Game->PlaySound(SFX_WHACKAMOLE_PENALTY2);
score=0;
time=1;
}
else Game->PlaySound(SFX_WHACKAMOLE_PENALTY1);
}
score = Max(score+curscore, 0);
moletype[i]=-1;
scets[i]=-1;
timer[i]=-Rand(cooldown);
}
timer[i]--;
if (timer[i]==0){
Screen->ComboD[curhole] = this->Data+4;
moletype[i]=-1;
scets[i]=-1;
timer[i]=-Rand(cooldown)-1;
}
}
}
if (time>0){
time--;
if (time<=0){
if (score>0)Game->PlaySound(SFX_WHACKAMOLE_GAME_OVER);
for (int i=0;i<16;i++){
if (holes[i]<0)continue;
curhole = holes[i];
if (moletype[i]<0)continue;
Screen->ComboD[curhole] = this->Data+5;
Screen->ComboC[curhole]=this->CSet;
moletype[i]=-1;
scets[i]=-1;
}
Screen->Message(str2);
Waitframe();
if (score>=target){
Game->PlaySound(SFX_SECRET);
Screen->TriggerSecrets();
Screen->State[ST_SECRET]=true;
}
}
}
Screen->DrawString(3, this->X-8, this->Y+8,FONT_WHACKAMOLE, 1, 0, 2, strui1, OP_OPAQUE);
Screen->DrawString(3, this->X-8, this->Y,FONT_WHACKAMOLE, 1, 0, 2, strui2, OP_OPAQUE);
Screen->DrawInteger(3, this->X, this->Y, FONT_WHACKAMOLE,1,0, -1, -1, Floor(time/60), 0, OP_OPAQUE);
Screen->DrawInteger(3, this->X, this->Y+8, FONT_WHACKAMOLE,1,0, -1, -1, score, 0, OP_OPAQUE);
Waitframe();
}
}
}