code:
class Saw extends ClickTool {
    static Resources = {
        images: [
            "saw",
            "notch", "blood",
        ],
        sounds: [
            "saw",
        ]
    };

    constructor(params, rm) {
        super(params, rm);
        this.world = params.world;

        this.name = "Saw";
        this.cursorImage = this.images["saw"];
        this.cursorImageShiftX = I2W(60);
        this.cursorImageShiftY = I2W(60);
        this.canTargetClothAlone = false;
    }

    initializeParticleEffects() {
        this.splashEffect = new SawSplash(this.rm, this.params);
    }

    // Drawing effects and splitting the body parts
    execute() {
        let garbageBodies = new Array();
        let rand1 = randfloat(200);
        let rand2 = randfloat(200);
        let notch = this.images["notch"];
        let blood = this.images["blood"];

        for (const [part, lp] of this.hitParts) {
            let name = part.name;
            let character = part.character;
            let b = part.box2dBody;

            garbageBodies.push(b);
            let newParts = part.split(lp);
            character.updateBodyParts(part, newParts);

            // Draw
            let ang = b.GetAngle();
            part.draw(notch, BodyPart.CONTOUR, lp, ang, {gco: "destination-out"});
            part.draw(notch, BodyPart.SKIN, lp, ang, {gco: "destination-out"});
            part.draw(notch, BodyPart.MEAT_ORGANS, lp, ang, {gco: "destination-out"});
            part.draw(notch, BodyPart.BONE, lp, ang, {gco: "destination-out"});
            let meatBloodMask = part.draw(blood, BodyPart.SKIN, lp, ang, {calculate_mask: true});
            let boneBloodMask = part.draw(blood, BodyPart.MEAT_ORGANS, lp, ang, {calculate_mask: true, mask: meatBloodMask});
            part.draw(blood, BodyPart.BONE, lp, ang, {mask: boneBloodMask});
            part.drawOnClothes(notch, lp, ang, {gco: "destination-out"});

            // Stop breathing
            switch (name) {
                case "neck":;
                case "breast":
                    character.stopBreath("breast");
                case "belly": character.stopBreath("belly");
            }

            // Apply random impulses
            /*let mass0 = bs[0].GetMass();
            let mass1 = bs[1].GetMass();
            let ix0, ix1, iy0, iy1;
            [ix0, iy0] = randcircle(mass0/3);
            [ix1, iy1] = randcircle(mass1/3);
            bs[0].ApplyImpulse(new b2Vec2(ix0,iy0), new b2Vec2(0,0));
            bs[1].ApplyImpulse(new b2Vec2(ix1,iy1), new b2Vec2(0,0));*/
        }

        // Disposing garbage bodies
        for (let i = 0; i < garbageBodies.length; i++) {
            this.world.DestroyBody(garbageBodies[i]);
            garbageBodies[i] = null;
        }
        refreshConnectedBodies(this.params);
    }

    doReaction(character, flags, direction) {
        if (direction == "center") {
            if (character.hp > 85) {
                character.forceShadow1(50);
                character.setEyes([["surprised_strong", 25], ["pain_strong", 25]]);
                character.setMouth([["clench_strong", 25], ["open_medium", 25]]);
            } else if (character.alive()) {
                character.forceShadow2(50);
                character.setEyes([["surprised_strong", 25], ["pain_strong", 25]]);
                character.setMouth([["clench_squiggly", 25], ["open_squiggly", 25]]);
            }
        } else {
            character.setEyes([["pain_strong", 25, direction], ["pain_weak", 25, direction]]);
            character.setMouth([["clench_strong", 25], ["open_medium", 25]]);
        }
    }

    damage(character, flags) {
        if (flags.neck) {
            character.changeHP(-100, true);
        } else if (flags.heart) {
            character.changeHP(-50, true);
            character.applyBleeding(5, true);
        } else if (flags.direction == "center") {
            character.changeHP(-25);
            character.applyBleeding(3, true);
        } else {
            character.changeHP(-6);
            if (flags.waist || flags.belly) {
                character.applyBleeding(3, true);
            } else {
                character.applyBleeding(1.5);
            }
        }
    }

