xxxxxxxxxx
48
var paddle;
function Paddle(){
this.width = 100;
this.height = 20;
this.speed = {
left: createVector(-8, 0),
right: createVector(8, 0)
}
this.position = createVector(
(width/2) - (this.width/2),
height - (this.height * 2)
)
this.draw = function(){
return rect(this.position.x,
this.position.y,
this.width,
this.height
)
}
this.move = function(direction){
return this.position.add(this.speed[direction]);
}
}
function setup() {
createCanvas(400, 400);
background(0);
paddle = new Paddle();
}
function draw() {
if(keyIsDown(LEFT_ARROW)){
paddle.move('left');
}
if(keyIsDown(RIGHT_ARROW)){
paddle.move('right');
}
paddle.draw();
}