Mercurial > vba-clojure
view clojure/com/aurellem/gb/badges.clj @ 227:d5dddf33543c
Added functions for getting and setting badges.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Sat, 24 Mar 2012 05:45:06 -0500 |
parents | |
children | edce489c3c21 |
line wrap: on
line source
1 (ns com.aurellem.gb.badges2 (:use (com.aurellem.gb gb-driver util constants))3 (:use (com.aurellem.world practice))4 (:import [com.aurellem.gb.gb_driver SaveState]))6 (def badges '(:boulder :cascade :thunder :marsh :rainbow :soul :volcano7 :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 (cons (peek coll) (this (pop coll) (int (/ n16 2))))))17 badges18 (aget (memory state) 0xD355)19 ))20 ([] (get-badges @current-state)))22 (defn set-badges23 "Sets the badges held by the player. badge-list may contain :boulder24 :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))))34 035 (vec badges))36 (set-memory state 0xD355))))39 ([badge-list] (set-badges @current-state badge-list)))47 ;; (let [mem (aget (memory state) 0xD354)]48 ;; ((fn this [coll n]49 ;; (cond (zero? n) '()50 ;; (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))51 ;; :else (cons (peek coll) (this (pop coll) (int (/ n52 ;; 2))))))53 ;; badges54 ;; (aget (memory state) 0xD354)55 ;; )))