    collision(part, mx, my) {
        if (!pointCollisionWithBody(part.box2dBody, mx, my))
            return false;
        let name = part.name;
        if (name == "head")
            return false;
        let lp = part.box2dBody.GetLocalPoint(new b2Vec2(mx / SCALE, my / SCALE));

        // Special rules for overlapping bodies
        if (name == "waist" && lp.y * SCALE >= 40)
            return false;
        if (name == "waist" && part.top == 0 && lp.y * SCALE - part.top > I2W(28))
            return true;
        if (name == "breast" && part.top == 0 && lp.y * SCALE <= I2W(160))
            return false;
        if (name == "breast" && part.bottom == part.height && part.bottom - lp.y * SCALE > I2W(20))
            return true;
        if (name == "belly" && (part.bottom - lp.y * SCALE > I2W(28) || lp.y * SCALE - part.top > I2W(28)))
            return true;
        if (part.bottom - lp.y * SCALE <= I2W(40) || lp.y * SCALE - part.top <= I2W(40))
            return false; // discard too small items (which are close to invisible anyways)
        return true;
    }

    animate() {
        let animateStep = this.animateStep;
        if (animateStep == 0) {
            playSound(this.sounds["saw"], this.params.volume);
            this.doReactionAll();
            this.splashEffect.apply(this.mx, this.my);
        } else if (animateStep == 25) {
            this.execute();
        } else if (animateStep == 45 || (animateStep > 25 && this.sounds["saw"].ended)) {
            this.damageAll();
            clearCtx(this.params.canvas.frontEffectCtx);
            this.finalize();
            return;
        }

        // Cursor vibration
        clearCtx(this.params.canvas.cursorCtx);
        if (animateStep % 2 == 0) {
            this.params.canvas.cursorCtx.drawImage(this.cursorImage,
                this.mx - this.cursorImageShiftX - I2W(20),
                this.my - this.cursorImageShiftY - I2W(20));
        } else {
            this.params.canvas.cursorCtx.drawImage(this.cursorImage,
                this.mx - this.cursorImageShiftX + I2W(20),
                this.my - this.cursorImageShiftY + I2W(20));
        }
        this.animateStep++;
        setTimeout(() => { this.animate(); }, TIMESTEP);
    }
}

class SawSplash extends ParticleEffect {
    constructor(rm, params) {
        super(rm, params);

        this.emitter.rate = new Proton.Rate(10, 0.05);

        // initial parameters
        this.emitter.addInitialize(new Proton.Body([
            "mods/tools/Saw/images/splash1.png",
            "mods/tools/Saw/images/splash2.png",
            "mods/tools/Saw/images/splash3.png",
        ], I2W(200), I2W(200)));
        this.emitter.addInitialize(new Proton.Life(0.3, 1.2));
        this.emitter.addInitialize(new Proton.Mass(0.7));
        this.emitter.addInitialize(new Proton.Velocity(new Proton.Span(0.7, 2.2), new Proton.Span(0, 360), "polar"));

        // behaviours
        this.emitter.addBehaviour(new Proton.Scale(new Proton.Span(1, 0.75), new Proton.Span(1.25, 1.5)));
        this.emitter.addBehaviour(new Proton.Alpha(1, 0));
        this.emitter.addBehaviour(new Proton.Rotate());
        this.emitter.addBehaviour(new Proton.RandomDrift());
        this.emissionCount = 0.4;

        this.make();
    }
}


code:
class Scissors extends ClickTool {
    static Resources = {
        images: [
            "scissors_open", "scissors_closed",
            "hole",
        ],
        sounds: [
            "scissors",
        ]
    };

    constructor(params, rm) {
        super(params, rm);
        this.ang = 0;

        this.name = "Scissors";
        this.cursorImage = this.images["scissors_open"];
        this.cursorImage2 = this.images["scissors_closed"];
        this.cursorImageShiftX = I2W(53);
        this.cursorImageShiftY = I2W(25);

        this.anim = new Animation();
        this.anim.addKeyframe(0, {"image": this.cursorImage2}, ()=>{
            playSound(this.sounds["scissors"], this.params.volume);
            this.execute();
            this.doReactionAll();
        });
        this.anim.addKeyframe(3, {"image": this.cursorImage});
        this.anim.addKeyframe(5, {}, ()=>{this.finalize();});
    }

    reset(mx, my, shortcut) {
        super.reset(mx, my, shortcut);
        this.ang = randfloat(D2R(360));
        this.collisionShape = rectShape(I2W(300), I2W(180), this.ang);
    }

