【WoofJS】Flappy bird
Play demo
サンプルコード
setBackdropURL("./docs/images/flappyback.png")
setBackdropStyle("cover")
var bird = new Image({
url: "./docs/images/bird.png",
width: 60,
height: 40,
x:0,
y:0
})
forever(() => {
bird.y -=2;
})
onMouseDown(() => {
bird.setRotationStyle('NO ROTATE')
bird.angle = UP;
bird.move(50);
})
pipes =[]
every(3, 'second', () => {
var pipe_1 = new Image({
url: "./docs/images/bottomPipe.png",
width: 100,
height: 500,
x:maxX,
y:random(minY,-70)
})
var pipe_2 = new Image({
url:"./docs/images/topPipe.png",
width: 100,
height: 500,
X:maxX,
y:pipe_1.y +680
})
pipes.push(pipe_1);
pipes.push(pipe_2);
})
forever(() => {
pipes.forEach(pipe => {
pipe.x -=3
if(pipe.x < minX){
pipe.delete();
}
})
})
var score = 0
var scoreText = new Text({
size:30,
x:minX + 70,
y:maxY -30,
text:()=> "SCORE:" +score
})
scoreText.sendToFront()
forever(() => {
pipes.forEach(pipe =>{
if(pipe.x < bird.x && pipe.x > bird.x -5){
score += 0.5;
}
})
})
var gameOver = new Text({
x:0,
y:0,
size:50,
text:"GAME OVER",
color:"red",
showing: false
})
gameOver.sendToFront()
forever(() => {
if(bird.y < minY){
gameOver.showing = true;
}
})
forever(() => {
pipes.forEach(pipe => {
if(pipe.touching(bird)){
gameOver.showing = true;
freeze()
}
})
})
この記事が気に入ったらサポートをしてみませんか?