Mercurial > vba-clojure
view clojure/com/aurellem/gb/badges.clj @ 319:92c47a9cdaea
adapting bootstrap to new util functions.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 03 Apr 2012 04:16:20 -0500 |
parents | edce489c3c21 |
children |
line wrap: on
line source
1 (ns com.aurellem.gb.badges2 (:use (com.aurellem.gb gb-driver util constants))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (def badges6 '(:boulder :cascade :thunder :rainbow7 :soul :marsh :volcano :earth))9 (defn get-badges10 "Returns a list of the current badges held by the player."11 ([state]12 ((fn this [coll n]13 (cond (zero? n) '()14 (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))15 :else (cons16 (peek coll)17 (this (pop coll) (int (/ n 2))))))18 badges19 (aget (memory state) 0xD355)))20 ([] (get-badges @current-state)))22 (defn set-badges23 "Sets the badges held by the player. badge-list may contain24 :boulder :cascade :thunder :marsh :rainbow :soul :volcano."25 ([state badge-list]26 (let [has-badge (set badge-list)]27 (->>28 ((fn [n coll]29 (cond30 (empty? coll) n31 (has-badge (peek coll)) (recur (inc(* 2 n)) (pop coll))32 :else (recur (* 2 n) (pop coll))))33 034 (vec badges))35 (set-memory state 0xD355))))36 ([badge-list] (set-badges @current-state badge-list)))38 (defn give-all-badges39 ([^SaveState state]40 (set-badges state badges))41 ([] (give-all-badges @current-state)))