    execute() {
        let ang = this.ang;

        for (const [part, lp] of this.hitParts) {
            part.drawOnClothes(this.images["hole"], lp, ang, {gco: "destination-out"});
        }
    }

    doReaction(character, flags, direction) {
        if (character.hp > 40) {
            character.setEyes(["ashamed_weak", 20, direction]);
            character.setMouth(["open_small", 20]);
        }
    }

    animate() {
        let v = this.anim.getValues(this.animateStep);
        this.anim.callActions(this.animateStep);
        clearCtx(this.params.canvas.cursorCtx);
        this.params.canvas.cursorCtx.drawImage(v.image,
            this.mx - this.cursorImageShiftX,
            this.my - this.cursorImageShiftY
        );

        super.animate();
    }
}

repo_name: Tomajc/torture

license: mit


code:
class Staplegun extends ClickTool {
    static Resources = {
        images: [
            "staplegun_cursor1", "staplegun_cursor2",
            "wound01", "wound02", "wound03", "staple",
        ],
        sounds: [
            "staple",
        ]
    };

    constructor(params, rm) {
        super(params, rm);

        this.cursorImage = this.images["staplegun_cursor1"];
        this.cursorImage2 = this.images["staplegun_cursor2"];

        this.name = "Staplegun";
        this.cursorImageShiftX = I2W(40);
        this.cursorImageShiftY = I2W(160);
        this.collisionShape = circleShape(I2W(36));
    }

    execute() {
        let wound = this.images["wound" + zfill(randint(1, 3), 2)];
        let ang = randfloat(D2R(360));

        let first = true;
        for (const [part, lp] of this.hitParts) {
            let meatMask = part.draw(wound, BodyPart.SKIN, lp, ang, {calculate_mask: true});
            part.draw(wound, BodyPart.MEAT_ORGANS, lp, ang, {mask: meatMask});
            if (first) part.addItem("Staple", this.images["staple"], lp, ang, 1000);
            first = false;
        }
    }

    doReaction(character, flags, direction) {
        character.setMouth(["clench_medium", 25]);
        if (flags.leye || flags.reye) {
            character.setEyes(["surprised_weak", 25, direction]);
        } else {
            character.setEyes(["pain_weak", 25, direction]);
        }
    }

    damage(character, flags) {
        if (flags.mouth)
            character.forceMouth("close_neutral");
        if (flags.leye)
            character.destroyLeye("close");
        if (flags.reye)
            character.destroyReye("close");
        if (flags.head) {
            character.changeHP(-1);
        } else {
            character.changeHP(-0.5);
        }
    }

    animate() {
        if (this.animateStep == 0) {
            playSound(this.sounds["staple"], this.params.volume);
            this.execute();
            this.doReactionAll();
            this.damageAll();
            this.releaseStoppedBodies();
            let ctx = this.params.canvas.cursorCtx;
            clearCtx(ctx);
            ctx.drawImage(this.cursorImage2,
                this.mx - this.cursorImageShiftX,
                this.my - this.cursorImageShiftY);
        }

        // End condition is triggered when the sound effect finishes
        if (this.sounds["staple"].ended) {
            this.finalize();
            return;
        }

        super.animate();
    }
}


code:
class Stungun extends ClickTool {
    static Resources = {
        images: [
            "stungun", "spark", "singe",
        ],
        sounds: [
            "spark",
        ]
    };

    constructor(params, rm) {
        super(params, rm);
        this.targetBodies = undefined;

        this.name = "Stungun";
        this.cursorImage = this.images["stungun"];
        this.cursorImageShiftX = I2W(60);
        this.cursorImageShiftY = I2W(60);
        this.collisionShape = circleShape(I2W(56));
        this.canTargetClothAlone = false;
    }

    initializeParticleEffects() {
        this.smokeEffect = new StungunSmoke(this.rm, this.params);

        // Must be initialized after the map is created
        // Yellow glow around body
        this.buff1Canvas = createCanvas(this.params.map.width, this.params.map.height);
        this.buff1Ctx = this.buff1Canvas.getContext("2d");
        // X-ray like effect displaying bones
        this.buff2Canvas = createCanvas(this.params.map.width, this.params.map.height);
        this.buff2Ctx = this.buff2Canvas.getContext("2d");
    }

