1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
// Brain Party
// Copyright (C) 2010 Paul Hudson (http://www.tuxradar.com/brainparty)
// Brain Party is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "sharpshooter.h"
#include "Minigame.h"
BPMiniGame_Sharpshooter::BPMiniGame_Sharpshooter(BPGame* game) : BPMiniGame(game) {
sfcBackground = TheGame->LoadBitmap("sharpshooter", 320, 416);
sfcTarget = TheGame->LoadBitmap("target", 64, 64);
sfcDontShoot = TheGame->LoadBitmap("marble_red", 64, 64);
Positions.Add(new BPPoint(20, 28));
Positions.Add(new BPPoint(120, 28));
Positions.Add(new BPPoint(220, 28));
Positions.Add(new BPPoint(70, 98));
Positions.Add(new BPPoint(170, 98));
Positions.Add(new BPPoint(20, 168));
Positions.Add(new BPPoint(120, 168));
Positions.Add(new BPPoint(220, 168));
Positions.Add(new BPPoint(70, 238));
Positions.Add(new BPPoint(170, 238));
Positions.Add(new BPPoint(20, 308));
Positions.Add(new BPPoint(120, 308));
Positions.Add(new BPPoint(220, 308));
LastCreatedTime = NumTargets = NumHit = 0;
CreateDelay = 500;
TargetLife = 1700;
PauseTime = 0;
SuccessTime = -1;
GameTitle = "Sharpshooter";
GameHelp = "Tap the screen to shoot as many targets as you can, but watch out - shooting bubbles will cost you points!";
GameHelp2 = "When shooting the targets, don't worry about ammo: you have infinite shots, and firing more doesn't lower your score. For maximum points, don't miss any targets!";
MiniGameType = ACTION;
}
BPMiniGame_Sharpshooter::~BPMiniGame_Sharpshooter() {
SAFE_DELETE(sfcBackground);
SAFE_DELETE(sfcTarget);
SAFE_DELETE(sfcDontShoot);
Targets.Clear();
Positions.Clear();
}
void BPMiniGame_Sharpshooter::Start() {
LastCreatedTime = TheGame->TickCount + 2000;
}
int BPMiniGame_Sharpshooter::GetWeight() {
int nummissed = 64 - NumHit;
return MinMax(500 - (nummissed * 6));
}
void BPMiniGame_Sharpshooter::Render() {
TheGame->DrawImage(sfcBackground, 0, 0);
for (int i = 0; i < Targets.Count; ++i) {
BPMiniGame_Sharpshooter_Target* target = Targets[i];
if (target->HitTime != -1 || target->CreatedTime + 150 > TheGame->TickCount) {
float diff;
if (target->HitTime == -1) {
// target is appearing
diff = (((target->CreatedTime + 150) - TheGame->TickCount) / 150.0f);
} else {
// target is disappearing
diff = (TheGame->TickCount - target->HitTime) / 150.0f;
}
if (diff > 1) diff = 1;
Colour col = Colour(1.0f, 1.0f, 1.0f, TheGame->Lerp(1.0f, 0, diff));
if (target->HitTime != -1) {
diff = 1 - diff;
}
if (target->TargetType == -1) {
TheGame->DrawImage(sfcTarget, target->X + sfcTarget->HalfWidth, target->Y + sfcTarget->HalfHeight, 0.0f, diff, col);
} else {
TheGame->DrawImage(sfcDontShoot, target->X + sfcTarget->HalfWidth, target->Y + sfcTarget->HalfHeight, 0.0f, diff, col);
}
} else {
if (target->TargetType == -1) {
TheGame->DrawImage(sfcTarget, target->X + sfcTarget->HalfWidth, target->Y + sfcTarget->HalfHeight, 0, 1.0f, (*TheGame->White));
} else {
TheGame->DrawImage(sfcDontShoot, target->X + sfcTarget->HalfWidth, target->Y + sfcTarget->HalfHeight, 0, 1.0f, (*TheGame->White));
}
}
}
}
void BPMiniGame_Sharpshooter::Tick() {
if (SuccessTime != -1 && SuccessTime + 500 < TheGame->TickCount) {
Success();
}
if (LastCreatedTime + CreateDelay + PauseTime < TheGame->TickCount) {
switch (TheGame->RandomRange(0, 5)) {
case 0:
case 1:
case 2:
case 3:
CreateTarget(-1);
break;
case 4:
case 5:
CreateTarget(1);
break;
case 6:
// take a breather
break;
}
}
for (int i = Targets.Count - 1; i >= 0; --i) {
BPMiniGame_Sharpshooter_Target* target = Targets[i];
if (target->HitTime != -1 && target->HitTime + 150 < TheGame->TickCount) {
Targets.RemoveAt(i);
continue;
}
if (target->CreatedTime != -1 && target->CreatedTime + TargetLife < TheGame->TickCount) {
if (target->HitTime == -1) {
target->HitTime = TheGame->TickCount;
}
}
}
}
void BPMiniGame_Sharpshooter::OnMouseDown() {
for (int i = Targets.Count - 1; i >= 0; --i) {
BPMiniGame_Sharpshooter_Target* target = Targets[i];
if (target->HitTime != -1) continue;
float distance = BPPoint::DistanceSquared(TouchEvent, BPPoint(target->X + sfcTarget->HalfWidth, target->Y + sfcTarget->HalfWidth));
if (distance < sfcTarget->HalfWidth * sfcTarget->HalfWidth) {
if (target->TargetType == -1) {
target->HitTime = TheGame->TickCount;
++NumHit;
TheGame->PlaySound("gun2");
} else {
target->HitTime = TheGame->TickCount;
NumHit -= 5;
TheGame->PlaySound("zap");
}
target->Hit = true;
return;
}
}
// if we're still here, it means we hit nothing - play the quieter of the two gun sounds
TheGame->PlaySound("gun1");
}
void BPMiniGame_Sharpshooter::OnMouseMove() {
}
void BPMiniGame_Sharpshooter::OnMouseUp() {
}
void BPMiniGame_Sharpshooter::CreateTarget(int type) {
if (NumTargets > 64) {
// create no more targets
if (Targets.Count == 0 && SuccessTime == -1) SuccessTime = TheGame->TickCount;
return;
}
if (TheGame->RandomRange(0, 4) == 2) {
PauseTime = 2000;
} else {
PauseTime = 0;
}
Positions.Shuffle();
int i;
bool usethis;
for (i = 0; i < Positions.Count; ++i) {
// find the first free position
usethis = true;
for (int j = 0; j < Targets.Count; ++j) {
if (Targets[j]->X == Positions[i]->X && Targets[j]->Y == Positions[i]->Y) {
usethis = false;
break;
}
}
if (usethis) break;
}
if (!usethis) {
// no free spaces!
return;
}
BPMiniGame_Sharpshooter_Target* target = new BPMiniGame_Sharpshooter_Target();
target->CreatedTime = TheGame->TickCount;
target->X = Positions[i]->X;
target->Y = Positions[i]->Y;
target->TargetType = type;
Targets.Add(target);
LastCreatedTime = TheGame->TickCount;
CreateDelay -= 2;
++NumTargets;
}
|