Created
July 27, 2017 13:02
-
-
Save bsorrentino/4fb5c4f5c78637803d8fd47b572f7a28 to your computer and use it in GitHub Desktop.
GA 2D engine - hitTestCircleRectangle issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <meta charset = "utf-8"> | |
| <title>SUBMARINE</title> | |
| <body> | |
| <script src="ga.js"></script> | |
| <script src="plugins.js"></script> | |
| <script type="text/javascript"> | |
| var SZ = 8; | |
| var g = new ga( 80*SZ, 60*SZ, setup); | |
| g.start(); | |
| var sea, | |
| bombs | |
| ; | |
| function setup() { | |
| g.backgroundColor = "white"; | |
| g.canvas.style.border = "1px black dashed"; | |
| var deepY = 9*SZ; | |
| var deep = g.rectangle( g.canvas.width, g.canvas.height - deepY, "cyan" ); | |
| deep.setPosition( 0, deepY ); | |
| var horizon = g.line( "blue", 1, 0, deep.y+1, deep.width, deep.y+1); | |
| sea = g.group( deep, horizon ); | |
| sea.interactive = false; | |
| var b1 = g.circle( 10, "red"); | |
| var b2 = g.circle( 10, "black"); | |
| b1.setPosition( 130, deep.y ); | |
| b2.setPosition( 330, deep.y ); | |
| bombs = [ b1, b2 ]; | |
| g.state = play; | |
| } | |
| function b_play( b ) { | |
| var hit = g.hitTestCircleRectangle( b, sea.children[0] ); | |
| if( hit ) { | |
| b.vy = 1 | |
| g.move(b); | |
| } | |
| else { | |
| b.visible = false; | |
| } | |
| } | |
| function play() { | |
| bombs.forEach( b_play ); | |
| } | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment