sei-ec-remote / project-1-issues

Open new issues here
1 stars 2 forks source link

Game project issue #120

Closed sam-phillips21 closed 1 year ago

sam-phillips21 commented 1 year ago

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

having an issues with key movements. set direction is coming back as not a function. eventlistener is working

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

const moveMtneer = () => {
    document.addEventListener('keypress', (e) => {
     if (['w', 'a', 's', 'd']) {
      moveMtneer.setDirection(e.key)
      if (key() == 'w') { this.direction.up = true }
      if (key() == 'a') { this.direction.left = true }
      if (key() == 's') { this.direction.down = true }
      if (key() == 'd') { this.direction.right = true }
    //   console.log(moveMtneer)
    }
  })
}

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

it says setdirection is not a function. i have am having trouble finding resources that can fix the issue

What is your best guess as to the source of the problem?

an issue with the way i have the function set up.

What things have you already tried to solve the problem?

ive tried to not have setDirection in a function: which let to setDirection is not a function. Ive put setDirection in a function and it comes back not a function...

Paste a link to your repository here

https://github.com/sam-phillips21/Project-one

sam-phillips21 commented 1 year ago

moveMtneer = movement
        console.log(moveMtneer)
        document.addEventListener('keypress', (event) => {
            console.log(event)
            if (['w', 'a', 's', 'd']) {
            if(keypress() == 'w') {direction.up = true}
        }
    })
kestler01 commented 1 year ago

can you show me the whole class definition and when we're calling our set direction ?

sam-phillips21 commented 1 year ago

class newMtneer {
    constructor(x, y, color, width, height) {
        this.x = x,
        this.y = y,
        this.color = color,
        this.width = width,
        this.height = height,
        this.alive = true,
        this.speed = 15,
        this.direction = {
            up: false,
            down: false,
            left: false,
            right: false,
        },
        this.setDirection = function (key) {
            console.log('key was pressed', key)

    }
}
}
sam-phillips21 commented 1 year ago

moveMtneer = movement
        console.log(moveMtneer)
        document.addEventListener('keydown', (event) => {
            console.log(event)
            if (['w', 'a', 's', 'd']) {
            if(onkeydown(event) == 'w') {this.direction.up = true}
        }
    })
sam-phillips21 commented 1 year ago

ive been removing the class, and messing the the lay out of the function above. i can. get it to register a keypress but still with errors.

kestler01 commented 1 year ago

refactored event handler to align with class and implemented new game object 😁