~technomancy/fennel-lang.org

ref: 720592c61574fec92d38bf2f884b92d0368c4acc fennel-lang.org/sample.html -rw-r--r-- 900 bytes
720592c6Phil Hagelberg august user group 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
<pre id="sample" class="code"><span class="comment">;; Sample: read the state of the keyboard and move the player accordingly
</span>(<span class="keyword">local</span> dirs {<span class="builtin">:up</span> [0 -1] <span class="builtin">:down</span> [0 1] <span class="builtin">:left</span> [-1 0] <span class="builtin">:right</span> [1 0]})

(<span class="keyword">each</span> [key [dx dy] (<span class="builtin">pairs</span> dirs)]
  (<span class="keyword">when</span> (<span class="type">love.keyboard.isDown</span> key)
    (<span class="keyword">let</span> [[px py] player
          x (<span class="keyword">+</span> px (<span class="keyword">*</span> dx <span class="type">player.speed</span> dt))
          y (<span class="keyword">+</span> py (<span class="keyword">*</span> dy <span class="type">player.speed</span> dt))]
      (<span class="builtin">world:move</span> player x y))))
</pre>