    // Not so realistic electrocution effects around the body
    updateSpark(step) {
        let sparkScale = 1.1 + Math.abs(step % 8 - 3.5) / 3.5 / 3;
        clearCtx(this.buff1Ctx);
        clearCtx(this.buff2Ctx);
        for (let i = 0; i < this.targetBodies.length; i++) {
            let part = this.targetBodies[i];
            let b = part.box2dBody;
            let bx = b.GetPosition().x * SCALE;
            let by = b.GetPosition().y * SCALE;
            let bang = b.GetAngle();

            let sHeight = part.height;
            let dHeight = part.bottom - part.top;
            let cWidth = part.skinCanvas.width;
            let cHeight = part.skinCanvas.height;

            this.buff1Ctx.save();
            this.buff1Ctx.translate(bx, by);
            this.buff1Ctx.rotate(bang);
            this.buff2Ctx.save();
            this.buff2Ctx.translate(bx, by);
            this.buff2Ctx.rotate(bang);
            if (part.name == "head") {
                dHeight += part.top; // Ugly fix, revamp this part completely
                this.buff1Ctx.drawImage(
                    part.skinCanvas,
                    0, (cHeight - sHeight) / 2 + 0,
                    cWidth, dHeight,
                    -cWidth * sparkScale / 2 - 2 * sparkScale, 0 - (sparkScale - 1) / 2 * dHeight,
                    cWidth * sparkScale, dHeight * sparkScale
                );
                this.buff2Ctx.drawImage(
                    part.boneCanvas,
                    0, (cHeight - sHeight) / 2 + 0,
                    cWidth, dHeight,
                    -cWidth / 2, 0,
                    cWidth, dHeight
                );
            } else {
                this.buff1Ctx.drawImage(
                    part.skinCanvas,
                    0, (cHeight - sHeight) / 2 + part.top,
                    cWidth, dHeight,
                    -cWidth * sparkScale / 2, part.top - (sparkScale - 1) / 2 * dHeight,
                    cWidth * sparkScale, dHeight * sparkScale
                );
                this.buff2Ctx.drawImage(
                    part.boneCanvas,
                    0, (cHeight - sHeight) / 2 + part.top,
                    cWidth, dHeight,
                    -cWidth / 2, part.top,
                    cWidth, dHeight
                );
            }
            this.buff1Ctx.restore();
            this.buff2Ctx.restore();
        }
        this.buff1Ctx.save();
        this.buff1Ctx.globalCompositeOperation = "source-atop";
        this.buff1Ctx.fillStyle = "#ffea00";
        this.buff1Ctx.fillRect(0, 0, this.buff1Canvas.width, this.buff1Canvas.height);
        this.buff1Ctx.restore();
        this.buff2Ctx.save();
        this.buff2Ctx.globalCompositeOperation = "source-atop";
        this.buff2Ctx.fillStyle = (step % 4 >= 2) ? "#212121" : "#cdcdcd";
        this.buff2Ctx.fillRect(0, 0, this.buff2Canvas.width, this.buff2Canvas.height);
        this.buff2Ctx.restore();
        clearCtx(this.params.canvas.frontEffectCtx);
        this.params.canvas.frontEffectCtx.save();
        this.params.canvas.frontEffectCtx.globalAlpha = 0.5 * (Math.abs(step % 6 - 2.5) / 2.5);
        this.params.canvas.frontEffectCtx.drawImage(this.buff1Canvas, 0, 0);
        this.params.canvas.frontEffectCtx.drawImage(this.buff2Canvas, 0, 0);
        this.params.canvas.frontEffectCtx.restore();
    }

    execute() {
        for (const [part, lp] of this.hitParts) {
            let meatMask = part.draw(this.images["singe"], BodyPart.SKIN, lp, 0, {calculate_mask: true});
            part.draw(this.images["singe"], BodyPart.MEAT_ORGANS, lp, 0, {mask: meatMask});
        }
    }

    doReaction(character, flags, direction) {
        character.setEyes(["surprised_strong", 80, direction]);
        if (character.hp > 90) {
            character.forceSweat(80, 1);
            character.setMouth(["open_medium", 80]);
        } else if (character.hp > 60) {
            character.forceSweat(80, 2);
            character.setMouth(["open_medium", 80]);
        } else if (character.hp > 30) {
            character.forceSweat(80, 2);
            character.setMouth(["open_squiggly", 80]);
        }
    }

