android - Dynamic Methods for Collision Handler in Java -


i want have set collision handeler game dont have copy alot of code , keep storage short. in method have in class, 2 specific objects.

   //inside collision class         public void checkcollision(block block, ball ball){    //do stuff variables given    } 

this mean can check collisions block + ball

my question is: possible able change object given example can use same method , parse in objects e.g. floor object , ball use block , ball.

also floor not avalible cant parse in block , ball if wants three

it save me having put in

    public void collision(block block, floor floor, ball ball){     } 

please ask if not understand, many

charlton santana

what if had method this:

// ... public void checkcollision(collidable a, collidable b) {     a.collidewith(b); } 

and interface

public interface collidable {      somereturntype collidewith(collidable coll); } 

in case can collide collidable 1 handling collision in collidewith method.

this idea not yet clear how want achieve effect. if extend answer can further.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -