(module (global $x (export "x") (mut f64) (f64.const 400)) (global $y (export "y") (mut f64) (f64.const 400)) (global $vx (mut f64) (f64.const 180)) (global $vy (mut f64) (f64.const -260)) (func (export "reset") (param $direction f64) (global.set $x (f64.const 400)) (global.set $y (f64.const 400)) (global.set $vx (f64.mul (f64.const 180) (local.get $direction))) (global.set $vy (f64.const -260))) (func (export "reflectY") (global.set $vy (f64.neg (global.get $vy)))) (func (export "step") (param $dt f64) (param $player f64) (param $opponent f64) (param $bricks i32) (result i32) (local $t f64) (local $hit i32) (local.set $t (f64.max (f64.const 0) (f64.min (f64.const 0.02) (local.get $dt)))) (global.set $x (f64.add (global.get $x) (f64.mul (global.get $vx) (local.get $t)))) (global.set $y (f64.add (global.get $y) (f64.mul (global.get $vy) (local.get $t)))) (if (f64.lt (global.get $x) (f64.const 8)) (then (global.set $x (f64.const 8)) (global.set $vx (f64.abs (global.get $vx))))) (if (f64.gt (global.get $x) (f64.const 792)) (then (global.set $x (f64.const 792)) (global.set $vx (f64.neg (f64.abs (global.get $vx)))))) (if (i32.and (f64.ge (global.get $y) (f64.const 550)) (f64.gt (global.get $vy) (f64.const 0))) (then (if (f64.lt (f64.abs (f64.sub (global.get $x) (local.get $player))) (f64.const 63)) (then (global.set $y (f64.const 550)) (global.set $vy (f64.neg (f64.abs (global.get $vy)))) (global.set $vx (f64.mul (f64.sub (global.get $x) (local.get $player)) (f64.const 5))) (local.set $hit (i32.const 3)))))) (if (f64.gt (global.get $y) (f64.const 620)) (then (return (i32.const 1)))) (if (i32.and (f64.le (global.get $y) (f64.const 38)) (f64.lt (global.get $vy) (f64.const 0))) (then (if (i32.or (local.get $bricks) (f64.lt (f64.abs (f64.sub (global.get $x) (local.get $opponent))) (f64.const 63))) (then (global.set $y (f64.const 38)) (global.set $vy (f64.abs (global.get $vy))))))) (if (f64.lt (global.get $y) (f64.const -20)) (then (return (i32.const 2)))) (local.get $hit)) )