//Scratchの学習パターン「Flying」のサンプルです
//https://scratch.mit.edu/search/projects?q=Cat%20Flying
//はたをクリックでニューゲーム
//キーボードの a キーでとびます

var bg = new Backdrop("img/bg1.png");

var building = new Sprite(200, -100, "img/building_1.svg");

var cat = new Sprite(0, 0, "img/plane.svg");

var text = new Sprite(0, 0, "img/game_over.svg");

building.addCostume("img/building_2.svg");

building.addCostume("img/building_3.svg");

var score = 0;

var y_speed = 0;

var energy = 0;

var high_score = 0;

text.hide();

cat.onGreenFlag( function(){
	score = 0;
	y_speed = 0;
	cat.goTo(0, 0);
	wait(1);
	forever {
		if (isKeyPressed('a')){
			y_speed += 1;
			energy -= 1;
		} else {
			y_speed -= 1;
		}
		cat.changeY(y_speed);
		if (cat.isTouching(building)){
			broadcastAndWait("end");
			if (high_score < score){
				high_score = score;
			}
			stop("all");
		}
		score += 1;
	}
});

building.onGreenFlag( function(){
	forever {
		building.nextCostume();
		building.goTo(240, -100);
		building.glideSecTo(10, -240, -100);
	}
});

text.onGreenFlag( function(){
	text.hide();
	hideVar(high_score);
});

text.onReceive("end", function(){
	text.show();   
	showVar(high_score);
});