    damage(character, flags) {
        if (flags.heart) {
            character.changeHP(-8, true);
        } else {
            character.changeHP(-6);
        }
    }

    animate() {
        let animateStep = this.animateStep;
        // Gets the parts which are going to be affected by cramps and yellow electro effect
        this.curPart;
        if (animateStep == 0) {
            for (const [part, _] of this.hitParts) {
                this.curPart = part
                this.targetBodies = getConnectedBodies(part);
                break;
            }
        }

        if (animateStep == 0) {
            playSound(this.sounds["spark"], this.params.volume);
            this.execute();
            this.releaseStoppedBodies();
            this.doReactionAll();
            this.smokeEffect.apply(this.mx, this.my);
        }

        // Cramps every connected body part
        for (let i = 0; i < this.targetBodies.length; i++) {
            let part = this.targetBodies[i];
            let b = part.box2dBody;
            let mass = b.GetMass();
            let ix, iy;
            [ix, iy] = randcircle(mass / 2);
            b.ApplyImpulse(new b2Vec2(ix, iy), new b2Vec2(0, 0));
        }

        // Electricity around the body
        clearCtx(this.params.canvas.frontEffectCtx);
        this.updateSpark(animateStep);

        // Small lightning shaped sparks around the stungun
        if (animateStep % 2) {
            this.params.canvas.frontEffectCtx.drawImage(this.images["spark"],
                this.mx - this.images["spark"].width / 2,
                this.my - this.images["spark"].height / 2);
        }

        // End animation when sound is finished
        if (this.sounds["spark"].ended) {
            clearCtx(this.params.canvas.frontEffectCtx);
            for (let chidx in this.characterFlags) {
                let character = this.characters[chidx];
                if (!character.waist.destroyed && connectedWith(character.waist, this.curPart) ) { // Pee
                    if (character.alive())
                        character.forceBlush(60);
                    character.setEyes(["ashamed_weak", 60]);
                    character.setMouth(["clench_weak", 60]);
                    character.pee();
                }
            }
            this.damageAll();
            this.finalize();
            return;
        }

        this.animateStep++;
        setTimeout(() => { this.animate(); }, TIMESTEP);
    }
}

class StungunSmoke extends ParticleEffect {
    constructor(rm, params) {
        super(rm, params);

        this.emitter.rate = new Proton.Rate(0.5, 0.05);

        // initial parameters
        this.emitter.addInitialize(new Proton.Body("mods/tools/Stungun/images/smoke.png", I2W(200), I2W(200)));
        this.emitter.addInitialize(new Proton.Life(1, 2));
        this.emitter.addInitialize(new Proton.Mass(1));
        this.emitter.addInitialize(new Proton.Velocity(new Proton.Span(1, 3), new Proton.Span(-30, 30), "polar"));

        // behaviours
        this.emitter.addBehaviour(new Proton.Scale(new Proton.Span(1, 0.75), new Proton.Span(1.25, 1.5)));
        this.emitter.addBehaviour(new Proton.Alpha(0.7, 0));
        this.emissionCount = 0.4;

        this.make();
    }
}


code:
class Syringe extends ClickTool {
    static Resources = {
        images: [
            "syringe_nothing", "syringe_nothing_2", "syringe_heal", "syringe_heal_2",
            "syringe_bleed", "syringe_bleed_2", "syringe_both", "syringe_both_2",
            "needle_mark",
        ],
        sounds: [
            "syringe",
        ]
    };

    constructor(params, rm) {
        super(params, rm);
        this.gui = true;

        this.cursorImage2 = this.images["syringe_both_2"];

        this.name = "Syringe";
        this.cursorImage = this.images["syringe_both"];
        this.cursorImageShiftX = I2W(8);
        this.cursorImageShiftY = I2W(8);
        this.canTargetClothAlone = false;

        this.healEffect = true;
        this.clearBleedingEffect = true;
    }

    execute() {
        for (const [part, lp] of this.hitParts) {
            let image = this.images["needle_mark"];
            let meatMask = part.draw(image, BodyPart.SKIN, lp, 0, {calculate_mask: true});
            part.draw(image, BodyPart.MEAT_ORGANS, lp, 0, {mask: meatMask});
        }
    }

