From 94e519c078a5ae909e0ac41e5216e55ae39490ce Mon Sep 17 00:00:00 2001 From: Simon Giesel Date: Tue, 20 Jun 2017 14:25:53 +0200 Subject: [PATCH] Hole detection --- index.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index d350688..72b36db 100644 --- a/index.html +++ b/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