d621976b4a1b entry-03-3

moar.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 09 Jul 2012 19:00:06 -0400
parents 458886294f3c
children 454c6e1c9cfd
branches/tags entry-03-3
files brain-dump.markdown src/caves/core.clj

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/brain-dump.markdown	Mon Jul 09 19:00:06 2012 -0400
@@ -0,0 +1,163 @@
+Ideas
+=====
+
+Remove the distinction between items and creatures.  ALL THING ARE ENTITY.
+
+    (defprocotol Entity
+      (tick [this game])
+      (get-location [this game?])
+      (get-id [this]))
+
+    (def Entity
+      (with-meta Entity :default-fns
+        {:tick         (fn [this game] game)
+         :get-location (fn [this game] (:location this))
+         :get-id       (fn [this] (:id this))}))
+
+
+Individual things will implement the protocol:
+
+    (defrecord Pixie [id location])
+
+    (extend-entity Pixie
+      (tick [this game]
+         (do-stuff game)))
+
+    (extend Pixie Entity
+      (merge {:tick (fn [this game] game)
+              :get-location (fn [this game] (:location this))
+              :get-id (fn [this] (:id this))}
+             {:tick (fn [this game]
+                      (do-stuff game))}))
+
+    (defmacro extend-entity [cls & fns]
+      (let [fnmap (into {}
+                    (for [[fn-name & fn-tail] fns]
+                      [(keyword fn-name) fn-tail]))]
+        `(extend ~cls Entity
+          (merge default-entity-fns
+                 ~fnmap))))
+
+The Entity protocol should be very sparse.  Most functionality will come from
+other protocols that can be "added in" on a case-by-case basis.  Like mixins,
+but without the monkeypatching clusterfuck.
+
+Sample Entities
+---------------
+
+A Fungus might look like:
+
+    (extend' Fungus Destructible ...)
+    (extend' Fungus Metabolizer ...)
+
+Funguses don't do much.  They do draw nutrition from the soil though, so their
+nutritional value should grow over time until they split.
+
+Goblins:
+
+    (extend' Goblin Mobile ...)
+    (extend' Goblin Destructible ...)
+    (extend' Goblin Attacker ...)
+    (extend' Goblin AI ...)
+    (extend' Goblin Container ...)
+    (extend' Goblin Wearer ...)
+    (extend' Goblin Wielder ...)
+    (extend' Goblin Eater ...)
+    (extend' Goblin Metabolizer ...)
+
+Goblines are mobs that can walk around, be killed, kill things, have an
+inventory, wear armor and wield weapons, eat food, and burn their eaten food.
+
+Pixies:
+
+    (extend' Pixie Mobile ...)
+    (extend' Pixie Destructible ...)
+    (extend' Pixie Attacker ...)
+    (extend' Pixie AI ...)
+
+    (extend' Pixie Item ...)
+    (extend' Pixie Applicable ...)
+    (extend' Pixie Edible ...)
+
+Here Pixies are entities that move around, can be destroyed (i.e. killed), can
+attack other entities, have an AI to decide actions (put this in tick?).  Sounds
+like a normal monster, but they can also function as an item if you pick them
+up.  They can then be applied or eaten.
+
+Ideas for Entity Protocols
+--------------------------
+
+### Entity
+
+Base protocol.  All entities must implement this.
+
+Basically it's implementation-related stuff that's not gameplay-related.
+
+Exception: materials?
+
+### Mobile
+
+Can move autonomously.
+
+### Item
+
+Can be placed in a container.
+
+### Armor
+
+Can be worn as armor by wearers.
+
+### Weapon
+
+Can be used as a weapon by wielders.
+
+### Container
+
+Can hold things that implement Item.  Creatures can be Containers -- this
+effectively means they have an inventory.
+
+### Food
+
+Can be eaten by Eaters (maybe).
+
+### Quaffable
+
+Can be drunk by drinkers.
+
+### Eater
+
+Can eat Food (maybe).
+
+### Drinker
+
+Can drink Quaffables (maybe).
+
+### Metabolizer
+
+Has a notion of "energy" that either decreases over time (hunger) or increases
+over time (photosynthesis).
+
+### Destructible
+
+Can be destroyed by physical (or magical) trauma.  Usually handled through HP
+counts.
+
+### Decaying
+
+Can transform to something else (or nothing) over a period of time.
+
+### Attacker
+
+Can physically attack other creatures.
+
+### Wielder
+
+Can use other entities as weapons if they implement Weapon.
+
+### Wearer
+
+Can use other entities as armor if they implement Armor.
+
+### Sentient
+
+Has an alignment.  Not sure about this one.
--- a/src/caves/core.clj	Sun Jul 08 21:55:31 2012 -0400
+++ b/src/caves/core.clj	Mon Jul 09 19:00:06 2012 -0400
@@ -38,6 +38,7 @@
   (s/put-string screen 0 0 "Sorry, better luck next time.")
   (s/put-string screen 0 1 "Press escape to exit, anything else to restart."))
 
+
 (defn get-viewport-coords [game vcols vrows]
   (let [location (:location game)
         [center-x center-y] location
@@ -47,8 +48,11 @@
         map-rows (count tiles)
         map-cols (count (first tiles))
 
-        start-x (max 0 (- center-x (int (/ vcols 2))))
-        start-y (max 0 (- center-y (int (/ vrows 2))))
+        start-x (- center-x (int (/ vcols 2)))
+        start-x (max 0 start-x)
+
+        start-y (- center-y (int (/ vrows 2)))
+        start-y (max 0 start-y)
 
         end-x (+ start-x vcols)
         end-x (min end-x map-cols)
@@ -60,6 +64,21 @@
         start-y (- end-y vrows)]
     [start-x start-y end-x end-y]))
 
+(defn draw-crosshairs [screen vcols vrows]
+  (let [crosshair-x (int (/ vcols 2))
+          crosshair-y (int (/ vrows 2))]
+      (s/put-string screen crosshair-x crosshair-y "X" {:fg :red})
+      (s/move-cursor screen crosshair-x crosshair-y)))
+
+(defn draw-world [screen vrows vcols start-x start-y end-x end-y tiles]
+  (doseq [[vrow-idx mrow-idx] (map vector
+                                   (range 0 vrows)
+                                   (range start-y end-y))
+          :let [row-tiles (subvec (tiles mrow-idx) start-x end-x)]]
+    (doseq [vcol-idx (range vcols)
+            :let [{:keys [glyph color]} (row-tiles vcol-idx)]]
+      (s/put-string screen vcol-idx vrow-idx glyph {:fg color}))))
+
 (defmethod draw-ui :play [ui game screen]
   (let [world (:world game)
         tiles (:tiles world)
@@ -67,17 +86,9 @@
         vcols cols
         vrows (dec rows)
         [start-x start-y end-x end-y] (get-viewport-coords game vcols vrows)]
-    (doseq [[vrow-idx mrow-idx] (map vector
-                                     (range 0 vrows)
-                                     (range start-y end-y))
-            :let [row-tiles (subvec (tiles mrow-idx) start-x end-x)]]
-      (doseq [vcol-idx (range vcols)
-              :let [{:keys [glyph color]} (row-tiles vcol-idx)]]
-        (s/put-string screen vcol-idx vrow-idx glyph {:fg color})))
-    (let [crosshair-x (int (/ vcols 2))
-          crosshair-y (int (/ vrows 2))]
-      (s/put-string screen crosshair-x crosshair-y "X" {:fg :red})
-      (s/move-cursor screen crosshair-x crosshair-y))))
+    (draw-world screen vrows vcols start-x start-y end-x end-y tiles)
+    (draw-crosshairs screen vcols vrows)))
+
 
 (defn draw-game [game screen]
   (clear-screen screen)
@@ -103,7 +114,7 @@
 (defmethod process-input :play [game input]
   (case input
     :enter     (assoc game :uis [(new UI :win)])
-    :backspace (assoc game :uis [(new UI :win)])
+    :backspace (assoc game :uis [(new UI :lose)])
     \q         (assoc game :uis [])
 
     \s (assoc game :world (smooth-world (:world game)))