Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //x and y are position of player and vx and vy are the velocities in respective directions
- public void tick() {
- x+=vx;
- y+=vy;
- collision();
- //movement
- //...
- }
- private void collision() {
- for(int i = 0; i< handler.object.size(); i++) {
- GameObject tempObject = handler.object.get(i);
- if(tempObject.getId() == ID.Block) {
- if(getBounds().intersects(tempObject.getBounds())) {
- x +=-vx;
- y +=-vy;
- }
- } //...
- public Rectangle getBounds() {
- return new Rectangle((int)x,(int)y,32,32);
- }
Add Comment
Please, Sign In to add comment