Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void moveLeft(){
- x -= speed;
- if(isCollision(player)) {
- x += speed + 1;
- }
- /*
- for (Rectangle v : myArr) {
- if (player.getX()>v.getX()+v.getWidth()) {
- x -= speed;
- }
- }
- */
- }
- public void moveRight(){
- x += speed;
- if(isCollision(player)) {
- x -= speed + 1;
- }
- /*
- for (Rectangle v : myArr) {
- if (player.getX()+player.getWidth()<v.getX()) {
- x += speed;
- }
- }
- */
- }
- private boolean isCollision(Rectangle object) {
- boolean collision = false;
- for(Rectangle rectangle : myArr) {
- if(object.intersects(rectangle)) {
- collision = true;
- break;
- }
- }
- return collision;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement