Skip to content

accidentalrebel/emacs-game-engine

Repository files navigation

emacs-game-engine

A minimal game engine for making games on and for Emacs.

This is my entry for the Lisp Jam at the Handmade Network Discord.

preview-1

Watch the video here.

Features

The engine offers functions that allows the following features

  • Buffer management
  • Draw canvas setup
  • Basic text-based drawing functions
  • Keyboard input
  • Mouse input
  • Audio output (Audio playing via external programs)

Why?

I made a couple of games for emacs. I had a lot of fun making those so I wanted to make a game engine that would allow me to make more.

Sample Code

A simple example program that detects keyboard movement and moves a player on the screen

(require 'emacs-game-engine)

;; Initialize the engine with the buffer name and number of cols and rows
(ege:init "Example Game" 80 24)

(setq player-pos-x 40)
(setq player-pos-y 12)

(ege:draw-text " Is any key pressed: " 2 1
	       '(:background "gray" :foreground "black"))

(ege:draw-text " Last pressed key: " 2 3
	       '(:background "gray" :foreground "black"))

(defun update()
  "Game update function."

  (if ege:key-pressed
      (progn
	(ege:draw-text " yes " 23 1
		       '(:background "red" :foreground "white"))
	
	(ege:draw-rect 21 3 10 1 "-")
	(ege:draw-text (concat " " ege:key-pressed " ")
		       21 3
		       '(:background "red" :foreground "white"))
	
	(ege:draw-char "*" player-pos-x player-pos-y)
	
	(cond ((or (string= ege:key-pressed "s")
		   (string= ege:key-pressed "<down>"))
	       (setq player-pos-y
		     (+ player-pos-y 1)))
	      ((or (string= ege:key-pressed "w")
		   (string= ege:key-pressed "<up>"))
	       (setq player-pos-y
		     (- player-pos-y 1))))
	(cond ((or (string= ege:key-pressed "d")
		   (string= ege:key-pressed "<right>"))
	       (setq player-pos-x
		     (+ player-pos-x 1)))
	      ((or (string= ege:key-pressed "a")
		   (string= ege:key-pressed "<left>"))
	       (setq player-pos-x
		     (- player-pos-x 1)))))
    (progn
      (ege:draw-text " no " 23 1
		     '(:background "red" :foreground "white"))
      ))

    (ege:draw-char "@" player-pos-x player-pos-y))

;; Registers the update function and sets the FPS to 24
(ege:register-update 'update 24)

There are more code examples in the examples folder. To run the examples, open the .el file and run the eval-bufer emacs command. Additionally, for the roguemacs-jam.el example, you also need to run the roguemacs-start command.

Dependencies

  • coordinate.el - A separate emacs library I made that provides convenience functions for editing buffers through col and row coondinates.

About

A game engine for making games on and for Emacs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published