Git Product home page Git Product logo

cl-tcod-tutorial's Introduction

Complete roguelike tutorial with libtcod and cl-tcod

Introduction

This is a port of the Python code from the "Complete Roguelike Tutorial, using python+libtcod" into Common Lisp using cl-tcod (the official version needs to be updated though, see below). It uses libtcod (a.k.a. "The Doryen Library") through the Common Foreign Function Interface, CFFI. Commentary on writing this tutorial in lisp will be found on my blog in the near future, and linked here.

The code is basically a straight "translation" from Python to Common Lisp, and is not necessarily "lispy" in it's current form. This was done on purpose to make it easy to refer to the original tutorial, and to reduce the chance of bugs in making sure this works as a proof of concept of a roguelike in lisp.

Everything works exactly the same in terms of gameplay and presentation, as near as I can tell. The only exception is that currently cannot restore savegames where a monster was confused (via a "scroll of confusion"). This is due to the use of a recursive anonymous function (lambda). There are probably several ways around this, but for the purposes of this tutorial translation this is a minor issue and will be left as is for now.

Technical Details

cl-tcod is in the process of being updated to fix some bugs with the latest version of libtcod. For now there is a working fork available on Github as cl-tcod.

This code has only been tested with the current versions of libtcod (1.6.2), SBCL (1.3.12), and SDL (2.0.5) on x86-64 Arch Linux.

Basic requirements

If current versions are prepackaged for your OS (downloaded binaries, apt-get, pacman, etc.) that is preferred, otherwise build from source.

  • Common Lisp (e.g. SBCL)
  • quicklisp
  • libtcod (and its requirements, namely SDL2)
  • cl-tcod (to quickload it, clone it to local-projects; see the FAQ)
  • GNU Emacs with SLIME (not required, but highly recommended)

Then all one needs to do is open one of the tutorial-part##.lisp files in Emacs and load it (M-x slime-load-file or C-c C-l) with SLIME running.

Status

All of the code works (other than the saving caveat mentioned above), but is missing some of the original Python comments and lisp specific comments. The code is not necessarily pretty, well organized, or in a final state. Updates will be made as the blog posts go up for each part. It is possible in the future to produce a "lisp first" approach to the tutorial, but that is not planned yet.

cl-tcod-tutorial's People

Contributors

podiki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cl-tcod-tutorial's Issues

LispWorks on Windows

I would like very much to go through your cl-tcod tutorial using my platform, LispWorks on WIndows.

I see libtocd is available on Windows. Would you reckon the tutorial is easily portable to LispWorks? Would you be available, your time permitting of course, to assist in case of LispWorks or Windows-side issues?

Fail to load tutorial-part01.lisp

I get the following error when trying to load tutorial-part01.lisp:

The assertion (PROBE-FILE TCOD::FONTFILE) failed with
TCOD::FONTFILE = "arial10x10.png".
   [Condition of type SIMPLE-ERROR]

The font file is in the dir, so I suspect that this is some kind of emacs/path issue, but I don't know how to resolve it.

crashes

Tutorial 1 crashes the entire lisp image at this line:

CL-USER> (tcod:console-init-root *screen-width* *screen-height* :title "lisp/libtcod tutorial" :fullscreen? nil)

Process sly-pty-1-1 killed
; Lisp connection closed unexpectedly: connection broken by remote peer
; --------------------------------------------------------

Style improvements

(via this comment on Reddit):

Mostly looks good, but I've got some style suggestions. Number one, I'd make constructors for your objects instead of inlining make-instance calls. For example:

(defun make-rect (x y w h)
  (let ((r (make-instance 'rect :x1 x :y1 y)))
    (setf (x2 r) (+ (x1 r) width)
          (y2 r) (+ (y1 r) height)
          (center r) (cons (floor (/ (+ (x1 r) (x2 r)) 2)) (floor (/ (+ (y1 r) (y2 r)) 2))))
    rect))

I also rearranged some functions to suggest some style improvements. I'd try to minimize declaring variables just to setf them later... usually you can just add a nested let, or use let*.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.