0  ,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3<W                                  ÎÌÌÌÌˆˆˆ¬ªªª¬ˆˆˆ¬ÌÌÌ¬ÌÀÌ¬ÌÀÌ¬ÌÀÌÌÌìîˆˆÌîªªÀîˆ¨ÀîÌ¬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌÌˆˆˆ¬ªªª¬ˆˆˆ¬ÌÌÌ¬ÌÌÌ¬ÌÀÌ¬ÌÀÌÌÌìîˆˆÌîªªÀîˆ¨ÀîÌ¬ÀÌÌ¬ÀÀÀ¬ÀÀÀ¬ÀÀ                                                                                                                                                                                                                                                                                                                                                                                                ¬ÌÌÌ¬ªªª¬ª¬ª¬ªÊÌ¬ªªªŒˆˆˆÌ ÀÌÎÌÌÎÌ¬ ÌªªÀì¬ªÀîªªÀîªªÀîˆˆÌî ÀìîÌÌîî¬ÌÌÌ¬ªªª¬ª¬ª¬ªÊÌ¬ªªªŒˆˆˆÌ ÀÌÎÌÌÎÌ¬ ÌªªÀì¬ªÀîªªÀîªªÀîˆˆÌî ÀìîÌÌîî€ ÿÿÿÿÿÿóó3ÿ3óÿ33?32?ô?33ó?ÿóóÿÿÿÿÿÿóó?ó3?ÿ33?32?ô?33ó?ÿóóÿÿÿÿÿÿóó3ÿ3óÿ33?32?ô?33ó?ÿóóÿÿóóÿÿ3ÿÿ333ÿ3233ó?ô?33ó?ÿóóÿÿóóÿÿ33ÿ33óÿ32?3ó?ô?33ó?ÿóóÿÿóóÿÿ33ÿ33332?ô?33ó?ÿóó?ÿóóÿÿóóÿÿ3?ó33?ÿ32?3ó?ô?33ó?ÿóóÿÿóóÿÿ33ÿ33óÿ32?3ó?ô?33ó?ÿóóÿÿóóÿÿ33ÿ33332?ô?33ó?ÿóó?ÿóóÿÿóóÿÿ33ÿ33óÿ32?3ó?ô?33ó?ÿóóÿÿóóÿÿ3ÿÿ333ÿ3233ó?ô?33ó?ÿóóÿÿÿÿÿÿóó?ó3?ÿ33?32?ô?33ó?ÿóó                                                                                                                                ÿÿÿÿÿÿóó3ÿ3óÿ33?32?ô?33ó?ÿóóÿÿÿÿÿÿóó?ó3?ÿ33?32?ô?33óÿ3?ÿÿÿóóÿÿ33ÿ33332?ô?33óóÿ??ÿÿÿÿÿÿóóÿÿ33ÿ33332?ô?33óóÿ??ÿÿÿÿÿÿÿÿÿÿóó?ó3?ÿ33?32?ô?33óÿ3?ÿ                                                                                                                                                                                                                                                                                                                                                                ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ?ÿÿÿó??13ó?13ó?C3ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ?ÿÿÿó??13ó?1<ó?C3ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ?ÿÿÿó??Á<ó?Á<ó?3ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ?ÿÿÿó??13ó?1<ó?3  L                                                                                                                         3                                                                                                                    3 33                                                                                                                    332                                                                                                                    0                                                                                                                    033                                                                                                                    0                                                                                                                     0 ^ ;; title:   hello kog
;; author:  tsuyaki 
;; desc:    short description
;; site:    website link
;; license: MIT License (change this to your license of choice)
;; version: 0.1
;; script:  fennel
;; strict:  true

;; lib

(fn filter [pred coll]
  (icollect [_ v (ipairs coll)] (when (pred v) v)))

;; (filter (fn [n] (not n)) [false true])

(fn some? [pred coll]
  (~= 0 (# (filter pred coll))))

;; (some? (fn [n] (not n)) [false true])

;; (some? (fn [n] (not n)) [true true])

(fn every? [pred coll]
  (not (some? (fn [n] (not (pred n))) coll)))

;; (every? (fn [n] (not n)) [true true])
;;(every? (fn [n] (not n)) [false true])
;; (every? (fn [n] (not n)) [false false])

(fn map [f coll]
  (icollect [_ v (ipairs coll)] (f v)))

(fn cal-fps [t fps]
  (// t (// 1000 fps)))

;; env vars
(var trans 15)
(var pos [0 0])
(var spd 1)
(var kog 256)
(var kog-run-idl 272)
(var kog-sleep-idl 288)
(var idle-timer 0)

;; animation
(fn kog-idle []
  (-> (cal-fps (time) 12)
      (% 200)
      ((fn [n] (if (> n 50) (+ (% n 3 ) kog) (+ (% n 12) kog))))))

(fn kog-run []
  (-> (cal-fps (time) 12)
      (% 5)
      (+ kog-run-idl)))

(fn kog-sleep []
  (-> (cal-fps (time) 1)
      (% 4)
      (+ kog-sleep-idl)))

;; moving logic

(fn left  [[x y]] [(- x spd) y]) 
(fn right [[x y]] [(+ x spd) y]) 
(fn up    [[x y]] [x (- y spd)]) 
(fn down  [[x y]] [x (+ y spd)]) 

(fn mv-pos [bdx cb pos]
  (if (btn bdx) (cb pos) pos))

(fn mv [pos]
  (->> pos
       (mv-pos 0 up)
       (mv-pos 1 down)
       (mv-pos 2 left)
       (mv-pos 3 right)
       ))

(fn mv-spr [idx [x y]]
  (spr idx x y trans 1 (if (btn 2) 1 0)))

;; status
(fn act? []
  (some? (fn [n] n) (map btn [0 1 2 3 4 5 6 7])))

(fn idle? []
  (not (act?))) 

(fn >thirty? []
  (do
    (when (= 0 (% (cal-fps (time) 30) 30))
      (set idle-timer (+ idle-timer 1)))
    (> idle-timer 30)))

;; life cycle
(fn _G.TIC []
  (cls 0)

  ;; (trace (// (time) (// 1000 60)))
  ;; (trace (time // 1000))
  (when (idle?)
    (mv-spr (if (>thirty?) (kog-sleep) (kog-idle)) pos))

  (when (act?)
    (let [npos (mv pos)]
      (set pos npos))
    (set idle-timer 0)
    (mv-spr (kog-run) pos))
)
