player $player, $player at x #400 and y #300, can update for $player. update $id, player $id?: , compute player $id velocity x , @is-down key a, @is-down key d , compute player $id velocity y , @is-down key w, @is-down key s . compute player $id velocity x, @key-state down a: , player $id velocity x computed , player velocity x #-250 . compute player $id velocity x, @key-state down d: , player $id velocity x computed , player velocity x #250 . compute player $id velocity x: , player $id velocity x computed , player velocity x #0 . compute player $id velocity y, @key-state down w: , player $id velocity y computed , player velocity y #-250 . compute player $id velocity y, @key-state down s: , player $id velocity y computed , player velocity y #250 . compute player $id velocity y: , player $id velocity y computed , player velocity y #0 . player $id velocity y computed, player $id velocity x computed: , player $id velocity computed . player $id velocity computed?, @key-state up $key: . player $id velocity computed?, @key-state down $key: . tick $dt? , player $id velocity computed , $id at x $x and y $y , player velocity y $vy , player velocity x $vx: , commit player $id motion $new-x-token $new-y-token , @expr eval $new-x-token [%1 * %2 + %3] $vx $dt $x , @expr eval $new-y-token [%1 * %2 + %3] $vy $dt $y . commit player $id motion $new-x-token $new-y-token, @expr success $x $new-x-token, @expr success $y $new-y-token: , finished update for $id , $id at x $x and y $y , @circle $x $y #20 . compute enemy $id velocity , $id at x $my-x and y $my-y? , player $player? , $player at x $player-x and y $player-y?: , find angle to player for enemy $id using $delta-x-token $delta-y-token , @expr eval $delta-x-token [%1 - %2] $player-x $my-x , @expr eval $delta-y-token [%1 - %2] $player-y $my-y . find angle to player for enemy $id using $delta-x-token $delta-y-token , @expr success $delta-x $delta-x-token , @expr success $delta-y $delta-y-token: , compute enemy $id motion using $angle-token , @atan2 from $delta-x $delta-y into $angle-token . compute enemy $id motion using $angle-token , @atan2 angle $angle $angle-token: , compute new enemy $id location using $vx-token $vy-token , @expr eval $vx-token [cos(%1) * 200] $angle , @expr eval $vy-token [sin(%1) * 200] $angle . compute new enemy $id location using $vx-token $vy-token , tick $dt? , $id at x $x and y $y , @expr success $vx $vx-token , @expr success $vy $vy-token: , complete enemy $id update using $x-token $y-token , @expr eval $x-token [%1 + %2 * %3] $x $vx $dt , @expr eval $y-token [%1 + %2 * %3] $y $vy $dt . complete enemy $id update using $x-token $y-token, @expr success $x $x-token, @expr success $y $y-token: , finished update for $id , $id at x $x and y $y , @circle $x $y #10 . update $id, enemy $id?: , compute enemy $id velocity . update $self, bullet $self? , $self at x $x and y $y , $self velocity is x $vx and y $vy? , tick $dt?: , move bullet $self using $x-token $y-token , @expr eval $x-token [%1 + %2 * %3] $x $vx $dt , @expr eval $y-token [%1 + %2 * %3] $y $vy $dt . move bullet $self using $x-token $y-token, @expr success $x $x-token, @expr success $y $y-token: , $self at x $x and y $y , check if bullet $self should be destroyed , finish bullet $self update . check if bullet $self should be destroyed, $self at x $x and y $y?: , is bullet $self in bounds checking $left-bounds $right-bounds $top-bounds $bottom-bounds , @compare $x and #0 producing $left-bounds , @compare $x and #800 producing $right-bounds , @compare $y and #0 producing $top-bounds , @compare $y and #600 producing $bottom-bounds . is bullet $self in bounds checking $left-bounds $right-bounds $top-bounds $bottom-bounds , @compare greater-than $left-bounds , @compare less-than $right-bounds , @compare greater-than $top-bounds , @compare less-than $bottom-bounds: bullet $self is in bounds. is bullet $self in bounds checking $left-bounds $right-bounds $top-bounds $bottom-bounds , @compare $invalid-1 $left-bounds , @compare $invalid-2 $right-bounds , @compare $invalid-3 $top-bounds , @compare $invalid-4 $bottom-bounds: bullet $self is out of bounds. bullet $self is out of bounds?, @compare $ord $token:. finish bullet $self update, bullet $self is out of bounds, bullet $self, $self at x $x and y $y, $self velocity is x $vx and y $vy: . finish bullet $self update, bullet $self is in bounds, $self at x $x and y $y?: , finished update for $self , @circle $x $y #5 . spawn-timer $self , $self is at #0 seconds , $self times out every #1 seconds , can update for $self . update $self, spawn-timer $self?, $self is at $time seconds, tick $dt?: , update timer $self using $new-time-token , @expr eval $new-time-token [%1 + %2] $time $dt . update timer $self using $new-time-token , $self times out every $time-out seconds? , @expr success $time $new-time-token: , update timer $self to $time seconds using $bounds-check , @compare $time and $time-out producing $bounds-check . update timer $self to $time seconds using $bounds-check , @compare less-than $bounds-check: , $self is at $time seconds, , finished update for $self . update timer $self to $time seconds using $bounds-check, @compare $invalid $bounds-check: , spawn enemy , $self is at #0 seconds , finished update for $self . spawn enemy: , compute enemy $id location using $turns-token , @random generate $turns-token . compute enemy $id location using $turns-token, @random get $turns $turns-token: , commit new enemy $id at x $x-token and y $y-token , @expr eval $x-token [cos(6.28318530718 * %1) * 500 + 400] $turns , @expr eval $y-token [sin(6.28318530718 * %1) * 500 + 300] $turns . commit new enemy $id at x $x-token and y $y-token, @expr success $x $x-token, @expr success $y $y-token: , enemy $id , $id at x $x and y $y , can update for $id . bullet-spawner $self , can mouse-pressed for $self. mouse-pressed $self $mouse-x $mouse-y $button, bullet-spawner $self? , player $p?, $p at x $player-x and y $player-y?: , shoot bullet at angle using $angle-token , compute shoot angle using $shoot-x-token $shoot-y-token producing $angle-token , @expr eval $shoot-x-token [%1 - %2] $mouse-x $player-x , @expr eval $shoot-y-token [%1 - %2] $mouse-y $player-y . compute shoot angle using $shoot-x-token $shoot-y-token producing $angle-token , @expr success $shoot-x $shoot-x-token , @expr success $shoot-y $shoot-y-token: , @atan2 from $shoot-x $shoot-y into $angle-token . shoot bullet at angle using $angle-token , player $p?, $p at x $player-x and y $player-y? , @atan2 angle $angle $angle-token: , create new bullet $id using $spawn-x-token $spawn-y-token $bullet-vx-token $bullet-vy-token , @expr eval $spawn-x-token [cos(%1) + %2] $angle $player-x , @expr eval $spawn-y-token [sin(%1) + %2] $angle $player-y , @expr eval $bullet-vx-token [cos(%1) * 500] $angle , @expr eval $bullet-vy-token [sin(%1) * 500] $angle . , create new bullet $id using $spawn-x-token $spawn-y-token $bullet-vx-token $bullet-vy-token , bullet-spawner $self? , @expr success $bullet-x $spawn-x-token , @expr success $bullet-y $spawn-y-token , @expr success $bullet-vx $bullet-vx-token , @expr success $bullet-vy $bullet-vy-token: , bullet $id , $id at x $bullet-x and y $bullet-y , $id velocity is x $bullet-vx and y $bullet-vy , can update for $id , finished mouse-pressed for $self . tick $dt?, can update for $id: , update $id . tick $dt: prepare next tick. mouse-pressed $x $y $button, can mouse-pressed for $id: , mouse-pressed $id $x $y $button . mouse-pressed $x $y $button: . prepare next tick?, finished $event for $id: can $event for $id. prepare next tick: .