;;; -*- Common Lisp -*- #| Copyright (c) 2007,2008 Gustavo Henrique Milaré This file is part of The Feebs War. The Feebs War is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The Feebs War is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with The Feebs War. If not, see . |# (in-package :the-feebs-war) (defun print-direction (dir) (case dir (0 #\N) (1 #\E) (2 #\S) (3 #\W))) (defun print-map () (format t "~%") ;add this line (dotimes (y *maze-y-size*) (dotimes (x *maze-x-size*) (let ((elt (aref *maze* x y))) (apply 'format t (cond ((wallp elt) (list " XX")) ((feeb-p (car elt)) (list " F~a" (print-direction (feeb-facing (car elt))))) ((fireball-p (car elt)) (list " *~a" (print-direction (fireball-direction (car elt))))) ((eq (car elt) :mushroom) (list " mm")) ((eq (car elt) :carcass) (list " cc")) (t (list " ")))))) (format t "~%")) (format t "~%")) ;add this line (defun simple-play (&optional layout) (if layout (change-layout layout)) (make-auto-feebs (- 10 (length *feebs-to-be*))) (initialize-feebs) (start-round) (loop until (finish-game-p) do (play-one-turn) (print-map) (sleep 0.7)) (format t "Game Over!!~%~%Scores:~%~%") (let ((scores nil)) (dolist (feeb *feebs*) (push (list (feeb-name feeb) (feeb-score feeb)) scores)) ;collect living feebs' sores (dolist (feeb *dead-feebs*) (push (list (feeb-name feeb) (feeb-score feeb)) scores)) ;collect dead feebs' scoes (sort scores #'> :key #'second) ;sort the scores in dcreasing order (dolist (score scores) (format t "~30@<~a:~> ~@d~%" (first score) (second score))))) ;print out scores #| (defconst *default-graphics* (make-feeb-graphics (load-and-convert-image "default-feeb.bmp"))) (defvar *cell-width* 32) (defvar *cell-heigth* 32) (defstruct graphic (walk (make-direction)) (flaming (make-direction))) (defstruct (direction (:conc-name nil)) (up (make-array 3)) (left (make-array 3)) (down (make-array 3)) (right (make-array 3))) (defun make-feeb-graphics (surface) (let ((graphic (make-graphic))) (progn (loop for field in '(walk flaming) and y0 from 0 by (* 4 *cell-heigth*) do (loop for dir in '(up left right down) and y from y0 by *cell-heigth* do (loop for ind below 3 and x from 0 by *cell-width* for aux = (surface :width *cell-width* :heigth *cell-heigth*) do (set-cell :x x :y y :width *cell-width* :heigth *cell-heigth* :surface surface) (draw-surface surface :surface aux) (setf (svref (slot-value (slot-value graphic field) dir) ind) aux)))) graphic))) (defgeneric create-graphics (feeb) &key (free-p t)) (defmethod create-graphics ((feeb pathname)) (let ((surf (load-and-convert-image feeb))) (make-feeb-grahpics surf) (free-surface surf))) (defmethod create-graphics ((feeb surface) &key free-p) (with-surface feeb (make-feeb-graphics)) (if free-p (fre-surface feeb))) (defvar *time* 0) (defun human-player (&rest args) (declare (ignore args)) (sdl:with-events (:wait) (:key-down-event (:key key) (case key (:sdl-key-up (return-from human-player :move-forward)) (:sdl-key-left (return-from human-player :turn-left)) (:sdl-key-right (return-from human-player :turn-right)) (:sdl-key-up (return-from human-player :turn-around)) (:sdl-key-space (return-from human-player :flame)) (:sdl-key-return (return-from human-player :wait)))) (:video-expose-event (sdl:update-display)))) (defun feebs (&key (delay 5) ; 4 min of game human-player files &aux (time 0)) "The main loop program. Single-step is no longer available. If human-player is supplied, it is taken as the name of human player, wich will controll a feeb with the keyboard. The end of the game only occurs if the player press ESC. If there is no human, *game-length* is used instead. A number of auto-feebs feebs are created by the system. Also, if there are more feebs supplied than places, the feeb wich is killed gives room to another feeb to be born." (initialize-feebs) (setf (sdl:frame-rate) 10) (init-maze *layout*) (dolist (file files) (load file)) (if human-player (define-feeb human-player #'human-player)) (sdl:with-init () (sdl:with-display () (sdl:with-events () (:idle () (sdl:update-display) (if zerop time (progn (setf time delay) (play-one-turn) (when (not *continue*) (return))) (decf time))) )) (setf *feebs-to-be* nil)) ;;; Feeb creation. ;; This a little better version of conservative-brain ;; all others (stupid or redundant) brains of original ;; feebs.lisp were eliminated (defun simple-brain (status proximity vision vision-left vision-right) (declare (ignore vision-left vision-right)) (let ((stuff (my-square proximity))) (cond ((and (consp stuff) (member :mushroom stuff :test #'eq)) :eat-mushroom) ((and (consp stuff) (member :carcass stuff :test #'eq)) :eat-carcass) ((and (ready-to-fire status) (> (energy-reserve status) 30) (dotimes (index (min (line-of-sight status) 5)) (if (find-if #'feeb-image-p (aref vision index)) (return t)))) :flame) ((and (not (eq (left-square proximity) :rock)) (> 2 (random 10))) :turn-left) ((and (not (eq (right-square proximity) :rock)) (> 2 (random 10))) :turn-right) ((plusp (line-of-sight status)) :move-forward) ((not (wallp (left-square proximity))) :turn-left) ((not (wallp (right-square proximity))) :turn-right) ((not (wallp (rear-square proximity))) :turn-around)))) |#