    doReaction(character, flags, direction) {
        if (this.healEffect || this.clearBleedingEffect) {
            character.setEyes([["pain_weak", 20, direction], ["happy_weak", 25, direction]]);
            if (character.hp > 90) {
                character.setMouth([["clench_weak", 20], ["happy_small", 25]]);
            } else {
                character.setMouth([["clench_medium", 20], ["happy_small", 25]]);
            }
        } else {
            character.setEyes([["pain_weak", 20, direction]]);
            if (character.hp > 90) {
                character.setMouth([["clench_weak", 20]]);
            } else {
                character.setMouth([["clench_medium", 20]]);
            }
        }
    }

    damage(character, flags) {
        if (this.healEffect) {
            character.changeHP(25); // heal
        }
        if (this.clearBleedingEffect) {
            character.clearBleeding();
        }
    }

    animate() {
        // No complex animation here, only a static image is displayed
        if (this.animateStep == 0) {
            clearCtx(this.params.canvas.cursorCtx);
            this.params.canvas.cursorCtx.drawImage(this.cursorImage2,
                this.mx - this.cursorImageShiftX,
                this.my - this.cursorImageShiftY);
            playSound(this.sounds["syringe"], this.params.volume);
            this.damageAll();
            this.doReactionAll();
            this.execute();
            this.releaseStoppedBodies();
        }
        if (this.animateStep == 25) {
            this.finalize();
            return;
        }

        super.animate();
    }

    updateCursorImage() {
        if (this.healEffect) {
            if (this.clearBleedingEffect) {
                this.cursorImage = this.images["syringe_both"];
                this.cursorImage2 = this.images["syringe_both_2"];
            } else {
                this.cursorImage = this.images["syringe_heal"];
                this.cursorImage2 = this.images["syringe_heal_2"];
            }
        } else {
            if (this.clearBleedingEffect) {
                this.cursorImage = this.images["syringe_bleed"];
                this.cursorImage2 = this.images["syringe_bleed_2"];
            } else {
                this.cursorImage = this.images["syringe_nothing"];
                this.cursorImage2 = this.images["syringe_nothing_2"];
            }
        }
    }

    toggleHealEffect() {
        this.healEffect = !this.healEffect;
        this.updateCursorImage();
    }

    toggleClearBleedingEffect() {
        this.clearBleedingEffect = !this.clearBleedingEffect;
        this.updateCursorImage();
    }
}

class SyringeGUI extends preact.Component {
    constructor(props) {
        super(props);
    }

    toggleHealEffect = () => {
        this.props.tool.toggleHealEffect();
    }

    toggleClearBleedingEffect = () => {
        this.props.tool.toggleClearBleedingEffect();
    }

    render() {
        return(html`
            <${Checkbox} value=${this.props.tool.healEffect} onChange=${this.toggleHealEffect} label="Heal"/>
            <${Checkbox} value=${this.props.tool.clearBleedingEffect} onChange=${this.toggleClearBleedingEffect} label="Clear bleeding"/>
        `);
    }
}


code:
class VibrEgg extends SingleTargetTool {
    static Resources = {
        images: [
            "cursor", "egg", "tape",
        ],
        sounds: [
            "egg",
        ]
    };

    constructor(params, rm) {
        super(params, rm);

        this.name = "Egg vibrator";
        this.cursorImage = this.images["cursor"];
        this.cursorImageShiftX = I2W(100);
        this.cursorImageShiftY = I2W(100);

        this.activeCharacters = {};
    }

    animate() {
        let character = this.singleCharacterTarget;
        if (this.animateStep == 0) {
            if (!character.waist.destroyed) {
                if (character.ID in this.activeCharacters) {
                    let item = this.activeCharacters[character.ID]
                    item.parent.removeItem(item);
                    delete this.activeCharacters[character.ID];
                } else {
                    let item = new EggItem(this.images["egg"], this.images["tape"],
                                this.sounds["egg"].cloneNode(), // To allow multiple instances of sound
                                character.waist, character.pussyRegion.GetLocalPosition(), this.params, this);
                    character.waist.addItem(item);
                    this.activeCharacters[character.ID] = item;
                }
            }

            this.finalize();
            return;
        }
        super.animate();
    }
}

