view clojure/com/aurellem/gb/badges.clj @ 298:95afeea88c3a

found a second good character-item that can serve as a target
author Robert McIntyre <rlm@mit.edu>
date Fri, 30 Mar 2012 22:41:25 -0500
parents edce489c3c21
children
line wrap: on
line source
1 (ns com.aurellem.gb.badges
2 (:use (com.aurellem.gb gb-driver util constants))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (def badges
6 '(:boulder :cascade :thunder :rainbow
7 :soul :marsh :volcano :earth))
9 (defn get-badges
10 "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
16 (peek coll)
17 (this (pop coll) (int (/ n 2))))))
18 badges
19 (aget (memory state) 0xD355)))
20 ([] (get-badges @current-state)))
22 (defn set-badges
23 "Sets the badges held by the player. badge-list may contain
24 :boulder :cascade :thunder :marsh :rainbow :soul :volcano."
25 ([state badge-list]
26 (let [has-badge (set badge-list)]
27 (->>
28 ((fn [n coll]
29 (cond
30 (empty? coll) n
31 (has-badge (peek coll)) (recur (inc(* 2 n)) (pop coll))
32 :else (recur (* 2 n) (pop coll))))
33 0
34 (vec badges))
35 (set-memory state 0xD355))))
36 ([badge-list] (set-badges @current-state badge-list)))
38 (defn give-all-badges
39 ([^SaveState state]
40 (set-badges state badges))
41 ([] (give-all-badges @current-state)))