Skip to reading
Adventure Mechanics & Effects

Give the porter his own clock

Edition 0.86.3.4

Build authored boxing, camera moves, weather, attachments, inspectable objects, a radio and two-object puzzles using the existing adventure tools and scripts.

Download PDFView PDF page

LIVE BOXING SCRIPT / E OF G

Append the whole function. Every physics tick advances both fighters, lets the porter decide to swing, then applies both results before it decides who won.

Code example
func _physics_process(dt: float) -> void:
    if not live:
        return
    var moved = room_stamp != Runtime.room_event_generation
    if moved or game_stamp != Runtime.runtime_generation:
        finish("")
        return
    if suspended():
        forget_keys()
        return
    for i in range(2):
        var f = fighters[i]
        var before = f.age
        f.age += dt
        f.charge = minf(1.0, f.charge + dt / 1.1)
        if before < READY and f.age >= READY:
            pose(i, "idle")
            var lane = player_guard()
            if i == 1:
                lane = ["high", "low", ""].pick_random()
            defend(i, lane)
    next_attack -= dt
    if next_attack <= 0 and fighters[1].age >= READY:
        punch(1, ["high", "low"].pick_random())
        next_attack = randf_range(0.90, 1.55)
    var to_porter = damage(0)
    var to_hero = damage(1)
    fighters[0].hp = maxi(0, fighters[0].hp - to_hero)
    fighters[1].hp = maxi(0, fighters[1].hp - to_porter)
    if fighters[0].hp == 0 or fighters[1].hp == 0:
        var win = fighters[1].hp == 0 and fighters[0].hp > 0
        if win:
            Runtime.variables["spar_won"] = true
        var tie = fighters[0].hp == 0 and fighters[1].hp == 0
        var result = "The porter yields." if win else "You yield."
        finish("Draw." if tie else result)
        return
    hud()
Page 25 of 29Permalink
Go to page