class EggItem extends Item {
    constructor(imageEgg, imageTape, sound, parent, lp, params, tool) {
        super("Egg vibrator", imageEgg, parent, lp, 0, params, 1000);
        this.tr_x = I2W(1);
        this.tr_y = randint(0, 1) == 1 ? I2W(1) : I2W(-1); // Somewhat randomized shaking ( / vs \ direction)
        this.ang = 0; // Forces a constant local angle, instead of a global one (important when waist is rotated)
        this.sound = sound;
        this.soundPlayedOnce = false; // sound.ended is only valid if the sound was played at least once, so this additional bool is needed
        this.tool = tool;
        this.tape = imageTape;
    }

    render(ctx) {
        let b = this.parent.box2dBody;
        let bx = b.GetPosition().x * SCALE;
        let by = b.GetPosition().y * SCALE;
        let bang = b.GetAngle();

        ctx.save();
        ctx.translate(bx, by);
        ctx.rotate(bang);
        ctx.translate(this.lp.x * SCALE, this.lp.y * SCALE);
        ctx.rotate(this.ang);
        ctx.translate(-this.image.width/2, -this.image.height/2);
        ctx.drawImage(this.image, this.tr_x, this.tr_y); // Shaking
        ctx.drawImage(this.tape, 0, 0);
        ctx.restore();
    }

    update() {
        this.tr_x *= -1;
        this.tr_y *= -1;
        if (connectedWith(this.parent.character.waist, this.parent.character.head)) {
            this.parent.character.changePleasure(0.1);
        }
        if (!this.soundPlayedOnce || this.sound.ended) {
            playSound(this.sound, this.params.volume);
            this.soundPlayedOnce = true;
        }
    }

    setParent(part) {
        super.setParent(part);
        this.parent.removeItem(this);
    }

    delete() {
        delete this.tool.activeCharacters[this.parent.character.ID];
    }
}


code:
class Vibrator extends DragTool {
    static Resources = {
        images: [
            "vibrator", "vibrator_on1", "vibrator_on2",
        ],
        sounds: [
            "vibrator",
        ]
    };

    constructor(params, rm) {
        super(params, rm);
        this.ang = 0;

        this.name = "Vibrator";
        this.cursorImageOff = this.images["vibrator"];
        this.cursorImageOn1 = this.images["vibrator_on1"];
        this.cursorImageOn2 = this.images["vibrator_on2"];
        this.cursorImage = this.cursorImageOff;
        this.cursorImageAnim = 0;
        this.cursorImageShiftX = I2W(68);
        this.cursorImageShiftY = I2W(68);
        this.soundPlayedOnce = false; // sound.ended is only valid if the sound was played at least once, so this additional bool is needed
        this.reactedOnce = false; // Force emotions only once per dragging session (resets on mouseUp)
    }

    doReaction(character, flags, direction) {
        if (character.orgasming) return;
        if ((flags.lnipple && !this.prevCharacterFlags.lnipple)
            || ( flags.rnipple && !this.prevCharacterFlags.rnipple)) {
            let mass = character.breast.box2dBody.GetMass();
            character.breast.box2dBody.ApplyImpulse(new b2Vec2(0, randfloat(-0.1, 0.1) * mass),
                                        new b2Vec2(0, character.lnippleRegion.GetLocalPosition().y));
            if (!this.reactedOnce) {
                character.setEyes(["ashamed_weak", 40]);
                character.setMouth(["clench_weak", 40]);
                this.reactedOnce = true;
            }
            character.forceBlush(40);
        }

        if (flags.pussy && !this.prevCharacterFlags.pussy) {
            let mass = character.waist.box2dBody.GetMass();
            character.waist.box2dBody.ApplyImpulse(new b2Vec2(0, randfloat(-0.8, 0.8) * mass), character.pussyRegion.GetLocalPosition());
            if (!this.reactedOnce) {
                character.setEyes(["ashamed_strong", 40]);
                character.setMouth(["clench_weak", 40]);
                this.reactedOnce = true;
            }
            character.forceBlush(40);
        }
    }

    damage(character, flags) {
        if (flags.pussy) {
            character.changePleasure(0.3);
        }
        if (flags.lnipple || flags.rnipple) {
            if (character.pleasure < 65) {
                character.changePleasure(0.15);
            }
        }
    }

