Collision Detection between two images in Java

前端 未结 9 1958
情歌与酒
情歌与酒 2020-11-27 06:53

I have two characters displayed in a game I am writing, the player and the enemy. defined as such:

public void player(Graphics g) {
    g.drawImage(plimg, x,         


        
9条回答
  •  不知归路
    2020-11-27 07:41

    No need to use rectangles ... compare the coordinates of 2 players constantly.

    like if(x1===x&&y1==y) remember to increase the range of x when ur comparing.

    if ur rectangle width is 30 take as if (x1>x&&x2>x+30)..likewise y

提交回复
热议问题