SketchBook

fuyuyasumi

//変数
var x = 150
var y = 650
var box1x = 10
var box1y = 0
var box2x = 10
var box2y = 0
var box3x = 10
var box3y = 0
var box4x = 10
var box4y = 0
var box5x = 10
var box5y = 0
var hit = 0
var score = 0
var touched = 0
var WIDTH = 400
var HEIGHT = 700
let targetx = x;

//スプライトを表示
function setup(){
createCanvas(WIDTH,HEIGHT);
background(255,255,255);
rect(box1x,box1y,30,300);
rect(box2x,box2y,30,300);
rect(box3x,box3y,30,300);
rect(box4x,box4y,30,300);
rect(box5x,box5y,30,300);

}

//メイン
function draw(){
if (box1x >= WIDTH){
box1x = 1
}
if (box1x <= WIDTH){
box1x = WIDTH
}
if (hit == 5){
alert("お疲れ様でした。あなたのスコアは:" + score)
}
background(255,255,255);
x = lerp(x,targetx,0.1);
//自機を表示
rect(x,y,50,50);
//----------------------------------------------
//敵機が動く
box1y = box1y + 8
//敵機の表示
rect(box1x,box1y,30,300);
//敵機のリスポーン
if (box1y > HEIGHT){
box1y = 50
box1x = random(0,400)
score = score + 256
}
//当たり判定
if (x + 25 > box1x && x < box1x + 30 && y + 25 > box1y && y < box1y + 300){
hit = hit + 1
}
//-----------------------------------------------
//----------------------------------------------
//敵機が動く
box2y = box2y + 8
//敵機の表示
rect(box2x,box2y,30,300);
//敵機のリスポーン
if (box2y > HEIGHT){
box2y = 50
box2x = random(0,400)
score = score + 256
}
//当たり判定
if (x + 25 > box2x && x < box2x + 30 && y + 25 > box2y && y < box2y + 300){
hit = hit + 1
}
//-----------------------------------------------
//----------------------------------------------
//敵機が動く
box3y = box3y + 8
//敵機の表示
rect(box3x,box3y,30,300);
//敵機のリスポーン
if (box3y > HEIGHT){
box3y = 50
box3x = random(0,400)
score = score + 256
}
//当たり判定
if (x + 25 > box3x && x < box3x + 30 && y + 25 > box3y && y < box3y + 300){
hit = hit + 1
}
//-----------------------------------------------
//----------------------------------------------
//敵機が動く
box4y = box4y + 8
//敵機の表示
rect(box4x,box4y,30,300);
//敵機のリスポーン
if (box4y > HEIGHT){
box4y = 50
box4x = random(0,400)
score = score + 256
}
//当たり判定
if (x + 25 > box4x && x < box4x + 30 && y + 25 > box4y && y < box4y + 300){
hit = hit + 1
}
//-----------------------------------------------
//----------------------------------------------
//敵機が動く
box5y = box5y + 8
//敵機の表示
rect(box5x,box5y,30,300);
//敵機のリスポーン
if (box5y > HEIGHT){
box5y = 50
box5x = random(0,400)
score = score + 256
}
//当たり判定
if (x + 25 > box5x && x < box5x + 30 && y + 25 > box5y && y < box5y + 300){
hit = hit + 1
}
//-----------------------------------------------

}





//自機の操作
function keyPressed() {
if (keyCode === LEFT_ARROW) {
targetx -= 25;
} else if (keyCode === RIGHT_ARROW) {
targetx += 25;
}
}