Browse Source

Add random enemy spawns

Lily Carpenter 9 years ago
parent
commit
14cca9ca70
2 changed files with 13 additions and 4 deletions
  1. 2 1
      NOTES.org
  2. 11 3
      src/crypts-and-corpses.lisp

+ 2 - 1
NOTES.org

@@ -6,7 +6,6 @@ http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=0x
6 6
 ** DONE Get bearlibterminal autowrapped and basic window working.
7 7
 CLOSED: [2016-01-01 Fri 22:52]
8 8
 ** High Priority
9
-*** TODO Randomly place enemies
10 9
 *** TODO Randomly place ally tombs
11 10
 - [ ] Player can wake up allies by entering room
12 11
 *** TODO Create enemy AI
@@ -18,6 +17,8 @@ CLOSED: [2016-01-01 Fri 22:52]
18 17
 - [ ] Detect whether enemies can be seen
19 18
 - [ ] If enemies, move to them and attack.
20 19
 - [ ] If not enemies, move toward player.
20
+*** DONE Randomly place enemies
21
+CLOSED: [2016-01-11 Mon 00:32]
21 22
 *** DONE Create player character
22 23
 CLOSED: [2016-01-10 Sun 21:00]
23 24
 - [X] Health (no regeneration)

+ 11 - 3
src/crypts-and-corpses.lisp

@@ -438,12 +438,20 @@
438 438
                (set-location floor x y map)
439 439
                (setf (gethash (calc-location x y map) terrain) floor)))))))))
440 440
 
441
+(defun spawn-enemies (map player)
442
+  (loop for room in (crawler::rooms (game-map-dungeon map))
443
+        when (not (equal room (find-room (get-location player) map))) do
444
+          (with-slots ((x1 crawler::x1) (x2 crawler::x2) (y1 crawler::y1) (y2 crawler::y2)) room
445
+            (dotimes (times (random 3))
446
+              (let* ((location (nearest-open-tile (gethash (calc-location x1 y1 map) (game-map-terrain map)) map))
447
+                     (enemy (make-instance 'enemy :location location)))
448
+                (when location
449
+                  (setf (gethash location (game-map-mobiles map)) enemy)))))))
450
+
441 451
 (defun initialize-map (map player)
442 452
   (fill-map-from-crawler map player)
443 453
   (setf (gethash (slot-value player 'location) (game-map-mobiles map)) player)
444
-  (let* ((location (nearest-open-tile player map))
445
-         (enemy (make-instance 'enemy :location location)))
446
-    (setf (gethash location (game-map-mobiles map)) enemy))
454
+  (spawn-enemies map player)
447 455
   map)
448 456
 
449 457
 (defun get-neighbors (tile map layer &key (filter-fun #'identity))