new checkCollision()

public void checkCollision(Dimension panelSize) { Rectangle2D.Double top = new Rectangle2D.Double(0, -10, panelSize.width, 10); Rectangle2D.Double bottom = new Rectangle2D.Double(0, panelSize.height, panelSize.width, 10); Rectangle2D.Double left = new Rectangle2D.Double(-10, 0, 10, panelSize.height); Rectangle2D.Double right = new Rectangle2D.Double(panelSize.width, 0, 10, panelSize.height); if (getBoundary().intersects(left) && speed.x < 0) speed.x *= -1; if (getBoundary().intersects(right) && speed.x > 0) speed.x *= -1; if (getBoundary().intersects(top) && speed.y < 0) speed.y *= -1; if (getBoundary().intersects(bottom) && speed.y > 0) speed.y *= -1; }
IAT 265 (Fall 2017)
Lab 05 Code

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.