JSFiddle - React, Tailwind, and code Playground

by Brian Wendt

JavaScript

class Terrain {

    constructor() {
        this.name = "";
        this.description = "";
        this.isPassable = true;
    }

    whileCreatureOnTerrain(Creature) {
        this.slowsMovement(Creature);
        this.causesDamage(Creature);
        this.applyMovementSound(Creature);
        this.otherEffects(Creature);
    }

    slowsMovement(Creature) {
        Creature.speedModifier(0);
    }

    causesDamage(Creature) {
        //Creature.damage();
    }

    otherEffects(Creature) {

    }

    applyMovementSound(Creature) {
        Creature.applyMovementSound(Sounds.Movement.default)
    }
}

class Water extends Terrain {
    constructor() {
        super()
        this.name = "Water";
        this.description = "A shallow puddle of water";
    }

    slowsMovement(Creature) {
        Creature.speedModifier(-3);
    }

    applyMovementSound(Creature) {
        Creature.applyMovementSound(Sounds.Movement.small_splash)
    }
}

class DeepWater extends Water {
    constructor() {
        super()
        this.name = "Deep Water";
        this.description = "A deep pool of water";
    }

    slowsMovement(Creature) {
        if (Creature.canSwim()) {
            Creature.speedModifier(-10);
        } else {
            Creature.speedModifier(-15);
        }
    }

    applyMovementSound(Creature) {
        if (Creature.canSwim()) {
            Creature.applyMovementSound(Sounds.Movement.swimming);
        } else {
        		Creature.applyMovementSound(Sounds.Movement.underwater);
        }
    }

    otherEffects(Creature) {
    		Creature.setSwimming(true);
        if (!Creature.canSwim()) {
        	Creature.setDrowning(true);
        }
    }
}

class Lava extends Terrain {
    constructor() {
        super()
        this.name = "Lava Pool";
        this.description = "A deep pool of multen lava.";
    }
    
    causesDamage(Creature) {
        Creature.damage(30, 500, DamageTypes.Fire); //damage amount, apply interval, damage type
    }

   ...