Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void collisonHandler(Helicopter h) {
- Rectangle r = h.getBoundingRectangle();
- /*
- * There was some problems with the bounds, so i had to set x pos here too
- */
- this.boundingRectangle.x = this.isFlipped() ? this.position.x + Settings.ANIMATION_WIDTH : this.position.x;
- //r.x = this.isFlipped() ? h.getPosition().x + Settings.ANIMATION_WIDTH : h.getPosition().x;
- if (r.overlaps(this.boundingRectangle)) {
- if (r.y > this.boundingRectangle.y) {
- this.updateVelocityByCollisionY();
- h.updateVelocityByCollisionY();
- }
- if (r.x > this.boundingRectangle.x) {
- System.out.println(this.boundingRectangle.x);
- System.out.println(r.x);
- this.updateVelocityByCollisionX();
- h.updateVelocityByCollisionX();
- }
- }
- }
- private void updateVelocityByCollisionX() {
- this.velocity.x *= -1;
- this.scaleX *= -1;
- this.position.add(this.velocity);
- this.position.add(this.velocity);
- if (!this.isFlipped()) {
- this.position.x += Settings.ANIMATION_WIDTH;
- } else {
- this.position.x -= Settings.ANIMATION_WIDTH;
- }
- }
- private void updateVelocityByCollisionY() {
- this.velocity.y *= -1;
- this.position.add(this.velocity);
- this.position.add(this.velocity);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement