Skip to content

Commit 853cfe7

Browse files
committed
put balloonatic code inside the plant
1 parent 770c8ce commit 853cfe7

File tree

3 files changed

+118
-145
lines changed

3 files changed

+118
-145
lines changed

game/js/CPlants.js

Lines changed: 116 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,41 +2998,130 @@ var oBalloon = InheritO(CPlants, {
29982998
width: 65,
29992999
height: 73,
30003000
beAttackedPointR: 45,
3001-
SunNum: "+75",
3001+
SunNum: "+150",
30023002
coolTime: "Wave",
30033003
HP: 1,
30043004
AlmanacGif: 1,
30053005
PicArr: ["images/Card/Plants/BalloonGoober.png", "images/Zombies/Balloon/0.png", "images/Zombies/Balloon/popped.png"],
30063006
Tooltip: "Drops sun when popped",
30073007
Produce:
3008-
'<font color="#28325A">Balloonatics have a chance to spawn every wave. Popping them produces 75 sun</font>.</font><br><p>Toughness: <font color="CC241D">low</font></p> ">:3" says the Balloonatic. ">:3" says the Balloonatic, again.',
3009-
CanGrow(c, b, f) {
3010-
var a = b + "_" + f;
3011-
var d = c[1];
3012-
var e = oS.ArP;
3013-
return e
3014-
? oGd.$LF[b] === 1
3015-
? f > 0 && f < e.ArC[1] && !(oGd.$Crater[a] || oGd.$Tombstones[a] || d)
3016-
: c[0] && !d
3017-
: d && d.EName === "oBalloon"
3018-
? 1
3019-
: oGd.$LF[b] === 1
3020-
? !(f < 1 || f > 9 || oGd.$Crater[a] || oGd.$Tombstones[a] || d)
3021-
: c[0] && !d;
3008+
'<font color="#28325A">Balloonatics have a chance to spawn every wave. Popping them produces 150 sun</font>.</font><br><p>Toughness: <font color="CC241D">low</font></p> ">:3" says the Balloonatic. ">:3" says the Balloonatic, again.',
3009+
Birth(_1, _2, row, _4) {
3010+
let balloonId = Math.floor(1 + Math.random() * 1000);
3011+
let endMode = "endOfAnimation";
3012+
3013+
function getAnimatedPosition(element) {
3014+
const computedStyle = getComputedStyle(element);
3015+
const left = parseFloat(computedStyle.left);
3016+
const top = parseFloat(computedStyle.top);
3017+
return { left, top };
3018+
}
3019+
3020+
if (!oBalloon.StyleSheet) {
3021+
let dynamicStyle = document.createElement("style");
3022+
document.head.appendChild(dynamicStyle);
3023+
oBalloon.StyleSheet = dynamicStyle.sheet;
3024+
}
3025+
3026+
function getRandomY() {
3027+
if (row) {
3028+
return GetY(row - 2) + 45;
3029+
}
3030+
return GetY(-1 + Math.floor(Math.random() * oS.R)) + 45;
3031+
}
3032+
3033+
let randomY = getRandomY();
3034+
let timeStep = oSym.TimeStep;
3035+
const timeInSec = (ms) => ms / 100;
3036+
const toTicks = (ms) => Math.round(ms / timeStep);
3037+
3038+
oBalloon.StyleSheet.insertRule(`@keyframes moveLeft${balloonId} { from { left: 910px; } to { left: -75px; } }`, oBalloon.StyleSheet.cssRules.length);
3039+
3040+
oBalloon.StyleSheet.insertRule(
3041+
`@keyframes bobbing${balloonId} { 0%, 100% { top: ${randomY}px; } 50% { top: ${randomY + 10}px; } }`,
3042+
oBalloon.StyleSheet.cssRules.length
3043+
);
3044+
3045+
let image = document.createElement("div");
3046+
image.style = `
3047+
background-image: url(images/Zombies/Balloon/balloonidle.png);
3048+
position: absolute;
3049+
display: block;
3050+
left: 875px;
3051+
top: ${randomY}px;
3052+
z-index: 99;
3053+
width: 154px;
3054+
height: 181px;
3055+
scale: 0.6038961039;
3056+
cursor: url(images/interface/Pointer.cur),pointer;
3057+
animation:
3058+
spritesheetIdle ${timeInSec(timeStep * 10)}s steps(30) infinite,
3059+
moveLeft${balloonId} ${timeInSec(timeStep * 130)}s linear,
3060+
bobbing${balloonId} ${timeInSec(timeStep * 20)}s ease-in-out infinite;
3061+
`;
3062+
3063+
EDPZ.appendChild(image);
3064+
3065+
image.onclick = function () {
3066+
image.onclick = null;
3067+
image.style = `
3068+
background-image: url(images/Zombies/Balloon/popped.png);
3069+
position: absolute;
3070+
display: block;
3071+
left: ${getAnimatedPosition(image).left}px;
3072+
top: ${randomY}px;
3073+
z-index: 99;
3074+
width: 154px;
3075+
height: 181px;
3076+
scale: 0.6038961039;
3077+
pointer-events: none;
3078+
animation: spritesheetPop ${timeInSec(timeStep * 10)}s 1 normal forwards steps(21);
3079+
`;
3080+
3081+
image.addEventListener("animationend", () => {
3082+
if (endMode === "endOfAnimation") {
3083+
image.style = `
3084+
background-image: url(images/Zombies/Balloon/popped.png);
3085+
background-position-x: -3080px;
3086+
position: absolute;
3087+
display: block;
3088+
left: ${getAnimatedPosition(image).left}px;
3089+
top: ${randomY}px;
3090+
z-index: 99;
3091+
width: 154px;
3092+
height: 181px;
3093+
scale: 0.6038961039;
3094+
pointer-events: none;
3095+
`;
3096+
endMode = "remove";
3097+
} else {
3098+
image.parentNode.removeChild(image);
3099+
}
3100+
});
3101+
3102+
oSym.addTask(toTicks(300), () => {
3103+
PlaySound2("balloon_pop");
3104+
oSym.addTask(toTicks(150), () => {
3105+
if ($("dSunNum").style.visibility === "") {
3106+
AppearSun(getAnimatedPosition(image).left + 40, randomY + 60, 125, false);
3107+
}
3108+
});
3109+
oSym.addTask(toTicks(2500), () => {
3110+
SetStyle(image, {
3111+
transition: "opacity 0.2s ease",
3112+
opacity: 0,
3113+
});
3114+
3115+
oSym.addTask(toTicks(400), () => {
3116+
image.parentNode.removeChild(image);
3117+
});
3118+
});
3119+
});
3120+
};
3121+
3122+
PlaySound2("ballooninflate");
30223123
},
30233124
InitTrigger() {},
3024-
HurtStatus: 0,
3025-
getHurt(e, b, a) {
3026-
var c = this;
3027-
var d = $(c.id).childNodes[1];
3028-
!(b % 3)
3029-
? (c.HP -= a) < 1
3030-
? c.Die()
3031-
: c.HP < 1334
3032-
? c.HurtStatus < 2 && ((c.HurtStatus = 2), (d.src = "images/Card/Plants/BalloonGoober.png"))
3033-
: c.HP < 2667 && c.HurtStatus < 1 && ((c.HurtStatus = 1), (d.src = "images/Zombies/Balloon/popped.png"))
3034-
: c.Die(1);
3035-
},
30363125
});
30373126
var oCattail = InheritO(oPeashooter, {
30383127
EName: "oCattail",

game/js/Cfunction.js

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -879,125 +879,9 @@ var oP = {
879879
};
880880
}
881881
},
882-
Balloon() {
883-
let balloonId = Math.floor(1 + Math.random() * 1000);
884-
let endMode = "endOfAnimation";
885-
886-
function getAnimatedPosition(element) {
887-
const computedStyle = getComputedStyle(element);
888-
const left = parseFloat(computedStyle.left);
889-
const top = parseFloat(computedStyle.top);
890-
return { left, top };
891-
}
892-
893-
if (!oP.balloonStyleSheet) {
894-
let dynamicStyle = document.createElement("style");
895-
document.head.appendChild(dynamicStyle);
896-
oP.balloonStyleSheet = dynamicStyle.sheet;
897-
}
898-
899-
function getRandomY() {
900-
let randomY = GetY(Math.floor(1 + Math.random() * oS.R));
901-
if (randomY > 430) {
902-
return getRandomY();
903-
}
904-
return randomY;
905-
}
906-
907-
let randomY = getRandomY();
908-
let timeStep = oSym.TimeStep;
909-
const timeInSec = (ms) => ms / 100;
910-
const toTicks = (ms) => Math.round(ms / timeStep);
911-
912-
oP.balloonStyleSheet.insertRule(`@keyframes moveLeft${balloonId} { from { left: 910px; } to { left: -75px; } }`, oP.balloonStyleSheet.cssRules.length);
913-
914-
oP.balloonStyleSheet.insertRule(
915-
`@keyframes bobbing${balloonId} { 0%, 100% { top: ${randomY}px; } 50% { top: ${randomY + 10}px; } }`,
916-
oP.balloonStyleSheet.cssRules.length
917-
);
918-
919-
let image = document.createElement("div");
920-
image.style = `
921-
background-image: url(images/Zombies/Balloon/balloonidle.png);
922-
position: absolute;
923-
display: block;
924-
left: 875px;
925-
top: ${randomY}px;
926-
z-index: 99;
927-
width: 154px;
928-
height: 181px;
929-
scale: 0.6038961039;
930-
cursor: url(images/interface/Pointer.cur),pointer;
931-
animation:
932-
spritesheetIdle ${timeInSec(timeStep * 10)}s steps(30) infinite,
933-
moveLeft${balloonId} ${timeInSec(timeStep * 130)}s linear,
934-
bobbing${balloonId} ${timeInSec(timeStep * 20)}s ease-in-out infinite;
935-
`;
936-
937-
$("dPZ").appendChild(image);
938-
939-
image.onclick = function () {
940-
image.onclick = null;
941-
image.style = `
942-
background-image: url(images/Zombies/Balloon/popped.png);
943-
position: absolute;
944-
display: block;
945-
left: ${getAnimatedPosition(image).left}px;
946-
top: ${randomY}px;
947-
z-index: 99;
948-
width: 154px;
949-
height: 181px;
950-
scale: 0.6038961039;
951-
pointer-events: none;
952-
animation: spritesheetPop ${timeInSec(timeStep * 10)}s 1 normal forwards steps(21);
953-
`;
954-
955-
image.addEventListener("animationend", () => {
956-
if (endMode === "endOfAnimation") {
957-
image.style = `
958-
background-image: url(images/Zombies/Balloon/popped.png);
959-
background-position-x: -3080px;
960-
position: absolute;
961-
display: block;
962-
left: ${getAnimatedPosition(image).left}px;
963-
top: ${randomY}px;
964-
z-index: 99;
965-
width: 154px;
966-
height: 181px;
967-
scale: 0.6038961039;
968-
pointer-events: none;
969-
`;
970-
endMode = "remove";
971-
} else {
972-
image.parentNode.removeChild(image);
973-
}
974-
});
975-
976-
oSym.addTask(toTicks(300), () => {
977-
PlaySound2("balloon_pop");
978-
oSym.addTask(toTicks(150), () => {
979-
if ($("dSunNum").style.visibility === "") {
980-
AppearSun(getAnimatedPosition(image).left + 40, randomY + 60, 125, false);
981-
}
982-
});
983-
oSym.addTask(toTicks(2500), () => {
984-
SetStyle(image, {
985-
transition: "opacity 0.2s ease",
986-
opacity: 0,
987-
});
988-
989-
oSym.addTask(toTicks(400), () => {
990-
image.parentNode.removeChild(image);
991-
});
992-
});
993-
});
994-
};
995-
996-
PlaySound2("ballooninflate");
997-
},
998882
AddZombiesFlag(d) {
999883
if (Math.floor(Math.random() * 5) === 1 && $("dSunNum").style.visibility === "") {
1000-
oP.Balloon();
884+
oBalloon.prototype.Birth();
1001885
}
1002886
const self = oP;
1003887
const largeFlags = oS.LargeWaveFlag;

game/js/Cheatcodes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let cheatCodes = {
66
CSpeed(1000, 10, 1000);
77
},
88
balloon: () => {
9-
oP.Balloon();
9+
oBalloon.prototype.Birth();
1010
},
1111
restartlevel: () => {
1212
SelectModal(oS.Lvl);

0 commit comments

Comments
 (0)