【WoofJS】アップルキャッチャー
Play demo
サンプルコード
setBackdropURL("./docs/images/bubbles-backdrop.jpeg")
setBackdropStyle("cover")
var apple = new Image({
url: "./docs/images/apple.png",
width: 60,
height: 68
})
var catcher = new Rectangle({
height:35,
width:45,
color:"blue",
y:minY+30,
x:0
})
forever(() => {
if (keysDown.includes('RIGHT')) {
catcher.x += 10;
}
if (keysDown.includes('LEFT')) {
catcher.x -= 10;
}
})
forever(() => {
if (mouseDown && mouseX < 0) {
catcher.x -=10;
}
if (mouseDown && mouseX > 0) {
catcher.x +=10;
}
})
ready(()=>{
apple.x = random(minX, maxX);
apple.y = maxY-30;
forever(() => {
apple.y -=5+ (0.5*level);
});
})
forever(() => {
if (catcher.x >= maxX) {
catcher.x =maxX
}
if (catcher.x <= minX) {
catcher.x =minX
}
})
forever(() => {
if (apple.touching(catcher)) {
apple.x = random(minX, maxX);
apple.y = maxY-30;
score +=1;
}
})
forever(() => {
if (apple.y <minY) {
new Text({
x:0,
y:0,
color:"red",
size:50,
text:"GAME OVER"
})
}
})
var score = 0;
var scoreText = new Text({
y:maxY-60,
x:minX +100,
size:30,
text:()=>'SCORE:' +score
})
var level =1;
var levelText = new Text({
y: maxY - 120,
x: minX +95,
size:30,
text:()=> 'LEVEL:'+level
})
forever(() => {
if (score==5) {
level ++;
score =0;
}
})
この記事が気に入ったらサポートをしてみませんか?