Gabriel-Gravin / Teamwork

Platform jump game
MIT License
0 stars 0 forks source link

Overview of game controls | Teamwork Game! #8

Open jellinki opened 9 months ago

jellinki commented 9 months ago

The game controls are very simple; A to move left, D to move right, and W to jump. I guess you could say it's more WAD than WASD because the "S" key is never actually used. Hmm.

C:\Users\katel\OneDrive\kvscode\new blog\linkblog\images\wasd.png

Above, you can see how we used event listeners to implement the WASD movement.

function updateSpriteAnimation() {
    if (frameX < maxFrame) {
        frameX++;
    } else {
        frameX = 0;
    }
}

function jump() {
    if (!isJumping && isOnGround) {
        spriteVelocityY = jumpStrength;
        isJumping = true;
        isOnGround = false;
    }
}

function moveLeft() {
    isMovingLeft = true;
    isIdle = false;
    frameY = 5;
    maxFrame = 9;
}

function moveRight() {
    isMovingRight = true;
    isIdle = false;
    frameY = 7;
    maxFrame = 9;
}

function idle() {
    isIdle = true;
    frameY = 0;
    maxFrame = 2;
}

Above, you can see the code that we used to call the sprite animations according to the player's movement at that point in time. The frames are named according to the spritesheet provided below:

C:\Users\katel\OneDrive\kvscode\new blog\linkblog\images\linksprites.png