sei-ec-remote / project-1-issues

Open new issues here
1 stars 2 forks source link

Dog won't sit #114

Closed hewinsonj closed 1 year ago

hewinsonj commented 1 year ago

What's the problem you're trying to solve?

The dog doesn't stop at the position I've designated.

Post any code you think might be relevant (one fenced block per file)


dog.updatePosition2 = function (spotNum) {
    const diffX = spotNum.x - dog.x;
    const diffY = spotNum.y - dog.y;
    if(diffX !== 0 && diffY !== 0){
      if(diffX > 0)
          dog.x += 10;
      else 
          dog.x -= 10;

      if(diffY > 0)
          dog.y += 10;
      else
          dog.y -= 10;
 } else {
    dog.x = 40
    dog.y = 205
 }
}```

### If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
I add the last else statement because he was stoping at a random spot on the canvas. So now he travels to the random spot then appears at x - 40 y - 205, which is where I want him. I'm just trying to get him to travel there instead of teleporting. 
### What is your best guess as to the source of the problem?
Something is telling him to stop at that random location but i don't know what.

### What things have you already tried to solve the problem?
I've adjusted the diff range, the location I want him to go and created a separate function just for sending him to his default location.

### Paste a link to your repository here[
](https://github.com/hewinsonj/PooPicker-Game)
kestler01 commented 1 year ago

looks like the argument being passed as spotNum may be our culprit here, can you share a console.log() and the code where we evoke that updatePosition2 method

hewinsonj commented 1 year ago

dog.updatePosition2 = function (spotNum) { const diffX = spotNum.x - dog.x; const diffY = spotNum.y - dog.y; if(diffX !== 0 && diffY !== 0){ if(diffX > 0) dog.x += 10; else dog.x -= 10;

  if(diffY > 0)
      dog.y += 10;
  else
      dog.y -= 10;
      console.log('this is x: ' + dog.x + 'this is y: ' + dog.y)

} else {

dog.x = 40
dog.y = 205

} }

Start Game index.js:270 this is x: 380this is y: 385 index.js:270 this is x: 370this is y: 375 index.js:270 this is x: 360this is y: 365 index.js:270 this is x: 350this is y: 355 index.js:270 this is x: 340this is y: 345 index.js:270 this is x: 330this is y: 335 index.js:270 this is x: 320this is y: 325 index.js:270 this is x: 310this is y: 315 index.js:270 this is x: 300this is y: 305 index.js:270 this is x: 290this is y: 295 index.js:270 this is x: 280this is y: 285 index.js:270 this is x: 270this is y: 275 index.js:270 this is x: 260this is y: 265 index.js:270 this is x: 250this is y: 255 index.js:270 this is x: 240this is y: 245 index.js:270 this is x: 230this is y: 235 index.js:270 this is x: 220this is y: 225 index.js:270 this is x: 210this is y: 215 index.js:270 this is x: 200this is y: 205

all of those are before it jumps to x-40 y-205

hewinsonj commented 1 year ago

Ok, reading that console log made me realize that I needed to change the && to ||, the y coordinate was being satisfied before the x was. Thanks

kestler01 commented 1 year ago

epic