vs26625 / platformer_3x

Apache License 2.0
0 stars 0 forks source link

Emote Function #21

Open kailynsanford opened 4 months ago

kailynsanford commented 4 months ago

We are working on trying to implement an emote functionality into the code, where when you press e the emote will appear and then slowly rises before dissapearing.

This is the code in new file emote.js

import PlayerBase from './playerBase.js';

export class Emote {
    constructor() {
        this.emote = {
            x: PlayerBase.x,
            y: PlayerBase.y,
            height: 40,
            width: 40,
            exist: 0,
        };

        document.addEventListener('keydown', this.handleKeyPress.bind(this));
    };

    updateEmote(emote) {
        emote.exist = 1;
        emote.y -= 2;
        if (emote.y < 0) {
            emote.exist = 0;
        }
    }

    renderEmote(emote) {
        if (emote.exist === 1) {
            const imageElement = document.createElement('img');
            imageElement.src = './image/platformer/heart_emote.jpg';
            imageElement.style.height = `${emote.height}px`;
            imageElement.style.width = `${emote.width}px`;
            document.body.appendChild(imageElement);
        }
    }

    animationLoop() {
        this.updateEmote(this.emote);
        this.renderEmote(this.emote);
        requestAnimationFrame(this.animationLoop.bind(this));
    }

}

This file creates the emote, however we haven't been able to implement the functionality in the game, and are currently trying to add the code so that the player can actually use it.