new checkCollision() - gracefully turn

public void checkCollision(Dimension panelSize) { double margin = 100; Rectangle2D.Double top = new Rectangle2D.Double(-margin, -margin, panelSize.width+margin*2, margin); Rectangle2D.Double bottom = new Rectangle2D.Double(-margin, panelSize.height, panelSize.width+margin*2, margin); Rectangle2D.Double left = new Rectangle2D.Double(-margin, -margin, margin, panelSize.height+margin*2); Rectangle2D.Double right = new Rectangle2D.Double(panelSize.width, -margin, margin, panelSize.height+margin*2); float coef = .1f; PVector acceleration = new PVector(); if (getBoundary().intersects(left)) acceleration = new PVector(1,0); else if (getBoundary().intersects(right)) acceleration = new PVector(-1,0); else if (getBoundary().intersects(top)) acceleration = new PVector(0,1); else if (getBoundary().intersects(bottom)) acceleration = new PVector(0,-1); acceleration.mult(coef*maxSpeed); speed.add(acceleration); }
IAT 265 (Fall 2017)
Snippets for Lab 6

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.