comparison 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
comparison
equal deleted inserted replaced
226:21641c1c3f87 227:d5dddf33543c
1 (ns com.aurellem.gb.badges
2 (:use (com.aurellem.gb gb-driver util constants))
3 (:use (com.aurellem.world practice))
4 (:import [com.aurellem.gb.gb_driver SaveState]))
5
6 (def badges '(:boulder :cascade :thunder :marsh :rainbow :soul :volcano
7 :earth))
8
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 (peek coll) (this (pop coll) (int (/ n
16 2))))))
17 badges
18 (aget (memory state) 0xD355)
19 ))
20 ([] (get-badges @current-state)))
21
22 (defn set-badges
23 "Sets the badges held by the player. badge-list may contain :boulder
24 :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
34 0
35 (vec badges))
36 (set-memory state 0xD355))))
37
38
39 ([badge-list] (set-badges @current-state badge-list)))
40
41
42
43
44
45
46
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 (/ n
52 ;; 2))))))
53 ;; badges
54 ;; (aget (memory state) 0xD354)
55 ;; )))
56