Управляемый шар
Поедай маленькие шары и расти
by twobomb three
CSS
html,body{
margin:0;
padding:0;
height:100%;
width:100%;
}
canvas{
outline:1px solid red;
}
JavaScript
var canvas, ctxW = 500,
ctxH = 300,
ctx,deltaTIme = 0,lTime = 0,player,keydown=[false,false],balls = [],maxBalls = 200;
Number.prototype.toRadian = function(){
return this * (Math.PI/180);
}
Number.prototype.toRadian = function(){
return this * (Math.PI/180);
}
window.onload = function() {
alert("Управление стрелками(удерживать)\nВверх\Вниз - скорость\nВлево\Вправо - поворот\nЦель собирать шарики чтобы увеличиваться")
canvas = document.createElement("canvas");
canvas.height = ctxH = document.body.clientHeight;
canvas.width = ctxW =document.body.clientWidth;
canvas.style.width = canvas.style.height = "99%";
document.body.appendChild(canvas);
ctx = canvas.getContext("2d");
player = new ball(50,50,20,"#F00",100);
player.otherCollision = function(){
for(var i = 0; i < balls.length;i++)
if(getDist(player.x,player.y,balls[i].x,balls[i].y) - player.radius+balls[i].radius*2 < 0){
player.radius+= balls[i].radius/10;
if(player.radius > 100)
player.radius = 100;
balls.splice(i--,1);
}
}
handler();
}
function ball(x,y,r,color,speed){
this.x = x;
this.y = y;
this.radius = r;
this.color = color;
this.angle = 0;
this.speed = 0 || speed;
this.stepAngle = 2;
this.stepSpeed = 2;
this.minSpeed = 50;
this.maxSpeed = 300;
this.move = function(){
if(keydown[0] == "l")
this.angle = (this.angle-this.stepAngle)%360;
else if(keydown[0] == "r")
this.angle = (this.angle+this.stepAngle)%360;
if(keydown[1] == "u")
this.speed = this.speed + this.stepSpeed > this.maxSpeed?this.maxSpeed:this.speed + this.stepSpeed;
else if(keydown[1] == "d")
this.speed = this.speed -...