I've been having some difficulty with cl-charms when trying to convert a basic roguelike program from C into a Common Lisp version of it
Here is the Common Lisp version of it that I wrote.
Code:
(load "~/quicklisp/setup.lisp")
(ql:quickload "cl-charms")
(defconstant +map+ #2A(
("#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#")
("#" " " " " " " " " " " " " "#" " " " " " " " " " " " " "#")
("#" " " " " " " " " " " " " " " " " " " " " " " " " " " "#")
("#" " " " " " " " " " " " " "#" "#" "#" " " "#" "#" "#" "#")
("#" "#" "#" "#" " " "#" "#" "#" " " " " " " "#" " " " " "#")
("#" " " " " " " " " " " " " " " " " " " " " "#" " " " " "#")
("#" " " " " " " " " " " " " " " " " " " " " "#" " " " " "#")
("#" " " " " " " " " " " " " "#" " " " " " " " " " " " " "#")
("#" " " " " " " " " " " " " " " " " " " " " "#" " " " " "#")
("#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#")))
(defun move ()
(cl-charms:keypad (cl-charms:initscr) 1)
(cl-charms:curs-set 0)
(setf y 1 x 1)
(let ((c (cl-charms:getch)))
(loop while (not (eq c 113)) do
;; printing map
(loop for yy from 0 to 9 do
(loop for xx from 0 to 14 do
(cl-charms:mvaddstr y x (aref +map+ yy xx))))
(if (and (eq c 107) (equal (aref +map+ (1- y) x) " "))
(incf y -1))
(if (and (eq c 106) (equal (aref +map+ (1+ y) x) " "))
(incf y))
(if (and (eq c 104) (equal (aref +map+ y (1- x)) " "))
(incf x -1))
(if (and (eq c 108) (equal (aref +map+ y (1+ x)) " "))
(incf x))
(if (and (eq c 98) (equal (aref +map+ (1+ y) (1- x)) " "))
(progn (incf y) (incf x -1)))
(if (and (eq c 121) (equal (aref +map+ (1- y) (1- x)) " "))
(progn (incf y -1) (incf x -1)))
(if (and (eq c 117) (equal (aref +map+ (1- y) (1+ x)) " "))
(progn (incf y -1) (incf x)))
(if (and (eq c 110) (equal (aref +map+ (1+ y) (1+ x)) " "))
(progn (incf y) (incf x)))
(cl-charms:mvaddstr y x "@"))))
(cl-charms:endwin))
And here's the C source code I translated it from.
Code:
#include <curses.h>
char *map[] =
{
"###############",
"# # #",
"# #",
"# ### ####",
"#### ### # #",
"# # #",
"# # #",
"# #",
"# # #",
"###############"
};
int main()
{
//initialize curses
keypad(initscr(), 1);
curs_set(0);
//player's starting coordinates
int y = 1;
int x = 1;
//placeholder for capturing keyboard input
char c;
do
{
//draw map
for(int yy = 0; yy < 10; yy++)
{
for(int xx = 0; xx < 15; xx++)
mvaddch(yy, xx, map[yy][xx]);
}
//move player if there is no wall in the way
if('k' == c && ' ' == map[y - 1][x])
{
y--;
}
if('j' == c && ' ' == map[y + 1][x])
{
y++;
}
if('h' == c && ' ' == map[y][x - 1])
{
x--;
}
if('l' == c && ' ' == map[y][x + 1])
{
x++;
}
if('b' == c && ' ' == map[y + 1][x - 1])
{
y++;
x--;
}
if('y' == c && ' ' == map[y - 1][x - 1])
{
y--;
x--;
}
if('u' == c && ' ' == map[y - 1][x + 1])
{
y--;
x++;
}
if('n' == c && ' ' == map[y + 1][x + 1])
{
y++;
x++;
}
//draw character
mvaddch(y, x, '@');
} while(('q' != (c = getch())));
//clean up after we've finished using curses
return endwin();
}
When I try to run the program I wrote with "clisp -i basic-movement.lisp", I get this error message.
Code:
READ from #<INPUT BUFFERED FILE-STREAM CHARACTER #P"basic-movement.lisp" @48>: an object cannot start with #\)
I don't really understand the error message I got from clisp, and any help to get this program into working order would be greatly appreciated.