xxxxxxxxxx
125
// マウスクリックすると投下します
// ゲームオーバーは実装していません
// p5playのコライダーをそのまま使っていますが、衝突が正しく判定されない場合があります
let fruits;
let dropFruit;
let nextFruit;
let score = 0;
function setup() {
createCanvas(800, 800);
textSize(32);
world.gravity.y = 10;
fruits = new Group();
stageW = 400;
stageH = 600;
floor = new Sprite(400,700,stageW,5);
floor.collider = 'static';
lWall = new Sprite(200,400,5,stageH);
lWall.collider = 'static';
rWall = new Sprite(600,400,5,stageH);
rWall.collider = 'static';
colorList = ['crimson','red','purple','gold','orange','red','yellow','pink','yellowgreen','green','white']
radiusList = [32,40,48,56,64,72,80,88,96,104,0];
nextFruit = new Sprite(700, 150);
let ns = parseInt(random(5));
nextFruit.textSize = ns;
nextFruit.color = colorList[ns];
nextFruit.diameter = radiusList[ns];
nextFruit.collider = 'static';
dropFruit = new Sprite(400, 100);
let ds = parseInt(random(5));
dropFruit.textSize = ds;
dropFruit.color = colorList[ds];
dropFruit.diameter = radiusList[ds];
dropFruit.collider = 'static';
}
function draw() {
background(255,255,240);
text(score, 50, 50);
if ((200 < mouseX) && (mouseX < 600)){
dropFruit.x = mouseX;
} else if (mouseX < 200){
dropFruit.x = 200;
} else {
dropFruit.x = 600;
}
fruits.collide(fruits, (a, b) => {
let as = a.textSize;
if (as == b.textSize){
a.textSize = as + 1;
a.color = colorList[as + 1];
a.diameter = radiusList[as + 1];
b.remove();
switch(as){
case 0:
score += 1;
break;
case 1:
score += 3;
break;
case 2:
score += 6;
break;
case 3:
score += 10;
break;
case 4:
score += 15;
break;
case 5:
score += 21;
break;
case 6:
score += 28;
break;
case 7:
score += 36;
break;
case 8:
score += 45;
break;
case 9:
score += 55;
break;
default:
break;
}
}
});
if (mouse.presses()) {
let f = new Sprite(dropFruit.x, 200);
let s = dropFruit.textSize;
//console.log(s);
f.textSize = s;
f.color = colorList[s];
f.diameter = radiusList[s];
fruits.add(f);
let ds = nextFruit.textSize;
dropFruit.textSize = ds;
dropFruit.color = colorList[ds];
dropFruit.diameter = radiusList[ds];
let ns = parseInt(random(5));
nextFruit.textSize = ns;
nextFruit.color = colorList[ns];
nextFruit.diameter = radiusList[ns];
}
}