🎮ArcadeLab

My ArcadeLab creator code is GOOFY-VIPER-BLADE-14 — it's how

by QuantumOtter56
115 lines2.4 KB🛠️ p5.js (creative coding)
▶ Play
let gameState = 0; let myTeam = ""; let targetProvince = ""; const provinceList = ["山东", "河北", "江苏", "山西", "河南", "湖北", "广东"]; let soldiers = []; let resultText = "";
function setup() {
createCanvas(700, 450);
textAlign(CENTER, CENTER);
textSize(22);
}
 
function draw() {
background(46, 64, 37);
 
if (gameState === 0) {
fill(255);
text("请选择作战阵营", width / 2, 70);
drawBtn(220, 160, 260, 70, "#216ed8", "中国军");
drawBtn(220, 260, 260, 70, "#c62828", "日本军");
}
 
else if (gameState === 1) {
fill(255);
text("请选择作战省份", width / 2, 60);
let startY = 110;
for (let i = 0; i < provinceList.length; i++) {
drawBtn(230, startY, 240, 40, "#555", provinceList[i]);
startY += 48;
}
}
 
else if (gameState === 2) {
fill(255);
text( ${myTeam} · ${targetProvince} 战场 , width / 2, 40);
updateSoldiers();
drawSoldiers();
if (resultText !== "") {
fill(255, 230, 0);
textSize(26);
text(resultText, width / 2, height / 2);
}
}
}
 
function drawBtn(x, y, w, h, color, txt) {
fill(color);
rect(x, y, w, h, 8);
fill(255);
text(txt, x + w / 2, y + h / 2);
if (mouseIsPressed && mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h) {
if (gameState === 0) {
myTeam = txt;
gameState = 1;
}
else if (gameState === 1) {
targetProvince = txt;
gameState = 2;
initBattle();
}
}
}
 
function initBattle() {
soldiers = [];
resultText = "";
for (let i = 0; i < 12; i++) {
soldiers.push({
team: "our",
x: 60,
y: 100 + i * 28,
hp: 2
});
}
for (let i = 0; i < 12; i++) {
soldiers.push({
team: "enemy",
x: 640,
y: 100 + i * 28,
hp: 2
});
}
}
 
function updateSoldiers() {
let ourAlive = soldiers.filter(s => s.team === "our" && s.hp > 0).length;
let enemyAlive = soldiers.filter(s => s.team === "enemy" && s.hp > 0).length;
if (ourAlive === 0) {
resultText = myTeam === "日本军" ? "占领成功!" : "阵地失守!";
return;
}
if (enemyAlive === 0) {
resultText = myTeam === "中国军" ? "成功守住省份!" : "进攻失败!";
return;
}
for (let s of soldiers) {
if (s.hp <= 0) continue;
if (s.team === "our") {
s.x += 0.8;
} else {
s.x -= 0.8;
}
for (let t of soldiers) {
if (t.hp <= 0 || s.team === t.team) continue;
let dist = abs(s.x - t.x);
if (dist < 30) {
t.hp -= 0.03;
}
}
}
}
 
function drawSoldiers() {
for (let s of soldiers) {
if (s.hp <= 0) continue;
if (s.team === "our") fill(33, 110, 216);
else fill(198, 40, 40);
rect(s.x, s.y, 16, 24);
}
}

Game Source: My ArcadeLab creator code is GOOFY-VIPER-BLADE-14 — it's how

Creator: QuantumOtter56

Libraries: p5

Complexity: moderate (115 lines, 2.4 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: my-arcadelab-creator-code-is-goofy-viper-quantumotter56" to link back to the original. Then publish at arcadelab.ai/publish.