var clock = 100;
$(document).ready(function () {
var timer = window.setInterval(function () {animTimer()}, clock);}
)
var maxw = 430;
var maxh = 760;
// on-clicks
var mode = 0;
var fishes = 0;
// diagonal pointers; maintain direction
var r = false;
var l = false;
var t = false;
var b = false;
$(document).ready(function () {
$(".fish").click(function () {
if (mode < 2) {
mode++;
} else {
mode = 0;
}
fishes++;
$("#score").html("You have " + fishes + " fish.");
fishCheck();
})})
function animTimer() {
moveFish($(".fish"));
}
function moveFish(obj) {
var left = obj.offset().left;
var top = obj.offset().top;
var moveTime = 50;
$("#position").html("The fish is at coordinates " + left + " and " + top + ".");
if (mode == 0) {
lineDiag(obj, moveTime, left, top);
} else if (mode == 1) {
lineStr(obj, moveTime, left, top);
} else {
lineRev(obj, moveTime, left, top);
}
}
function lineDiag (obj, moveTime, left, top) {
if ((left <= 20 || l == true) && left <= maxw && !(top <= 300) ) { // bounce off left wall but keep direction
l = true;
r = false;
t = false;
b = false;
obj.animate({ "left": "+=10px", "top": "-=10px"}, moveTime); // up-right
return;
}
if ((top <= 300 || t == true) && top <= maxh && !(left >= maxw)) { // bounce off top wall
l = false;
r = false;
t = true;
b = false;
obj.animate({ "left": "+=10px", "top": "+=10px"}, moveTime); // down-right
return;
}
if ((left >= maxw || r == true) && !(top >= maxh)) {
l = false;
r = true;
t = false;
b = false;
obj.animate({ "left": "-=10px", "top": "+=10px"}, moveTime); // down-left
return;
}
if ((top >= maxh || b == true) && !(left <= 20)) {
l = false;
r = false;
t = false;
b = true;
obj.animate({ "left": "-=10px", "top": "-=10px"}, moveTime); // up-left
return;
}
obj.animate({ "left": "+=10px", "top": "+=10px"}, moveTime); // if no other instruction, down-right (occurs at start)
return;
}
function lineStr (obj, moveTime, left, top) {
if ((left <= maxw) && (top <= 300)) {
obj.animate({ "left": "+=10px"}, moveTime); // right
return;
}
if ((left >= maxw) && (top <= maxh)) {
obj.animate({ "top": "+=10px"}, moveTime); // down
return;
}
if ((left >= 20) && (top >= maxh)) {
obj.animate({ "left": "-=10px"}, moveTime); // left
return;
}
if ((left <= 20) && (top >= 300)) {
obj.animate({ "top": "-=10px"}, moveTime); // up
return;
}
obj.animate({ "top": "+=10px"}, moveTime); // if off-centered, default to down
return;
}
function lineRev (obj, moveTime, left, top) {
if ((left <= maxw) && (top >= maxh)) {
obj.animate({ "left": "+=10px"}, moveTime); // right
return;
}
if ((left >= maxw) && (top >= 300)) {
obj.animate({ "top": "-=10px"}, moveTime); // up
return;
}
if ((left >= 20) && (top <= 300)) {
obj.animate({ "left": "-=10px"}, moveTime); // left
return;
}
if ((left <= 20) && (top <= maxh)) {
obj.animate({ "top": "+=10px"}, moveTime); // down
return;
}
obj.animate({ "top": "+=10px"}, moveTime); // if off-centered, default to down
return;
}
function fishCheck() {
if (fishes == 25) {
document.getElementById("desc").style.backgroundImage = "url('https://thaddiusstemp.com/tinyfish.png')";
document.getElementById("stats").style.backgroundImage = "url('https://thaddiusstemp.com/tinyfish.png')";
}
if (fishes == 50) {
$("#desc").html("Here is a normal fish of a fish. Click the fish to change the way it fishes.
Click fish times to activate FISH MODE.")
}
if (fishes == 75) {
alert("Fish mode imminent!");
}
if (fishes == 99) {
alert("I tried to warn you...");
}
if (fishes == 100) {
document.body.style.backgroundImage = "url('https://thaddiusstemp.com/tinyfish.png')";
$("#desc").html("Fish fish fish fish fish fish fish fish. Fish fish fish fish fish fish fish fish fishes.
Fish fish fish fish fish FISH MODE.")
}
}