4922d66cbba5

Clean up sidebar, add health and energy
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 07 Jan 2017 16:26:29 +0000
parents 692ec1bec892
children 8961421a3c9b
branches/tags (none)
files package.lisp src/entities/player.lisp src/main.lisp

Changes

diff -r 692ec1bec892 -r 4922d66cbba5 package.lisp
--- a/package.lisp	Sat Jan 07 16:14:15 2017 +0000
+++ b/package.lisp	Sat Jan 07 16:26:29 2017 +0000
@@ -50,6 +50,10 @@
   (:export
     :player
     :make-player
+    :player/health
+    :health-description
+    :player/energy
+    :energy-description
 
     :coords
     :coords/x
diff -r 692ec1bec892 -r 4922d66cbba5 src/entities/player.lisp
--- a/src/entities/player.lisp	Sat Jan 07 16:14:15 2017 +0000
+++ b/src/entities/player.lisp	Sat Jan 07 16:26:29 2017 +0000
@@ -1,7 +1,23 @@
 (in-package :ap.entities)
 
+(defun health-description (health-value)
+  (cond ((< health-value 0.0) "dead")
+        ((< health-value 10.0) "almost dead")
+        ((< health-value 50.0) "in bad shape")
+        ((< health-value 70.0) "feeling decent")
+        ((<= health-value 100.0) "feeling healthy")))
 
-(define-entity player (coords visible))
+(defun energy-description (energy-value)
+  (cond ((< energy-value 0.0) "starving")
+        ((< energy-value 30.0) "famished")
+        ((< energy-value 50.0) "very hungry")
+        ((< energy-value 70.0) "hungry")
+        ((< energy-value 80.0) "peckish")
+        ((<= energy-value 100.0) "full")))
+
+(define-entity player (coords visible)
+  (health :accessor player/health :initform 100.0)
+  (energy :accessor player/energy :initform 100.0))
 
 (defun make-player ()
   (create-entity 'player
diff -r 692ec1bec892 -r 4922d66cbba5 src/main.lisp
--- a/src/main.lisp	Sat Jan 07 16:14:15 2017 +0000
+++ b/src/main.lisp	Sat Jan 07 16:26:29 2017 +0000
@@ -23,7 +23,7 @@
 
 (defparameter *wat* nil)
 (defparameter *player* nil)
-(defparameter *sidebar-width* 20)
+(defparameter *sidebar-width* 30)
 
 
 ;;;; More Utils Lol
@@ -165,6 +165,18 @@
       (with-color (window (visible/color entity))
         (charms:write-string-at-point window (visible/glyph entity) sx sy)))))
 
+(defun render-sidebar (window)
+  (charms:clear-window window)
+  (border window)
+  (write-string-left window
+                     (format nil "You are ~A" (health-description
+                                                (player/health *player*)))
+                     1 1)
+  (write-string-left window
+                     (format nil "        ~A" (energy-description
+                                                (player/energy *player*)))
+                     1 2))
+
 
 (defun world-map-input (window)
   (case (charms:get-char window)
@@ -175,13 +187,13 @@
     (:down  (zapf *view-y* (clamp (1+ %) 0 20000)))))
 
 (defun world-map ()
-  (with-dims ((- *screen-width* 2) (- *screen-height* 2))
+  (with-dims ((- *screen-width* 2) (- *screen-height* 1))
     (with-panels-and-windows
         ((map-pan map-win (- *width* *sidebar-width*) *height* 0 0)
          (bar-pan bar-win *sidebar-width* *height* (- *width* *sidebar-width*) 0))
       (iterate
-        (charms:clear-window bar-win)
-        (border bar-win)
+        (with-window-dims bar-win
+          (render-sidebar bar-win))
         (with-window-dims map-win
           (center-view-on-player *width* *height*)
           (render-map map-win))