java - Player Movement Direction Logic -
consider points , b walls , point o player inside walls.
so o b.
i want player move left when touches rightpoint b. , move right when touches leftpoint a.
the screen being rendered , player position either incremented 5 right direction or -5 left direction.
what tried do: put in if else if statement. if distance between , o zero, player position gets +5 incrementation. if distance between o , b zero, player position gets -5 incrementation. touches wall(say right wall), moves -5 , 5 , again -5 , 5.
i understand why happening not have logic implement this.
code: sorry not post actual code. im on mobile internet. dont have computer internet.
suppose leftwall @ 50, 0 , rightwall @ 550, 0 , player @ 50, 0.
//this being rendered.
if (rightwall - playerpos <=0){ posincrement = -5; } if (leftwall - playerpos <=0){ posincrement = 5; } translatex (playerpos);
if player should between walls, implies left wall should have position lower the player position. player position shuld equal or larger 50 , equal or smaller 550
so correct logic can be
if (rightwall - playerpos <=0){ posincrement = -5; } if (playerpos - leftwall <=0){ posincrement = 5; }
Comments
Post a Comment