-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaddle.js
46 lines (43 loc) · 963 Bytes
/
paddle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var Paddle = function(){
var image = imageFromPath( 'images/paddle.png' )
var o = {
image: image,
speed: 10,
x: 150,
y: 550,
alive: true
}
var canvas = document.querySelector("#id-canvas")
o.moveLevel = function( x ){
if( x < 0 ){
x = 0
}
else if( x > canvas.width - o.image.width ){
o.x = canvas.width - o.image.width
}
else o.x = x
}
o.moveUpright = function( y ){
if( y < 0 ){
y = 0
}
else if( y > canvas.height - o.image.height ){
console.log("o.image.height"+o.image.height)
o.y = canvas.height - o.image.height
}
else o.y = y
}
o.moveRight = function(){
o.moveLevel( o.x + o.speed )
}
o.moveLeft = function(){
o.moveLevel( o.x - o.speed )
}
o.moveUp = function(){
o.moveUpright( o.y - o.speed )
}
o.moveDown = function(){
o.moveUpright( o.y + o.speed )
}
return o
}