Javascript Collision Detection

前端 未结 1 1298
生来不讨喜
生来不讨喜 2021-02-09 19:43

I\'m trying to make a snake game in javascript, but I am struggling with collision detection. I\'ve tried various methods so far, but in desperation, have settled storing all th

1条回答
  •  梦谈多话
    2021-02-09 20:25

    You function here needs a little work and it may fix your problem.

    this.collide = function(){
      for(var z=0; z

    2 things are wrong.

    1. You are dropping out of the loop the first comparison. You will want to do something like if (something overlaps) return true then outside of both loops return false if you make it through successfully
    2. You will want to make sure that the z segment != q segment or you will always have a collision

    Looks cool. Lets see Mario next ;)

    0 讨论(0)
提交回复
热议问题