Snippets

Michael Gale GWD hammer game logic

Created by Michael Gale last modified
// Increment counter on hit-box click

var hitBox = document.querySelector('.hitbox');

var incrementElement = document.getElementById('increment');

// set the string to be an incrementable number
incrementElement.innerHTML = 0;

// reusable hitbox function
function hitBoxHandler(e) {

    if (incrementElement.innerHTML < 2) {

        e.preventDefault();
        incrementElement.innerHTML++;
        incrementElement.innerHTML = incrementElement.innerHTML;

    } else {
        // Go to the game over screen
        
        gwd.actions.gwdPagedeck.goToPage('pagedeck', 'page1_2', 'none', 0, 'linear', 'top');

        incrementElement.innerHTML = 0; //reset score to 0
    }
}


hitBox.addEventListener("click", hitBoxHandler);
var anywhereOnStage = document.getElementById('gwd-ad');

// Mouse Down Handler
anywhereOnStage.addEventListener("mousedown", function(e) {
    e.preventDefault();
    this.classList.add('mouseDown');
    return false;
});

// Mouse Up handler
anywhereOnStage.addEventListener("mouseup", function() {
    this.classList.remove('mouseDown');
});

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.