You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

2 years ago
function Paddle(){
this.isRectangle = true;
this.isPaddle = true;
this.move = function(){
if (keyIsDown(LEFT_ARROW) && this.x - strokePadding > 0) this.x -= this.v;
if (keyIsDown(RIGHT_ARROW) && this.x + this.width + strokePadding < wWidth) this.x += this.v;
}
}
var itemCount = 6; //Change if necessary
var FastBall = 1;
var FastPaddle = 2;
var SlowBall = 3;
var SlowPaddle = 4;
var CreateBall = 5;
var UpgradeBricks = 6;
function Item(x, y, radius, v, item){
this.isItem = true;
this.isEllipse = true;
this.x = x;
this.y = y;
this.radius = radius;
this.v = v;
this.item = item;
this.move = function() {this.y += this.v}
}
function Brick(){
this.isRectangle = true;
this.isBrick = true;
}
function Frameborder(x, y, width, height){
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.isRectangle = true;
this.isFrameborder = true;
this.isBrick = false;
}
function Ball(){
this.isEllipse = true;
this.calcVelocityX = function(p, vx){
var divider = (this.x - (p.x - this.radius)) / (p.width + this.radius * 2 + strokePadding * 4); //Number between 0 and 1
var range = divider - 0.5; //Number between -0.5 and 0.5
range = range * this.v.mag / 0.5; //Number between -magnitude and magnitude
range += vx; //Number between -(magnitude+abs(vx)) and magnitude+abs(vx)
newVx = range * this.v.mag / (this.v.mag + abs(vx)); //Number between -magnitude and magnitude
return newVx;
}
this.calcVelocityY = function(){
var vy = sqrt(pow(this.v.mag, 2) - pow(this.v.x, 2)); //Pythagoras to keep velocity constant
return vy;
}
this.isLost = function(){
var b = this;
if (b.y - b.radius > wHeight) return true;
return false;
}
this.move = function(){
this.x += this.v.x;
this.y += this.v.y;
}
}