Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

4.1 KB
Raw Blame
#!/usr/bin/env python3
"""src/fconst.h: the float constants of Celeste's movement as their IEEE single bits (src/sf.c computes with them),
each worked out the way the C code of the NumWorks port (Player.cs's constants) works it out, in single precision."""
import os

import numpy as np

f = np.float32
C = {
    "0": f(0), "1": f(1), "HALF": f(.5), "2": f(2), "3": f(3), "4": f(4), "5": f(5), "6": f(6), "8": f(8),
    "DT": f(0.0166667),
    "MaxFall": f(160), "Gravity": f(900), "HalfGravThreshold": f(40), "FastMaxFall": f(240), "FastMaxAccel": f(300),
    "MaxRun": f(90), "RunAccel": f(1000), "RunReduce": f(400), "AirMult": f(.65), "DuckFriction": f(500),
    "DuckCorrectSlide": f(50), "DodgeSlideSpeedMult": f(1.2), "DuckSuperJumpXMult": f(1.25),
    "DuckSuperJumpYMult": f(.5), "JumpGraceTime": f(.1), "JumpSpeed": f(-105), "JumpHBoost": f(40),
    "VarJumpTime": f(.2), "CeilingVarJumpGrace": f(.05), "WallSpeedRetentionTime": f(.06),
    "WallJumpForceTime": f(.16), "WallSlideStartMax": f(20), "WallSlideTime": f(1.2),
    "BounceVarJumpTime": f(.2), "BounceSpeed": f(-140), "BounceAutoJumpTime": f(.1),
    "SuperBounceVarJumpTime": f(.2), "SuperBounceSpeed": f(-185), "SuperJumpH": f(260),
    "SuperWallJumpSpeed": f(-160), "SuperWallJumpVarTime": f(.25), "DashSpeed": f(240), "EndDashSpeed": f(160),
    "EndDashUpMult": f(.75), "DashTime": f(.15), "DashCooldown": f(.2), "DashRefillCooldown": f(.1),
    "DashAttackTime": f(.3), "ClimbMaxStamina": f(110), "ClimbUpCost": f(100) / f(2.2), "ClimbStillCost": f(100) / f(10),
    "ClimbJumpCost": f(110) / f(4), "ClimbNoMoveTime": f(.1), "ClimbTiredThreshold": f(20), "ClimbUpSpeed": f(-45),
    "ClimbDownSpeed": f(80), "ClimbSlipSpeed": f(30), "ClimbAccel": f(900), "ClimbGrabYMult": f(.2),
    "ClimbHopY": f(-120), "ClimbHopX": f(100), "ClimbHopForceTime": f(.2), "ClimbJumpBoostTime": f(.2),
    "LiftYCap": f(-130), "LiftXCap": f(250), "JumpThruAssistSpeed": f(-40), "Diag": f(0.70710677),
    "ReboundSpeedX": f(120), "ReboundSpeedY": f(-120), "ReboundVarJumpTime": f(.15), "SideBounceSpeed": f(240),
    "SideBounceForce": f(.3), "TransitionSpeed": f(60) * f(0.0166667), "IntroRise": f(-120) * f(0.0166667),
    "IntroJumpSpeed": f(-100), "IntroGravity": f(0.0166667) * f(800), "WalkIn": f(64) * f(0.0166667),
    "LiftTime": f(.16), "StrawbReset": f(2.5), "Respawn": f(.6), "IdleVariant": f(3), "SixtyHalf": f(.12),
    "HairFlash": f(.12), "Wall": f(1.2) * f(.5), "Freeze": f(.05), "Shake": f(.3), "DashShake": f(.2), "Hop": f(.5),
    "Collect": f(.15), "BerryFollow": f(.3),
}
C["WallJumpHSpeed"] = C["MaxRun"] + C["JumpHBoost"]
C["SuperWallJumpH"] = C["MaxRun"] + C["JumpHBoost"] * f(2)
C["RunAccelAir"] = C["RunAccel"] * C["AirMult"]
C["RunReduceAir"] = C["RunReduce"] * C["AirMult"]
C["WallSlideHalf"] = C["WallSlideTime"] * f(.5)
C["FastHalf"] = C["MaxFall"] + (C["FastMaxFall"] - C["MaxFall"]) * f(.5)
C["DashDiag"] = C["Diag"] * C["DashSpeed"]
C["EndDashDiag"] = C["Diag"] * C["EndDashSpeed"]
C["RunAccel40"] = C["RunAccel"] / f(40)

out = ["/* Generated by tools/fconst.py: Celeste's movement constants as single-precision bits. */", "#ifndef FCONST_H",
       "#define FCONST_H"]
for k, v in C.items():
    out.append("#define F_%s 0x%08Xul /* %r */" % (k, np.float32(v).view(np.uint32), float(np.float32(v))))


def sine_in(t):   # Ease.SineIn: (float)(-Math.Cos(MathHelper.PiOver2 * t) + 1.0), the product a float's
    import math
    x = np.float32(np.float32(1.5707964) * np.float32(t))
    return np.float32(-math.cos(float(x)) + 1.0)


def zip_table(step):   # ZipMover.Sequence: at = Approach(at, 1, step * DT) until 1, Ease.SineIn(at) each frame
    at, out = f(0), []
    d = f(step) * f(0.0166667)
    while at < f(1):
        at = min(f(at + d), f(1))
        out.append(sine_in(at))
    return out


for name, step in (("ZIP_OUT", 2), ("ZIP_BACK", 0.5)):
    t = zip_table(step)
    out.append("#define %s_N %d" % (name, len(t)))
    out.append("#define %s {%s}" % (name, ", ".join("0x%08Xul" % np.float32(v).view(np.uint32) for v in t)))
out.append("#endif")
open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src", "fconst.h"), "w").write("\n".join(out) + "\n")