package elm_playground_gamekits
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Genre kits for Playground games: platformers, racing, shoot 'em ups, fighting and more
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.3.6.tar.gz
md5=7c636383d146d30ac6f2fa234a6253c8
sha512=c79f3823c5f8f57e5038eb640d487c61168b84aa07c61999d6622ef9fd0c890e2b03b4c6a7cdbbe9352a49e25dda00ac7bb14693cee8e3d7beeed251351a2af0
doc/src/elm_playground_gamekits.kit_sports/Free_ball.ml.html
Source file Free_ball.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37(* Claude Code * * Copyright (C) 2026 Yoann Padioleau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * (LGPL) as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. *) open Playground open Basics (* See Free_ball.mli *) type t = { x : number; y : number; vx : number; vy : number } let still (x : number) (y : number) : t = { x; y; vx = 0.; vy = 0. } let roll ~(friction : number) ?(push = (0., 0.)) (b : t) : t = let ax, ay = push in let vx = (b.vx + ax) * friction and vy = (b.vy + ay) * friction in { x = b.x + vx; y = b.y + vy; vx; vy } let touch ~(glued : bool) ~(speed : number) ~(reach : number) ~(hold : number) ((px, py) : number * number) ((dx, dy) : number * number) (b : t) : t option = if Float.hypot (b.x - px) (b.y - py) > reach then None else let d = Float.max 1e-9 (Float.hypot dx dy) in if glued then Some { x = px + (dx / d * hold); y = py + (dy / d * hold); vx = 0.; vy = 0. } else Some { b with vx = speed * dx / d; vy = speed * dy / d } let bounce_in ~(half_w : number) ~(half_h : number) ~(keep : number) (b : t) : t = let x, vx = if b.x < 0. - half_w then (0. - half_w, Float.abs b.vx * keep) else if b.x > half_w then (half_w, 0. - (Float.abs b.vx * keep)) else (b.x, b.vx) in let y, vy = if b.y < 0. - half_h then (0. - half_h, Float.abs b.vy * keep) else if b.y > half_h then (half_h, 0. - (Float.abs b.vy * keep)) else (b.y, b.vy) in { x; y; vx; vy } let speed (b : t) : number = Float.hypot b.vx b.vy let near (r : number) ((x, y) : number * number) (b : t) : bool = Float.hypot (b.x - x) (b.y - y) < r
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>