Guest User

Untitled

a guest
Nov 13th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. //x and y are position of player and vx and vy are the velocities in respective directions
  2. public void tick() {
  3. x+=vx;
  4. y+=vy;
  5.  
  6. collision();
  7. //movement
  8. //...
  9. }
  10. private void collision() {
  11. for(int i = 0; i< handler.object.size(); i++) {
  12. GameObject tempObject = handler.object.get(i);
  13.  
  14. if(tempObject.getId() == ID.Block) {
  15. if(getBounds().intersects(tempObject.getBounds())) {
  16. x +=-vx;
  17. y +=-vy;
  18. }
  19.  
  20. } //...
  21. public Rectangle getBounds() {
  22. return new Rectangle((int)x,(int)y,32,32);
  23. }
Add Comment
Please, Sign In to add comment