-- CONSTANTS local SPIN_TIME = TICRATE / 4 local SPINOUT_MULT = 8 local TUMBLE_HEIGHT = 20 local VOLTAGE_PER_TRICK = 5 local MINI_TRICK_THRUST = 4*FRACUNIT local MINI_TRICK_ANGLE = ANGLE_90 local TUMBLE_BONUS = 2 -- PLAYER SPAWN local function resetMiniTricks(player) player.minitricking = false player.trickVoltage = 0 player.trickCount = 0 player.trickTimer = 0 player.didUpTrick = false player.prevAccel = false player.prevTurnDir = 0 player.prevThrowDir = 0 player.prevFastfall = 0 player.releasedAccelInAir = false -- Must release accel after leaving ground player.trickpanel = TRICKSTATE_NONE end local function resetBoost(player) player.voltage = 0 player.storedair = 0 player.aiddeflation = 0 player.trickboosting = false end addHook("PlayerSpawn", function(player) resetMiniTricks(player) resetBoost(player) end) -- FUNCTIONS local function wasfastfalling(player) return player.prevFastfall and player.prevFastfall ~= 0 end local function isfastfalling(player) return player.fastfall and player.fastfall ~= 0 end -- PLAYER THINK addHook("PlayerThink", function(player) if player.mo and player.mo.valid then -- Reset accel release requirement when landing if P_IsObjectOnGround(player.mo) then player.releasedAccelInAir = false end -- Check if player released accel while in air if not P_IsObjectOnGround(player.mo) then if not (player.cmd.buttons & BT_ACCELERATE) then player.releasedAccelInAir = true end end if not P_IsObjectOnGround(player.mo) -- "Ready to Trick" and player.minitricking == false and player.trickpanel ~= TRICKSTATE_READY and player.trickTimer == 0 and player.releasedAccelInAir == true and player.spinouttimer == 0 and player.trickpanel ~= TRICKSTATE_BACK and not isfastfalling(player) then if player.cmd.forwardmove > 0 then if player.cmd.turning > 0 then -- RIGHT P_Thrust(player.mo, player.mo.angle + MINI_TRICK_ANGLE, MINI_TRICK_THRUST) player.trickpanel = TRICKSTATE_RIGHT player.trickVoltage = $ + VOLTAGE_PER_TRICK player.minitricking = true player.trickTimer = SPIN_TIME elseif player.cmd.turning < 0 then -- LEFT P_Thrust(player.mo, player.mo.angle - MINI_TRICK_ANGLE, MINI_TRICK_THRUST) player.trickpanel = TRICKSTATE_LEFT player.trickVoltage = $ + VOLTAGE_PER_TRICK player.minitricking = true player.trickTimer = SPIN_TIME elseif player.cmd.throwdir < 0 then -- UP (tumble) K_TumblePlayer(player, nil, nil, true) player.trickVoltage = $ + VOLTAGE_PER_TRICK + (player.trickCount*TUMBLE_BONUS) player.minitricking = true player.trickTimer = SPIN_TIME end if player.minitricking == true then -- Apply for every. S_StartSound(player.mo, sfx_kc2e) player.trickCount = $ + 1 end end elseif not P_IsObjectOnGround(player.mo) then -- "While Tricking" if player.trickTimer <= 0 then player.minitricking = false if player.trickpanel == TRICKSTATE_RIGHT then player.trickpanel = TRICKSTATE_NONE elseif player.trickpanel == TRICKSTATE_LEFT then player.trickpanel = TRICKSTATE_NONE elseif player.tumbleheight > 0 then K_TumbleInterrupt(player) player.tumbleheight = 0 player.spinouttimer = 0 player.trickpanel = TRICKSTATE_BACK end else player.trickTimer = $ - 1 end if (player.cmd.buttons & BT_SPINDASH) then player.minitricking = false if player.mo.momz > 0 then player.mo.momz = 0 end player.trickTimer = 0 S_StartSound(player.mo, sfx_s260) end elseif player.trickVoltage >= 1 then -- Apply mini voltage drop on falling if wasfastfalling(player) then -- Did the player fastfall? (Press Spindash) P_Thrust(player.mo, player.mo.angle, (FRACUNIT*((player.trickCount/5)+1)*player.trickVoltage)/((player.trickTimer/10)+1)) player.voltage = $ + FRACUNIT*((player.trickCount/5)+1)*player.trickVoltage*3/4 if player.speed > FRACUNIT*500 then player.voltage = $ + player.speed player.speed = FRACUNIT*500 end elseif player.trickTimer > 0 then player.spinouttimer = $ + player.trickTimer*SPINOUT_MULT if player.tumbleheight > 0 then S_StartSound(player.mo, sfx_s3kb1) else S_StartSound(player.mo, sfx_s3kb2) end else player.trickboosting = true player.speedboost = $ + (player.trickVoltage) player.voltage = $ + FRACUNIT*((player.trickCount/5)+1)*player.trickVoltage end P_Thrust(player.mo, player.mo.angle, (FRACUNIT*10)) S_StopSound(player.mo, sfx_kc2e) S_StartSound(player.mo, sfx_s23c) resetMiniTricks(player) end -- Air / Voltage Deflation on Non Fastfall finish if not wasfastfalling(player) and P_IsObjectOnGround(player.mo) and player.voltage then -- Deflating balloon P_Thrust(player.mo, player.mo.angle, FixedSqrt((2*FRACUNIT)/TICRATE+(player.voltage/(TICRATE*10)))) player.voltage = $ - FixedSqrt((FRACUNIT)/TICRATE + $ / (TICRATE*10)) if player.voltage <= 0 then resetBoost(player) end end -- Store for next frame player.prevFastfall = player.fastfall end end) -- HUD local function miniTHud(v, p, c) if p.minitricking ~= false then v.drawString(120, 50, "TRICKING!", 0, "right") end v.drawString(6, 50, "Trick Voltage: " .. (p.trickVoltage or 0), V_MONOSPACE, "small") v.drawString(6, 55, "Trick Count: " .. (p.trickCount or 0), V_MONOSPACE, "small") v.drawString(6, 60, "Trick Timer: " .. (p.trickTimer or 0), V_MONOSPACE, "small") v.drawString(6, 65, "Air Balloon: " .. (p.voltage/FRACUNIT or "NONE"), V_MONOSPACE, "small") end --hud.add(miniTHud)