Hole detection
This commit is contained in:
parent
ea64de94a6
commit
94e519c078
1 changed files with 14 additions and 4 deletions
18
index.html
18
index.html
|
@ -18,7 +18,8 @@ var ctx,
|
|||
pX,
|
||||
pY,
|
||||
bVec,
|
||||
borders = []
|
||||
borders = [],
|
||||
hole = []
|
||||
|
||||
/************************/
|
||||
/*** _GAME VARIABLES_ ***/
|
||||
|
@ -32,7 +33,8 @@ var _COLOR_GRASS = '#388E3C',
|
|||
|
||||
var _MAX_BRACKET = 100,
|
||||
_BALL_SPEED = 100,
|
||||
_BALL_SPEED_THRESHOLD = 10
|
||||
_BALL_SPEED_THRESHOLD = 10,
|
||||
_HOLE_WIDTH = 15
|
||||
|
||||
$(function(){
|
||||
ctx = $('canvas')[0].getContext('2d')
|
||||
|
@ -43,7 +45,8 @@ var _COLOR_GRASS = '#388E3C',
|
|||
drawBorder(23+200, 10+70, 50, 50)
|
||||
drawBorder(23, 500+10-10, 500, 10)
|
||||
drawBorder(500+23-10, 10, 10, 500)
|
||||
drawHole(432, 366)
|
||||
// drawHole(432, 366)
|
||||
drawHole(140, 100)
|
||||
setInterval(animLoop, 5)
|
||||
|
||||
$(document).mousemove(function(e){
|
||||
|
@ -82,6 +85,7 @@ var _COLOR_GRASS = '#388E3C',
|
|||
if(bVec != null){
|
||||
collide()
|
||||
drawBall(bX = bX-bVec[0], bY = bY-bVec[1])
|
||||
checkHole()
|
||||
}
|
||||
else
|
||||
drawBall(bX, bY)
|
||||
|
@ -117,10 +121,11 @@ var _COLOR_GRASS = '#388E3C',
|
|||
|
||||
function drawHole(x, y) {
|
||||
staticctx.beginPath()
|
||||
staticctx.arc(x, y, 20, 0, Math.PI*2)
|
||||
staticctx.arc(x, y, _HOLE_WIDTH, 0, Math.PI*2)
|
||||
staticctx.fillStyle = _COLOR_HOLE
|
||||
staticctx.fill()
|
||||
staticctx.closePath()
|
||||
hole = [x, y]
|
||||
}
|
||||
|
||||
function drawBall(x, y) {
|
||||
|
@ -192,6 +197,11 @@ var _COLOR_GRASS = '#388E3C',
|
|||
}
|
||||
}
|
||||
|
||||
function checkHole() {
|
||||
if(bX >= hole[0]-_HOLE_WIDTH/2 && bX <= hole[0]+_HOLE_WIDTH/2 && bY >= hole[1] && bY-_HOLE_WIDTH/2 <= hole[1]+_HOLE_WIDTH/2)
|
||||
alert('Hole')
|
||||
}
|
||||
|
||||
/** CLASSES **/
|
||||
function Border(x, y, width, height) {
|
||||
this.x = x
|
||||
|
|
Reference in a new issue