Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #3 -- code to make you win doesn't work #11

Open
MJP8 opened this issue Apr 14, 2021 · 1 comment · May be fixed by #13
Open

Bug #3 -- code to make you win doesn't work #11

MJP8 opened this issue Apr 14, 2021 · 1 comment · May be fixed by #13
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@MJP8
Copy link
Owner

MJP8 commented Apr 14, 2021

Describe the bug
When you make the player jump to get the treasure the win() function isn't called.

To Reproduce
Steps to reproduce the behavior:

  1. Go to http://192.168.7.33/object/
  2. Use the arrow keys to navigate to the treasure
  3. Press the up arrow key to jumpto it if needed
  4. See error

Expected behavior
I thought it would call the win() function (which is this:

function win() { // create a function that runs when you win
    $('.win').show(); // show the message with JQuery
    $('.game').hide(); // hide the rest of the game
};

)
This is were the win() function is called:

class Player { // create a player sprite class
    constructor(visibility) {
        this.visibility = visibility;
        setInterval(function() { // repeat this with a interval in between
            if (Math.abs(parseInt($('.player').css('left')) - parseInt($('.enemy').css('left'))) < parseInt($('.enemy').width()) && Math.abs(parseInt($('.player').css('top')) - $('.enemy').css('top')) < $('.enemy').height()) { // if the player if touching the enemy...
                game_over(); // then call the game_over function
            } else if (Math.abs(parseInt($('.player').css('top')) - parseInt($('.treasure').css('top'))) < parseInt($('.treasure').height())) { // otherwise if the player is touching the treasure...
                win(); // then call the win function
            };
        }, 1000); // do this each second
        $(document).on('keydown', ...

        }
    }
}

/cc @elijahparker

@MJP8 MJP8 added bug Something isn't working help wanted Extra attention is needed labels Apr 14, 2021
@MJP8 MJP8 added this to the Todo milestone Apr 14, 2021
@MJP8 MJP8 added this to To do in Adding the main OOJS. via automation Apr 14, 2021
@MJP8
Copy link
Owner Author

MJP8 commented Apr 24, 2021

I fixed #12 but now the code to make you lose doesn't work too:

class Player { // create a player sprite class
    constructor(visibility) {...
    setInterval(function() { // repeat this with a interval in between
            if (Math.abs(parseInt($('.player').css('left')) - parseInt($('.enemy').css('left'))) < parseInt($('.enemy').width()) && Math.abs(parseInt($('.player').css('top')) - $('.enemy').css('top')) < $('.enemy').height()) { // if the player if touching the enemy...
                game_over(); // then call the game_over function
            } else if (Math.abs(parseInt($('.player').css('top')) - parseInt($('.treasure').css('top'))) < parseInt($('.treasure').height())) { // otherwise if the player is touching the treasure...
                win(); // then call the win function
            };
        }, 1000); // do this each second...

MJP8 added a commit that referenced this issue Jun 3, 2021
@MJP8 MJP8 linked a pull request Jun 5, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Development

Successfully merging a pull request may close this issue.

2 participants