    drag() {
        if (!this.soundPlayedOnce || this.sounds["vibrator"].ended) {
            playSound(this.sounds["vibrator"], this.params.volume);
            this.soundPlayedOnce = true;
        }
        this.cursorImageAnim++;
        if (this.cursorImageAnim % 2 == 0) {
            this.cursorImage = this.cursorImageOn2;
        } else {
            this.cursorImage = this.cursorImageOn1;
        }
        this.doReactionAll();
        this.damageAll();
    }

    mouseUp(mx, my) {
        super.mouseUp(mx, my);
        this.cursorImageAnim = 0;
        this.reactedOnce = false;
        this.cursorImage = this.cursorImageOff;
    }
}


code:
class Whip extends ClickTool {
    static Resources = {
        images: [
            "whip_cursor1", "whip_cursor2",
            "scratch01", "scratch02",
            "whip_hole01", "whip_hole02",
        ],
        sounds: [
            "whip",
        ]
    };

    constructor(params, rm) {
        super(params, rm);
        this.cursorImage = this.images["whip_cursor1"];
        this.cursorImage2 = this.images["whip_cursor2"];

        this.name = "Whip";
        this.cursorImageShiftX = I2W(8);
        this.cursorImageShiftY = I2W(8);
        this.collisionShape = circleShape(I2W(100));

        this.anim = new Animation();
        this.anim.addKeyframe(0, {"ang": 0, "image": this.cursorImage2});
        this.anim.addKeyframe(5, {"image": this.cursorImage2}, ()=>{
            playSound(this.sounds["whip"], this.params.volume);
            this.execute();
            this.doReactionAll();
            this.damageAll();
            this.releaseStoppedBodies();
        });
        this.anim.addKeyframe(6, {"ang": Math.PI / 4 / 5 * 6}, ()=>{this.finalize();});
        this.anim.interpolations["ang"] = "rotation";
    }

    execute() {
        let scratch = this.images["scratch" + zfill(randint(1, 2), 2)];
        let hole = this.images["whip_hole" + zfill(randint(1, 2), 2)];
        let ang = randfloat(2 * Math.PI);

        for (const [part, lp] of this.hitParts) {
            let meatMask = part.draw(scratch, BodyPart.SKIN, lp, ang, {calculate_mask: true});
            part.draw(scratch, BodyPart.MEAT_ORGANS, lp, ang, {mask: meatMask});
            part.drawOnClothes(hole, lp, ang, {gco: "destination-out"});
        }
    }

    doReaction(character, flags, direction) {
        if (character.hp > 90) {
            character.setMouth(["clench_weak", 25]);
        } else {
            character.setMouth(["clench_medium", 25]);
        }
        if (flags.leye || flags.reye) {
            character.setEyes(["pain_strong", 25, direction]);
        } else {
            character.setEyes(["pain_weak", 25, direction]);
        }
    }

    damage(character, flags) {
        character.changeHP(-0.5);
    }

    animate() {
        let v = this.anim.getValues(this.animateStep);
        let ctx = this.params.canvas.cursorCtx;
        clearCtx(ctx);
        ctx.save();
        ctx.translate(
            this.mx - v.image.width / 2 + I2W(1200),
            this.my - v.image.height / 2 + I2W(800)
        );
        ctx.rotate(v.ang);
        ctx.drawImage(v.image,
            -v.image.width - I2W(200), -v.image.height);
        ctx.restore();
        this.anim.callActions(this.animateStep);

        super.animate();
    }
}


code:
<!DOCTYPE html>

        <meta charset="utf-8">
        <title>Torture Chamber</title>
        <link rel="stylesheet" type="text/css" href="game.css">
        <link rel="stylesheet" type="text/css" href="custom_ui.css">
        <link rel="stylesheet" type="text/css" href="custom_file_input.css">
        <link rel="icon" type="image/x-icon" href="../common/favicon.png">

            <input type="file" style="visibility: hidden" id="game-files" webkitdirectory directory multiple title="Select Game Folder"/>
            Select Game Folder

                <canvas id="canvas">
                    html5 canvas required - please download a compatible browser
                </canvas>


code:
Copyright (c) 2018, Fredrick R. Brennan (<copypaste@kittens.ph>),

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.