summaryrefslogtreecommitdiff
path: root/the-price-of-a-cup-of-coffee.lisp
blob: af7e73a37c9832364f3fdca947c7e3bf43cd7f6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;;;; the-price-of-a-cup-of-coffee.lisp

(in-package #:the-price-of-a-cup-of-coffee)

(defun make-keyword-symbol (s)
  "Makes a keyword from a string or symbol."
  (let ((s (format nil "~a" s)))
    (read-from-string
     (format nil ":~a"
             (substitute #\- #\Space s)))))


(defmacro def-normal-class (name super &rest slots)
  "Defines a class with the given name and slots, with accessors and initargs for each slot."
  `(defclass ,name ,super
     (,@(loop :for slot :in slots
              :when (consp slot)
                :collect (list (car slot)
                               :accessor (car slot)
                               :initform (cadr slot)
                               :initarg (make-keyword-symbol (car slot)))
              :else
                :collect (list slot
                               :accessor slot
                               :initform nil
                               :initarg (make-keyword-symbol slot))))))


(def-normal-class pedestrian ()
  (walk-vec (list 2 0))
  (comfort-rad 60)
  (react-per-sec 1)
  (anger 0.1)
  (kindness 0.02)
  (generosity 0.25)
  (vulnerability 3))


(def-normal-class ()
  (stress 0)
  (money 0)
  (coldness 0)
  (sick-p nil)
  (speed 5)
  (relax-rate 1)


(defun main ()
  (sdl2:with-init (:everything)
    (sdl2:with-window (win :w 800 :h 600 :title "The Price Of A Cup Of Coffee" :flags '(:shown))
      (sdl2:with-renderer (rndr win :flags '(:accelerated))
        (sdl2:with-event-loop (:method :poll)

          (:keydown (:keysym keysym)
                    (if (sdl2:scancode= (sdl2:scancode-value keysym) :scancode-escape)
                        (sdl2:push-event :quit)))
          (:idle ())

          (:quit () t))))))