id
int64 0
45.1k
| file_name
stringlengths 4
68
| file_path
stringlengths 14
193
| content
stringlengths 32
9.62M
| size
int64 32
9.62M
| language
stringclasses 1
value | extension
stringclasses 6
values | total_lines
int64 1
136k
| avg_line_length
float64 3
903k
| max_line_length
int64 3
4.51M
| alphanum_fraction
float64 0
1
| repo_name
stringclasses 779
values | repo_stars
int64 0
882
| repo_forks
int64 0
108
| repo_open_issues
int64 0
90
| repo_license
stringclasses 8
values | repo_extraction_date
stringclasses 146
values | sha
stringlengths 64
64
| __index_level_0__
int64 0
45.1k
| exdup_ids_cmlisp_stkv2
sequencelengths 1
47
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
39,330 | spotlight-test.asd | conjunctive_spotlight/spotlight-test.asd | (defsystem spotlight-test
:author "Conjunctive"
:maintainer "Conjunctive"
:license "AGPL-3.0"
:version "0.2.1"
:homepage "https://github.com/conjunctive/spotlight"
:source-control (:git "[email protected]:conjunctive/spotlight.git")
:description "Test system for Spotlight"
:depends-on ("spotlight"
"alexandria"
"prove")
:components ((:module "t"
:serial t
:components
((:file "spotlight"))))
:perform (test-op (op c) (symbol-call :prove-asdf :run-test-system c)))
| 553 | Common Lisp | .asd | 16 | 27.875 | 73 | 0.629423 | conjunctive/spotlight | 0 | 0 | 0 | AGPL-3.0 | 9/19/2024, 11:46:12 AM (Europe/Amsterdam) | 61d537bcbbfd3a59b58006196e155cf60a4072a34c7df255d1ff1fd0d1fd0152 | 39,330 | [
-1
] |
39,331 | spotlight.asd | conjunctive_spotlight/spotlight.asd | (defsystem spotlight
:author "Conjunctive"
:maintainer "Conjunctive"
:license "AGPL-3.0"
:version "0.2.1"
:homepage "https://github.com/conjunctive/spotlight"
:source-control (:git "[email protected]:conjunctive/spotlight.git")
:description "Functional references for Common Lisp"
:depends-on ("alexandria")
:components ((:module "src"
:serial t
:components ((:file "spotlight"))))
:long-description
#.(uiop:read-file-string
(uiop:subpathname *load-pathname* "README.org"))
:in-order-to ((test-op (test-op spotlight-test))))
| 583 | Common Lisp | .asd | 16 | 31.625 | 67 | 0.68254 | conjunctive/spotlight | 0 | 0 | 0 | AGPL-3.0 | 9/19/2024, 11:46:12 AM (Europe/Amsterdam) | f534cb8238be1500e26f1c482d77c14809d00e1e7ef2daf8d1e70caee44ee2e4 | 39,331 | [
-1
] |
39,351 | tokens.lisp | yildizozan_clisp-parser/src/tokens.lisp | (defvar *tokens* (make-hash-table :test 'equal))
(setf (gethash "and" *tokens*) "KW_AND")
(setf (gethash "or" *tokens*) "KW_OR")
(setf (gethash "not" *tokens*) "KW_NOT")
(setf (gethash "equal" *tokens*) "KW_EQUAL")
(setf (gethash "less" *tokens*) "KW_LESS")
(setf (gethash "nil" *tokens*) "KW_NIL")
(setf (gethash "list" *tokens*) "KW_LIST")
(setf (gethash "append" *tokens*) "KW_APPEND")
(setf (gethash "concat" *tokens*) "KW_CONCAT")
(setf (gethash "deffun" *tokens*) "KW_DEFFUN")
(setf (gethash "for" *tokens*) "KW_FOR")
(setf (gethash "if" *tokens*) "KW_IF")
(setf (gethash "exit" *tokens*) "KW_EXIT")
(setf (gethash "load" *tokens*) "KW_LOAD")
(setf (gethash "disp" *tokens*) "KW_DISP")
(setf (gethash "true" *tokens*) "KW_TRUE")
(setf (gethash "false" *tokens*) "KW_FALSE")
(setf (gethash "+" *tokens*) "OP_PLUS")
(setf (gethash "-" *tokens*) "OP_MINUS")
(setf (gethash "/" *tokens*) "OP_DIV")
(setf (gethash "*" *tokens*) "OP_MULT")
(setf (gethash "(" *tokens*) "OP_OP")
(setf (gethash ")" *tokens*) "OP_CP")
(setf (gethash "*" *tokens*) "OP_DBLMULT")
(setf (gethash "\"" *tokens*) "OP_OC")
(setf (gethash "\"" *tokens*) "OP_CC")
(setf (gethash "," *tokens*) "OP_COMMA")
(defvar *operators* (make-hash-table :test 'equal))
(setf (gethash #\+ *operators*) "OP_PLUS")
(setf (gethash #\- *operators*) "OP_MINUS")
(setf (gethash #\/ *operators*) "OP_DIV")
(setf (gethash #\* *operators*) "OP_MULT")
(setf (gethash #\( *operators*) "OP_OP")
(setf (gethash #\) *operators*) "OP_CP")
(setf (gethash #\* *operators*) "OP_DBLMULT")
(setf (gethash #\" *operators*) "OP_OC")
(setf (gethash #\" *operators*) "OP_CC")
(setf (gethash #\, *operators*) "OP_COMMA") | 1,658 | Common Lisp | .lisp | 39 | 41.461538 | 51 | 0.62585 | yildizozan/clisp-parser | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:12 AM (Europe/Amsterdam) | e6abc975039d20bc375f7c1bc1fd3cd5a30a68d622796cd2aa0ca237dec33767 | 39,351 | [
-1
] |
39,352 | gpp_lexer.lisp | yildizozan_clisp-parser/src/gpp_lexer.lisp | ; *********************************************
; * 341 Programming Languages *
; * Fall 2019 *
; * Author: Ozan Yıldız *
; *********************************************
;; utility functions
(load "tokens.lisp")
(load "lib.lisp")
(defun gppinterpreter (filename)
(with-open-file (stream filename)
(do ((line (read-line stream nil) (read-line stream nil)))
((null line))
;;(print (init line))
(if (is-definition (init line))
(format t "~a~%" "COMMENT")
(if (is-comment (init line) )
(format t "~a~%" "COMMENT")
(let ((*current* (init line)))
;;(print (parse2 (init line))) ;; <-----
(mapcan
#'(lambda (*item*)
;(print (gethash *item* *tokens*))
(cond
;;((null *current*))
((is-value (init *item*)) (format t "~a~%" "VALUE"))
((gethash *item* *tokens*) (format t "~a~%" (gethash *item* *tokens*)))
((is-identifier (init *item*)) (format t "~a~%" "IDENTIFIER"))
;;(t (print *current*))
)
)
(parse2 (init line)))
)
)
) ;; end of is-definition
)
)
)
| 1,381 | Common Lisp | .lisp | 37 | 26.432432 | 91 | 0.395545 | yildizozan/clisp-parser | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:12 AM (Europe/Amsterdam) | baa5bbbb16b7ccc651bd5a0623141012ef08d1bfb9b4369bbde26c34df1bde88 | 39,352 | [
-1
] |
39,353 | lib.lisp | yildizozan_clisp-parser/src/lib.lisp |
(defun char-by-char (in)
"Read char by char but input must be string"
(with-input-from-string (is in)
(do ((c (read-char is) (read-char is nil 'the-end)))
((not (characterp c)))
(format t "~S " c)))
)
;; Create adustable string
(defun make-adjustable-string (s)
"Create adustable string"
(make-array 0
:fill-pointer 0
:adjustable t
:element-type 'character ))
(defun lexer (filename)
"Reduce function, accumulator is *current* variable!"
(let ((*current* (make-adjustable-string "")))
(with-open-file (stream filename)
(do ((*char* (read-char stream nil)
(read-char stream nil)))
((null *char*))
;;(print *char*)
(if (char/= *char* #\Space)
(progn
(vector-push-extend *char* *current*)
;;(print *current*)
(when (gethash *current* *tokens*)
;;(print (gethash *current* *tokens*))
(setf *current* (make-adjustable-string ""))
)
(when (check-value *current*)
)
)
)
))
(print *current*)))
;; First trim space after string to char list
(defun init (str)
(coerce (string-trim '(#\Space) str) 'list)
)
;;
(defun is-definition (*lst*)
(if (and (char= (car *lst*) #\") (char= (car (last *lst*)) #\"))
t
nil
)
)
(defun is-comment (*lst*)
(if (and (char= (car *lst*) #\;) (char= (car *lst*) #\;))
t
nil
)
)
(defun is-digit (*char*)
(if (digit-char-p *char*)
t
nil))
(defun is-numeric (*lst*)
(if (= (length *lst*) 1)
(is-digit (car *lst*))
(and (is-digit (car *lst*)) (is-numeric (cdr *lst*)) )
)
)
(defun is-value (*lst*)
(cond
((not (digit-char-p (car *lst*))) nil)
(t
(if (= (digit-char-p (car *lst*)) 0) ;; Check first item not zero
nil
(is-numeric *lst*)
)
)
)
)
(defun is-alphanumeric-string (*lst*)
(if (= (length *lst*) 1)
(alphanumericp (car *lst*))
(and (alphanumericp (car *lst*)) (is-alphanumeric-string (cdr *lst*)) )
)
)
(defun is-identifier (*lst*)
(if (digit-char-p (car *lst*)) ;; Check first item not number
nil
(is-alphanumeric-string *lst*)
)
)
(defun parse (*lst*)
(let ((*current* (make-adjustable-string "")) (*tokens* '()))
(loop for *char* in *lst*
do (if *char* ;; Continue when not nil.
(if (char= *char* #\Space) ;; If there is character space, split.
(progn
(setf *tokens* (push *current* *tokens*))
(setf *current* (make-adjustable-string ""))
)
(vector-push-extend *char* *current*)
)
)
)
;; last part without space because
;; there is not space character last end of list
(setf *tokens* (push *current* *tokens*))
;; Reverse
(reverse *tokens*)
)
)
(defun parse2 (*lst*)
;;(print *lst*)(terpri)
(let ((*current* (make-adjustable-string "")) (*groups* '()))
(loop for *char* in *lst*
do
;;(format t "~a -> ~a" *char* *current*)
;;(vector-push-extend *char* *current*)
(cond
((char= *char* #\Space)
(progn
(if (> (length *current*) 0) (setf *groups* (push *current* *groups*)))
(setf *current* (make-adjustable-string ""))
)
)
((gethash *char* *operators*)
(progn
(if (> (length *current*) 0) (setf *groups* (push *current* *groups*)))
(setf *groups* (push (string *char*) *groups*))
(setf *current* (make-adjustable-string ""))
)
)
(t (vector-push-extend *char* *current*))
)
;;(vector-push-extend *char* *current*)
;;(terpri)
)
;; last part without space because
;; there is not space character last end of list
;;(setf *groups* (push *current* *groups*))
;; Delete
(remove "" *groups* :test #'equal) ;; Equal have to string compare
(remove " " *groups* :test #'equal) ;; Equal have to string compare
;; Reverse
(reverse *groups*)
)
) | 4,280 | Common Lisp | .lisp | 142 | 22.633803 | 85 | 0.518916 | yildizozan/clisp-parser | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:12 AM (Europe/Amsterdam) | 0c4c95b0a79b6d1dcad10304de40e87d8feb925045684e5e845475ad64496f9f | 39,353 | [
-1
] |
39,354 | driver.lisp | yildizozan_clisp-parser/src/driver.lisp | ; *********************************************
; * 341 Programming Languages *
; * Fall 2019 *
; * Author: Ozan Yıldız *
; *********************************************
;; utility functions
(load "gpp_lexer.lisp")
(gppinterpreter "example.g++") | 320 | Common Lisp | .lisp | 8 | 38.5 | 47 | 0.326861 | yildizozan/clisp-parser | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:12 AM (Europe/Amsterdam) | 4abd4c9b00c6c32417f389cd727246fb54ea308722d1add3735a3cf9105d1b53 | 39,354 | [
-1
] |
39,355 | test.lisp | yildizozan_clisp-parser/src/test.lisp | ; *********************************************
; * 341 Programming Languages *
; * Fall 2019 *
; * Author: Ozan Yıldız *
; *********************************************
;; utility functions
(load "tokens.lisp")
(load "lib.lisp")
;; -----------------------------------------------------
;; Test code...
(defun test_on_test_data ()
(print "....................................................")
(print "Testing ....")
(print "....................................................")
(terpri)
(print "....................................................")
(print "Test func init")
(print "....................................................")
(terpri)
(format t "(list 1 2 123) => ~a~%" (init "(list 1 2 123)") )
(print "....................................................")
(print "Test func is-alphanumeric-string")
(print "....................................................")
(terpri)
(format t "sumup8 is-alphanumeric-string ~a~%" (is-alphanumeric-string '(#\s #\u #\m #\u #\p #\8)))
(format t "(deffun is-alphanumeric-string ~a~%" (is-alphanumeric-string '(#\( #\d #\e #\f #\f #\u #\n)))
(print "....................................................")
(print "Test func is-identifier")
(print "....................................................")
(terpri)
(format t "8sumup is-identifier ~a~%" (is-identifier '(#\8 #\u #\m #\u #\p #\8)))
(format t "sum8up is-identifier ~a~%" (is-identifier '(#\s #\u #\m #\8 #\u #\p)))
(format t "sumup8 is-identifier ~a~%" (is-identifier '(#\s #\u #\m #\u #\p #\8)))
(print "....................................................")
(print "Test func is-numberic")
(print "....................................................")
(terpri)
(format t "123 is-numberic ~a~%" (is-numeric (init "123")) )
(format t "123a is-numberic ~a~%" (is-numeric (init "123a")) )
(print "....................................................")
(print "Test func is-value")
(print "....................................................")
(terpri)
(format t "123 is-value ~a~%" (is-value (init "123")) )
(format t "0123 is-value ~a~%" (is-value (init "0123")) )
(format t "1230 is-value ~a~%" (is-value (init "1230")) )
(format t "( is-value ~a~%" (is-value (init "(")) )
(print "....................................................")
(print "Test func is-definition")
(print "....................................................")
(terpri)
(format t "\"Definition\" is-definition ~a~%" (is-definition (init "\"Definition\"")) )
(format t "(list 1 2) is-definition ~a~%" (is-definition (init "(list 1 2)")) )
(print "....................................................")
(print "Test func is-comment")
(print "....................................................")
(terpri)
(format t ";; helloworld.g++ is-comment ~a~%" (is-comment (init ";; helloworld.g++")) )
(format t "(list 1 2) is-comment ~a~%" (is-comment (init "(list 1 2)")) )
)
;; test code...
(test_on_test_data) | 3,113 | Common Lisp | .lisp | 62 | 47.080645 | 109 | 0.370102 | yildizozan/clisp-parser | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:12 AM (Europe/Amsterdam) | 3540ba2b232c7d38d10c65487da7be4980c63eb7653bd88d957de8048350b3cd | 39,355 | [
-1
] |
39,359 | example.g++ | yildizozan_clisp-parser/src/example.g++ | ;; helloworld.g++
(deffun sumup (x)
(if (equal x 0)
1
(+ x (sumup (-x 1)))
)
)
(list 1 2 123)
(liste 1 2 3) | 133 | Common Lisp | .l | 9 | 11 | 28 | 0.464 | yildizozan/clisp-parser | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:12 AM (Europe/Amsterdam) | 84fe38b3a80ac5ffb263e197c8497a883ef1018f443dfcbf45ea85442b16883f | 39,359 | [
190466
] |
39,377 | package.lisp | khinsen_h5cl/package.lisp | (defpackage :h5cl
(:use :cl)
(:export :open-hdf5
:close-hdf5
:hdf5-ref
:hdf5-containing-file
:hdf5-path
:make-hdf5-group
:make-hdf5-dataset
:hdf5-dataset-element-type
:hdf5-dataset-rank
:hdf5-dataset-dimensions))
| 316 | Common Lisp | .lisp | 12 | 16.75 | 37 | 0.529605 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 4b946b076aaa3f1fc6a71695c23acb2af4db83d0543693aec660e510ba6b74c4 | 39,377 | [
-1
] |
39,378 | files.lisp | khinsen_h5cl/files.lisp | (in-package :h5cl)
(defclass hdf5-file (hdf5-location)
((filename
:initarg :filename
:reader hdf5-file-filename
:documentation "Filename")
(fapl-id
:initarg :fapl-id
:documentation "File access property list id")))
(defmethod hdf5-containing-file ((file hdf5-file))
file)
(defmethod hdf5-path ((file hdf5-file))
"/")
(defmethod print-object ((object hdf5-file) out)
(with-slots (filename) object
(print-unreadable-object (object out :type t)
(format out "filename = ~s" filename))))
(defun h5open (filename mode)
(let* ((fapl-id (hdf5:h5pcreate hdf5:+H5P-FILE-ACCESS+))
(file-id (prog2
(hdf5:h5pset-fclose-degree fapl-id :H5F-CLOSE-STRONG)
(hdf5:h5fopen filename mode fapl-id))))
(unless (< 0 (hdf5:h5iis-valid file-id))
(error "File could not be opened: ~s." filename))
(let ((file-object (make-instance 'hdf5-file
:id file-id :filename filename :fapl-id fapl-id)))
(trivial-garbage:finalize file-object
#'(lambda ()
(close-id file-id)
(close-id fapl-id)))
file-object)))
(defun h5create (filename)
(let* ((fapl-id (hdf5:h5pcreate hdf5:+H5P-FILE-ACCESS+))
(file-id (prog2
(hdf5:h5pset-fclose-degree fapl-id :H5F-CLOSE-STRONG)
(hdf5:h5fcreate filename
hdf5:+H5F-ACC-TRUNC+
hdf5:+H5P-DEFAULT+
fapl-id))))
(unless (< 0 (hdf5:h5iis-valid file-id))
(error "File could not be created: ~s." filename))
(let ((file-object (make-instance 'hdf5-file
:id file-id :filename filename :fapl-id fapl-id)))
(trivial-garbage:finalize file-object
#'(lambda ()
(close-id file-id)
(close-id fapl-id)))
file-object)))
(defun open-hdf5 (filename
&key
direction
(if-exists nil if-exists-supplied-p)
(if-does-not-exist nil if-does-not-exist-supplied-p))
"Open the HDF5 file FILENAME."
;; HDF5 files can always be read, so :output is interpreted as :io.
(when (eql direction :output)
(setf direction :io))
(case direction
(:input
(unless if-does-not-exist-supplied-p
(setf if-does-not-exist :error))
(if (probe-file filename)
(h5open (namestring filename) hdf5:+H5F-ACC-RDONLY+)
(case if-does-not-exist
(:error (error "File does not exist: ~s" filename))
(nil nil))))
(:io
(unless if-exists-supplied-p
(setf if-exists :error))
(unless if-does-not-exist-supplied-p
(setf if-does-not-exist :create))
(if (probe-file filename)
(case if-exists
(:error (error "File exists: ~s" filename))
(nil nil)
(:supersede
(delete-file filename)
(h5create (namestring filename)))
(:overwrite
(h5create (namestring filename)))
(:append
(h5open (namestring filename) hdf5:+H5F-ACC-RDWR+)))
;; TODO
(case if-does-not-exist
(:error (error "file does not exist"))
(nil nil)
(:create
(h5create (namestring filename))))))))
(defun close-hdf5 (hdf5-file)
"Close HDF5-FILE"
(with-slots (id fapl-id) hdf5-file
(close-id id)
(setf id nil)
(close-id fapl-id)
(setf fapl-id nil)))
| 3,701 | Common Lisp | .lisp | 95 | 27.705263 | 88 | 0.544469 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 9a7e16ba2faf3669ecd55fa5b4d817b28ae3c3d20de6a621d991826a982b1db1 | 39,378 | [
-1
] |
39,379 | accessors.lisp | khinsen_h5cl/accessors.lisp | (in-package :h5cl)
(defgeneric hdf5-ref (hdf5-object item-spec &rest more-item-specs)
(:documentation "Access items inside a HDF5 object"))
(defmethod hdf5-ref ((location hdf5-location) path &rest more-item-specs)
(let* ((location-id (hdf5-object-id location))
(object-id (hdf5:h5oopen location-id path hdf5:+H5P-DEFAULT+)))
(unless (< 0 (hdf5:h5iis-valid object-id))
(error "Path could not be opened ~s." path))
(let ((object
(case (hdf5:h5iget-type object-id)
(:H5I-GROUP
(make-instance 'hdf5-group
:id object-id
:file (hdf5-containing-file location)
:name (get-name-for-id object-id)))
(:H5I-DATASET
(make-instance 'hdf5-dataset
:id object-id
:file (hdf5-containing-file location)
:name (get-name-for-id object-id)))
(:H5I-DATATYPE
(make-instance 'hdf5-datatype
:id object-id
:file (hdf5-containing-file location)
:name (get-name-for-id object-id)))
(t (error "Not a group, dataset, or datatype: ~s" path)))))
(trivial-garbage:finalize object
#'(lambda ()
(close-id object-id)))
(if (null more-item-specs)
object
(apply #'hdf5-ref object more-item-specs)))))
(defmethod hdf5-ref ((dataset hdf5-dataset) first-item-spec &rest more-item-specs)
(cond
((and (eq first-item-spec 't)
(null more-item-specs))
(read-dataset dataset))
(t (error "Not yet implemented: ~s" (cons first-item-spec more-item-specs)))))
| 1,885 | Common Lisp | .lisp | 38 | 33.421053 | 82 | 0.511931 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 81c399c2e9481808d63f3e6cedda16dc2d9f47def2b946378aeabc6850cb8f93 | 39,379 | [
-1
] |
39,380 | tests.lisp | khinsen_h5cl/tests.lisp | (in-package :h5cl-test)
(def-suite :h5cl)
(in-suite :h5cl)
(defun make-temporary-file-name ()
(uiop:with-temporary-file (:pathname pn :prefix "h5cl-test" :type "h5")
pn))
(defmacro with-temporary-filename (symbol &body body)
`(let ((,symbol (make-temporary-file-name)))
(unwind-protect
,@body
(uiop:delete-file-if-exists ,symbol))))
(defmacro with-temporary-file (symbol &body body)
(let ((fn-symbol (gensym)))
`(with-temporary-filename ,fn-symbol
(let ((,symbol (open-hdf5 ,fn-symbol :direction :io)))
(unwind-protect
,@body
(close-hdf5 ,symbol))))))
(defmacro with-temporary-file-write-then-read (symbol write read)
(let ((fn-symbol (gensym)))
`(with-temporary-filename ,fn-symbol
(let ((,symbol (open-hdf5 ,fn-symbol :direction :io)))
(unwind-protect
,write
(close-hdf5 ,symbol)))
(let ((,symbol (open-hdf5 ,fn-symbol :direction :input)))
(unwind-protect
,read
(close-hdf5 ,symbol))))))
(test create-new-file
;; Use open-hdf5
(finishes
(with-temporary-filename fn
(let ((h5file (open-hdf5 fn :direction :io)))
(close-hdf5 h5file))))
;; Use the non-exported low-level function h5create
(finishes
(with-temporary-filename fn
(let ((h5file (h5cl::h5create (namestring fn))))
(close-hdf5 h5file))))
;; TODO add tests for failures
)
(test open-existing-file
(signals simple-error
(with-temporary-filename fn
(let ((h5file (open-hdf5 fn :direction :input)))
(close-hdf5 h5file))))
(finishes
(with-temporary-filename fn
(let ((h5file (open-hdf5 fn :direction :io)))
(close-hdf5 h5file)
(let ((h5file (open-hdf5 fn :direction :input)))
(close-hdf5 h5file))))))
(test make-group
(with-temporary-file h5file
(let ((group (make-hdf5-group h5file "test")))
(is (eq (hdf5-containing-file group) h5file))
(is (equal (hdf5-path group) "/test"))
(let ((subgroup (make-hdf5-group group "subtest")))
(is (eq (hdf5-containing-file subgroup) h5file))
(is (equal (hdf5-path subgroup) "/test/subtest"))))))
(test make-dataset
(with-temporary-file h5file
(let* ((data (make-array '(2 2)
:element-type '(unsigned-byte 16)
:initial-contents '((1 2) (3 4))))
(dataset (make-hdf5-dataset h5file "test"
(array-dimensions data)
:initial-contents data)))
(is (= (hdf5-dataset-rank dataset) (array-rank data)))
(is (equal (hdf5-dataset-dimensions dataset) (array-dimensions data)))
(is (equal (hdf5-dataset-element-type dataset) '(unsigned-byte 16)))
(is (eq (hdf5-containing-file dataset) h5file))
(is (equal (hdf5-path dataset) "/test")))))
(test write-and-read-dataset
(dolist (type '((unsigned-byte 8)
(unsigned-byte 16)
(unsigned-byte 32)
(unsigned-byte 64)
(signed-byte 8)
(signed-byte 16)
(signed-byte 32)
(signed-byte 64)))
(with-temporary-file h5file
(let* ((data (make-array '(2 2)
:element-type type
:initial-contents '((1 2) (3 4))))
(dataset (make-hdf5-dataset h5file "test"
(array-dimensions data)
:initial-contents data))
(read-data (hdf5-ref dataset 't)))
(is (equal (array-element-type data) (array-element-type read-data)))
(is (equalp data read-data))))))
(test write-and-read-file
(dolist (type '((unsigned-byte 8)
(unsigned-byte 16)
(unsigned-byte 32)
(unsigned-byte 64)
(signed-byte 8)
(signed-byte 16)
(signed-byte 32)
(signed-byte 64)))
(let ((data (make-array '(2 2)
:element-type type
:initial-contents '((1 2) (3 4)))))
(with-temporary-file-write-then-read h5file
(make-hdf5-dataset h5file "test"
(array-dimensions data)
:initial-contents data)
(progn
(let* ((dataset (hdf5-ref h5file "test"))
(read-data (hdf5-ref dataset 't)))
(is (equal (array-element-type data) (array-element-type read-data)))
(is (equalp data read-data))))))))
| 4,678 | Common Lisp | .lisp | 114 | 29.991228 | 81 | 0.547891 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | d0e418a86372e7c4dc8bdd46d2acd6de39068f3e7681c3aeb1c7181e74cdc95c | 39,380 | [
-1
] |
39,381 | datasets.lisp | khinsen_h5cl/datasets.lisp | (in-package :h5cl)
(defclass hdf5-dataset (hdf5-named-object)
())
;;
;; Return information about datasets
;;
(defun hdf5-dataset-element-type (dataset)
"Return a type specifier for the elements of DATASET. For non-numeric
types, the return value is not a valid Common Lisp type specifier."
(let* ((datatype-id (hdf5:h5dget-type (hdf5-object-id dataset)))
(native-type-id (hdf5:h5tget-native-type datatype-id :H5T-DIR-DEFAULT)))
(unless (and (< 0 (hdf5:h5iis-valid datatype-id))
(< 0 (hdf5:h5iis-valid native-type-id)))
(error "Invalid datatype id"))
(close-id datatype-id)
(let ((type
(let ((class (hdf5:h5tget-class native-type-id))
(precision (hdf5:h5tget-precision native-type-id))
(sign (hdf5:h5tget-sign native-type-id)))
(case class
(:H5T-INTEGER (case sign
(:H5T-SGN-NONE (list 'unsigned-byte precision))
(:H5T-SGN-2 (list 'signed-byte precision))
(otherwise (error "Unknown sign type: ~s" sign))) )
(:H5T-FLOAT (case precision
(32 'single-float)
(64 'double-float)
(otherwise (error "Unknown float precision: ~s" precision))))
;; Note: this is not a valid Common Lisp type specifier!
(otherwise (list 'hdf5-type class precision))))))
(close-id native-type-id)
type)))
(defun hdf5-dataset-rank (dataset)
(let ((dataspace-id (hdf5:h5dget-space (hdf5-object-id dataset))))
(unless (< 0 (hdf5:h5iis-valid dataspace-id))
(error "Invalid dataspace id"))
(let ((rank (hdf5:h5sget-simple-extent-ndims dataspace-id)))
(close-id dataspace-id)
rank)))
(defun hdf5-dataset-dimensions (dataset)
(let ((dataspace-id (hdf5:h5dget-space (hdf5-object-id dataset))))
(unless (< 0 (hdf5:h5iis-valid dataspace-id))
(error "Invalid dataspace id"))
(let ((rank (hdf5:h5sget-simple-extent-ndims dataspace-id))
dimensions max-dimensions)
(cffi:with-foreign-objects ((dims 'hdf5:hsize-t rank)
(maxdims 'hdf5:hsize-t rank))
(hdf5:h5sget-simple-extent-dims dataspace-id dims maxdims)
(setf dimensions
(loop for i below rank
collect (cffi:mem-aref dims 'hdf5:hsize-t i)))
(setf max-dimensions
(loop for i below rank
collect (cffi:mem-aref maxdims 'hdf5:hsize-t i))))
(close-id dataspace-id)
(values dimensions max-dimensions))))
;;
;; Create datasets
;;
(defun create-dataspace (dimensions &optional max-dimensions)
(let* ((rank (list-length dimensions))
(dimensions-ptr (cffi:foreign-alloc 'hdf5:hsize-t :count rank
:initial-contents dimensions))
(max-dimensions-ptr (if max-dimensions
(cffi:foreign-alloc 'hdf5:hsize-t :count rank
:initial-contents max-dimensions)
hdf5:+NULL+))
(space (hdf5:h5screate-simple rank dimensions-ptr max-dimensions-ptr)))
(cffi:foreign-free dimensions-ptr)
(when max-dimensions (cffi:foreign-free max-dimensions-ptr))
space))
(defun create-dataset (location path dimensions max-dimensions element-type)
(let* ((location-id (hdf5-object-id location))
(dspace-id (create-dataspace dimensions max-dimensions)))
(unless (< 0 (hdf5:h5iis-valid dspace-id))
(error "Invalid dataspace id"))
(let ((dataset-id
(hdf5:h5dcreate2 location-id path element-type dspace-id
hdf5:+H5P-DEFAULT+
hdf5:+H5P-DEFAULT+
hdf5:+H5P-DEFAULT+)))
(close-id dspace-id)
(unless (< 0 (hdf5:h5iis-valid dataset-id))
(error "Invalid dataset id")))
(hdf5-ref location path)))
(defun write-dataset (location path dimensions max-dimensions element-type data)
(let* ((cffi-type (lisp-type->cffi-type element-type))
(hdf5-type (cffi-type->hdf5-type cffi-type))
(size (apply #'* dimensions))
(dataset (create-dataset location path dimensions max-dimensions hdf5-type)))
(cffi:with-foreign-object (f-array cffi-type size)
(if (arrayp data)
(dotimes (i size)
(setf (cffi:mem-aref f-array cffi-type i) (row-major-aref data i)))
(dotimes (i size)
(setf (cffi:mem-aref f-array cffi-type i) data)))
(hdf5:h5dwrite (hdf5-object-id dataset)
hdf5-type
hdf5:+H5S-ALL+ hdf5:+H5S-ALL+ hdf5:+H5P-DEFAULT+
f-array))
dataset))
(defun make-hdf5-dataset (location path dimensions
&key element-type
initial-element
initial-contents
max-dimensions)
;; Check initial contents
(when (and initial-element initial-contents)
(error "Can't specify both :INITIAL-ELEMENT and :INITIAL-CONTENTS"))
;; Check dimensions and max-dimensions
(unless (and (consp dimensions) (listp max-dimensions))
(error "DIMENSIONS and MAX-DIMENSIONS must tbe lists."))
(when (and max-dimensions
(not (= (list-length dimensions) (list-length max-dimensions))))
(error "MAX-DIMENSIONS must have the same length as DIMENSIONS."))
(when (or (< (list-length dimensions) 1)
(> (list-length dimensions) 32))
(error "The length of DIMENSIONS must be between 1 and 32."))
(when (some #'(lambda (x) (or (not (integerp x)) (< x 1))) dimensions)
(error "The elements of DIMENSIONS must be positive integers."))
(when (and max-dimensions
(some #'(lambda (x) (and x (or (not (integerp x)) (< x 1))))
max-dimensions))
(error "The elements of MAX-DIMENSIONS must be positive integers or NIL."))
(when (and max-dimensions
(some #'null
(mapcar #'(lambda (x y) (or (null y) (<= x y)))
dimensions max-dimensions)))
(error "A dimension must not exceed it's corresponding maximum."))
(when (and max-dimensions
(some #'identity
(mapcar #'(lambda (x y) (and y (> x y)))
dimensions max-dimensions)))
(error "A dimension must not exceed it's corresponding maximum."))
;; Check element type
(unless element-type
(when initial-element
(setf element-type (type-of initial-element)))
(when (and initial-contents
(arrayp initial-contents))
(setf element-type (array-element-type initial-contents)))
(unless element-type
(error "Element type cannot be deduced from initial contents.")))
;; Convert initial contents to array if necessary
(when (and initial-contents
(not (arrayp initial-contents)))
(setf initial-contents (make-array dimensions
:element-type element-type
:initial-contents initial-contents)))
;; Create the dataset and write the initial contents
(write-dataset location path dimensions max-dimensions
element-type (or initial-element initial-contents)))
;;
;; Read datasets
;;
(defun read-dataset (dataset)
(let* ((element-type (hdf5-dataset-element-type dataset))
(cffi-type (lisp-type->cffi-type element-type))
(hdf5-type (cffi-type->hdf5-type cffi-type))
(dimensions (hdf5-dataset-dimensions dataset))
(size (apply #'* dimensions))
(flat-array (make-array (list size)
:element-type element-type))
(array (make-array dimensions
:element-type element-type
:displaced-to flat-array)))
(cffi:with-foreign-object (f-array cffi-type size)
(hdf5:h5dread (hdf5-object-id dataset)
hdf5-type
hdf5:+H5S-ALL+ hdf5:+H5S-ALL+ hdf5:+H5P-DEFAULT+
f-array)
(dotimes (i size)
(setf (aref flat-array i) (cffi:mem-aref f-array cffi-type i))))
(values array flat-array)))
| 8,378 | Common Lisp | .lisp | 174 | 36.712644 | 90 | 0.591453 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 8a6d6e72ab5e1e29a569aa87a2df261b478cc2e03c62cc5b57c4b1ac0d6502fa | 39,381 | [
-1
] |
39,382 | datatypes.lisp | khinsen_h5cl/datatypes.lisp | (in-package :h5cl)
;;
;; Type management is bit messy because there are three levels to deal with:
;; - Common Lisp types
;; - C types (as defined by cffi)
;; - HDF5 types (as defined by hdf5-cffi)
;;
;; For now, h5cl supports only data in the form of specialized arrays whose
;; element types are
;; - short-float
;; - double-float
;; - integer subtypes other than bignum
;;
;; A note about floats: the Common Lisp standard does not guarantee
;; that short-float and double-float correspond to IEEE 754
;; single/double precision binary floats, but this is the case in all
;; of today's implementations I am aware of. With an implementation that
;; uses different representations, writing floats to HDF5 and then reading
;; them back will not yield identical values.
;;
(defun lisp-type->cffi-type (type-spec)
"Find the corresponding cffi type for the elements of a specialized
array whose element-type is TYPE-SPEC. Supports floats and integers
execpt for bignums."
(let ((el-type (upgraded-array-element-type type-spec)))
(cond ((subtypep el-type 'single-float) :float)
((subtypep el-type 'double-float) :double)
((subtypep el-type '(unsigned-byte 8)) :uint8)
((subtypep el-type '(unsigned-byte 16)) :uint16)
((subtypep el-type '(unsigned-byte 32)) :uint32)
((subtypep el-type '(unsigned-byte 64)) :uint64)
((subtypep el-type '(signed-byte 8)) :int8)
((subtypep el-type '(signed-byte 16)) :int16)
((subtypep el-type '(signed-byte 32)) :int32)
((subtypep el-type '(signed-byte 64)) :int64)
(t (error "Type ~s not supported." el-type)))))
(defun cffi-type->hdf5-type (cffi-type)
"Find the HDF5 type corresponding to CFFI-TYPE."
(case cffi-type
(:uint8 hdf5::+H5T-NATIVE-UINT8+)
(:uint16 hdf5::+H5T-NATIVE-UINT16+)
(:uint32 hdf5::+H5T-NATIVE-UINT32+)
(:uint64 hdf5::+H5T-NATIVE-UINT64+)
(:int8 hdf5::+H5T-NATIVE-INT8+)
(:int16 hdf5::+H5T-NATIVE-INT16+)
(:int32 hdf5::+H5T-NATIVE-INT32+)
(:int64 hdf5::+H5T-NATIVE-INT64+)
(:float hdf5:+H5T-NATIVE-FLOAT+)
(:double hdf5:+H5T-NATIVE-DOUBLE+)))
;;
;; A class for named datatypes
;;
(defclass hdf5-datatype (hdf5-named-object)
())
| 2,266 | Common Lisp | .lisp | 54 | 37.962963 | 76 | 0.675431 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 909fe767c0bb6b98a2f1fa39ae1cd218e12ccd946c188b6379caeda0164ebd42 | 39,382 | [
-1
] |
39,383 | basics.lisp | khinsen_h5cl/basics.lisp | (in-package :h5cl)
;; A hdf5-object is anything that has an HDF5 id. This includes
;; files, datasets, groups, and more.
(defclass hdf5-object ()
((id
:initarg :id
:reader hdf5-object-id
:documentation "C-level id (type hid_t)")))
;; All HDF5 objects must be closed after use, at least to free memory.
(defun close-id (id)
"Close an HDF5 id"
(when id
(unless (< 0 (hdf5:h5iis-valid id))
(error "Invalid id"))
(let ((type (hdf5:h5iget-type id)))
(cond ((eql type :H5I-ATTR) (hdf5:h5aclose id))
((eql type :H5I-DATASET) (hdf5:h5dclose id))
((eql type :H5I-DATASPACE) (hdf5:h5sclose id))
((eql type :H5I-DATATYPE) (hdf5:h5tclose id))
((eql type :H5I-FILE) (hdf5:h5fclose id))
((eql type :H5I-GENPROP-LST) (hdf5:h5pclose id))
((eql type :H5I-GROUP) (hdf5:h5gclose id))
(t (error (format nil "Can't close id ~a" type)))))))
;; Some HDF5 obects refer to named entities within a file. This function
;; retrieves the name of such an object from its id.
(defun get-name-for-id (id)
"Return the name corresponding to a HDF5 object id"
(let* ((size (1+ (hdf5:h5iget-name id hdf5:+NULL+ 0)))
(name (cffi:foreign-alloc :char :count size)))
(prog2
(hdf5:h5iget-name id name size)
(cffi:foreign-string-to-lisp name)
(cffi:foreign-free name))))
;;
;; A base class for the HDF5 objects accessible via
;; a path in a file: groups, datasets, and named datatypes.
;;
(defclass hdf5-named-object (hdf5-object)
((file
:initarg :file
:documentation "File in which the group resides")
(name
:initarg :name
:documentation "Name of the object")))
(defmethod print-object ((object hdf5-named-object) out)
(with-slots (file name) object
(print-unreadable-object (object out :type t)
(format out "~s in file ~s" name (hdf5-file-filename file)))))
(defgeneric hdf5-containing-file (hdf5-object)
(:documentation "Return the HDF5 file containing HDF5-OBJECT"))
(defmethod hdf5-containing-file ((object hdf5-named-object))
(with-slots (file) object
file))
(defgeneric hdf5-path (hdf5-object)
(:documentation "Return the path to HDF5-OBJECT inside its containing file"))
(defmethod hdf5-path ((object hdf5-named-object))
(with-slots (name) object
name))
;;
;; A base class for HDF5 locations: files and groups
;;
(defclass hdf5-location (hdf5-object) ())
| 2,447 | Common Lisp | .lisp | 62 | 34.822581 | 79 | 0.671591 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 5efb3f55a1b5691539e6e7075bfe0c4efcbaa075de8a44fa69cf9e651776d63d | 39,383 | [
-1
] |
39,384 | groups.lisp | khinsen_h5cl/groups.lisp | (in-package :h5cl)
(defclass hdf5-group (hdf5-named-object hdf5-location)
())
;;
;; Create a new group
;;
(defun make-hdf5-group (location path)
(let* ((location-id (hdf5-object-id location))
(group-id (hdf5:h5gcreate2 location-id
path
hdf5:+H5P-DEFAULT+
hdf5:+H5P-DEFAULT+
hdf5:+H5P-DEFAULT+)))
(unless (< 0 (hdf5:h5iis-valid group-id))
(error "Group ~s could not be created in ~s." path location))
(close-id group-id))
(hdf5-ref location path))
| 623 | Common Lisp | .lisp | 17 | 25.294118 | 67 | 0.524046 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | d4abec9497e02c25ed937a1f80e3004c6272b6e3f6cce2dc74521459ce85e1eb | 39,384 | [
-1
] |
39,385 | h5cl.asd | khinsen_h5cl/h5cl.asd | (asdf:defsystem h5cl
:description "High-level HDF5 interface"
:version "0.0.1"
:author "Konrad Hinsen"
:license "GPL3"
:homepage "https://github.com/khinsen/h5cl"
:depends-on (:hdf5-cffi
:trivial-garbage
:uiop)
:serial t
:components ((:file "package")
(:file "basics")
(:file "files")
(:file "groups")
(:file "datasets")
(:file "datatypes")
(:file "accessors"))
:in-order-to ((test-op (test-op :h5cl.test))))
| 547 | Common Lisp | .asd | 18 | 21.722222 | 48 | 0.531191 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | e7eb584a1056726457d56258926a1e13d042f0743bccdd47bf4f4407163f20d1 | 39,385 | [
-1
] |
39,386 | h5cl.test.asd | khinsen_h5cl/h5cl.test.asd | (defsystem h5cl.test
:description "Tests for high-level HDF5 interface"
:version "0.0.1"
:author "Konrad Hinsen"
:license "GPL3"
:homepage "https://github.com/khinsen/h5cl"
:depends-on (:h5cl
:fiveam
:uiop)
:serial t
:components ((:file "package.test")
(:file "tests"))
:perform (test-op :after (op c)
(eval (read-from-string "(5am:run! :h5cl)"))))
| 432 | Common Lisp | .asd | 14 | 23.928571 | 66 | 0.58134 | khinsen/h5cl | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 2bc83dfd86dbc4e199d82d7dade9e6645ba0016f24dcb86e28588119c892dc62 | 39,386 | [
-1
] |
39,414 | ieee-floats.lisp | matth-love_cl-las/lisp/ieee-floats.lisp | ;;; Functions for converting floating point numbers represented in
;;; IEEE 754 style to lisp numbers.
;;;
;;; See http://common-lisp.net/project/ieee-floats/
(defpackage :ieee-floats
(:use :common-lisp)
(:export :make-float-converters
:encode-float32
:decode-float32
:encode-float64
:decode-float64))
(in-package :ieee-floats)
;; The following macro may look a bit overcomplicated to the casual
;; reader. The main culprit is the fact that NaN and infinity can be
;; optionally included, which adds a bunch of conditional parts.
;;
;; Assuming you already know more or less how floating point numbers
;; are typically represented, I'll try to elaborate a bit on the more
;; confusing parts, as marked by letters:
;;
;; (A) Exponents in IEEE floats are offset by half their range, for
;; example with 8 exponent bits a number with exponent 2 has 129
;; stored in its exponent field.
;;
;; (B) The maximum possible exponent is reserved for special cases
;; (NaN, infinity).
;;
;; (C) If the exponent fits in the exponent-bits, we have to adjust
;; the significand for the hidden bit. Because decode-float will
;; return a significand between 0 and 1, and we want one between 1
;; and 2 to be able to hide the hidden bit, we double it and then
;; subtract one (the hidden bit) before converting it to integer
;; representation (to adjust for this, 1 is subtracted from the
;; exponent earlier). When the exponent is too small, we set it to
;; zero (meaning no hidden bit, exponent of 1), and adjust the
;; significand downward to compensate for this.
;;
;; (D) Here the hidden bit is added. When the exponent is 0, there is
;; no hidden bit, and the exponent is interpreted as 1.
;;
;; (E) Here the exponent offset is subtracted, but also an extra
;; factor to account for the fact that the bits stored in the
;; significand are supposed to come after the 'decimal dot'.
(defmacro make-float-converters (encoder-name
decoder-name
exponent-bits
significand-bits
support-nan-and-infinity-p)
"Writes an encoder and decoder function for floating point
numbers with the given amount of exponent and significand
bits (plus an extra sign bit). If support-nan-and-infinity-p is
true, the decoders will also understand these special cases. NaN
is represented as :not-a-number, and the infinities as
:positive-infinity and :negative-infinity. Note that this means
that the in- or output of these functions is not just floating
point numbers anymore, but also keywords."
(let* ((total-bits (+ 1 exponent-bits significand-bits))
(exponent-offset (1- (expt 2 (1- exponent-bits)))) ; (A)
(sign-part `(ldb (byte 1 ,(1- total-bits)) bits))
(exponent-part `(ldb (byte ,exponent-bits ,significand-bits) bits))
(significand-part `(ldb (byte ,significand-bits 0) bits))
(nan support-nan-and-infinity-p)
(max-exponent (1- (expt 2 exponent-bits)))) ; (B)
`(progn
(defun ,encoder-name (float)
,@(unless nan `((declare (type float float))))
(multiple-value-bind (sign significand exponent)
(cond ,@(when nan `(((eq float :not-a-number)
(values 0 1 ,max-exponent))
((eq float :positive-infinity)
(values 0 0 ,max-exponent))
((eq float :negative-infinity)
(values 1 0 ,max-exponent))))
((zerop float)
(values 0 0 0))
(t
(multiple-value-bind (significand exponent sign) (decode-float float)
(let ((exponent (+ (1- exponent) ,exponent-offset))
(sign (if (= sign 1.0) 0 1)))
(unless (< exponent ,(expt 2 exponent-bits))
(error "Floating point overflow when encoding ~A." float))
(if (< exponent 0) ; (C)
(values sign (ash (round (* ,(expt 2 significand-bits) significand)) exponent) 0)
(values sign (round (* ,(expt 2 significand-bits) (1- (* significand 2)))) exponent))))))
(let ((bits 0))
(declare (type (unsigned-byte ,total-bits) bits))
(setf ,sign-part sign
,exponent-part exponent
,significand-part significand)
bits)))
(defun ,decoder-name (bits)
(declare (type (unsigned-byte ,total-bits) bits))
(let* ((sign ,sign-part)
(exponent ,exponent-part)
(significand ,significand-part))
,@(when nan `((when (= exponent ,max-exponent)
(return-from ,decoder-name
(cond ((not (zerop significand)) :not-a-number)
((zerop sign) :positive-infinity)
(t :negative-infinity))))))
(if (zerop exponent) ; (D)
(setf exponent 1)
(setf (ldb (byte 1 ,significand-bits) significand) 1))
(unless (zerop sign)
(setf significand (- significand)))
(scale-float (float significand ,(if (> total-bits 32) 1.0d0 1.0))
(- exponent ,(+ exponent-offset significand-bits)))))))) ; (E)
;; And instances of the above for the common forms of floats.
(make-float-converters encode-float32 decode-float32 8 23 nil)
(make-float-converters encode-float64 decode-float64 11 52 nil)
;;; Copyright (c) 2006 Marijn Haverbeke
;;;
;;; This software is provided 'as-is', without any express or implied
;;; warranty. In no event will the authors be held liable for any
;;; damages arising from the use of this software.
;;;
;;; Permission is granted to anyone to use this software for any
;;; purpose, including commercial applications, and to alter it and
;;; redistribute it freely, subject to the following restrictions:
;;;
;;; 1. The origin of this software must not be misrepresented; you must
;;; not claim that you wrote the original software. If you use this
;;; software in a product, an acknowledgment in the product
;;; documentation would be appreciated but is not required.
;;;
;;; 2. Altered source versions must be plainly marked as such, and must
;;; not be misrepresented as being the original software.
;;;
;;; 3. This notice may not be removed or altered from any source
;;; distribution.
| 6,272 | Common Lisp | .lisp | 130 | 42.146154 | 117 | 0.659006 | matth-love/cl-las | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | edc5b470b1a8e1745eff5ea7a58ec9dbeb05ba18f7cda361cf1b7ffb79b702a5 | 39,414 | [
402084
] |
39,431 | Prime_array.lisp | DiegoNavaca_Primes_array/Prime_array.lisp | ; Basic function to check if a number is prime
(defun is_prime (num)
(let ((squrt (sqrt num)) (it 1))
(loop
(when (= (mod num (aref prime_array it)) 0) (return nil)) ; If it's divisible, then it's not prime
(when (> (aref prime_array it) squrt) (return t)) ; If the loop ends, then it's prime
(incf it)
)
)
)
; Function to make an array of prime numbers
; @param limit_by_value: if t, calculate all prime numbers from 2 to limit
; if nil, calculate the first (limit) prime numbers
(defun primes_into_array (limit limit_by_value)
(setf prime_array (make-array limit :fill-pointer 0))
(let ((count 0) (it 5))
(vector-push 2 prime_array) ; For the function to work properly we have to initialice the first prime
(incf count)
(when (> limit 1)
(vector-push 3 prime_array) ; We want to check only odd numbers so we have to add 3 to the list
(incf count)
(when (> limit 2)
(loop
(when (is_prime it) ; If it's prime we add it to the list
(vector-push it prime_array)
(incf count)
)
(incf it 2) ; We skip even numbers
(if limit_by_value
(when (>= it limit) (return prime_array))
(when (= count limit) (return prime_array)) ; When we reach the number of primes whe want we stop
)
)
)
)
)
)
; Write the array into a .txt file
; @param name: name of the file you want to write
(defun write_file (&optional (name "primes"))
(let ((len (length prime_array)))
(with-open-file (str (concatenate 'string "./" name ".txt" ) ; Open or create the file in which to write the array
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(format str "~d~%" len) ; Write the length of the array first
(loop for i from 0 to (- len 1)
do
(format str "~d~%" (aref prime_array i)) ; Write a number in each line
)
)
)
)
; Load the array from a .txt file
; @param filename: file to load
(defun load_file (&optional (filename "./primes.txt"))
(let ((in (open filename :if-does-not-exist nil)))
(when in
(setf prime_array (make-array (parse-integer (read-line in nil)) :fill-pointer 0)) ; Create or redefine the with the capacity read from the file
(loop for line = (read-line in nil)
while line do (vector-push (parse-integer line) prime_array)) ; Fill the array
(close in)
)
)
)
; A few function calls to test that everything works fine
(primes_into_array 100 nil)
(write_file)
(load_file)
(write prime_array)
| 2,829 | Common Lisp | .lisp | 70 | 34.485714 | 151 | 0.580821 | DiegoNavaca/Primes_array | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 81a41c4087ff37f85df225eacec4d651fa38aa80b8ea98d3cdef27766b3f2c97 | 39,431 | [
-1
] |
39,448 | nfa.lisp | DrTaxi98_NFA/Lisp/nfa.lisp | ;;;; nfa.lisp: regular languages compiler and NFA tester
;;;; Copyright (C) 2020 Andrea Tassi
;;;;
;;;; This program 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.
;;;;
;;;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
;;;;
;;;; Author's email address: [email protected]
;; T if functor is reserved, nil otherwise.
(defun is-reserved-functor (functor)
(or (eql functor 'seq)
(eql functor 'or)
(eql functor 'star)
(eql functor 'plus)))
;; Returns a function that controls if the arguments
;; of functor respect its arity.
(defun functor-arity (functor)
(cond ((or (eql functor 'seq) (eql functor 'or))
(lambda (arity) (>= arity 2)))
((or (eql functor 'star) (eql functor 'plus))
(lambda (arity) (= arity 1)))))
;; T if symbol is a symbol of the alphabet, nil otherwise.
(defun is-alphabetical-symbol (symbol)
(cond ((atom symbol) T)
(T (not (is-reserved-functor (first symbol))))))
;; T if RE is a regular expression, nil otherwise.
(defun is-regexp (RE)
(if (is-alphabetical-symbol RE)
T
(and (funcall (functor-arity (first RE)) (length (rest RE)))
(car (mapcar 'is-regexp (rest RE))))))
;; Returns the list of the deltas of the automata FA.
(defun deltas-list (FA)
(rest (rest FA)))
;; Returns the automata obtained by the RE compilation,
;; if it is a regexp, nil otherwise.
;; If it can't compile RE, it returns nil.
(defun nfa-regexp-comp (RE)
(if (is-regexp RE)
(thompsons-construction RE)
nil))
;; Returns the automata built with the
;; Thompson's Construction for the regexp RE.
(defun thompsons-construction (RE)
(cond ((atom RE)
(thompsons-construction-symbol RE))
((eql (first RE) 'seq)
(thompsons-construction-seq (rest RE)))
((eql (first RE) 'or)
(thompsons-construction-or (rest RE)))
((eql (first RE) 'star)
(thompsons-construction-star (rest RE)))
((eql (first RE) 'plus)
(thompsons-construction-plus (rest RE)))
(T (thompsons-construction-symbol RE))))
;; Returns the automata built with the
;; Thompson's Construction to recognise symbol.
(defun thompsons-construction-symbol (symbol)
(let ((initial (gensym "q"))
(final (gensym "q")))
(append (list initial)
(list final)
(list (list initial symbol final)))))
;; Returns the automata built with the
;; Thompson's Construction for the regexp
;; with functor 'seq' and arguments args.
(defun thompsons-construction-seq (args)
(if (null (rest args))
(nfa-regexp-comp (first args))
(let ((first-nfa (nfa-regexp-comp (first args)))
(second-nfa (thompsons-construction-seq (rest args))))
(append (list (first first-nfa))
(list (second second-nfa))
(deltas-list first-nfa)
(list (list (second first-nfa) 'epsilon (first second-nfa)))
(deltas-list second-nfa)))))
;; Returns the automata built with the
;; Thompson's Construction for the regexp
;; with functor 'or' and arguments args.
(defun thompsons-construction-or (args)
(if (null (rest args))
(nfa-regexp-comp (first args))
(let ((initial (gensym "q"))
(first-nfa (nfa-regexp-comp (first args)))
(second-nfa (thompsons-construction-or (rest args)))
(final (gensym "q")))
(append (list initial)
(list final)
(list (list initial 'epsilon (first first-nfa)))
(list (list initial 'epsilon (first second-nfa)))
(deltas-list first-nfa)
(deltas-list second-nfa)
(list (list (second first-nfa) 'epsilon final))
(list (list (second second-nfa) 'epsilon final))))))
;; Returns the automata built with the
;; Thompson's Construction for the regexp
;; with functor 'star' and argument arg.
(defun thompsons-construction-star (arg)
(let ((nfa (thompsons-construction-plus arg)))
(append nfa
(list (list (first nfa) 'epsilon (second nfa))))))
;; Returns the automata built with the
;; Thompson's Construction for the regexp
;; with functor 'plus' and arguments arg.
(defun thompsons-construction-plus (arg)
(let ((initial (gensym "q"))
(nfa (nfa-regexp-comp (first arg)))
(final (gensym "q")))
(append (list initial)
(list final)
(list (list initial 'epsilon (first nfa)))
(deltas-list nfa)
(list (list (second nfa) 'epsilon final))
(list (list (second nfa) 'epsilon (first nfa))))))
;; T if Input is a list of symbols of the alphabet,
;; nil otherwise.
(defun is-alphabetical-list (Input)
(if (null Input) T
(and (is-alphabetical-symbol (first Input))
(is-alphabetical-list (rest Input)))))
;; T if FA has the structure of an automata,
;; nil otherwise.
(defun is-nfa (FA)
(if (atom FA) nil
(and (>= (length FA) 3)
(atom (first FA))
(atom (second FA))
(is-deltas-list (deltas-list FA)))))
;; T if deltas is a list of delta-transitions,
;; nil otherwise.
(defun is-deltas-list (deltas)
(if (= (length deltas) 1)
(is-delta (first deltas))
(and (is-delta (first deltas))
(is-deltas-list (rest deltas)))))
;; T if delta is a delta-transition,
;; nil otherwise.
(defun is-delta (delta)
(if (atom delta) nil
(and (= (length delta) 3)
(atom (first delta))
(is-alphabetical-symbol (second delta))
(atom (third delta)))))
;; T if Input for the automata FA is completely consumed
;; and the automata is in a final state.
;; Input is a Lisp list of symbols of the alphabet.
;; If FA has not the correct structure of an automata,
;; it reports an error.
;; Otherwise, it returns T if FA recognises Input,
;; nil if it doesn't.
(defun nfa-test (FA Input)
(cond ((and (atom Input) (not (null Input)))
nil)
((not (is-alphabetical-list Input))
nil)
((not (is-nfa FA))
(format *standard-output*
"Error: ~S is not a Finite State Automata.~%"
FA))
(T (nfa-accept FA Input (first FA)))))
;; T if Input for the automata FA in the current-state
;; is completely consumed and the automata
;; is in a final state.
(defun nfa-accept (FA Input current-state)
(let ((next-state (first (apply-delta (deltas-list FA)
(first Input)
current-state)))
(epsilon-transitions (apply-delta (deltas-list FA)
'epsilon
current-state)))
(cond ((not (null epsilon-transitions))
(let ((accept-transition
(nfa-accept FA Input (first epsilon-transitions))))
(if (not (null accept-transition))
accept-transition
(nfa-accept FA Input (second epsilon-transitions)))))
((null Input)
(eql current-state (second FA)))
((eql (first Input) 'epsilon)
(nfa-accept FA (rest Input) current-state))
((null next-state)
nil)
(T (nfa-accept FA (rest Input) next-state)))))
;; Returns a list of all the possible states
;; that are reachable through all the possible
;; delta-transitions from the list deltas
;; that accept symbol starting from state.
(defun apply-delta (deltas symbol state)
(let ((first-delta (first deltas)))
(cond ((null deltas)
nil)
((and (eql state (first first-delta))
(equal symbol (second first-delta)))
(append (list (third first-delta))
(apply-delta (rest deltas) symbol state)))
(T (apply-delta (rest deltas) symbol state)))))
;;;; eof nfa.lisp
| 7,903 | Common Lisp | .lisp | 206 | 33.985437 | 78 | 0.663837 | DrTaxi98/NFA | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | 96c0c2a6f43d6d0a5d4f1ba6233d934170c6b361cbe0198f81ed77635de87187 | 39,448 | [
-1
] |
39,450 | nfa.pl | DrTaxi98_NFA/Prolog/nfa.pl | %%%% -*- Mode: Prolog -*-
/* nfa.pl: regular languages compiler and NFA tester
Copyright (C) 2020 Andrea Tassi
This program 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.
This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
Author's email address: [email protected]
*/
/* Facts: 'seq', 'or', 'star' and 'plus'
are reserved functors.
*/
reserved_functor(seq).
reserved_functor(or).
reserved_functor(star).
reserved_functor(plus).
% True when Functor is not a reserved functor.
is_not_reserved_functor(Functor) :-
reserved_functor(Functor),
!,
fail.
is_not_reserved_functor(_).
/* True when Arity respects the arity of the functor
(the first argument).
*/
functor_arity(seq, Arity) :-
Arity >= 2,
!.
functor_arity(or, Arity) :-
Arity >= 2,
!.
functor_arity(star, Arity) :-
Arity is 1,
!.
functor_arity(plus, Arity) :-
Arity is 1,
!.
/* True when Term is a symbol of the alphabet
(atomic or compound without a reserved functor).
*/
is_alphabetical_symbol(Term) :-
atomic(Term),
!.
is_alphabetical_symbol(Term) :-
compound(Term),
!,
functor(Term, Functor, _),
is_not_reserved_functor(Functor).
/* True when RE is a regular expression
(terms with reserved functors must respect their arity).
*/
is_regexp(RE) :-
is_alphabetical_symbol(RE),
!.
is_regexp(RE) :-
compound(RE),
functor(RE, Functor, Arity),
reserved_functor(Functor),
!,
functor_arity(Functor, Arity),
RE =.. [_ | Args],
are_args_regexps(Args).
/* True when the arguments of a compound term
are regular expressions.
*/
are_args_regexps([]) :-
!.
are_args_regexps([Arg | OtherArgs]) :-
!,
is_regexp(Arg),
are_args_regexps(OtherArgs).
/* True when RE is compilable into an automata,
which is added to the Prolog database.
FA_Id becomes the automata identificator
(it must be a Prolog term without variables).
*/
nfa_regexp_comp(FA_Id, RE) :-
nonvar(FA_Id),
is_regexp(RE),
RE =.. [Functor | Args],
thompsons_construction(FA_Id, Functor, Args).
/* True when the automata is identificated by FA_Id
and Symbol is a symbol of the alphabet that generates
two states and a delta transition between them.
*/
thompsons_construction(FA_Id, Symbol, []) :-
!,
is_alphabetical_symbol(Symbol),
gensym(q, Initial),
assert(nfa_initial(FA_Id, Initial)),
gensym(q, Final),
assert(nfa_final(FA_Id, Final)),
assert(nfa_delta(FA_Id, Initial, Symbol, Final)).
/* True when the automata identificated by FA_Id
is built to accept a regexp with the functor 'seq'.
*/
thompsons_construction(FA_Id, seq, [Arg]) :-
!,
nfa_regexp_comp(FA_Id, Arg).
thompsons_construction(FA_Id, seq, [Arg | OtherArgs]) :-
!,
nfa_regexp_comp(FA_Id, Arg),
retract(nfa_initial(FA_Id, FirstInitial)),
retract(nfa_final(FA_Id, FirstFinal)),
thompsons_construction(FA_Id, seq, OtherArgs),
retract(nfa_initial(FA_Id, SecondInitial)),
assert(nfa_initial(FA_Id, FirstInitial)),
assert(nfa_delta(FA_Id, FirstFinal, epsilon, SecondInitial)).
/* True when the automata identificated by FA_Id
is built to accept a regexp with the functor 'or'.
*/
thompsons_construction(FA_Id, or, [Arg]) :-
!,
nfa_regexp_comp(FA_Id, Arg).
thompsons_construction(FA_Id, or, [Arg | OtherArgs]) :-
!,
gensym(q, Initial),
nfa_regexp_comp(FA_Id, Arg),
retract(nfa_initial(FA_Id, FirstInitial)),
retract(nfa_final(FA_Id, FirstFinal)),
thompsons_construction(FA_Id, or, OtherArgs),
retract(nfa_initial(FA_Id, SecondInitial)),
retract(nfa_final(FA_Id, SecondFinal)),
gensym(q, Final),
assert(nfa_initial(FA_Id, Initial)),
assert(nfa_final(FA_Id, Final)),
assert(nfa_delta(FA_Id, Initial, epsilon, FirstInitial)),
assert(nfa_delta(FA_Id, Initial, epsilon, SecondInitial)),
assert(nfa_delta(FA_Id, FirstFinal, epsilon, Final)),
assert(nfa_delta(FA_Id, SecondFinal, epsilon, Final)).
/* True when the automata identificated by FA_Id
is built to accept a regexp with the functor 'star'.
*/
thompsons_construction(FA_Id, star, Arg) :-
!,
thompsons_construction(FA_Id, plus, Arg),
nfa_initial(FA_Id, Initial),
nfa_final(FA_Id, Final),
assert(nfa_delta(FA_Id, Initial, epsilon, Final)).
/* True when the automata identificated by FA_Id
is built to accept a regexp with the functor 'plus'.
*/
thompsons_construction(FA_Id, plus, [Arg]) :-
!,
gensym(q, Initial),
nfa_regexp_comp(FA_Id, Arg),
gensym(q, Final),
retract(nfa_initial(FA_Id, InternalInitial)),
assert(nfa_initial(FA_Id, Initial)),
retract(nfa_final(FA_Id, InternalFinal)),
assert(nfa_final(FA_Id, Final)),
assert(nfa_delta(FA_Id, Initial, epsilon, InternalInitial)),
assert(nfa_delta(FA_Id, InternalFinal, epsilon, InternalInitial)),
assert(nfa_delta(FA_Id, InternalFinal, epsilon, Final)).
/* True when Input for the automata identificated
by FA_Id it's completely consumed and the automata
is in a final state.
*/
nfa_test(FA_Id, Input) :-
nfa_initial(FA_Id, Initial),
nfa_accept(FA_Id, Input, Initial).
/* True when the input is completely consumed
and the automata FA_Id is in a final state.
*/
nfa_accept(FA_Id, [], Final) :-
nfa_final(FA_Id, Final),
!.
% epsilon-transition, where Input is not consumed.
nfa_accept(FA_Id, Input, FirstState) :-
nfa_delta(FA_Id, FirstState, epsilon, SecondState),
nfa_accept(FA_Id, Input, SecondState),
!.
/* True when the first symbol of the input is 'epsilon'
and the state doesn't change.
*/
nfa_accept(FA_Id, [epsilon | OtherSymbols], FirstState) :-
!,
nfa_accept(FA_Id, OtherSymbols, FirstState).
/* True when the first symbol of the input is consumed
and the automata FA_Id passes to another state.
*/
nfa_accept(FA_Id, [Symbol | OtherSymbols], FirstState) :-
!,
is_alphabetical_symbol(Symbol),
nfa_delta(FA_Id, FirstState, Symbol, SecondState),
nfa_accept(FA_Id, OtherSymbols, SecondState).
/* True when all the defined automatas are removed
from the Prolog database.
*/
nfa_clear :-
nfa_clear(_),
fail.
nfa_clear.
/* True when the automata FA_Id is removed
from the Prolog database.
*/
nfa_clear(FA_Id) :-
retract(nfa_initial(FA_Id, _)),
retract(nfa_final(FA_Id, _)),
retract(nfa_delta(FA_Id, _, _, _)),
fail.
nfa_clear(_).
/* True when all the defined automatas
are listed with their structure.
*/
nfa_list :-
nfa_initial(FA_Id, _),
nfa_list(FA_Id),
fail.
nfa_list.
/* True when the automata FA_Id
is listed with his structure.
*/
nfa_list(FA_Id) :-
listing(nfa_initial(FA_Id, _)),
listing(nfa_final(FA_Id, _)),
listing(nfa_delta(FA_Id, _, _, _)).
%%%% -*- eof: nfa.pl -*-
| 7,591 | Common Lisp | .l | 224 | 29.133929 | 76 | 0.666712 | DrTaxi98/NFA | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:20 AM (Europe/Amsterdam) | f8245b8df483f76bc580cc4552d156d58583bb0709169287f98c928cc166ad21 | 39,450 | [
-1
] |
39,466 | GuessMyNumber.lisp | Xevion_lisp-projects/games/GuessMyNumber/GuessMyNumber.lisp | (defparameter *small* 1)
(defparameter *big* 100)
(defun start-over ()
(defparameter *small* 1)
(defparameter *big* 100)
(guess-my-number)
)
(defun smaller()
(setf *small* (1- (guess-my-number)))
(print (guess-my-number))
)
(defun bigger()
(setf *big* (1+ (guess-my-number)))
(print (guess-my-number))
)
(defun guess-my-number ()
(ash (+ *small* *big*) -1)
)
(defun game-loop ()
(flet ((prompt (string)
(format "~A " string)
(finish-output)
(read nil 'eof nil)))
(fresh-line)
(let
((last "?"))
(loop while (not (equal last "="))
do (setf last (prompt (format t "Is '~A' Smaller (<) or Larger (>)?" (guess-my-number))))
(cond
((string= last "<") (smaller))
((string= last ">") (bigger))
((string= last "=") (start-over))
(t (print "Invalid Input") (print last) (fresh-line))
)
'DONE))
)
)
(print (equal "+" "+"))
(game-loop) | 1,159 | Common Lisp | .lisp | 39 | 20.128205 | 109 | 0.461116 | Xevion/lisp-projects | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | c1ab5e5af2277a2de86cd2e247dddb48f84e21b3069adb33b89bad907be6c38c | 39,466 | [
-1
] |
39,467 | Prompt.lisp | Xevion_lisp-projects/scripts/Prompt.lisp | (defun read-3-numbers-&-format-sum ()
(flet ((prompt (string)
(format t "~&~a: " string)
(finish-output)
(read nil 'eof nil)))
(let ((x (prompt "first number"))
(y (prompt "second number"))
(z (prompt "third number")))
(format t "~&the sum of ~a, ~a, & ~a is:~%~%~a~%"
x y z (+ x y z)))))
(read-3-numbers-&-format-sum) | 397 | Common Lisp | .lisp | 11 | 28 | 55 | 0.483204 | Xevion/lisp-projects | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | f85a18cda7fbcfbe7cf18a6716b2bb4e3f01bed3a7cfa99b2ce7baa577f913da | 39,467 | [
-1
] |
39,468 | MonthLength.lisp | Xevion_lisp-projects/scripts/MonthLength.lisp | (defconstant jan 1)
(defconstant feb 2)
(defconstant mar 3)
(defconstant apr 4)
(defconstant may 5)
(defconstant jul 6)
(defconstant jun 7)
(defconstant aug 8)
(defconstant oct 9)
(defconstant sep 10)
(defconstant nov 11)
(defconstant dec 12)
(defun isLeapYear ()
true
)
(defun month-length (mon)
(case mon
((jan mar may jul aug oct dec) 31)
((apr jun sep nov 30)
(feb (if (isLeapYear) 29 28))
(otherwise "Unknown Month.")
)
))
(print (month-length 'jan)) | 503 | Common Lisp | .lisp | 24 | 18.041667 | 43 | 0.679245 | Xevion/lisp-projects | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | 4c33d5ac6e5c2a74c89bfaee9184b61afb7e14a8511c8dc09b32584704ce22f8 | 39,468 | [
-1
] |
39,487 | levenshtein-tests.lisp | vaelen_levenshtein/levenshtein-tests.lisp | ;; Copyright 2020, Andrew C. Young <[email protected]>
;;
;; This program 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.
;;
;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
(defpackage :levenshtein-tests
(:use :common-lisp)
(:export :run))
(in-package :levenshtein-tests)
(defparameter *test-data*
'(("cat" "hat" 1)
("cat" "catt" 1)
("cat" "ct" 1)
("cat" "c" 2)
("cat" "" 3)
("book" "back" 2)
("kitten" "sitting" 3)
("Saturday" "Sunday" 3)
("abcdefghijk" "abcdefghiijk" 1)
("abcdefghijk" "abcdefghjk" 1)
("abcdefghijk" "abcdefghIjk" 1)
("abcdefghijk" "abdefGhiijkl" 4)))
(defparameter *methods*
(list #'levenshtein:simple
#'levenshtein:iterate))
(defun test-distance (method string1 string2 expected)
"Test the distance function using specific inputs and a specific method."
(let ((result (levenshtein:distance string1 string2 :method method)))
(if (not (= expected result))
(format t
"ERROR: Distance test failed. Method: ~A, Strings: ~A ~A, Expected: ~A, Got: ~A~%"
method string1 string2 expected result))))
(defun run ()
"Run distance tests for all methods."
(loop for method in *methods* do
(loop for data in *test-data* do
(test-distance method (first data) (second data) (third data)))))
| 1,865 | Common Lisp | .lisp | 46 | 36.543478 | 98 | 0.684327 | vaelen/levenshtein | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | a5ac30a58fae8f3b24605e592718d40f4d0c860fcf6bf9f254dde967febafcbf | 39,487 | [
-1
] |
39,488 | levenshtein.lisp | vaelen_levenshtein/levenshtein.lisp | ;; Copyright 2020, Andrew C. Young <[email protected]>
;;
;; This program 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.
;;
;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
(defpackage :levenshtein
(:use :common-lisp)
(:export
#:distance
#:simple
#:iterate
#:test
#:main))
(in-package :levenshtein)
(defun simple (s1 s2 &optional (limit -1) (dist 0))
"Returns the levenshtein distance between two strings using recursion."
(cond ((not (listp s1)) (simple (coerce s1 'list) s2 limit dist)) ; Coerce inputs to lists
((not (listp s2)) (simple s1 (coerce s2 'list) limit dist)) ; Coerce inputs to lists
((and (> limit 0) (> dist limit)) dist) ; If the limit has been passed, return
((= (length s1) 0) (+ (length s2) dist)) ; When the shorter string ends
((= (length s2) 0) (+ (length s1) dist)) ; add the remaining character count
((equal (first s1) (first s2))
(simple (rest s1) (rest s2) limit dist)) ; Match
(t (min
(simple (rest s1) (rest s2) limit (1+ dist)) ; Substitution
(simple s1 (rest s2) limit (1+ dist)) ; Insertion
(simple (rest s1) s2 limit (1+ dist)))))) ; Deletion
(defun iterate (string1 string2 &optional (limit -1) (dist 0))
"Returns the levenshtein distance between two strings using iteration."
(if (not (listp string1)) (setf string1 (coerce string1 'list))) ; Coerce inputs to lists
(if (not (listp string2)) (setf string2 (coerce string2 'list))) ; Coerce inputs to lists
(let ((queue (list (vector string1 string2 dist)))
(result nil))
(flet ((add-to-queue (s1 s2 d)
(push (vector s1 s2 d) queue))
(add-result (d)
(setf result (if (not result) d (min result d)))))
(loop while (not (null queue)) do
(let* ((entry (pop queue))
(s1 (elt entry 0))
(s2 (elt entry 1))
(d (elt entry 2)))
(cond ((and result (>= d result)))
((and (> limit 0) (> d limit)) (add-result d))
((= (length s1) 0) (add-result (+ d (length s2)))) ; End of first string
((= (length s2) 0) (add-result (+ d (length s1)))) ; End of second string
((equal (first s1) (first s2)) ; Match
(add-to-queue (rest s1) (rest s2) d))
(t (progn
(add-to-queue (rest s1) (rest s2) (1+ d)) ; Substitution
(add-to-queue s1 (rest s2) (1+ d)) ; Insertion
(add-to-queue (rest s1) s2 (1+ d)))))) ; Deletion
finally (return result)))))
(defun distance (string1 string2 &key (limit -1) (method #'iterate) (distance 0))
"Returns the levenshtein distance between two strings."
(funcall method string1 string2 limit distance))
(defun main ()
(if (< (length (uiop:command-line-arguments)) 2)
(format t "Usage: levenshtein <first word> <second word> [limit]~%")
(let ((string1 (first (uiop:command-line-arguments)))
(string2 (second (uiop:command-line-arguments)))
(limit (third (uiop:command-line-arguments))))
(let ((d (distance string1 string2 :limit (if limit (parse-integer limit) -1))))
(format t "~A~%" d)
d))))
| 4,019 | Common Lisp | .lisp | 74 | 46.202703 | 108 | 0.576796 | vaelen/levenshtein | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | 6f0a9908be1e4b8db4b65895bb81fbf44e7f81f46f37cbd26d6e4a0233391c95 | 39,488 | [
-1
] |
39,489 | levenshtein.asd | vaelen_levenshtein/levenshtein.asd | (defsystem "levenshtein"
:components ((:file "levenshtein"))
:in-order-to ((test-op (test-op "levenshtein/tests"))))
(defsystem "levenshtein/executable"
:build-operation program-op
:build-pathname "levenshtein" ;; shell name
:entry-point "levenshtein::main" ;; thunk
:components ((:file "levenshtein")))
(defsystem "levenshtein/tests"
:depends-on ("levenshtein")
:components ((:file "levenshtein-tests"))
:perform (test-op (o c) (uiop:symbol-call :levenshtein-tests '#:run)))
| 504 | Common Lisp | .asd | 12 | 38.666667 | 72 | 0.706122 | vaelen/levenshtein | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | 67a3a8e17038dc022d6cc6902ea3a117c92655dedbe26f518ed966fd303dbaf6 | 39,489 | [
-1
] |
39,491 | Makefile | vaelen_levenshtein/Makefile | LISP=sbcl
all: build
build:
$(LISP) --eval '(require "asdf")' --eval '(asdf:make :levenshtein/executable)' --quit
clean:
rm levenshtein
| 141 | Common Lisp | .l | 6 | 21.666667 | 86 | 0.719697 | vaelen/levenshtein | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | 1b8293c97613fadbab75aed20fb42b2bcfd088d7521d6b2b6e693375bb07f3f5 | 39,491 | [
-1
] |
39,508 | elfunctions.lisp | ZerglingOne_elisp-functions/elfunctions.lisp | (defun index (aList anIndex)
(cond ((> anIndex 0) (index (cdr aList) (- anIndex 1)))
((< anIndex 0) NIL)
((= anIndex 0) (car aList))))
(defvar currentversions nil)
(defvar servicemethods nil)
(defvar apimethods nil)
(defvar repomethods nil)
(defvar microservicename nil)
(defvar servicename nil)
(defvar reponame nil)
(defvar apiname nil)
(defvar artifactnames nil)
(setq servicemethods "")
(setq repomethods "")
(setq apimethods "")
(setq microservicename "")
(setq empty-char '‎)
(defun clearmethods ()
(setq servicemethods "")
(setq repomethods "")
)
(defun feign ()
(kill-new "import org.springframework.cloud.openfeign.FeignClient;
")
(kill-append "@FeignClient(value = \"" nil)
(kill-append (read-string "value = ") nil)
(kill-append "\", path = \"/api/" nil)
(kill-append (read-string "path = ") nil)
(kill-append "\")" nil)
(alttab-and-paste)
)
(defun restcon ()
(kill-new "import org.springframework.web.bind.annotation.RequestMapping;
")
(kill-append "import org.springframework.web.bind.annotation.RestController;
" nil)
(kill-append "
" nil)
(kill-append "@RestController
" nil)
(kill-append "@RequestMapping(value = \"/api/" nil)
(kill-append (read-string "value = ") nil)
(kill-append "\")" nil)
"Rest controller copied to clipboard"
(alttab-and-paste)
)
(defun upcopy ()
(kill-new (upcase (current-kill 0)))
(alttab-and-paste)
)
(defun downcopy()
(kill-new (downcase (current-kill 0)))
(alttab-and-paste)
)
(defun camel ()
(setq temp (read-string "write your camel: "))
(kill-new
(concat
(car (split-string temp))
(eval (append '(concat) (cdr (split-string (capitalize temp)))))
)
)
(makunbound 'temp)
"copied to clipboard"
)
(defun camelwp(string)
(concat
(car (split-string string))
(eval (append '(concat) (cdr (split-string (capitalize string)))))
)
)
(defun pascal ()
(kill-new
(eval ( append '(concat) (split-string (capitalize (read-string "enter the pascalized string: ")))))
)
)
(defun kebab ()
(kill-new
(replace-regexp-in-string " " "-" (read-string "enter the kebabized string: "))
)
)
(defun snake ()
(kill-new
(replace-regexp-in-string " " "_" (read-string "enter the slithery snake string: "))
)
)
(defun dragon ()
(kill-new
(replace-regexp-in-string " " "_" (upcase (read-string "enter the dragonized string: ")))
)
)
(defun dragonwp (string)
(replace-regexp-in-string " " "_" (upcase string))
)
(defun query ()
(kill-new
(concat "SELECT * FROM GCDEV."
(dragonwp
(read-string "type table name spaces instead of underscores: ")
)
";"
)
)
)
(defun swagger ()
(w32-shell-execute "open"
(concat "http://localhost:" (read-string "port number: ") "/swagger-ui.html"))
)
(defun reload ()
(load "elfunctions.lisp")
)
(defun turtle ()
'(turtle)
)
(defun eval-string (string)
(eval (car (read-from-string string)))
)
(defvar test)
(setq test 0)
(defun runfuncs ()
(while (= test 0)
(setq temp (read-string "function name: "))
(cond
((string= temp "runfuncs") (setq temp "turtle"))
((not (string= temp "quit")) (ignore-errors (eval-string (concat "(" temp ")"))))
((string= temp "quit") (setq test 1))
)
)
(setq test 0)
"done!"
)
(defun replace-copy ()
(kill-new
(replace-regexp-in-string
(read-string "replace: ")
(read-string "with: ")
(current-kill 0)
)
)
(alttab-and-paste)
)
(defun prepare-for-post ()
(kill-new
(replace-regexp-in-string
"\(defun" " \(defun" (current-kill 0)
)
)
(kill-new
(replace-regexp-in-string
"\n\t*)\n" ")" (current-kill 0)
)
)
(kill-new
(replace-regexp-in-string
")[\n\s\t]*)" "))" (current-kill 0)
)
)
(kill-new
(replace-regexp-in-string
"\t" " " (current-kill 0)
)
)
(kill-new
(replace-regexp-in-string
")\s+)" "))" (current-kill 0)
)
)
)
(defun nobody ()
(kill-new
(replace-regexp-in-string
"\s*\n*\s*{\n[^\}]*\}" ";" (current-kill 0)
)
)
(alttab-and-paste)
)
(defun make-web-api ()
(setq apimethods "")
(setq servicemethods "")
(setq repomethods "")
(setq servicename "")
(setq reponame "")
(setq microservicename "")
(setq microservicename (read-string "micro-service name(e.g. \"<Object Name>\" -> I<Object Name>Repo <Object Name>Service etc.): "))
(setq servicename (concat microservicename "Service"))
(setq reponame (concat "I" microservicename "Repo"))
(setq again "Y")
(while (string= again "Y")
(generate-web-methods)
(setq again (upcase (read-string "add another method? Y/y to continue: ")))
)
(setq apimethods (concat "\t@Autowired\n\tprivate " servicename " " (downcase microservicename) "Service;\n" apimethods))
(setq servicemethods ( concat "\t@Autowired\n\tprivate " reponame " " (downcase microservicename) "Repo;\n" servicemethods))
(read-string "press enter to put repo methods into clipboard")
(getrepomethods)
(alttab-and-paste)
(read-string "press enter to put service methods into clipboard")
(getservicemethods)
(alttab-and-paste)
(read-string "press enter to put api methods into clipboard")
(getapimethods)
(alttab-and-paste)
)
(defun make-db-api ()
(setq apimethods "")
(setq servicemethods "")
(setq repomethods "")
(setq servicename "")
(setq reponame "")
(setq microservicename "")
(setq microservicename (read-string "micro-service name(e.g. \"<Object Name>\" -> I<Object Name>Repo <Object Name>Service etc.): "))
(setq servicename (concat microservicename "Service"))
(setq reponame (concat "I" microservicename "Repo"))
(setq again "Y")
(while (string= again "Y")
(generate-db-methods)
(setq again (upcase (read-string "add another method? Y/y to continue: ")))
)
(setq apimethods (concat "\t@Autowired\n\tprivate " servicename " " (downcase microservicename) "Service;\n" apimethods))
(setq servicemethods ( concat "\t@Autowired\n\tprivate " reponame " " (downcase microservicename) "Repo;\n" servicemethods))
(read-string "press enter to put repo methods into clipboard")
(getrepomethods)
(alttab-and-paste)
(read-string "press enter to put service methods into clipboard")
(getservicemethods)
(alttab-and-paste)
(read-string "press enter to put api methods into clipboard")
(getapimethods)
(alttab-and-paste)
)
(defun make-web-methods ()
(setq apimethods "")
(setq servicemethods "")
(setq repomethods "")
(setq servicename "")
(setq reponame "")
(setq microservicename "")
(setq microservicename (read-string "micro-service name(e.g. \"<Object Name>\" -> I<Object Name>Repo <Object Name>Service etc.): "))
(setq servicename (concat microservicename "Service"))
(setq reponame (concat "I" microservicename "Repo"))
(setq again "Y")
(while (string= again "Y")
(generate-web-methods)
(setq again (upcase (read-string "add another method? Y/y to continue: ")))
)
(read-string "press enter to put repo methods into clipboard")
(getrepomethods)
(alttab-and-paste)
(read-string "press enter to put service methods into clipboard")
(getservicemethods)
(alttab-and-paste)
(read-string "press enter to put api methods into clipboard")
(getapimethods)
(alttab-and-paste)
)
(defun make-db-methods ()
(setq apimethods "")
(setq servicemethods "")
(setq repomethods "")
(setq servicename "")
(setq reponame "")
(setq microservicename "")
(setq microservicename (read-string "micro-service name(e.g. \"<Object Name>\" -> I<Object Name>Repo <Object Name>Service etc.): "))
(setq servicename (concat microservicename "Service"))
(setq reponame (concat "I" microservicename "Repo"))
(setq again "Y")
(while (string= again "Y")
(generate-db-methods)
(setq again (upcase (read-string "add another method? Y/y to continue: ")))
)
(read-string "press enter to put repo methods into clipboard")
(getrepomethods)
(alttab-and-paste)
(read-string "press enter to put service methods into clipboard")
(getservicemethods)
(alttab-and-paste)
(read-string "press enter to put api methods into clipboard")
(getapimethods)
(alttab-and-paste)
)
(defun generate-web-methods ()
(setq entry "")
(setq parametertype "")
(setq passdownparams "")
(setq parameters "")
(setq parameterswithtypes "")
(setq httpmethod (capitalize (read-string "http method: ")))
(setq path (read-string "path: "))
(if (not (string= path "")) (setq path (concat "(\"" path "\")")))
(setq return-type (read-string "return type: "))
(setq methodname (camelwp(read-string "method name(type lowercase with spaces): ")))
(setq another "Y")
(while (string= another "Y")
(setq parametername (read-string "parameter name?: "))
(setq entry (read-string "path, param, or body?: "))
(if (string= (upcase entry) "PATH") (setq parametertype (concat "@PathVariable(\"" parametername "\") ")) nil)
(if (string= (upcase entry) "PARAM") (setq parametertype (concat "@RequestParam(\"" parametername "\") ")) nil)
(if (string= (upcase entry) "BODY") (setq parametertype "@RequestBody") nil)
(setq passdownparams (concat passdownparams parametername))
(setq entry (read-string "parameter data type: "))
(setq entry (concat entry " " parametername))
(setq another (upcase (read-string "another? y/Y to continue: ")))
(if(string= another "Y") (setq entry (concat entry ", ")) nil)
(if(string= another "Y") (setq passdownparams (concat passdownparams ", ")) nil)
(setq parameters (concat parameters entry))
(setq parameterswithtypes (concat parameterswithtypes parametertype entry))
)
(setq parameters (concat "(" parameters ")"))
(setq passdownparams (concat "(" passdownparams ")"))
(setq parameterswithtypes (concat "(" parameterswithtypes ")"))
(setq apimethods (concat apimethods "\n\t@" httpmethod "Mapping" path "\n"
"\tpublic " return-type " " methodname parameterswithtypes "{\n\t\t" (downcase microservicename) "Service." methodname passdownparams ";\n\t}"))
(setq servicemethods (concat servicemethods "\n\tpublic " return-type " " methodname parameters "{\n\t\t"
(downcase microservicename) "Repo." methodname passdownparams ";\n\t}"))
(setq repomethods (concat repomethods "\n\t@" httpmethod "Mapping" path "\n"
"\tpublic " return-type " " methodname parameterswithtypes ";"))
)
(defun generate-db-methods ()
(setq entry "")
(setq parametertype "")
(setq parameters "")
(setq passdownparams "")
(setq parameterswithtypes "")
(setq httpmethod (capitalize (read-string "http method: ")))
(setq path (read-string "path: "))
(if (not (string= path "")) (setq path (concat "(\"" path "\")")))
(setq return-type (read-string "return type: "))
(setq repomethodname (camelwp(read-string "repo method name(type lowercase wtih spaces): ")))
(setq methodname (camelwp(read-string "non-repo method name(type lowercase with spaces): ")))
(setq another "Y")
(while (string= another "Y")
(setq parametername (read-string "parameter name?: "))
(setq entry (read-string "path, param, or body?: "))
(if (string= (upcase entry) "PATH") (setq parametertype (concat "@PathVariable(\"" parametername "\") ")) nil)
(if (string= (upcase entry) "PARAM") (setq parametertype (concat "@RequestParam(\"" parametername "\") ")) nil)
(if (string= (upcase entry) "BODY") (setq parametertype "@RequestBody") nil)
(setq entry (read-string "parameter data type: "))
(setq passdownparams (concat passdownparams parametername))
(setq entry (concat entry " " parametername))
(setq another (upcase (read-string "another? y/Y to continue: ")))
(if(string= another "Y") (setq entry (concat entry ", ")) nil)
(if(string= another "Y") (setq passdownparams (concat passdownparams ", ")) nil)
(setq parameters (concat parameters entry))
(setq parameterswithtypes (concat parameterswithtypes parametertype entry))
)
(setq parameters (concat "(" parameters ")"))
(setq passdownparams (concat "(" passdownparams ")"))
(setq parameterswithtypes (concat "(" parameterswithtypes ")"))
(setq apimethods (concat apimethods "\n\t@" httpmethod "Mapping" path "\n"
"\tpublic " return-type " " methodname parameterswithtypes "{\n\t\t" (downcase microservicename) "Service." methodname passdownparams ";\n\t}"))
(setq servicemethods (concat servicemethods "\n\tpublic " return-type " " methodname parameters "{\n\t\t"
(downcase microservicename) "Repo." methodname passdownparams ";\n\t}"))
(setq repomethods (concat repomethods "\n\t@" httpmethod "Mapping" path "\n"
"\tpublic " return-type " " repomethodname parameters ";"))
)
(defun getapimethods ()
(kill-new apimethods)
)
(defun getservicemethods ()
(kill-new servicemethods)
)
(defun getrepomethods ()
(kill-new repomethods)
)
(defun alttab ()
(w32-shell-execute "open"
"C:/Program Files/emacs/share/AHKMacros/emacsalttab.ahk")
)
(defun alttab-and-paste ()
(w32-shell-execute "open"
"C:/Program Files/emacs/share/AHKMacros/emacsalttabpaste.ahk")
)
(defun open-macros-folder ()
(w32-shell-execute "open"
"C:/Program Files/emacs/share/AHKMacros")
)
(defun elfunctions ()
(w32-shell-execute "open"
"C:/Program Files/emacs/share/emacs/25.3/site-lisp/elfunctions.lisp"
)
)
(defun get-all-model-versions ()
(setq filenamer "")
(setq filecontents "")
(setq artifacto "")
(setq artifactonum "")
(setq artifactnam nil)
(setq artifactos nil)
(w32-shell-execute "open"
"C:/Program Files/emacs/bin/versionscript.bat")
(sit-for 1)
(setq initialfiles (directory-files-recursively "C:/Program Files/emacs/bin/mavens" ""))
(setq copy-of-files (copy-alist initialfiles))
(while copy-of-files
(setf filenamer (pop copy-of-files))
(setq templist (split-string filenamer "/"))
(while (not (string-match "-models" (setf artifacto (concat (pop templist) ":")))))
(setq currentfilecontentsraw (with-temp-buffer (insert-file-contents filenamer) (buffer-string)))
(setq filelines (split-string currentfilecontentsraw "\n"))
(while (not (string-match "release"
(setf artifactonum (pop filelines)))))
(setf artifactonum (replace-regexp-in-string "[<>/\t\s]*release[<>/]*" "" artifactonum))
(setf artifactos (append artifactos (list (concat artifacto artifactonum))))
(setf artifactnam (append artifactnam (list artifacto)))
)
(setq artifactnames (copy-alist artifactnam))
(setq currentversions (copy-alist artifactos))
"Got all model versions"
)
(defun change-all-model-versions (filepath)
(get-all-model-versions)
(setq models (copy-alist currentversions))
(setq extension ".gradle")
(setq allgradles (directory-files-recursively filepath extension))
(setq gradlecopy (copy-alist allgradles))
(setq currentfilepath "")
(setq currentfiledata "")
(setq currentname "")
(setq currentmodel "")
(while gradlecopy
(setq names (copy-alist artifactnames))
(setq values (copy-alist currentversions))
(setf currentfilepath (pop gradlecopy))
(setf currentfiledata (with-temp-buffer
(insert-file-contents currentfilepath) (buffer-string)))
(while names
(setf currentname (pop names))
(setf currentmodel (pop values))
(setf currentfiledata (replace-regexp-in-string (concat currentname "[0-9]+\.[0-9]+") currentmodel currentfiledata)))
(write-region currentfiledata nil currentfilepath)
)
(makunbound 'models)
(makunbound 'extension)
(makunbound 'allgradles)
(makunbound 'gradlecopy)
(makunbound 'currentfilepath)
(makunbound 'currentfiledata)
(makunbound 'currentname)
(makunbound 'currentmodel)
(makunbound 'names)
(makunbound 'values)
)
(defun eval-string (string)
(eval (car (read-from-string (format "(progn %s)" string)))))
(defun iorl()
(cond
((string= (upcase (current-kill 0)) "I") (print "that is an eye"))
((string= (upcase (current-kill 0)) "L") (print "that is an ell"))
((print "that is neither an eye nor an ell"))))
(defun swagser ()
(setq service-name (read-string "service name: "))
(setq ymls (directory-files-recursively "C:/Users/<User>/Documents/Git/devconfig-local" "yml"))
(setq potentialpath "")
(setq top-path nil)
(setq theport "")
(while ymls
(setf potentialpath (pop ymls))
(cond (
(string-match-p service-name potentialpath)
(setf top-path potentialpath)
(setf ymls nil))))
(cond (top-path
(setq ymlfile (with-temp-buffer
(insert-file-contents top-path) (buffer-string)))
(string-match "server:[ \n\t]*port:[^0-9]*\\([0-9]+\\)" ymlfile)
(setf theport (match-string 1 ymlfile))
(print theport)
(w32-shell-execute "open"
(concat "http://localhost:" theport "/swagger-ui.html")))
("not found"))
)
(defun renamers ()
(setq paths (directory-files-recursively "C:/Users/<User>/Documents/Git" "\\Application.java"))
(setq shortenedpaths nil)
(while paths
(setq pathchecker (pop paths))
(if (string-match-p "/Application\.java" pathchecker) (setf shortenedpaths (append shortenedpaths (list pathchecker))))))
(defun killport(port)
(w32-shell-execute
"open" "powershell"
(concat "-Command Stop-Process (Get-NetTCPConnection -State Listen -LocalPort " (int-to-string port) ").OwningProcess"))
)
(defun docker-refresh ()
(w32-shell-execute "open" "powershell"
"-Command cd C:\\Users\\<User>\\Documents\ndocker-compose down\nY\nStop-Process -Name \"powershell\" -Force")
(sit-for 25)
(w32-shell-execute "open" "powershell"
"-Command cd C:\\Users\\<User>\\Documents\nrmdir .\\zk-single-kafka-multiple\\ -Recurse\ndocker-compose up\n"))
(defun duplicates (alist)
(setq bmem nil)
(setq clist nil)
(while alist
(setf bmem (pop alist))
(if (member bmem alist) (setf clist (append clist (list bmem)))))
clist
)
(defun sr ()
(w32-shell-execute "open" "http://localhost:8761"))
(defun compile-services (&optional stringlist)
(setq git-path "C:\\Program Files\\Git\\git-cmd.exe")
(setq options "\"cd C:\\Users\\<User>\\Documents\\Git&")
(setq temp "")
(setq top-name "")
(while stringlist
(setq services (directory-files "C:/Users/<User>/Documents/Git"))
(setq currentservice (pop stringlist))
(setq temp "quit")
(while services
(setq servicename (pop services))
(if (string-match-p currentservice servicename) (progn (setf top-name servicename) (setf services nil))))
(w32-shell-execute "open" git-path (concat options "cd " top-name "&gradlew clean bootjar&exit\"") 6))
(while (not (string= temp "quit"))
(setq services (directory-files "C:/Users/<User>/Documents/Git"))
(setq temp (read-string "service name (quit to end): "))
(cond
((string= temp "quit") nil)
((not (string= temp ""))
(while services
(setq servicename (pop services))
(if (string-match-p temp servicename) (progn (setf top-name servicename) (setf services nil))))
(w32-shell-execute "open" git-path (concat options "cd " top-name "&gradlew clean bootjar&exit\"") 6))))
)
(defun run-services (&rest stringlist)
(setq git-path "C:\\Program Files\\Git\\git-cmd.exe")
(setq options "\"cd C:\\Users\\<User>\\Documents\\Git&")
(setq temp "")
(setq top-name "")
(while stringlist
(setq services (directory-files "C:/Users/<User>/Documents/Git"))
(setq currentservice (pop stringlist))
(setq temp "quit")
(while services
(setq servicename (pop services))
(if (string-match-p currentservice servicename) (progn (setf top-name servicename) (setf services nil))))
(setq current-path (concat "C:/Users/<User>/Documents/Git/" top-name "/build/libs"))
(w32-shell-execute "open" git-path (concat options "cd " top-name "&gradlew clean bootjar&cd build/libs&TITLE " top-name
"&java -jar -Xmx512m " (car (directory-files current-path nil "\.jar")) "\"") 6))
(while (not (string= temp "quit"))
(setq services (directory-files "C:/Users/<User>/Documents/Git"))
(setq temp (read-string "service name (quit to end): "))
(cond
((string= temp "quit") nil)
((not (string= temp ""))
(while services
(setq servicename (pop services))
(if (string-match-p temp servicename) (progn (setf top-name servicename) (setf services nil))))
(setq current-path (concat "C:/Users/<User>/Documents/Git/" top-name "/build/libs"))
(w32-shell-execute "open" git-path (concat options "cd " top-name "&gradlew clean bootjar&cd build/libs&"
"java -jar -Xmx512m " (car (directory-files current-path nil "\.jar")) "\"") 6))))
)
(defun clear ()
(comint-clear-buffer) empty-char)
(defun bitbucket ()
(w32-shell-execute "open" "https://bitbucket.org/dashboard/overview"))
(defun taskman ()
(w32-shell-execute "open" "taskmgr.exe") empty-char)
(defun strip-secrets ()
(kill-new
(replace-regexp-in-string
"'\{cipher\}.*"
"\(cipher stripped via function\)"
(current-kill 0)
)
)
"Ciphers stripped"
)
(defun unbind-all ()
(setq filepathunbind "c:/Program Files/emacs/share/emacs/25.3/site-lisp/elfunctions.lisp")
(setq filedataunbind (with-temp-buffer (insert-file-contents filepathunbind) (buffer-string)))
(setq filelinesunbind (split-string filedataunbind "\n"))
(setq flagor '(thishelpsevaluateastrue))
(while flagor
(setq splitor (split-string (pop filelinesunbind) " "))
(while (string= (car splitor) "") (pop splitor))
(setq firstone (car splitor))
(setq secondone (cadr splitor))
(cond
(secondone
(if (string-match-p "unbind" secondone) (setf flagor nil))))
(cond
((and flagor firstone)
(if (string-match-p "setq" firstone) (eval-string (concat "(makunbound '" secondone ")"))))))
(reload)
(makunbound 'filepathunbind)
(makunbound 'filedataunbind)
(makunbound 'filelinesunbind)
(makunbound 'flagor)
(makunbound 'splitor)
(makunbound 'firstone)
(makunbound 'secondone)
"done"
)
| 21,472 | Common Lisp | .lisp | 593 | 33.573356 | 151 | 0.702242 | ZerglingOne/elisp-functions | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | 46a9ee0983aa768f2bd2f52ad3bdab00c89a2b2ba55ed51f380f04bdc8e3be93 | 39,508 | [
-1
] |
39,511 | emacsalttab.ahk | ZerglingOne_elisp-functions/AHKMacros/emacsalttab.ahk | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Event ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SendEvent {Alt Down}
SendEvent {Tab}
SendEvent {Alt Up} | 383 | Common Lisp | .l | 7 | 52.285714 | 89 | 0.798387 | ZerglingOne/elisp-functions | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | c96cd5728e6782b429e09864edd96f1e36d253d12738cd8fc1b6400e58cf4b19 | 39,511 | [
-1
] |
39,512 | emacsalttabpaste.ahk | ZerglingOne_elisp-functions/AHKMacros/emacsalttabpaste.ahk | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. /;
#Warn ; Enable warnings to assist with detecting common errors. /;
SendMode Event ; Recommended for new scripts due to its superior speed and reliability./;
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory./;
SendEvent {Alt Down}
SendEvent {Tab}
SendEvent {Alt Up}
Sleep, 250
SendEvent {Ctrl down}
SendEvent {v}
SendEvent {Ctrl Up} | 466 | Common Lisp | .l | 11 | 39.727273 | 92 | 0.776286 | ZerglingOne/elisp-functions | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:29 AM (Europe/Amsterdam) | 7d7d70872385d05cc414b0dca9e76b669d89ebfa326df4aaea1ae71cfb4209d1 | 39,512 | [
-1
] |
39,527 | audio-res.lisp | maurooaranda_spong/audio-res.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 this S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
;; An audio resource class to group some logic.
(defclass audio-fx ()
((fx :initarg :fx-name :initform (error "Must provide a fx name.")
:accessor fx-name)
(resource :initarg :resource :initform (error "Must provide a resource.")
:accessor resource)))
| 978 | Common Lisp | .lisp | 18 | 52.055556 | 76 | 0.743455 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 0f7365954d786c5a85257c482b3f17074202f1bc0f319964af4c7c9f1e33bef3 | 39,527 | [
-1
] |
39,528 | globals.lisp | maurooaranda_spong/globals.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
(defparameter *asset-dir*
(make-pathname :host (pathname-host #.(or *compile-file-truename*
*load-truename*))
:directory (pathname-directory #.(or *compile-file-truename*
*load-truename*)))
"Directory where we find assets for the game.")
;;; Settings.
(defparameter *window-width* 640 "Width of the game window.")
(defparameter *window-height* 480
"Height of the game window. Try a 4:3 or a 16:9 relation")
(defparameter *paddle-acceleration* 200
"The default paddle speed change, when moving vertically.
The paddle accelerates its velocity to either 200 (positive or negative),
or 0, effectively stoping.")
(defparameter *paddle-width* 8 "Width of the paddle.")
(defparameter *paddle-height* 20 "Height of the paddle.")
(defparameter *ball-length* 4 "Lenght of the ball, which is a square.")
(defparameter *ball-initial-x-speed* 200
"The initial x-velocity for the ball.")
(defparameter *ball-max-x-speed* 450
"Maximum x-velocity for the ball.
If set too high, can cause tunneling.")
(defparameter *score-objective* 10 "Goals to win S-Pong.")
;; Font definitions. The font `*ttf-spong-font*' is the default font,
;; and the rest are used within `sdl:with-font'.
(let ((f (merge-pathnames "font.ttf" *asset-dir*)))
(defparameter *ttf-spong-font* (make-instance 'sdl:ttf-font-definition
:size 16 :filename f))
(defparameter *ttf-score-font* (make-instance 'sdl:ttf-font-definition
:size 32 :filename f))
(defparameter *ttf-small-font* (make-instance 'sdl:ttf-font-definition
:size 8 :filename f)))
(defparameter *frame-rate* 60 "Set this frame rate for the game.")
;;; Variables used by S-Pong.
;; Like in Pong, S-Pong has two players: Left and Right.
;; Players control paddles and interact with the ball to score points.
(defvar *player-left* nil "The left player of S-Pong.")
(defvar *player-right* nil "The right player of S-Pong.")
(defvar *ball* nil "The S-Pong ball.")
(defvar *serving-player* nil
"The player that will serve the ball when the next point begins.")
(defvar *winner* nil "The player that has won the last S-Pong match.")
(defvar *game-objects* nil "All S-Pong objects.")
(defvar *players* nil "All players.")
(defvar *sounds* nil
"A plist with the sound effects to play.
Each keyword is the action, and the value is the sound effect corresponding
to the action.")
(defvar *modifiers* nil "Modifier sprites, that spice up the game.")
(defvar *current-modifier* nil "The modifier that currently can be obtained.")
(defparameter *mod-rate-appearence* nil
"Hits to count until a modifier appears.")
| 3,300 | Common Lisp | .lisp | 64 | 49.25 | 78 | 0.739144 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 6cbc5f8ccb9ea27d0b1bd8d19bbd39fabfbce82acbb7e6e79e95ef32ccd13d03 | 39,528 | [
-1
] |
39,529 | player.lisp | maurooaranda_spong/player.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
;;; The S-Pong Player class.
;; This is a player that controls an object (in S-Pong, a paddle), and that has
;; a score.
(defclass player ()
((score :initarg :score :initform 0 :accessor current-score)))
(defclass spong-player (player paddle)
((name :accessor player-name)
(hits :initform 0 :accessor hits)
(up-key :initarg :up-key :accessor up-key)
(down-key :initarg :down-key :accessor down-key)
(modifier :initarg :modifier :initform nil :accessor modifier)))
(defmethod initialize-instance :after ((player spong-player) &key position serve-op)
(setf (player-name player) (if (or (not position) (eq position :left))
"Left Player" "Right Player"))
(let ((x (if (or (not position) (eq position :left)) 10
(- *window-width* 10 *paddle-width*))))
(setf (pos-x player) x)
(setf (serve-op player) serve-op)))
(defmethod accelerate ((player spong-player) direction)
(call-next-method player
(or direction
(cond ((and (up-key player)
(sdl:key-held-p (up-key player)))
:up)
((and (down-key player)
(sdl:key-held-p (down-key player)))
:down)))))
(defmethod hit ((player spong-player))
(sdl-mixer:play-sample (getf *sounds* :paddle-hit))
(incf (hits player))
;; Shift the ball, so it doesn't bounce repeatedly with the paddle.
(setf (pos-x *ball*)
(funcall (serve-op player) (pos-x *ball*) (width player))))
(defmethod add-score ((player player))
(incf (current-score player)))
(defmethod score ((player spong-player))
(sdl-mixer:play-sample (getf *sounds* :score))
(add-score player)
(mapcar #'(lambda (p) (setf (hits p) 0)) *players*)
(setf *current-modifier* nil))
(defmethod reset ((player spong-player))
(reset-score player))
(defmethod reset-score ((player spong-player) &optional (new-score 0))
(setf (current-score player) new-score))
(defmethod won-p ((player player) objective)
(>= (current-score player) objective))
(defmethod draw-winner ((winner spong-player))
(sdl:draw-string-solid-* (format nil "~a wins!" (player-name winner))
(- (/ *window-width* 2) 75) 60))
(defgeneric after-opponent-hit (spong-player spong-ball))
(defmethod after-opponent-hit ((p spong-player) (ball spong-ball))
(declare (ignore p ball))
nil)
(defclass left-player (spong-player)
((up-key :initform :sdl-key-w)
(down-key :initform :sdl-key-s)))
(defmethod serve ((player left-player))
(values (+ *ball-initial-x-speed*) (random-sim 50)))
(defmethod hit :after ((player left-player))
(multiple-value-bind (dx dy)
(if (and (modifier player) (modifies-p (modifier player) :hit))
(modify (modifier player) :hit :player player)
(default-hit player))
(setf (vel-x *ball*) dx)
(setf (vel-y *ball*) dy)))
(defmethod score :after ((player left-player))
(setf *serving-player* *player-right*))
(defclass right-player (spong-player)
((up-key :initform :sdl-key-up)
(down-key :initform :sdl-key-down)))
(defmethod serve ((player right-player))
(values (- *ball-initial-x-speed*) (random-sim 50)))
(defmethod default-hit ((player left-player))
(values (- (max (- *ball-max-x-speed*) (* 1.03 (vel-x *ball*))))
(let ((new-dy (random-ab 10 150))
(topp (> (pos-y *ball*)
(+ (pos-y player) (/ (height player) 2)))))
(if (< (vel-y *ball*) 0)
(if topp new-dy (- new-dy))
(if topp new-dy (- new-dy))))))
(defmethod default-hit ((player right-player))
(values (- (min *ball-max-x-speed* (* 1.03 (vel-x *ball*))))
(let ((new-dy (random-ab 10 150))
(topp (> (pos-y *ball*)
(+ (pos-y player) (/ (height player) 2)))))
(if (< (vel-y *ball*) 0)
(if topp new-dy (- new-dy))
(if topp new-dy (- new-dy))))))
(defmethod hit :after ((player right-player))
(multiple-value-bind (dx dy)
(if (and (modifier player) (modifies-p (modifier player) :hit))
(modify (modifier player) :hit :player player)
(default-hit player))
(setf (vel-x *ball*) dx)
(setf (vel-y *ball*) dy)))
(defmethod score :after ((player right-player))
(setf *serving-player* *player-left*))
(defclass right-player-ai (right-player)
((im-ball :accessor imaginary-ball :initform nil)
(up-key :initform nil)
(down-key :initform nil)))
(defmethod after-opponent-hit ((ai right-player-ai) (ball spong-ball))
(setf (imaginary-ball ai)
(make-instance 'spong-ball
:x (pos-x ball) :y (pos-y ball) :side (width ball)
:dx (+ 5 (vel-x ball)) :dy (vel-y ball))))
(defmethod stop ((ai right-player-ai))
(setf (imaginary-ball ai) nil))
(defmethod hit ((ai right-player-ai))
(stop ai)
(call-next-method ai))
(defmethod accelerate ((ai right-player-ai) direction)
(declare (ignore direction))
(let ((im (imaginary-ball ai)))
(call-next-method ai
(when im
(update im (sdl:dt))
;; Handle imaginary ball collision with the wall.
(cond
((<= (pos-y im) 0)
(setf (pos-y im) 0)
(setf (vel-y im) (- (vel-y im))))
((>= (pos-y im) (- *window-height* (height im)))
(setf (pos-y im) (- *window-height* (height im)))
(setf (vel-y im) (- (vel-y im)))))
(cond ((> (pos-y im) (+ (pos-y ai) (/ (height ai) 2)))
:down)
((< (pos-y im) (+ (pos-y ai) (/ (height ai) 2)))
:up))))))
| 5,958 | Common Lisp | .lisp | 141 | 38.41844 | 84 | 0.655596 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 0ccfd50a804af26d4d969f30782cfb95f96b7c341d611f7ffd1170ac31652f56 | 39,529 | [
-1
] |
39,530 | random-x.lisp | maurooaranda_spong/random-x.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
;;; Misc functions.
(defun random-sim (n)
"Return a random number, between -N and N."
(- (random (1+ (* 2 n))) n))
(defun random-ab (a b)
"Return a random number between A and B. Expects A to be smaller than B."
(+ a (random (1+ (- b a)))))
(defun random-negate (n)
"Negate a number 50% of the time."
(or (and (eql (random 2) 1) n) (- n)))
| 1,058 | Common Lisp | .lisp | 22 | 46.227273 | 76 | 0.71137 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 731e53a678da40715c298c4938134f4c993b6fa15c80f9eba49917d1b79589d0 | 39,530 | [
-1
] |
39,531 | paddle.lisp | maurooaranda_spong/paddle.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
;;; The S-Pong Paddle class.
(defclass paddle (rectangle)
((y :initform (/ *window-height* 2))
(width :initform *paddle-width*) (height :initform *paddle-height*)
(acceleration :initarg :speed :initform *paddle-acceleration*
:accessor acceleration)
(vel-x :initarg :dx :initform 0 :accessor vel-x)
(vel-y :initarg :dy :initform 0 :accessor vel-y)
(color :initform sdl:*white*)
(serve-op :initarg :serve-op :accessor serve-op)))
(defmethod accelerate ((paddle paddle) direction)
(setf (vel-y paddle) (cond
((eq direction :up) (- (acceleration paddle)))
((eq direction :down) (acceleration paddle))
(t 0))))
(defmethod update ((paddle paddle) dt)
;; Adjust in case of paddle hitting the wall.
(setf (pos-y paddle) (round
(if (< (vel-y paddle) 0)
(max 0 (+ (pos-y paddle) (* (vel-y paddle) dt)))
(min (- *window-height* (height paddle))
(+ (pos-y paddle) (* (vel-y paddle) dt)))))))
| 1,648 | Common Lisp | .lisp | 34 | 45.411765 | 71 | 0.700685 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 9509c72002a1f478d1fa6af41555618426786681341685f3bf8c3cea1a4eb150 | 39,531 | [
-1
] |
39,532 | sprite.lisp | maurooaranda_spong/sprite.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
(defclass sprite (rectangle)
((filename :initarg :file :accessor filename)
(image :accessor image)
(x :accessor pos-x)
(y :accessor pos-y)
(width :accessor width)
(height :accessor height)))
(defmethod initialize-instance :after ((s sprite) &key)
(setf (image s) (sdl:load-image (merge-pathnames (filename s) *asset-dir*)))
(setf (width s) (sdl:width (image s)))
(setf (height s) (sdl:width (image s))))
(defmethod draw ((s sprite) &key x y)
(setf (pos-x s) x)
(setf (pos-y s) y)
(sdl:draw-surface-at-* (image s) x y))
| 1,253 | Common Lisp | .lisp | 27 | 44.074074 | 78 | 0.718622 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 6ecfcdd7df04daa43387b4e322d150241d82ce6518eef47fb5f6e12c9cdb13f8 | 39,532 | [
-1
] |
39,533 | rectangle.lisp | maurooaranda_spong/rectangle.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
(defclass rectangle (shape)
((width :accessor width :initarg :width)
(height :accessor height :initarg :height)
(color :initarg :color :accessor rect-color)))
(defmethod render ((rect rectangle))
(sdl:draw-box-* (pos-x rect) (pos-y rect) (width rect) (height rect)
:clipping nil :color (rect-color rect)))
(defclass square (rectangle)
((side :initarg :side)))
(defmethod initialize-instance :after ((square square) &key side)
(setf (width square) side)
(setf (height square) side))
| 1,208 | Common Lisp | .lisp | 24 | 48.166667 | 71 | 0.741497 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | cc38ab20f45a5c27ba4606192fe07322b6dbb8db139f435f346042456616632e | 39,533 | [
-1
] |
39,534 | powerup.lisp | maurooaranda_spong/powerup.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
(defclass powerup ()
((listeners :initarg :listeners :initform nil :accessor listeners)))
(defmethod modifies-p ((powerup powerup) event)
(assoc event (listeners powerup)))
(defmethod modify ((powerup powerup) event &rest args)
(funcall (cdr (assoc event (listeners powerup))) powerup args))
(defgeneric activate (powerup spong-player))
(defmethod activate ((powerup powerup) (player spong-player))
(when (modifier player)
(expire (modifier player) player)))
(defgeneric expire (powerup spong-player))
(defclass expirable-powerup (powerup)
((life :initarg :life :accessor life)))
(defmethod decrease-life ((powerup expirable-powerup) &optional (delta 1))
(decf (life powerup) delta))
(defmethod expire-check-p ((powerup expirable-powerup))
(<= (life powerup) 0))
(defmethod expire ((powerup expirable-powerup) (player spong-player))
(setf (modifier player) nil))
(defclass defensive-powerup (expirable-powerup)
((prev-height :initarg :prev-height :accessor prev-height)
(new-height :initarg :new-height :initform 30 :accessor new-height)))
(defmethod initialize-instance :after ((powerup defensive-powerup) &key)
(setf (listeners powerup)
(acons :hit
#'(lambda (powerup &rest player)
(decrease-life powerup)
(when (expire-check-p powerup)
(expire powerup (getf (car player) :player)))
(default-hit (getf (car player) :player)))
(listeners powerup))))
(defmethod activate :after ((powerup defensive-powerup) (player spong-player))
(setf (modifier player) powerup)
(setf (prev-height powerup) (height player))
(setf (height player) (new-height powerup)))
(defmethod expire :after ((powerup defensive-powerup) (player spong-player))
(setf (height player) (prev-height powerup)))
(defclass quick-powerup (expirable-powerup)
((prev-acc :initarg :prev-acc :accessor prev-acc)
(new-acc :initarg :new-acc :initform 240 :accessor new-acc)))
(defmethod initialize-instance :after ((powerup quick-powerup) &key)
(setf (listeners powerup)
(acons :hit
#'(lambda (powerup &rest player)
(decrease-life powerup)
(when (expire-check-p powerup)
(expire powerup (getf (car player) :player)))
(default-hit (getf (car player) :player)))
(listeners powerup))))
(defmethod activate :after ((powerup quick-powerup) (player spong-player))
(setf (modifier player) powerup)
(setf (prev-acc powerup) (acceleration player))
(setf (acceleration player) (new-acc powerup)))
(defmethod expire :after ((powerup quick-powerup) (player spong-player))
(setf (acceleration player) (prev-acc powerup)))
(defclass power-powerup (expirable-powerup)
nil)
(defmethod activate :after ((powerup power-powerup) (player spong-player))
(setf (modifier player) powerup))
(defmethod power-hit ((powerup power-powerup) (player left-player))
(values (- (max (- *ball-max-x-speed*) (* 1.5 (vel-x *ball*))))
(let ((new-vel (random-ab 10 150)))
(if (< (vel-y *ball*) 0) (- new-vel) new-vel))))
(defmethod power-hit ((powerup power-powerup) (player right-player))
(values (- (min *ball-max-x-speed* (* 1.5 (vel-x *ball*))))
(let ((new-vel (random-ab 10 150)))
(if (< (vel-y *ball*) 0) (- new-vel) new-vel))))
(defmethod initialize-instance :after ((powerup power-powerup) &key)
(setf (listeners powerup)
(acons :hit
#'(lambda (powerup &rest player)
(decrease-life powerup)
(when (expire-check-p powerup)
(expire powerup (getf (car player) :player)))
(power-hit powerup (getf (car player) :player)))
(listeners powerup))))
| 4,285 | Common Lisp | .lisp | 88 | 45.193182 | 78 | 0.714388 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 9cab2f9b509c1eaae64dff0d8b5ea58910b502cf9ce53700ecbc1b9d6afba245 | 39,534 | [
-1
] |
39,535 | shape.lisp | maurooaranda_spong/shape.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
(defclass shape ()
((x :accessor pos-x :initarg :x)
(y :accessor pos-y :initarg :y)))
| 794 | Common Lisp | .lisp | 15 | 51.266667 | 71 | 0.74677 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | c146940c808a57ba186475b52ac6a2675f0d98508621506044fc34bdf8348597 | 39,535 | [
-1
] |
39,536 | packages.lisp | maurooaranda_spong/packages.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package :cl-user)
(defpackage :com.the-blackbeard.spong
(:use common-lisp)
(:nicknames "spong")
(:export :spong))
| 787 | Common Lisp | .lisp | 16 | 47.5 | 71 | 0.753264 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 88d0dd6abf1bcfba07ed57442ea26a387eb5b0263766247ade211b1ccba1817c | 39,536 | [
-1
] |
39,537 | ball.lisp | maurooaranda_spong/ball.lisp | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(in-package #:com.the-blackbeard.spong)
;;; The S-Pong Ball class.
(defclass spong-ball (square)
((x :initform (- (/ *window-width* 2) *ball-length*))
(y :initform (- (/ *window-height* 2) *ball-length*))
(vel-x :initarg :dx :initform (random-negate *ball-initial-x-speed*)
:accessor vel-x)
(vel-y :initarg :dy :initform (random-sim 50) :accessor vel-y)
(color :initform sdl:*white*)))
(defmethod reset ((ball spong-ball))
(setf (pos-x ball) (/ *window-width* 2))
(setf (pos-y ball) (/ *window-height* 2))
(setf (vel-x ball) (random-negate *ball-initial-x-speed*))
(setf (vel-y ball) (random-sim 50)))
(defmethod update ((ball spong-ball) dt)
(setf (pos-x ball) (round (+ (pos-x ball) (* (vel-x ball) dt))))
(setf (pos-y ball) (round (+ (pos-y ball) (* (vel-y ball) dt)))))
(defgeneric collide-p (spong-ball obj)
(:documentation "Check collision between two objects."))
(defmethod collide-p ((ball spong-ball) (obj rectangle))
(let ((dt (sdl:dt)))
(cond
((and (not
(or (> (pos-x ball) (+ (pos-x obj) (width obj)))
(> (pos-x obj) (+ (pos-x ball) (width ball)))))
(not
(or (> (pos-y ball) (+ (pos-y obj) (height obj)))
(> (pos-y obj) (+ (pos-y ball) (height ball)))))))
((let ((next-x (+ (pos-x ball) (* (vel-x ball) dt)))
(next-y (+ (pos-y ball) (* (vel-y ball) dt))))
(and (not
(or (> next-x (+ (pos-x obj) (width obj)))
(> (pos-x obj) (+ next-x (width ball)))))
(not
(or (> next-y (+ (pos-y obj) (height obj)))
(> (pos-y obj) (+ next-y (height ball)))))))))))
| 2,241 | Common Lisp | .lisp | 47 | 44.085106 | 71 | 0.630664 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 980b29e710307c5606121350c4ab931a49d07c3ea041b8478f85989b2c45ed8c | 39,537 | [
-1
] |
39,538 | spong.asd | maurooaranda_spong/spong.asd | ;; Copyright (C) 2020 Mauro Aranda
;; S-Pong 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.
;; S-Pong 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 S-Pong. If not, see <http://www.gnu.org/licenses/>.
(defpackage :com.the-blackbeard.spong-system (:use :asdf :cl))
(in-package :com.the-blackbeard.spong-system)
(defsystem #:spong
:name "S-pong"
:author "Mauro Aranda <[email protected]"
:version "1.0"
:maintainer "Mauro Aranda <[email protected]"
:licence "GPLv3"
:description "A Pong implementation in Common Lisp"
:long-description ""
:depends-on (:lispbuilder-sdl :lispbuilder-sdl-mixer :lispbuilder-sdl-ttf)
:components ((:file "packages")
(:file "random-x" :depends-on ("packages"))
(:file "globals" :depends-on ("packages"))
(:file "shape" :depends-on ("packages"))
(:file "rectangle" :depends-on ("packages" "shape"))
(:file "audio-res" :depends-on ("packages"))
(:file "sprite" :depends-on ("packages"))
(:file "ball" :depends-on ("packages" "rectangle" "globals"
"random-x"))
(:file "paddle" :depends-on ("packages" "rectangle"))
(:file "player" :depends-on ("packages" "paddle" "globals"
"ball"))
(:file "powerup" :depends-on ("packages" "sprite" "player"))
(:file "spong" :depends-on ("packages" "rectangle" "audio-res"
"sprite" "powerup"))))
| 1,869 | Common Lisp | .asd | 37 | 45.513514 | 76 | 0.674699 | maurooaranda/spong | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:37 AM (Europe/Amsterdam) | 932bd636e171771792a5aa84f4d549f8334589366a7f6bfdecbda035b40f2c13 | 39,538 | [
-1
] |
39,565 | fibonacci.lisp | mets634_LispFun/src/fibonacci.lisp | (defpackage fibonacci
(:use :cl)
(:export :fibonacci-rec :fibonacci-closure :main))
(in-package :fibonacci)
(declaim (ftype (function (fixnum) fixnum) fibonacci-rec))
(defun fibonacci-rec (n)
"calculates fibonacci using recursion definition f(n) = f(n-1) + f(n-2)"
(if (< n 2)
n
(+ (fibonacci-rec (- n 2)) (fibonacci-rec (- n 1)))))
(defun make-fibonacci ()
(let ((curr 0) (next 1) temp)
(lambda ()
(setf temp next)
(setf next (+ curr next))
(setf curr temp))))
(declaim (ftype (function (fixnum) list) fibonacci-closure))
(defun fibonacci-closure (n)
(let ((fib-gen (make-fibonacci)))
(loop repeat n collect (funcall fib-gen))))
(declaim (ftype (function (fixnum) fixnum) fibonacci-loop))
(defun fibonacci-loop (n)
(do ((i 0 (1+ i))
(curr 0 next)
(next 1 (+ curr next)))
((< n i) curr)))
(defun main (argv)
(print (fibonacci-rec (parse-integer (read-line)))))
| 945 | Common Lisp | .lisp | 28 | 29.75 | 74 | 0.635061 | mets634/LispFun | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | c5d132eb69130e9649c4981b341ec63346df01131bf137131f57f5b312c4fe3d | 39,565 | [
-1
] |
39,566 | hello-world.lisp | mets634_LispFun/src/hello-world.lisp | (defpackage hello-world
(:use :cl)
(:export :print-hello-world))
(in-package :hello-world)
(defun print-hello-world ()
(format t "Hello World!"))
| 153 | Common Lisp | .lisp | 6 | 23.333333 | 31 | 0.69863 | mets634/LispFun | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 89ba0434c8ac6523a726111f3ac278ebf01cb1022daf0c17f561db9e86d25048 | 39,566 | [
-1
] |
39,567 | lisp-fun.asd | mets634_LispFun/lisp-fun.asd | (asdf:defsystem "lisp-fun"
:version "0.1.0"
:author "mets634"
:license "GNU General Public License v3.0"
:depends-on ()
:components ((:module "src"
:components
((:file "hello-world")
(:file "fibonacci"))))
:description "A project to play around with Common Lisp")
| 311 | Common Lisp | .asd | 10 | 25.4 | 59 | 0.61794 | mets634/LispFun | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 3830dadee679d7516e9ae2763e013c6148cfecf20cde1f8674d4d99262ae6f01 | 39,567 | [
-1
] |
39,585 | fact.lisp | NiramayVaidya_Basic_LISP_Codes/fact.lisp | (princ (funcall (lambda (n) (if (<= n 0) 1 (* n (lambda (- n 1))))) 4)
| 71 | Common Lisp | .lisp | 1 | 70 | 70 | 0.485714 | NiramayVaidya/Basic_LISP_Codes | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | eabb84e5b0c06f5d592f7866be97e454074196791d42c5bdbb0889cf8bc1bc7e | 39,585 | [
-1
] |
39,586 | factorial.lisp | NiramayVaidya_Basic_LISP_Codes/factorial.lisp | (princ (funcall ((lambda (f) (lambda (n) (funcall f f n))) (lambda (f n) (if (= n 0) 1 (* n (funcall f f (- n 1)))))) 4))
| 122 | Common Lisp | .lisp | 1 | 121 | 121 | 0.512397 | NiramayVaidya/Basic_LISP_Codes | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | aa8e5301e76137cfcae7ff9d780ebf092f37c1ed71356e1445476062e25acd3b | 39,586 | [
-1
] |
39,587 | 7elem.cl | NiramayVaidya_Basic_LISP_Codes/7elem.cl | (defun elem7 (list) "returns 7th element of the list if present, else returns not present message" (if (>= (length list) 7) (princ (nth 6 list)) (princ "7th element not present")))
(princ #\newline)
(elem7 '(1 2 3 4 5 6))
(princ #\newline)
| 240 | Common Lisp | .cl | 4 | 59 | 180 | 0.690678 | NiramayVaidya/Basic_LISP_Codes | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | cffc353b9318db5184347b28b70a1013347b5759204a2be3ef8e6c453cad9309 | 39,587 | [
-1
] |
39,588 | basic_1.cl | NiramayVaidya_Basic_LISP_Codes/basic_1.cl | (princ (fboundp 'quadratic))
(princ #\newline)
(defun quadratic (a b c x) "Returns the value of the quadratic polynomial a*x^2+b*x+c at x" (+ (* a x x) (* b x) c))
(princ (fboundp 'quadratic))
(princ #\newline)
(princ (function quadratic))
(princ #\newline)
(princ (describe 'quadratic))
(princ #\newline)
(princ (type-of 'quadratic))
(symbol-plist 'quadratic)
(princ #\newline)
(princ (quadratic 2 4 2 3))
(princ #\newline)
(defun factorial (n) "Returns the factorial of n" (if (<= n 0) 1 (* n (factorial (- n 1)))))
(princ (factorial 3))
(princ #\newline)
(defun fibonacci (n) "Returns the nth fibonacci number" (if (<= n 2) 1 (+ (fibonacci (- n 1)) (fibonacci (- n 2)))))
(princ (fibonacci 5))
(princ #\newline)
| 715 | Common Lisp | .cl | 20 | 34.75 | 116 | 0.670504 | NiramayVaidya/Basic_LISP_Codes | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | b2276183af53833a17067a10534e5fe42622dfffee41efb5f650921bae6fcb58 | 39,588 | [
-1
] |
39,589 | basic.cl | NiramayVaidya_Basic_LISP_Codes/basic.cl | (princ "Hello World")
(princ #\newline)
(princ (and nil 2))
(princ #\newline)
(princ (and 1 2))
(princ #\newline)
;the next uncommented statement below is equivalent to the above statement
;;another type of comment, more importance
;;;and another though even more important
#| block
comment |#
(princ (if 1 2 nil))
(princ #\newline)
(princ (and))
(princ #\newline)
(princ (or nil 2))
(princ #\newline)
(princ (if nil 2 2))
(princ #\newline)
(princ (if 1 1 2))
(princ #\newline)
(princ (if nil 1 2))
(princ #\newline)
(princ (+ 1 2 3 4 5))
(princ #\newline)
;;if the division ans comes out to be an integer with both arguments as integers,
;;then the ans is printed, else if it comes out to be a float with both arguments
;;as integers, then the ratio form gets printed
;;if one of the arguments is float then in all cases ans is printed in float
(princ (/ 33 2))
(princ #\tab)
(princ (/ 32 2))
(princ #\tab)
(princ (/ pi 2))
(princ #\newline)
(princ (* 33 2))
(princ #\newline)
(princ (float (/ 33 2)))
(princ #\newline)
(princ (max 1 2 3 4 5))
(princ #\newline)
(princ (cos (/ pi 4)))
(princ #\newline)
(princ (gcd 2142 3066))
(princ #\newline)
(princ (= (* 3 14) 42.0 (/ 714 17)))
(princ #\newline)
(princ (< 1/2 2/3 3/4))
(princ #\newline)
(princ (and (integerp 42) (rationalp 42) (rationalp 1/42) (realp 42) (realp 1/42) (realp 42.0)))
(print #\tab)
(print #\newline)
| 1,373 | Common Lisp | .cl | 52 | 25.384615 | 96 | 0.684848 | NiramayVaidya/Basic_LISP_Codes | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | f00dc3828e2e3d164b86b32e876103492534d7a4551896a0da70b5d24680e553 | 39,589 | [
-1
] |
39,590 | list.cl | NiramayVaidya_Basic_LISP_Codes/list.cl | (princ (car (cdr (cdr '(7 (* 5 4) (+ 3 1) (/ 4 1) 65)))))
(princ #\newline)
(princ (cdr '(7 (* 5 4) (+ 3 1) (/ 4 1) 65)))
(princ #\newline)
(princ (cdr (cdr '(7 (* 5 4) (+ 3 1) (/ 4 1) 65))))
(princ #\newline)
(princ (cdar '((a b) c d e)))
(princ #\newline)
(princ (cadr '((a b) c d e)))
| 288 | Common Lisp | .cl | 9 | 31 | 57 | 0.487455 | NiramayVaidya/Basic_LISP_Codes | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | e4eee2a207183b38c0ece61feacfe7a1511ad17a7566ddf2e3c59fb1118fb1f6 | 39,590 | [
-1
] |
39,591 | basic_2.cl | NiramayVaidya_Basic_LISP_Codes/basic_2.cl | (princ (characterp #\a))
(princ #\newline)
(princ (alpha-char-p #\a))
(princ #\newline)
(princ (char-upcase #\a))
(princ #\newline)
(princ (char-code #\a))
(princ #\newline)
(princ (code-char 98))
(princ #\newline)
(princ (char= #\a #\b))
(princ #\newline)
(princ (char< #\a #\b))
(princ #\newline)
(defun nextchar (c) "returns the next character from c" (code-char (+ (char-code c) 1)))
(princ (nextchar #\a))
(princ #\newline)
| 431 | Common Lisp | .cl | 17 | 24.235294 | 88 | 0.652913 | NiramayVaidya/Basic_LISP_Codes | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 87442bc21e63473e480122f90f757904d1beb4b95ab1eb509d7169981f352a14 | 39,591 | [
-1
] |
39,614 | util.lisp | borodust_decent-game/src/util.lisp | (cl:in-package :decent-game)
(declaim (special *world*))
(defparameter *debug-rendering* nil)
(defclass state-input-handler (gk.input:input-handler) ())
(defvar +zero-pos+ (gk:vec2 0 0))
(defvar *observation-repeat* 0)
(defun now () (bodge-util:real-time-seconds))
(defun get-player () (player-of (world-of (current-game-state))))
(defun current-game-state () (gk.fsm:current-state))
(defmethod gk:post-initialize :around ((this state-input-handler))
(gk.input:activate-input-handler this)
(call-next-method))
(defmethod gk:pre-destroy :around ((this state-input-handler))
(call-next-method)
(gk.input:deactivate-input-handler this))
(defgeneric dispose (object)
(:method (object) (declare (ignore object))))
(defgeneric observe (object)
(:method (object) (declare (ignore object))))
(defgeneric render (object &key &allow-other-keys)
(:method (object &key) (declare (ignore object))))
(defmethod render :around (object &key)
(gk:with-pushed-canvas ()
(call-next-method)))
(defun shout (control &rest args)
(format t "~&~A" (apply #'format nil control args))
(finish-output t))
(defun draw-multiline-text (text position &key font line-height (fill-color +black+))
(let ((total-height 0)
(line-height (- (or line-height 0))))
(gk:with-pushed-canvas ()
(bodge-util:dolines (line text)
(gk:draw-text line position :font font :fill-color fill-color)
(gk:translate-canvas 0 line-height)
(incf total-height line-height)))
total-height))
(defmacro when-initial-observation (&body body)
`(when (zerop *observation-repeat*)
,@body))
(defun draw-loading-bar (percentage pos &key
(light-color +color-alien-light+)
(dark-color +color-alien-dark+)
(bar-width 128)
(bar-height 16))
(let ((ratio (/ percentage 100))
(backdrop-scale-factor (/ bar-width 100))
(bar-scale-factor (if (zerop percentage) 0 (/ bar-width percentage))))
(gk:draw-rect pos
(* 100 backdrop-scale-factor)
bar-height
:fill-paint dark-color)
(gk:draw-rect pos
(* (* percentage bar-scale-factor) ratio)
bar-height
:fill-paint light-color)))
| 2,408 | Common Lisp | .lisp | 55 | 35.290909 | 85 | 0.621016 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | b322e8d4a3e7ad85afb9e41941d97316fa671c3504530cf749edb4eab944ac52 | 39,614 | [
-1
] |
39,615 | event.lisp | borodust_decent-game/src/event.lisp | (cl:in-package :decent-game)
(defvar *event-table* (make-hash-table))
(defun subscribe-to-event (event-id action)
(pushnew action (gethash event-id *event-table*)))
(defun unsubscribe-from-event (event-id action)
(a:deletef (gethash event-id *event-table*) action))
(defun trigger-event (event-id &rest args &key &allow-other-keys)
(loop for action in (gethash event-id *event-table*)
do (etypecase action
(symbol (apply (symbol-function action) event-id :allow-other-keys t args))
(function (apply action event-id :allow-other-keys t args)))))
| 593 | Common Lisp | .lisp | 11 | 48.545455 | 88 | 0.703833 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 8ef66e08d77b24d99afe648a451bd3e280e849ecefc86ed4e319d9d53224c65e | 39,615 | [
-1
] |
39,616 | resources.lisp | borodust_decent-game/src/resources.lisp | (cl:in-package :decent-game)
(defun asset-path (pathname)
(asdf:system-relative-pathname :decent-game (merge-pathnames pathname "assets/")))
(defvar *pack-table* (make-hash-table))
(defvar *resource-table* (make-hash-table))
(defun register-resource (name)
(setf (gethash name *resource-table*) t))
(defun remove-resource (name)
(remhash name *resource-table*))
(defun resource-loaded-p (name)
(gethash name *resource-table*))
(defclass resource-pack ()
((prepared :initform nil)
(count :initform 0)
(total :initform 0)))
(defgeneric resource-pack-resources (pack)
(:method-combination append))
(defun filter-resource-pack-resources (pack)
(remove-duplicates (resource-pack-resources pack)))
(defun pack-resource-prepared-p (pack resource)
(with-slots (prepared) pack
(member resource prepared)))
(defun notice-pack-resource (pack resource)
(with-slots (prepared count) pack
(let ((resources (filter-resource-pack-resources pack)))
(when (and (member resource resources)
(not (member resource prepared)))
(push resource prepared)
(incf count)))))
(defmethod initialize-instance :after ((this resource-pack) &key)
(with-slots (prepared total count) this
(let ((resources (filter-resource-pack-resources this)))
(setf total (length resources))
(loop for resource in resources
do (let ((packs (push this (gethash resource *pack-table*))))
(unless (second packs)
(gk:prepare-resources resource)))
(when (resource-loaded-p resource)
(notice-pack-resource this resource))))))
(defun load-resource-pack (name)
(if (null name)
(format t "~&Can't load resource-pack with class-name of ~A.~% IGNORED" name)
(make-instance name)))
(defun pack-prepared-p (pack)
(with-slots (count total) pack
(= count total)))
(defun pack-total-count (pack)
(with-slots (total) pack
total))
(defun pack-prepared-count (pack)
(with-slots (count) pack
count))
(defun dispose-resource-pack (pack)
(let ((resources (filter-resource-pack-resources pack)))
(loop for name in resources
unless (a:deletef (gethash name *pack-table*) pack)
do (remove-resource name)
(gk:dispose-resources name)
(remhash name *pack-table*))))
(defun notice-pack-resources (&rest names)
(loop for name in names
do (register-resource name)
(loop for pack in (gethash name *pack-table*)
do (notice-pack-resource pack name))))
(defun dispose-pack-resources ()
(apply #'gk:dispose-resources
(loop for resource being the hash-key of *pack-table*
collect resource))
(clrhash *pack-table*)
(clrhash *resource-table*))
(defmacro define-resource-pack (name (&rest parent-classes) &body resources)
(a:with-gensyms (this resource-list)
`(progn
(defclass ,name (,@(if parent-classes
parent-classes
(list 'resource-pack)))
())
(let ((,resource-list (a:flatten (list ,@resources))))
(defmethod resource-pack-resources append ((,this ,name))
(declare (ignore ,this))
,resource-list)))))
| 3,299 | Common Lisp | .lisp | 81 | 33.765432 | 84 | 0.654934 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 95d21dc719475a08a48d04168c6ec80c863309b19b922c82ab65aef2a132d115 | 39,616 | [
-1
] |
39,617 | hud.lisp | borodust_decent-game/src/hud.lisp | (cl:in-package :decent-game)
;;; player life bar
(gk:define-image player-life-bar-left (asset-path "img/hud/player-life-bar/player-life-bar-left.png")
:use-nearest-interpolation t)
(gk:define-image player-life-bar-middle (asset-path "img/hud/player-life-bar/player-life-bar-middle.png")
:use-nearest-interpolation t)
(gk:define-image player-life-bar-right (asset-path "img/hud/player-life-bar/player-life-bar-right.png")
:use-nearest-interpolation t)
(define-animation player-life-bar-cell (asset-path "img/hud/player-life-bar/player-life-bar-cell.png") :frames 2)
;;; boss life bar
(gk:define-image boss-life-bar-left (asset-path "img/hud/boss-life-bar/boss-life-bar-left.png")
:use-nearest-interpolation t)
(gk:define-image boss-life-bar-middle (asset-path "img/hud/boss-life-bar/boss-life-bar-middle.png")
:use-nearest-interpolation t)
(gk:define-image boss-life-bar-right (asset-path "img/hud/boss-life-bar/boss-life-bar-right.png")
:use-nearest-interpolation t)
(define-animation boss-life-bar-cell (asset-path "img/hud/boss-life-bar/boss-life-bar-cell.png") :frames 2)
(define-resource-pack boss-life-bar-resources ()
'boss-life-bar-left
'boss-life-bar-middle
'boss-life-bar-right
'boss-life-bar-cell)
(define-resource-pack player-life-bar-resources ()
'player-life-bar-left
'player-life-bar-middle
'player-life-bar-right
'player-life-bar-cell)
(defun draw-player-life-bar (player position)
(with-accessors ((hp hp) (hp-max hp-max)) player
(gk:with-pushed-canvas ()
(gk:translate-canvas (gk:x position) (gk:y position))
(gk:draw-image +zero-pos+ 'player-life-bar-left )
(draw-in-row 'player-life-bar-middle hp-max 4 (gk:vec2 13 0))
(gk:draw-image (gk:vec2 (+ (* hp-max 4) 13) 0) 'player-life-bar-right)
(draw-in-row 'player-life-bar-cell hp 4 (gk:vec2 12 3) :animationp t))))
(defun draw-boss-life-bar (boss position)
(when (null boss)
(return-from draw-boss-life-bar nil))
(with-accessors ((hp hp) (hp-max hp-max)) boss
(gk:with-pushed-canvas ()
(gk:translate-canvas (gk:x position) (gk:y position))
(gk:draw-image +zero-pos+ 'boss-life-bar-left )
(draw-in-row 'boss-life-bar-middle hp-max 8 (gk:vec2 8 0))
(gk:draw-image (gk:vec2 (+ (* hp-max 8) 8) 0) 'boss-life-bar-right)
(draw-in-row 'boss-life-bar-cell hp 8 (gk:vec2 8 -6) :animationp t))))
(defun draw-in-row (to-draw x x-offset pos &key (animationp nil))
(let ((xpos (gk:x pos))
(ypos (gk:y pos)))
(dotimes (i x)
(if animationp
(draw-animation to-draw (now) (gk:vec2 (+ xpos (* i x-offset)) ypos))
(gk:draw-image (gk:vec2 (+ xpos (* i x-offset)) ypos) to-draw)))))
| 2,687 | Common Lisp | .lisp | 52 | 47.634615 | 113 | 0.694624 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 810dcd8d0a6cf206c69e3f861159040e87526194896926e3ccf8edfe10003f66 | 39,617 | [
-1
] |
39,618 | color.lisp | borodust_decent-game/src/color.lisp | (in-package :decent-game)
(defun randcolor ()
"Returns a random color as a gamekit:vec4."
(gk:vec4 (/ (random 100) 100)
(/ (random 100) 100)
(/ (random 100) 100)
1))
(defun alphacolor (alpha color)
"Returns a gamekit:vec4 color with an alpha value of alpha,
without modifying the original argument."
(gk:vec4 (gk:x color) (gk:y color) (gk:z color) alpha))
(defun hexcolor (hexcode &optional (a 1))
"Takes a string which represents a hexadecimal color. (e.g. #ffffff for white)
and returns the appropriate gamekit:vec4, which corresponds to that color.
You can also pass an optional opacity value as a second argument"
(let* ((color-string (subseq hexcode 1))
(r (float (/ (parse-integer (subseq color-string 0 2) :radix 16) 255)))
(g (float (/ (parse-integer (subseq color-string 2 4) :radix 16) 255)))
(b (float (/ (parse-integer (subseq color-string 4 6) :radix 16) 255))))
(gk:vec4 r g b a)))
(defvar +black+ (gk:vec4 0 0 0 1))
(defvar +color-alien-light+ (hexcolor "#F4004C"))
(defvar +color-alien-dark+ (hexcolor "#CB0035"))
| 1,112 | Common Lisp | .lisp | 23 | 43.782609 | 81 | 0.669437 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 945856febac1a5d0cbb3fcf769a28809daa89d9cc5420e69a6f34f790cc2b906 | 39,618 | [
-1
] |
39,619 | text.lisp | borodust_decent-game/src/text.lisp | ; Load Screen - text menu (main-load-screen)
; Text Info Screen On Game Start describing game premise. (info-on-start)
; ESC screen - text menu (main-esc-menu)
; Death screen - text menu (death-screen)
; Boss Fight (boss-battle)
; Final Outcome Text Summary (final-outcome)
; End Credits (end-credits)
; Template is at *
; https://gitlab.com/borodust/decent-game/-/blob/master/brainstorming/text-template.lisp
;; First cut-scene giving premise
(cl:in-package :decent-game)
(defdialogue (:info-on-start
(:type :cutscene)
;; in order of complexity - pick one
;; hero lying down,hero dying, hero lying with burning city behind
(:image :info-on-start))
"The sounds of battle fade. You are dying. Why is something you just can't remeber. Aliens, humanoids with machine parts, or was it the other way around?")
;; Second screen for early game premise info
(defdialogue (:info-on-start-1
(:type :cutscene)
;; graphic - in order of complexity - pick one
;; cyborg weapon or device to left, alien weapon or bio-container
(:image :info-on-start-1)
(:choices
(:pick-cyborg :test #'picked-cyborg-p ) "Pick the Cyborg gear"
(:pick-alien :test #'picked-alien-p ) "Pick the Alien tech"
(:human :test #'human-p) "Go without unknown enhancements"))
"Perhaps there's some life in You left.
Close-by, a cybernetic gear pack and an alien container.
Pick one or go without?")
;; On player death
(defdialogue (:death-screen
(:type :cutscene)
;; graphic - pick one
;; player dead , player dead custom, player dead with background, or maybe game paused with death info as OSD and menu?
(:image :death-screen)
(:choices
;; TODO is this how we do the death screen menu?
(:last-checkpoint ) "Load last checkpoint"
(:restart) "New game / Restart"))
"You died.")
(defdialogue (:final-outcome
(:type :cutscene)
;; graphics -TODO discuss. at least 2 for happy ending and bad ending? generic gameplay screenshot?
(:image :final-outcome)
(:choices
(:pick-alien :test #'picked-alien-p ) "Using out-of control biotech, You have lost Your humanity for victory."
(:pick-cyborg :test #'picked-cyborg-p) "By fusing Yourself with machines, You have lost Your humanity for victory"
(:human :test #'human-p) "Through the battles, You managed to keep Your humanity. Will you give others this chance?")))
;;Boss taunts
(defdialogue (:first-enemy-kill ;; TODO cheapest event for boss taunts? Random through game?
(:type :osd)
(:image :boss-image-id))
"Not You! Again! Let me know when you get tired of dying... Again.")
;; TODO - should osd / taounts be done at all? How would they be implemented / hooks events? On every enemy kill?
| 3,040 | Common Lisp | .lisp | 55 | 46.072727 | 157 | 0.636577 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | cb1559e69d9865629029e916d6a1f81e027c8693c3baeb1420f61ae655b63dcc | 39,619 | [
-1
] |
39,620 | timer-util.lisp | borodust_decent-game/src/timer-util.lisp | (in-package #:decent-game)
(defvar *timers* nil)
;;;; Timers
;;;;----------------------------------------------------------------------------
(defun now ()
(/ (get-internal-real-time) internal-time-units-per-second))
(defun timer-time (timer) (car timer))
(defun timer-handler (timer) (cdr timer))
(defun insert-timer (timer timers)
"Inserts `timer' into the `timers' list, while making sure `timers' stays sorted.
Doesn't modify the original `timers' list."
(if (endp timers)
(list timer)
(if (> (timer-time (first timers))
(timer-time timer))
(cons timer timers)
(cons (first timers)
(insert-timer timer (rest timers))))))
(defun add-timer (target handler)
(setf *timers* (insert-timer (cons target handler) *timers*)))
(defun process-timers ()
;; this does not take advantage of *timers* being sorted. For robustness. :D
(let ((expired (find-if (lambda (timer)
(>= (now)
(car timer)))
*timers*)))
(when expired
(funcall (cdr expired))
(setf *timers* (delete expired *timers*))
(process-timers))))
| 1,193 | Common Lisp | .lisp | 30 | 32.366667 | 83 | 0.55816 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 73776ba5bab4f62f3f433fc3f26f9f33971183faeb9b2903a9521ff01b2fe58c | 39,620 | [
-1
] |
39,621 | physics.lisp | borodust_decent-game/src/physics.lisp | (cl:in-package :decent-game)
(defparameter *universe-scale* 10)
(defparameter *body-fill-color* (gk:vec4 1 0 0 0.5))
(defparameter *body-stroke-color* (gk:vec4 1 0 0 0.8))
(defvar +zero-rot+ (b:mat2 1 0
0 1))
;;;
;;; UNIVERSE
;;;
(defgeneric collide (this that)
(:method (this that)
(declare (ignore this that))
t))
(defgeneric process-collision (this that)
(:method (this that) (declare (ignore this that))))
(defclass universe (b:disposable)
((universe :initform nil :reader %universe-of)))
(defmethod initialize-instance :after ((this universe) &key gravity)
(with-slots (universe) this
(flet ((%collide (this that)
(collide (b.phy:shape-substance this) (b.phy:shape-substance that)))
(%process-collision (this that)
(process-collision (b.phy:shape-substance this) (b.phy:shape-substance that))))
(setf universe (b.phy:make-universe :2d
:on-pre-solve #'%collide
:on-post-solve #'%process-collision)
(b.phy:gravity universe) (b:div gravity *universe-scale*)))))
(b:define-destructor universe (universe)
(b:dispose universe))
(defmethod dispose :after ((this universe))
(b:dispose this))
(defun make-universe (gravity)
(make-instance 'universe :gravity gravity))
(defun observe-universe (universe step &optional (repeats 1))
(with-slots (universe) universe
(loop repeat repeats
for i from 0
do (let ((*observation-repeat* i))
(b.phy:observe-universe universe step)))))
;;;
;;; SHAPE
;;;
(defclass shape (b:disposable)
((handle :initarg :handle :reader handle-of)
(offset :initarg :offset)))
(b:define-destructor shape (handle)
(b:dispose handle))
(defmethod dispose :after ((this shape))
(b:dispose this))
(defclass box-shape (shape)
((width :initarg :width)
(height :initarg :height)
(radius :initarg :radius)))
(defun make-box-shape (universe body width height substance offset radius)
(let* ((w (/ width *universe-scale*))
(h (/ height *universe-scale*))
(radius (or radius 0))
(offset (or offset +zero-pos+))
(handle (b.phy:make-box-shape universe
w h
:body body
:substance substance
:radius (/ (or radius) *universe-scale*)
:offset (b:add
(b:div offset *universe-scale*)
(b:vec2 (/ w 2) (/ h 2))))))
(make-instance 'box-shape
:handle handle
:width width
:height height
:offset offset
:radius radius)))
(defmethod render ((this box-shape) &key position rotation color)
(with-slots (offset width height radius) this
(let ((pos (or position +zero-pos+))
(rot (or rotation 0)))
(gk:translate-canvas (+ (gk:x offset) (gk:x pos))
(+ (gk:y offset) (gk:y pos)))
(gk:rotate-canvas rot)
(gk:draw-rect +zero-pos+ width height
:fill-paint (or color *body-fill-color*)
:rounding radius))))
(defclass circle-shape (shape)
((radius :initarg :radius)))
(defun make-circle-shape (universe body radius substance offset)
(let* ((r (/ radius *universe-scale*))
(offset (or offset +zero-pos+))
(handle (b.phy:make-circle-shape universe r
:offset (b:div offset *universe-scale*)
:body body
:substance substance)))
(make-instance 'circle-shape
:handle handle
:radius radius
:offset offset)))
(defmethod render ((this circle-shape) &key position color)
(with-slots (offset radius) this
(let ((pos (or position +zero-pos+)))
(gk:translate-canvas (+ (gk:x offset) (gk:x pos))
(+ (gk:y offset) (gk:y pos)))
(gk:draw-circle +zero-pos+ radius
:fill-paint (or color *body-fill-color*)))))
;;;
;;; BODY
;;;
(defclass body (b:disposable)
((universe :initarg :universe)
(body :initform nil)
(shapes :initform (list nil))))
(defgeneric provide-body (object universe &key &allow-other-keys))
(defgeneric provide-shape (object body universe &key &allow-other-keys))
(defun body-position (body)
(with-slots (body) body
(b:mult (b.phy:body-position body) *universe-scale*)))
(defun body-rotation (body)
(with-slots (body) body
(b.phy:body-rotation body)))
(defun (setf body-rotation) (value body)
(with-slots (body) body
(setf (b.phy:body-rotation body) (if (zerop value)
+zero-rot+
(b:euler-angle->mat2 value)))))
(defun (setf body-position) (value body)
(with-slots (body) body
(setf (b.phy:body-position body) (b:div value *universe-scale*))))
(defun body-linear-velocity (body)
(with-slots (body) body
(b:mult (b.phy:body-linear-velocity body) *universe-scale*)))
(defun (setf body-linear-velocity) (value body)
(with-slots (body) body
(setf (b.phy:body-linear-velocity body) (b:div value *universe-scale*))))
(defun body-angular-velocity (body)
(with-slots (body) body
(b:mult (b.phy:body-linear-velocity body) *universe-scale*)))
(defun (setf body-angular-velocity) (value body)
(with-slots (body) body
(setf (b.phy:body-angular-velocity body) (/ value *universe-scale*))))
(defun apply-force (body force)
(with-slots (body) body
(b.phy:apply-force body (b:div force *universe-scale*))))
(defun apply-torque (body force)
(with-slots (body) body
(b.phy:apply-torque body (/ force *universe-scale*))))
(defun (setf collision-surface-velocity) (value)
(setf (b.phy:collision-surface-velocity) (b:div value *universe-scale*)))
(defun (setf collision-friction) (value)
(setf (b.phy:collision-friction) (/ value *universe-scale*)))
(defun attach-box-shape (body width height &key offset sensor radius)
(with-slots ((this-body body) shapes universe) body
(let ((shape (make-box-shape universe this-body
width height
sensor
offset
radius)))
(push shape (cdr shapes))
shape)))
(defun attach-circle-shape (body radius &key offset sensor)
(with-slots ((this-body body) shapes universe) body
(let ((shape (make-circle-shape universe this-body radius sensor offset)))
(push shape (cdr shapes))
shape)))
(defun detach-shape (body shape)
(with-slots (shapes) body
(a:deletef (cdr shapes) shape)
(dispose shape)))
(defmethod provide-body ((this body) universe &key kinematic)
(if kinematic
(b.phy:make-kinematic-body universe)
(b.phy:make-rigid-body universe)))
(defmethod initialize-instance :after ((this body) &rest args &key universe)
(unless universe
(error ":universe missing"))
(with-slots (body shapes) this
(setf body (apply #'provide-body this universe args))
(push (apply #'provide-shape this body universe args) (cdr shapes))))
(b:define-destructor body (body shapes)
(loop for shape in (rest shapes)
do (dispose shape))
(b:dispose body))
(defmethod dispose :after ((this body))
(b:dispose this))
(defmethod render ((this body) &key color)
(with-slots (shapes) this
(when *debug-rendering*
(let ((pos (body-position this))
(rot (b:mat2->euler-angle (body-rotation this))))
(loop for shape in (rest shapes)
do (render shape :position pos :rotation rot :color color))))))
;;;
;;; BOX
;;;
(defclass box-body (body) ())
(defmethod provide-shape ((this box-body) body universe &key width height substance mass offset radius)
(let ((shape (make-box-shape universe
body
width height
substance
offset
radius)))
(when mass
(b.phy:infuse-box-mass body mass (/ width *universe-scale*) (/ height *universe-scale*)))
shape))
(defun make-box-body (universe width height &key kinematic owner mass)
(make-instance 'box-body :universe (%universe-of universe)
:width width
:height height
:substance owner
:mass mass
:kinematic kinematic
:allow-other-keys t))
;;;
;;; CIRCLE
;;;
(defclass circle-body (body) ())
(defmethod provide-shape ((this circle-body) body universe &key radius substance mass offset)
(let* ((r (/ radius *universe-scale*))
(shape (make-circle-shape universe body radius (or substance this) offset)))
(when mass
(b.phy:infuse-circle-mass body mass r))
shape))
(defun make-circle-body (universe radius &key owner mass offset)
(make-instance 'circle-body :universe (%universe-of universe)
:radius radius
:substance owner
:mass mass
:offset offset
:allow-other-keys t))
| 9,621 | Common Lisp | .lisp | 227 | 32.211454 | 103 | 0.584238 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 13c420fc3875aba6b200fe21ced19f55d390b42d96e5799435a7e167f69a59d6 | 39,621 | [
-1
] |
39,622 | animation.lisp | borodust_decent-game/src/animation.lisp | (cl:in-package :decent-game)
(defparameter *animation-fps* 6)
(defparameter *animation-sprite-origin* (gk:vec2 0 0))
(defun draw-animation-sprite (image time position frame-count mirror-x mirror-y)
(let ((sprite-width (/ (gk:image-width image) frame-count))
(current-frame (mod (truncate (* time *animation-fps*)) frame-count)))
(setf (gk:x *animation-sprite-origin*) (* current-frame sprite-width))
(bodge-canvas:antialias-shapes nil)
(gk:draw-image position image :origin *animation-sprite-origin*
:width sprite-width
:mirror-x mirror-x
:mirror-y mirror-y)))
(defgeneric draw-animation (name time position &key mirror-x mirror-y))
(defmacro define-animation (name path &key frames)
(unless frames
(error ":frames must be specified"))
`(progn
(gk:define-image ,name ,path :use-nearest-interpolation t)
(defmethod draw-animation ((id (eql ',name)) time position &key mirror-x mirror-y)
(draw-animation-sprite id time position ,frames mirror-x mirror-y))))
| 1,113 | Common Lisp | .lisp | 20 | 46.8 | 87 | 0.658065 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 77f021c5378f26de9c45001ab41044c4b8bbda39cee66f4e3f86742897e0a902 | 39,622 | [
-1
] |
39,623 | packages.lisp | borodust_decent-game/src/packages.lisp | (cl:defpackage :decent-game
(:use :cl)
(:local-nicknames (#:a #:alexandria)
(#:gk #:trivial-gamekit)
(#:gk.fsm #:trivial-gamekit.fistmachine)
(#:gk.input #:trivial-gamekit.input-handler)
(#:b #:cl-bodge.engine)
(#:b.phy #:cl-bodge.physics))
(:export #:play))
| 365 | Common Lisp | .lisp | 9 | 27.777778 | 64 | 0.485955 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 7df2b2cc607a3167355b69aff38f40f36cae5a44f8fabcd16cd58a2ae795d778 | 39,623 | [
-1
] |
39,624 | bullet.lisp | borodust_decent-game/src/objects/bullet.lisp | (cl:in-package :decent-game)
(defparameter *bullet-ttl* 2)
(defgeneric ttl-of (this))
(defclass bullet ()
((body :initform nil)
(spawn-time :initform (bodge-util:real-time-seconds))
(velocity :initarg :velocity :accessor velocity-of)))
(defmethod ttl-of ((this bullet))
*bullet-ttl*)
(defmethod initialize-instance :after ((this bullet) &key world position velocity)
(with-slots (body) this
(setf body (make-circle-body (universe-of world) 4 :owner this :mass 0.1)
(body-position body) position)))
(defmethod dispose :after ((this bullet))
(with-slots (body) this
(dispose body)))
(defun bullet-destroyed-p (bullet)
(with-slots (spawn-time) bullet
(> (- (bodge-util:real-time-seconds) spawn-time) (ttl-of bullet))))
(defun destroy-bullet (bullet)
(with-slots (spawn-time) bullet
(setf spawn-time 0)))
(defmethod collide :around ((this bullet) anything)
(unless (bullet-destroyed-p this)
(call-next-method))
nil)
(defmethod collide :around (anything (this bullet))
(unless (bullet-destroyed-p this)
(call-next-method))
nil)
(defmethod collide :after ((this bullet) (that obstacle))
(declare (ignore that))
(destroy-bullet this))
(defmethod collide :after ((that obstacle) (this bullet))
(declare (ignore that))
(destroy-bullet this))
(defmethod observe ((this bullet))
(with-slots (body velocity) this
(setf (body-linear-velocity body) velocity)))
(defgeneric render-bullet (object)
(:method (object) (declare (ignore object))))
(defmethod render ((this bullet) &key)
(with-slots (body) this
(gk:with-pushed-canvas ()
(unless (bullet-destroyed-p this)
(let ((pos (body-position body)))
(gk:translate-canvas (- (gk:x pos) 10) (- (gk:y pos) 4)))
(render-bullet this)))
(when *debug-rendering*
(render body))))
(defun make-bullet (bullet-class world position velocity)
(make-instance bullet-class :world world
:position position
:velocity velocity))
(defclass enemy-bullet (bullet) ())
(defclass player-bullet (bullet) ())
| 2,139 | Common Lisp | .lisp | 56 | 33.267857 | 82 | 0.681308 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 56d2abbf654f7926d98875266977349f69a3da0e1ef589591e7cc08d460cccfc | 39,624 | [
-1
] |
39,625 | stats.lisp | borodust_decent-game/src/objects/stats.lisp | (cl:in-package :decent-game)
(defclass stats ()
((hp :accessor hp)
(hp-max :initarg :hp-max
:accessor hp-max)
(strength :initarg :strength
:accessor strength)
(attack-speed :initarg :attack-speed
:accessor attack-speed)
(movement-speed :initarg :movement-speed
:accessor movement-speed
:documentation "Movement speed in pixels per second."))
(:default-initargs
:hp-max 10
:strength 1
:attack-speed 24
:movement-speed 50)
(:documentation "This class holds all of the characters stats."))
(defmethod initialize-instance :after ((this stats) &key)
(setf (hp this) (hp-max this)))
| 690 | Common Lisp | .lisp | 20 | 27.85 | 74 | 0.646707 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 024b2eb4fe53a5ad6222344df4724740fb05cd7bf4f542410c8f9cd6f0c6909e | 39,625 | [
-1
] |
39,626 | player.lisp | borodust_decent-game/src/objects/player.lisp | (cl:in-package :decent-game)
(defparameter *player-movement-speed* 48)
(defparameter *player-jump-strength* 10000)
(define-animation player-idle-right (asset-path "img/player/player-idle-right.png") :frames 2)
(define-animation player-idle-left (asset-path "img/player/player-idle-left.png") :frames 2)
(define-animation player-run-right (asset-path "img/player/player-run-right.png") :frames 4)
(define-animation player-run-left (asset-path "img/player/player-run-left.png") :frames 4)
(define-animation player-slash-right (asset-path "img/player/player-slash-right.png") :frames 2)
(define-animation player-slash-left (asset-path "img/player/player-slash-left.png") :frames 2)
(define-animation player-shoot-right (asset-path "img/player/player-shoot-right.png") :frames 2)
(define-animation player-shoot-left (asset-path "img/player/player-shoot-left.png") :frames 2)
(define-animation player-hurt-right (asset-path "img/player/player-hurt-right.png") :frames 1)
(define-animation player-hurt-left (asset-path "img/player/player-hurt-left.png") :frames 1)
(define-animation player-jump-right (asset-path "img/player/player-jump-right.png") :frames 2)
(define-animation player-jump-left (asset-path "img/player/player-jump-left.png") :frames 2)
(define-animation player-jumping-right (asset-path "img/player/player-jumping-right.png") :frames 1)
(define-animation player-jumping-left (asset-path "img/player/player-jumping-left.png") :frames 1)
(define-animation player-falling-right (asset-path "img/player/player-falling-right.png") :frames 1)
(define-animation player-falling-left (asset-path "img/player/player-falling-left.png") :frames 1)
(define-animation player-dying-right (asset-path "img/player/player-dying-right.png") :frames 3)
(define-animation player-dying-left (asset-path "img/player/player-dying-left.png") :frames 3)
(define-animation player-projectile-0-right (asset-path "img/player/player-projectile-0-right.png") :frames 2)
(define-animation player-projectile-0-left (asset-path "img/player/player-projectile-0-left.png") :frames 2)
(gk:define-sound blaster-shot (asset-path "snd/sfx/select_001.ogg"))
(define-resource-pack player-resources (player-life-bar-resources)
'player-idle-right
'player-idle-left
'player-run-right
'player-run-left
'player-slash-right
'player-slash-left
'player-shoot-right
'player-shoot-left
'player-hurt-right
'player-hurt-left
'player-jump-right
'player-jump-left
'player-jumping-right
'player-jumping-left
'player-falling-right
'player-falling-left
'player-dying-right
'player-dying-left
'player-projectile-0-right
'player-projectile-0-left
'blaster-shot)
(defclass player (ground-fighter)
())
(defmethod provide-fighter-body ((this player) &key world position)
(let ((body (make-circle-body (universe-of world)
5
:owner this
:mass 1)))
(setf (body-position body) (or position (gk:vec2 50 20)))
(attach-box-shape body 18 28 :sensor (make-instance 'player-hitbox :owner this)
:radius 5 :offset (gk:vec2 -9 -3))
body))
(defun make-player (world &key position)
(make-instance 'player :world world
:position position))
(defun stop-player (player)
(setf (states player) (list)))
(defun jump-player (player)
(unless (null player)
(unless (or (jumping-p player) (falling-p player))
(with-slots (states body direction) player
(cond ((idle-p player)
(apply-force body (gk:vec2 0 *player-jump-strength*)))
(t (let ((reverse-thrust (gk:vec2 0 1) ;;(gk:vec2 (* -.3713907 direction) 0.92847675)
)) ;; -0.3713907 0.92847675
(apply-force body (gk:mult reverse-thrust *player-jump-strength*)))))))))
(defmethod collide :after ((this sensor) (that player))
(trigger-sensor-event this))
(defmethod render ((this player) &key)
(with-slots (states body) this
(with-slots (body-angular-velocity
body-linear-velocity
body-position)
body
(let ((position (body-position body)))
(gk:translate-canvas (- (gk:x position) 16)
(- (gk:y position) 5)))
(let ((time (bodge-util:real-time-seconds)))
(cond ((facing-right-p this)
(cond
((shooting-p this)
(draw-animation 'player-shoot-right time +zero-pos+))
((jumping-p this)
(draw-animation 'player-jumping-right time +zero-pos+))
((falling-p this)
(draw-animation 'player-falling-right time +zero-pos+))
((running-p this)
(draw-animation 'player-run-right time +zero-pos+))
(t (draw-animation 'player-idle-right time +zero-pos+))))
((facing-left-p this)
(cond
((shooting-p this)
(draw-animation 'player-shoot-left time +zero-pos+))
((jumping-p this)
(draw-animation 'player-jumping-left time +zero-pos+))
((falling-p this)
(draw-animation 'player-falling-left time +zero-pos+))
((running-p this)
(draw-animation 'player-run-left time +zero-pos+))
(t (draw-animation 'player-idle-left time +zero-pos+))))
(t (error "Player should only be able to either face left or right.")))))))
(defmethod speed-of ((this player))
*player-movement-speed*)
(defmethod render-bullet ((this player-bullet))
(if (plusp (gk:x (velocity-of this)))
(gk:draw-image +zero-pos+ 'player-projectile-0-right)
(gk:draw-image +zero-pos+ 'player-projectile-0-left)))
(defmethod shoot ((this player))
(with-slots (last-direction) this
(with-world (world)
(unless (zerop last-direction)
(let ((sign (/ last-direction (abs last-direction)))
(pos (body-position (body-of this))))
(spawn-bullet 'player-bullet world
(gk:add pos (gk:vec2 0 10))
(gk:vec2 (* sign 500) 0))
(gk:play-sound 'blaster-shot))))))
(defun register-player-damage (player)
(with-slots (body) player
(unless (untouchable-p player)
(apply-force body (gk:mult (gk:normalize (gk:vec2 -1 0.3)) 1000))
(damage-for 1 player)
(when (dead-p player)
(add-timer (+ (now) .495) ; because animation is .5 seconds long (3 frames)
(lambda () (trigger-event :player-death))))
(make-untouchable-for 1 player))))
(defmethod collide :after ((this player-hitbox) (that enemy-bullet))
(when-initial-observation
(register-player-damage (owner-of this))
(destroy-bullet that)))
(defmethod collide :after ((that enemy-bullet) (this player-hitbox))
(when-initial-observation
(register-player-damage (owner-of this))
(destroy-bullet that)))
(defmethod collide :after ((this player-hitbox) (that enemy-hitbox))
(when-initial-observation
(register-player-damage (owner-of this))))
(defmethod collide :after ((that enemy-hitbox) (this player-hitbox))
(when-initial-observation
(register-player-damage (owner-of this))))
| 7,312 | Common Lisp | .lisp | 145 | 42.462069 | 110 | 0.655356 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 8c8c9f353d2242a4f064aaf27c579dd2badbcf7e1bcbae2be449b13129d47017 | 39,626 | [
-1
] |
39,627 | level.lisp | borodust_decent-game/src/objects/level.lisp | (cl:in-package :decent-game)
(defparameter *sensor-color* (gk:vec4 0 0 0.8 0.5))
(declaim (special *level-width*
*level-height*
*image*
*tile-width*
*tile-height*
*tile-map*
*image-map*
*level-universe*))
(defgeneric level-image-map (level))
(defgeneric level-resources (level))
(defmacro define-level (name path &body images)
(a:with-gensyms (image-map-var level-resources)
(let (image-defines image-map image-resources)
(loop for image-decl in images
do (destructuring-bind (image-name image-path image-id)
image-decl
(push image-name image-resources)
(push `(gk:define-image ,image-name ,image-path
:use-nearest-interpolation t)
image-defines)
(push `(,image-id ',image-name) image-map)))
`(progn
(gk:define-text ,name ,path)
,@image-defines
(let ((,image-map-var (a:plist-hash-table
(list ,@(reduce #'append image-map))
:test 'equal)))
(defmethod level-image-map ((this (eql ',name)))
(declare (ignore this))
,image-map-var))
(let ((,level-resources '(,name ,@image-resources)))
(defmethod level-resources ((this (eql ',name)))
,level-resources))))))
;;;
;;; TILE
;;;
(defclass tile ()
((image :initarg :image)
(origin :initarg :origin)
(width :initarg :width)
(height :initarg :height)))
(defmethod render ((this tile) &key)
(with-slots (image origin width height) this
(gk:draw-image +zero-pos+ image :origin origin
:width width
:height height)))
(defun find-tile (gid)
(gethash gid *tile-map*))
;;;
;;; CONTROL
;;;
(defclass control () ())
(defmethod collide :around ((this control) (that control))
nil)
;;;
;;; SENSOR
;;;
(defclass sensor (control)
((body :initform nil)
(fired :initform nil)
(options :initarg :options)
(event :initarg :event)
(width :initarg :width)
(height :initarg :height)))
(defmethod initialize-instance :after ((this sensor) &key position width height)
(with-slots (body) this
(setf body (make-box-body *level-universe* width height :kinematic t :owner this)
(body-position body) position)))
(defun trigger-sensor-event (sensor)
(with-slots (fired event options) sensor
(unless fired
(setf fired t)
(apply #'trigger-event event options))))
(defmethod collide :around ((this sensor) that)
(call-next-method)
nil)
(defmethod collide :around (that (this sensor))
(collide this that))
(defmethod dispose :after ((this sensor))
(with-slots (body) this
(dispose body)))
(defmethod render ((this sensor) &key)
(with-slots (body width height) this
(render body :color *sensor-color*)))
;;;
;;; OBSTACLE
;;;
(defclass obstacle (control)
((body :initform nil)))
(defmethod dispose :after ((this obstacle))
(with-slots (body) this
(dispose body)))
(defmethod render ((this obstacle) &key)
(with-slots (body) this
(render body)))
(defmethod collide ((this obstacle) (that obstacle))
nil)
(defclass platform (obstacle)
((position :initarg :position)))
(defclass rectangle-platform (platform)
((width :initarg :width)
(height :initarg :height)))
(defmethod initialize-instance :after ((this rectangle-platform) &key)
(with-slots (body width height position) this
(setf body (make-box-body *level-universe* width height :kinematic t :owner this)
(body-position body) position)))
(defclass polygon-platform (platform)
((point-offsets :initarg :offsets)))
;;;
;;; CONTROL-PLANE
;;;
(defgeneric player-spawn-position-of (object))
(defgeneric find-enemy-spawn (object name))
(defclass control-plane ()
((player-spawn :initarg :player-spawn :reader player-spawn-position-of)
(enemy-spawn-table :initarg :enemy-spawn-table)
(platforms :initarg :platforms)
(sensors :initarg :sensors)))
(defmethod dispose :after ((this control-plane))
(with-slots (platforms sensors) this
(loop for platform in platforms
do (dispose platform))
(loop for object in sensors
do (dispose object))))
(defmethod render ((this control-plane) &key)
(with-slots (platforms sensors) this
(loop for platform in platforms
do (render platform))
(loop for sensor in sensors
do (render sensor))))
(defmethod find-enemy-spawn ((this control-plane) name)
(with-slots (enemy-spawn-table) this
(gethash name enemy-spawn-table)))
;;;
;;; SCENERY
;;;
(defclass scenery ()
((type :initarg :kind :reader kind-of)
(grid :initarg :grid)))
(defmethod render ((this scenery) &key)
(with-slots (grid) this
(loop for x from 0 below (array-dimension grid 0)
do (loop for y from 0 below (array-dimension grid 1)
do (a:when-let ((tile (find-tile (aref grid x y))))
(gk:with-pushed-canvas ()
(gk:translate-canvas (* x *tile-width*) (* y *tile-height*))
(render tile)))))))
;;;
;;; LEVEL
;;;
(defclass level ()
((sceneries :initform nil)
(tile-map :initform (make-hash-table :test #'equal))
(tile-width :initarg :tile-width)
(tile-height :initarg :tile-height)
(control-plane :initform nil)))
(defmethod dispose :after ((this level))
(with-slots (control-plane) this
(dispose control-plane)))
(defmethod player-spawn-position-of ((this level))
(with-slots (control-plane) this
(player-spawn-position-of control-plane)))
(defmethod initialize-instance :after ((this level) &key layers tiles)
(with-slots (sceneries tile-map control-plane) this
(flet ((%copy-to-map (key value)
(setf (gethash key tile-map) value)))
(loop for map in tiles
do (maphash #'%copy-to-map map)))
(loop for layer in layers
when (typep layer 'control-plane)
do (setf control-plane layer)
when (typep layer 'scenery)
do (push layer sceneries))
(a:nreversef sceneries)))
(defmethod render ((this level) &key kind)
(with-slots (sceneries tile-map tile-width tile-height control-plane) this
(let ((*tile-map* tile-map)
(*tile-width* tile-width)
(*tile-height* tile-height))
(loop for scenery in sceneries
when (or (not kind) (eq (kind-of scenery) kind))
do (render scenery))
(when (eq kind :control-plane)
(render control-plane)))))
(defmethod find-enemy-spawn ((this level) name)
(with-slots (control-plane) this
(find-enemy-spawn control-plane name)))
;;;
;;; PARSING
;;;
(defun invert-absolute-y (y &optional height)
(- (* *level-height* *tile-height*) y (or height 0)))
(defun parse-level-properties (props)
(a:alist-hash-table props :test 'equal))
(defun get-level-property (props key)
(first (gethash key props)))
(defun level-properties->plist (props)
(loop for key being the hash-key of props using (hash-value value)
append (list (a:make-keyword (uiop:standard-case-symbol-name key))
(if (rest value)
value
(first value)))))
(defun parse-platform (&key kind position width height points &allow-other-keys)
(let ((position (destructuring-bind (x y) position
(gk:vec2 x (invert-absolute-y y height))))
(offsets (loop for point in points
collect (apply #'gk:vec2 point))))
(ecase kind
(:square (make-instance 'rectangle-platform :position position
:width width
:height height))
(:polygon (make-instance 'polygon-platform :position position
:point-offsets offsets)))))
(defun parse-sensor (&key kind position width height properties &allow-other-keys)
(let ((position (destructuring-bind (x y) position
(gk:vec2 x (invert-absolute-y y height))))
(props (parse-level-properties properties)))
(ecase kind
(:square (make-instance 'sensor :position position
:width width
:height height
:event (a:make-keyword
(uiop:standard-case-symbol-name
(get-level-property props "event")))
:options (level-properties->plist props))))))
(defun parse-control-plane (&key objects &allow-other-keys)
(let ((enemy-spawn-table (make-hash-table :test 'equal))
player-spawn platforms sensors)
(loop for object in objects
do (destructuring-bind (&rest args &key position properties
&allow-other-keys)
object
(let* ((props (parse-level-properties properties))
(type (get-level-property props "kind"))
(position (gk:vec2 (first position)
(invert-absolute-y (second position)))))
(a:switch (type :test #'equal)
("player-spawn" (setf player-spawn position))
("enemy-spawn" (setf
(gethash (get-level-property props "enemy") enemy-spawn-table)
position))
("platform" (push (apply #'parse-platform args) platforms))
("sensor" (push (apply #'parse-sensor args) sensors))))))
(make-instance 'control-plane :player-spawn player-spawn
:enemy-spawn-table enemy-spawn-table
:platforms platforms
:sensors sensors)))
(defun parse-scenery (&key properties gids &allow-other-keys)
(let ((props (parse-level-properties properties)))
(make-instance 'scenery
:kind (a:switch ((get-level-property props "kind") :test #'equal)
("foreground" :foreground)
("background" :background))
:grid (loop with grid = (make-array (list *level-width* *level-height*))
for i from 0
for gid in gids
for y = (- *level-height* 1 (if (= i 0) 0 (truncate (/ i *level-width*))))
for x = (mod i *level-width*)
do (setf (aref grid x y) gid)
finally (return grid)))))
(defun parse-layer (&rest args &key name type &allow-other-keys)
(cond
((eq type :layer)
(apply #'parse-scenery args))
((and (eq type :objgr)
(equal "control" name))
(apply #'parse-control-plane args))))
(defun parse-tile (&key image position &allow-other-keys)
(destructuring-bind (&key source height &allow-other-keys) (or image *image*)
(a:if-let ((image-resource (gethash source *image-map*)))
(destructuring-bind (x y) position
(make-instance 'tile :image image-resource
:origin (gk:vec2 x (- height y *tile-height*))
:width *tile-width*
:height *tile-height*))
(error "Mapping for ~A tile image is not found" source))))
(defun parse-tileset (&key image tiles tile-width tile-height &allow-other-keys)
(let ((*tile-width* tile-width)
(*tile-height* tile-height)
(*image* image))
(loop with tile-map = (make-hash-table :test 'equal)
for (gid tile) in tiles
do (setf (gethash gid tile-map) (apply #'parse-tile tile))
finally (return tile-map))))
(defun parse-level (&key layers tilesets width height tile-width tile-height &allow-other-keys)
(let ((*level-width* width)
(*level-height* height)
(*tile-width* tile-width)
(*tile-height* tile-height))
(make-instance 'level :layers (loop for layer in layers
for parsed = (apply #'parse-layer layer)
when parsed
collect parsed)
:tiles (loop for tileset in tilesets
collect (apply #'parse-tileset tileset))
:tile-width tile-width
:tile-height tile-height)))
(defun make-level (name universe)
(let ((*image-map* (level-image-map name))
(*level-universe* universe))
(with-input-from-string (in (gk:get-text name))
(apply #'parse-level (uiop:with-safe-io-syntax () (read in))))))
| 13,082 | Common Lisp | .lisp | 304 | 32.414474 | 105 | 0.578582 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 963741c4f4446ceda4eec2397b0245e955a4aaf7b258874a84e291e02b36a28f | 39,627 | [
-1
] |
39,628 | menu.lisp | borodust_decent-game/src/objects/menu.lisp | (cl:in-package :decent-game)
(gk:define-font bold-pixel-operator (asset-path "fnt/pixel-operator/PixelOperatorMono8-Bold.ttf"))
(gk:define-font pixel-operator (asset-path "fnt/pixel-operator/PixelOperatorMono8.ttf"))
(define-resource-pack font-resources ()
'pixel-operator
'bold-pixel-operator)
(defparameter *menu-item-selector-pos* (gk:vec2 -20 0))
(defclass menu ()
((items :initform nil)
(selected :initform nil)
(text-font :initform (gk:make-font 'pixel-operator 8))
(selector-font :initform (gk:make-font 'bold-pixel-operator 8))))
(defmethod initialize-instance :after ((this menu) &key items)
(with-slots (selected (this-items items)) this
(unless items
(error ":items should not be nil"))
(let* ((item-alist (a:plist-alist items))
(len (length item-alist)))
(setf this-items (make-array len :initial-contents item-alist)
selected 0))))
(defun make-menu (items)
(make-instance 'menu :items items))
(defun select-next-menu-item (menu)
(with-slots (selected items) menu
(setf selected (mod (1+ selected) (length items)))))
(defun select-prev-menu-item (menu)
(with-slots (selected items) menu
(setf selected (mod (1- selected) (length items)))))
(defun invoke-menu-item-action (menu)
(with-slots (selected items) menu
(funcall (cdr (aref items selected)))))
(defmethod render ((this menu) &key (fill-color +color-alien-dark+))
(with-slots (selected items text-font selector-font) this
(loop for (name . action) across items
for i from 0
do (gk:translate-canvas 0 -20)
(when (= selected i)
(gk:draw-text ">>" *menu-item-selector-pos* :font selector-font :fill-color fill-color))
(gk:draw-text name +zero-pos+ :font text-font :fill-color fill-color))))
| 1,824 | Common Lisp | .lisp | 39 | 41.487179 | 103 | 0.686686 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 23456bf05706cc40738f8c003b7a93217a2eec946cdccbe2265e878c86873939 | 39,628 | [
-1
] |
39,629 | world.lisp | borodust_decent-game/src/objects/world.lisp | (cl:in-package :decent-game)
(defparameter *observation-step* 0.01)
(defparameter *observation-repeats* 4)
(defgeneric world-of (state))
(defclass world ()
((universe :initform nil :reader universe-of)
(level :initform nil :reader level-of)
(player :initform nil :reader player-of)
(enemies :initform nil :accessor enemies-of)
(bullets :initform nil)))
(defmethod initialize-instance :after ((this world) &key level-name)
(with-slots (universe level player) this
(setf universe (make-universe (gk:vec2 0 -100))
level (make-level level-name universe)
player (make-player this :position (player-spawn-position-of level)))))
(defun make-world (level-name)
(make-instance 'world :level-name level-name))
(defmethod dispose :after ((this world))
(with-slots (universe level player enemies bullets) this
(dispose player)
(loop for enemy in enemies
do (dispose enemy))
(loop for bullet in bullets
do (dispose bullet))
(dispose level)
(dispose universe)))
(defun observe-world (world)
(with-slots (universe player enemies bullets) world
(let ((*world* world))
(observe-universe universe *observation-step* *observation-repeats*)
(observe player)
(loop for enemy in enemies
do (if (dead-p enemy)
(progn
(a:deletef enemies enemy)
(dispose enemy))
(observe enemy)))
(loop for bullet in bullets
do (if (bullet-destroyed-p bullet)
(progn
(a:deletef bullets bullet)
(dispose bullet))
(observe bullet))))))
(defmethod render ((this world) &key)
(with-slots (level player enemies bullets) this
(render level :kind :background)
(with-slots (body) player
(gk:translate-canvas (truncate (+ (- (gk:x (body-position body))) 100)) 0))
(render level :kind :foreground)
(when *debug-rendering*
(render level :kind :control-plane))
(loop for enemy in enemies
do (render enemy))
(loop for bullet in bullets
do (render bullet))
(render player)))
(defun spawn-enemy (world type spawn-name &key offset)
(with-slots (level enemies) world
(a:if-let ((pos (find-enemy-spawn (level-of world) spawn-name)))
(push (make-enemy type world :position (gk:add pos (or offset +zero-pos+))) enemies)
(warn "Failed to find enemy spawn ~A" spawn-name))))
(defun spawn-bullet (bullet-class world position velocity)
(with-slots (bullets) world
(push (make-bullet bullet-class world position velocity) bullets))
(values))
(defmacro with-world ((world) &body body)
`(let ((,world (world-of (gk.fsm:current-state))))
,@body))
(defmethod boss-exists-p ((this world))
(find-if (lambda (x) (eq (type-of x) 'boss)) (enemies-of this)))
(defmethod get-boss-of ((this world))
(find-if (lambda (x) (eq (type-of x) 'boss)) (enemies-of this)))
| 3,007 | Common Lisp | .lisp | 72 | 34.902778 | 90 | 0.649485 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 8bbce8ec528828eeba5723e237617c4142f36a024133ae4144b7caf8b8676cf1 | 39,629 | [
-1
] |
39,630 | fighter.lisp | borodust_decent-game/src/objects/fighter.lisp | (cl:in-package :decent-game)
(defgeneric position-of (object))
(defgeneric velocity-of (object))
(defgeneric speed-of (object)
(:method (object)
(declare (ignore object))
0))
(defgeneric shoot (object))
;;;
;;; GENERIC FIGHTER
;;;
(defclass fighter (stats)
((states :initform (list) :accessor states)
(body :initform nil :reader body-of)
(next-dmg-time :initform -1 :accessor next-dmg-time))
(:documentation "Something that can fight, has a body and stats."))
(defgeneric provide-fighter-body (fighter &key &allow-other-keys))
(defmethod dispose :after ((this fighter))
(with-slots (body) this
(dispose body)))
(defmethod initialize-instance :after ((this fighter) &rest args &key &allow-other-keys)
(with-slots (body) this
(setf body (apply #'provide-fighter-body this args))))
(defmethod damage-for (amount (this fighter))
"Damages the `hp' of `this' for `amount'. `This' can't fall below 0 hp."
(with-slots (hp) this
(decf hp (a:clamp amount 0 hp))))
(defmethod heal-for (amount (this fighter))
"Heals the `hp' of `this' for `amount'. `This' can't heal beyond `hp-max'."
(with-slots (hp hp-max) this
(incf hp (a:clamp amount amount (- hp-max hp)))))
(defmethod increase-max-hp-by (x (this fighter))
(with-slots (hp-max) this
(incf hp-max x)))
(defmethod add-state (state (this fighter))
"Adds `state' to the players `states' list.
With the exception of :left and :right. Those are added to `facing'."
(with-slots (states) this
(if (keywordp state)
(pushnew state states)
(error "~&state must be a keyword. Got ~A~%" state))))
(defmethod remove-state (state (this fighter))
"Removes `state' to the players `states' list."
(with-slots (states) this
(if (keywordp state)
(a:deletef states state)
(error "~&state must be a keyword. Got ~A~%" state))))
(defmethod render :around ((this fighter) &key)
(with-slots (body) this
(call-next-method)
(when *debug-rendering*
(render body))))
(defmethod position-of ((this fighter))
(with-slots (body) this
(body-position body)))
(defmethod velocity-of ((this fighter))
(with-slots (body) this
(body-linear-velocity body)))
(defmethod moving-right-p ((this fighter))
(let ((x-vel (gk:x (velocity-of this))))
(and (plusp x-vel)
(> x-vel .1))))
(defmethod moving-left-p ((this fighter))
(let ((x-vel (gk:x (velocity-of this))))
(and (minusp x-vel)
(< x-vel -.1))))
(defun maintain-upright-stance (fighter)
(with-slots (body) fighter
(setf (body-angular-velocity body) 0
(body-rotation body) 0)))
(defmethod observe :before ((this fighter))
(maintain-upright-stance this))
(defmethod hurt-p ((this fighter))
(member :hurt (states this)))
;;;
;;; GROUND FIGHTER
;;;
(defclass ground-fighter (fighter)
((direction :initarg :direction
:accessor direction
:initform 0
:documentation "-1 for left, 0 for both, +1 for right")
(last-direction :initarg :last-direction
:accessor last-direction
:initform 1
:documentation "Indicates which direction the player faced last. +1 = right, -1 = left")))
(defmethod collide :before ((this ground-fighter) (that obstacle))
(with-slots (states direction) this
(setf (collision-friction) 30
(collision-surface-velocity) (cond
((> direction 0) (gk:vec2 (speed-of this) 0))
((< direction 0) (gk:vec2 (- (speed-of this)) 0))
(t (gk:vec2 0 0)))))
t)
(defmethod dead-p ((this fighter))
(member :dead (states this)))
(defmethod dying-p ((this fighter))
(member :dying (states this)))
(defmethod facing-right-p ((this ground-fighter))
(plusp (last-direction this)))
(defmethod facing-left-p ((this ground-fighter))
(minusp (last-direction this)))
(defmethod idle-p ((this ground-fighter))
(null (states this)))
(defmethod running-p ((this ground-fighter))
(member :running (states this)))
(defmethod jumping-p ((this ground-fighter))
(let ((y-velocity (gk:y (velocity-of this))))
(and (plusp y-velocity)
(> y-velocity .5))))
(defmethod falling-p ((this ground-fighter))
(let ((y-velocity (gk:y (velocity-of this))))
(and (minusp y-velocity)
(< y-velocity -.5))))
(defmethod shooting-p ((this ground-fighter))
(member :shooting (states this)))
(defun update-fighter-running-state (this new-direction)
(with-slots (direction last-direction) this
(incf direction new-direction)
(if (= 0 direction)
(remove-state :running this)
(progn
(add-state :running this)
(setf last-direction direction)))))
(defun stop-moving (fighter)
(with-slots (direction) fighter
(remove-state :running fighter)
(setf direction 0)))
(defmethod move-right ((this ground-fighter))
(update-fighter-running-state this 1))
(defmethod stop-move-right ((this ground-fighter))
(update-fighter-running-state this -1))
(defmethod move-left ((this ground-fighter))
(update-fighter-running-state this -1))
(defmethod stop-move-left ((this ground-fighter))
(update-fighter-running-state this 1))
(defmethod stop-running ((this ground-fighter))
(remove-state :running this))
(defmethod start-shooting ((this ground-fighter))
(add-state :shooting this))
(defmethod stop-shooting ((this ground-fighter))
(remove-state :shooting this))
(defmethod make-untouchable-for (time (this fighter))
(with-slots (next-dmg-time) this
(setf next-dmg-time (+ (bodge-util:real-time-seconds) time))))
(defmethod untouchable-p ((this fighter))
(< (now) (next-dmg-time this)))
(defmethod kill ((this fighter))
(add-state :dead this))
| 5,851 | Common Lisp | .lisp | 149 | 34.134228 | 109 | 0.663472 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | c3a4a9dd46b40cbbcfef8f696a7604f1b35de589bc06a4a91daf9569b0d83f8e | 39,630 | [
-1
] |
39,631 | dialogue.lisp | borodust_decent-game/src/objects/dialogue.lisp | (cl:in-package :decent-game)
(defgeneric dialogue-type (event))
(defgeneric dialogue-image (event))
(defgeneric dialogue-choices (event))
(defgeneric dialogue-text (event))
(defgeneric dialogue-choice-id (event choice))
(defgeneric dialogue-choice-test (event choice))
(defgeneric dialogue-choice-text (event choice))
(defgeneric trigger-dialogue (event-id &key &allow-other-keys))
(defun dialogue-choice-active-p (event choice)
(or (null (dialogue-choice-test event choice))
(funcall (dialogue-choice-test event choice))))
(defmacro defdialogue (event-and-opts &body text)
(a:with-gensyms (this-event-type this-choice-type choices)
(destructuring-bind (event &rest opts) (a:ensure-list event-and-opts)
(labels ((%generate-method (name value)
`(defmethod ,name ((,this-event-type (eql ',event)))
(declare (ignore ,this-event-type))
,@value))
(%generate-choice-list (definition)
`(list ,@(loop for (choice . text) on definition by #'cddr
collect (destructuring-bind (event &rest values) (a:ensure-list choice)
(declare (ignore values))
event))))
(%generate-choice-method (name choice value)
`(defmethod ,name ((,this-event-type (eql ',event))
(,this-choice-type (eql ',choice)))
(declare (ignore ,this-event-type ,this-choice-type))
,@value))
(%generate-choice-methods (definition)
(loop for (choice . text) on definition by #'cddr
append (destructuring-bind (event &key test) (a:ensure-list choice)
`(,(%generate-choice-method 'dialogue-choice-id event (list event))
,(%generate-choice-method 'dialogue-choice-test event (list test))
,(%generate-choice-method 'dialogue-choice-text event
(list (first text))))))))
`(progn
,(%generate-method 'dialogue-text text)
,@(loop for (opt . values) in opts
for method = (ecase opt
(:type (%generate-method 'dialogue-kind (list (first values))))
(:image (%generate-method 'dialogue-image (list (first values))))
(:choices `(progn
(let ((,choices ,(%generate-choice-list values)))
,(%generate-method 'dialogue-choices (list choices)))
,@(%generate-choice-methods values))))
collect method)
(defmethod trigger-dialogue ((,this-event-type (eql ',event)) &key)
(declare (ignore ,this-event-type))
(gk.fsm:transition-to 'dialogue-screen :event ,event))
(subscribe-to-event ,event 'trigger-dialogue))))))
(defclass dialogue ()
((dialogue :initform nil)
(selected :initform 0)
(box-font :initform (gk:make-font 'bold-pixel-operator 8))
(choice-font :initform (gk:make-font 'pixel-operator 8))))
(defmethod initialize-instance :after ((this dialogue) &key event)
(with-slots (dialogue selected) this
(setf dialogue event
selected 0)))
(defun make-dialogue (event)
(make-instance 'dialogue :event event))
(defun select-next-dialogue-choice (dialogue)
(with-slots (selected) dialogue
(incf selected)))
(defun select-prev-dialogue-choice (dialogue)
(with-slots (selected) dialogue
(decf selected)))
(defun invoke-dialogue-choice (dialogue)
(with-slots (dialogue selected) dialogue
(loop with i = 0
for choice in (dialogue-choices dialogue)
if (and (= selected i)
(dialogue-choice-active-p dialogue choice))
return (trigger-event choice)
else
do (incf i))))
(defun maintain-dialogue (dialogue)
(with-slots (dialogue selected) dialogue
(let ((active-choice-count (loop for choice in (dialogue-choices dialogue)
when (dialogue-choice-active-p dialogue choice)
count choice)))
(when (and (> active-choice-count 0)
(or (>= selected active-choice-count)
(< selected 0)))
(setf selected (mod selected active-choice-count))))))
(defmethod render ((this dialogue) &key)
(with-slots (dialogue selected box-font choice-font) this
(gk:with-pushed-canvas ()
(gk:translate-canvas 10 94)
(gk:draw-rect +zero-pos+ 236 40 :stroke-paint +black+)
(gk:translate-canvas 5 24)
(draw-multiline-text (dialogue-text dialogue) +zero-pos+
:font box-font
:line-height 16))
(gk:with-pushed-canvas ()
(gk:translate-canvas 75 75)
(loop with i = 0
for choice in (dialogue-choices dialogue)
for text = (dialogue-choice-text dialogue choice)
when (and text (dialogue-choice-active-p dialogue choice))
do (when (eq selected i)
(gk:with-pushed-canvas ()
(gk:translate-canvas -20 0)
(gk:draw-text ">>" +zero-pos+ :font box-font)))
(let ((height
(draw-multiline-text text +zero-pos+
:font choice-font
:line-height 14)))
(gk:translate-canvas 0 height))
(incf i)))))
| 5,823 | Common Lisp | .lisp | 111 | 37.333333 | 103 | 0.550554 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 419a1912af81a77ed00993c13c3f33a564e6f5cd3487fba35fd03441fd5fbb93 | 39,631 | [
-1
] |
39,632 | hitbox.lisp | borodust_decent-game/src/objects/hitbox.lisp | (cl:in-package :decent-game)
;;;
;;; HITBOX
;;;
(defclass hitbox ()
((owner :initarg :owner :initform nil :reader owner-of)))
(defmethod collide :around ((this hitbox) anything)
(call-next-method)
nil)
(defmethod collide :around (anything (this hitbox))
(call-next-method)
nil)
(defclass player-hitbox (hitbox) ())
(defclass enemy-hitbox (hitbox) ())
| 369 | Common Lisp | .lisp | 14 | 24.071429 | 59 | 0.711816 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 8eeb6341d392302014cc238f91638949a2ef3fd629db59d81f8720210d7166ff | 39,632 | [
-1
] |
39,633 | enemy.lisp | borodust_decent-game/src/objects/enemies/enemy.lisp | (cl:in-package :decent-game)
(defclass enemy () ())
(defun make-enemies (&key world enemy-type-list)
(let ((enemies nil))
(dolist (enemy-type enemy-type-list enemies)
(push (make-instance enemy-type :world world) enemies))))
(defun render-enemies (enemy-list)
(dolist (enemy enemy-list)
(render enemy)))
(defun make-enemy (type world &key position)
(make-instance type :world world :position position))
(defun register-enemy-damage (enemy)
(unless (>= 0 (hp (owner-of enemy)))
(damage-for (strength (get-player)) (owner-of enemy))
(add-state :hurt (owner-of enemy))
(add-timer (+ (now) .2)
(lambda () (remove-state :hurt (owner-of enemy))))
(when (>= 0 (hp (owner-of enemy)))
(add-state :dying (owner-of enemy))
(add-timer (+ (now) .3) (lambda () (kill (owner-of enemy)))))))
(defmethod collide :after ((this enemy-hitbox) (that player-bullet))
(register-enemy-damage this)
(destroy-bullet that))
(defmethod collide :after ((that player-bullet) (this enemy-hitbox))
(register-enemy-damage this)
(destroy-bullet that))
| 1,105 | Common Lisp | .lisp | 26 | 38.153846 | 69 | 0.670423 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 0b9cc4333d1d85b75ad3ab8f3316b4c5bf738b1e67b8eca2d065f5d31d675ede | 39,633 | [
-1
] |
39,634 | alien.lisp | borodust_decent-game/src/objects/enemies/alien.lisp | (cl:in-package :decent-game)
(defclass alien (enemy)
()
(:default-initargs
:direction -1)
(:documentation "Contains common properties of aliens."))
| 159 | Common Lisp | .lisp | 6 | 23.666667 | 59 | 0.721854 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 9e9b2c834b7a2140684ae9c6b6d211c6c553938fd055fc16166d33656867c7bf | 39,634 | [
-1
] |
39,635 | alien-stinger.lisp | borodust_decent-game/src/objects/enemies/alien-stinger.lisp | (cl:in-package :decent-game)
(defparameter *alien-stinger-movement-speed* 40)
(define-animation alien-stinger-0-fly-0
(asset-path "img/alien-stinger-0/alien-stinger-0-fly-0.png")
:frames 2)
(define-animation alien-stinger-0-attack-sting-0
(asset-path "img/alien-stinger-0/alien-stinger-0-attack-sting-0.png")
:frames 2)
(define-animation alien-stinger-0-hurt
(asset-path "img/alien-stinger-0/alien-stinger-0-hurt.png")
:frames 1)
(define-animation alien-stinger-0-dying
(asset-path "img/alien-stinger-0/alien-stinger-0-dying.png")
:frames 4)
(define-resource-pack alien-stinger-0-resources ()
'alien-stinger-0-hurt
'alien-stinger-0-dying
'alien-stinger-0-fly-0
'alien-stinger-0-attack-sting-0)
(defclass alien-stinger (alien fighter)
()
(:default-initargs
:hp-max 1)
(:documentation "A medium sized alien enemy, which stings downwards."))
(defmethod observe ((this alien-stinger))
(let* ((player-pos (position-of (player-of *world*)))
(alien-pos (position-of this))
(target-vec (b:subt player-pos alien-pos))
(target-vel (gk:mult (gk:normalize target-vec) *alien-stinger-movement-speed*))
(alien-vel (velocity-of this)))
(apply-force (body-of this) (gk:div (gk:subt target-vel alien-vel) *observation-step*))))
(defmethod provide-fighter-body ((this alien-stinger) &key world position)
(let ((body (make-circle-body (universe-of world)
5
:owner this
:mass 1)))
(setf (body-position body) position)
(attach-box-shape body 16 32 :sensor (make-instance 'enemy-hitbox :owner this)
:radius 5
:offset (gk:vec2 -8 -5))
body))
;;; rendering
(defmethod render ((this alien-stinger) &key)
(with-slots (body) this
(let ((position (body-position body)))
(gk:translate-canvas (- (gk:x position) 15) (- (gk:y position) 5)))
(let ((time (bodge-util:real-time-seconds)))
(if (moving-right-p this)
(cond ((dying-p this) (draw-animation 'alien-stinger-0-dying time +zero-pos+ :mirror-x t))
((hurt-p this) (draw-animation 'alien-stinger-0-hurt time +zero-pos+ :mirror-x t))
(t (draw-animation 'alien-stinger-0-fly-0 time +zero-pos+ :mirror-x t)))
(cond ((dying-p this) (draw-animation 'alien-stinger-0-dying time +zero-pos+))
((hurt-p this) (draw-animation 'alien-stinger-0-hurt time +zero-pos+))
(t (draw-animation 'alien-stinger-0-fly-0 time +zero-pos+)))))))
| 2,621 | Common Lisp | .lisp | 54 | 40.537037 | 100 | 0.636257 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 79c0e2b246006cd14580c3c220c97d5627f77b765967cc384f44a2b58456cc4f | 39,635 | [
-1
] |
39,636 | alien-shooter.lisp | borodust_decent-game/src/objects/enemies/alien-shooter.lisp | (cl:in-package :decent-game)
(defparameter *alien-shooter-sense-field-radius* 80)
(defparameter *alien-shooter-shoot-radius* 60)
(defparameter *alien-shooter-close-radius* 30)
(defparameter *alien-shooter-movement-speed* 30)
(defparameter *alien-shooter-shooting-delay* 0.8)
(define-animation alien-shooter-0-walk-0
(asset-path "img/alien-shooter-0/alien-shooter-0-walk-0.png")
:frames 3)
(define-animation alien-shooter-0-attack-shoot-0
(asset-path "img/alien-shooter-0/alien-shooter-0-attack-ranged-0.png")
:frames 2)
(define-animation alien-shooter-0-hurt
(asset-path "img/alien-shooter-0/alien-shooter-0-hurt.png")
:frames 1)
(define-animation alien-shooter-0-dying
(asset-path "img/alien-shooter-0/alien-shooter-0-dying.png")
:frames 4)
(define-animation alien-shooter-0-attack-projectile-0
(asset-path "img/alien-shooter-0/alien-shooter-0-projectile-0.png")
:frames 1)
(define-resource-pack alien-shooter-0-resources ()
'alien-shooter-0-walk-0
'alien-shooter-0-attack-shoot-0
'alien-shooter-0-hurt
'alien-shooter-0-dying
'alien-shooter-0-attack-projectile-0)
(defclass alien-shooter (alien ground-fighter)
((last-shot :initform nil))
(:default-initargs
:hp-max 2
:strength 5
:attack-speed 12 ; frames between attacks
:movement-speed 50)
(:documentation "A small alien enemy, which shoots thorns."))
(defmethod render-bullet ((this enemy-bullet))
(gk:draw-image +zero-pos+ 'alien-shooter-0-attack-projectile-0))
(defmethod provide-fighter-body ((this alien-shooter) &key world position)
(let ((body (make-circle-body (universe-of world)
5
:owner this
:mass 1)))
(setf (body-position body) (or position (gk:vec2 120 20)))
(attach-box-shape body 24 22 :sensor (make-instance 'enemy-hitbox :owner this)
:radius 5
:offset (gk:vec2 -12 -3))
body))
(defmethod shoot ((this alien-shooter))
(with-slots (last-direction last-shot) this
(with-world (world)
(unless (zerop last-direction)
(let ((sign (/ last-direction (abs last-direction)))
(pos (body-position (body-of this))))
(spawn-bullet 'enemy-bullet world
(gk:add pos (gk:vec2 10 10))
(gk:vec2 (* sign 500) 0))
(setf last-shot (bodge-util:real-time-seconds)))))))
(defun start-alien-shooting (shooter)
(with-slots (last-shot) shooter
(unless last-shot
(setf last-shot 0))))
(defun stop-alien-shooting (shooter)
(with-slots (last-shot) shooter
(setf last-shot nil)))
(defmethod observe ((this alien-shooter))
(with-slots (last-shot) this
(let* ((player-pos (position-of (player-of *world*)))
(alien-pos (position-of this))
(target-vec (b:subt alien-pos player-pos))
(len (b:vector-length target-vec)))
(flet ((follow-player ()
(cond
((< len *alien-shooter-close-radius*) (stop-moving this))
((> (gk:x target-vec) 0) (stop-moving this) (move-left this))
((< (gk:x target-vec) 0) (stop-moving this) (move-right this))))
(shoot-player ()
(stop-moving this)
(start-alien-shooting this))
(wander-around ()
(stop-alien-shooting this)
(stop-moving this)))
(cond
((< len *alien-shooter-shoot-radius*) (shoot-player) (follow-player))
((< len *alien-shooter-sense-field-radius*) (shoot-player))
(t (wander-around)))))
(when (and last-shot (> (- (bodge-util:real-time-seconds) last-shot)
*alien-shooter-shooting-delay*))
(shoot this))))
;;; rendering
(defmethod render ((this alien-shooter) &key)
(with-slots (body) this
(let ((position (body-position body)))
(gk:translate-canvas (- (gk:x position) 14) (- (gk:y position) 5)))
(let ((time (bodge-util:real-time-seconds)))
(cond ((facing-right-p this)
(cond
((dying-p this) (draw-animation 'alien-shooter-0-dying time +zero-pos+ :mirror-x t))
((hurt-p this) (draw-animation 'alien-shooter-0-hurt time +zero-pos+ :mirror-x t))
(t (draw-animation 'alien-shooter-0-walk-0 time +zero-pos+ :mirror-x t))))
((facing-left-p this)
(cond
((dying-p this) (draw-animation 'alien-shooter-0-dying time +zero-pos+))
((hurt-p this) (draw-animation 'alien-shooter-0-hurt time +zero-pos+))
(t (draw-animation 'alien-shooter-0-walk-0 time +zero-pos+))))
(t (error "Alien-shooter should only be able to either face left or right.")))
)))
(defmethod speed-of ((this alien-shooter))
*alien-shooter-movement-speed*)
| 4,930 | Common Lisp | .lisp | 108 | 37 | 99 | 0.615641 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 6c83a6e38cfd9edd2b15d6f866922ae7468e0010892b10623d13850ccba54cb4 | 39,636 | [
-1
] |
39,637 | boss.lisp | borodust_decent-game/src/objects/enemies/boss.lisp | (cl:in-package :decent-game)
(define-animation boss-idle (asset-path "img/boss/boss-idle.png") :frames 2)
(define-animation boss-attack (asset-path "img/boss/boss-attack.png") :frames 5)
(define-animation boss-hurt (asset-path "img/boss/boss-hurt.png") :frames 1)
(define-animation boss-dying (asset-path "img/boss/boss-dying.png") :frames 3)
(define-resource-pack boss-resources (boss-life-bar-resources)
'boss-idle
'boss-attack
'boss-hurt
'boss-dying)
(defclass boss (enemy ground-fighter)
()
(:default-initargs
:hp-max 10
:direction -1)
(:documentation "The final boss."))
(defmethod provide-fighter-body ((this boss) &key world position)
(let ((body (make-circle-body (universe-of world)
5
:owner this
:mass 1)))
(setf (body-position body) (or position (gk:vec2 120 20)))
(attach-box-shape body 24 22 :sensor (make-instance 'enemy-hitbox :owner this)
:radius 5
:offset (gk:vec2 -12 -3))
body))
(defun make-boss ()
(make-instance 'boss))
(defmethod render ((this boss) &key)
(with-slots (states body) this
(let ((position (body-position body)))
(gk:with-pushed-canvas ()
(gk:translate-canvas (- (gk:x position) 14) (- (gk:y position) 12))
(let ((time (now)))
(cond ((dying-p this) (draw-animation 'boss-dying time +zero-pos+))
((hurt-p this) (draw-animation 'boss-hurt time +zero-pos+))
(t (draw-animation 'boss-idle time +zero-pos+))))))))
| 1,615 | Common Lisp | .lisp | 37 | 35.324324 | 82 | 0.607643 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 870fddfee6e9d9c3aebcb5e96258fc77dca0edf87ecb53d725d1a6b7996ad164 | 39,637 | [
-1
] |
39,638 | gameplay.lisp | borodust_decent-game/src/debug/gameplay.lisp | (cl:in-package :decent-game)
(define-level test-level (asset-path "tld/test/test.sxp")
(test-level-tilesheet (asset-path "tld/test/tiles.png") "tiles.png"))
(define-resource-pack gameplay-debug-resources (boss-resources
player-resources
alien-shooter-0-resources
alien-stinger-0-resources)
(level-resources 'test-level))
;;;
;;; INIT
;;;
(defclass init-gameplay-debug-screen () ())
(defmethod gk:post-initialize ((this init-gameplay-debug-screen))
(gk.fsm:transition-to 'loading-screen :pack 'gameplay-debug-resources
:next-state 'gameplay-debug-screen))
;;;
;;; SCENE
;;;
(defclass gameplay-debug-screen (state-input-handler)
((world :initform nil :reader world-of)
(pack :initarg :pack)))
(defun spawn-debug-flyer (action &key)
(declare (ignore action))
(with-slots (world) (gk.fsm:current-state)
(loop repeat 1
for offset = (gk:vec2 (- (random 10) 5) (- (random 10) 5))
do (spawn-enemy world 'alien-stinger "flyer-0" :offset offset))))
(defun spawn-debug-shooter (action &key)
(declare (ignore action))
(with-slots (world) (gk.fsm:current-state)
(loop repeat 1
for offset = (gk:vec2 (- (random 10) 5) (- (random 10) 5))
do (spawn-enemy world 'alien-shooter "shooter-0" :offset offset))))
(defmethod gk:post-initialize ((this gameplay-debug-screen))
(with-slots (world) this
(setf world (make-world 'test-level))
(subscribe-to-event :spawn-flyer-0 'spawn-debug-flyer)
(subscribe-to-event :spawn-shooter-0 'spawn-debug-shooter)))
(defmethod gk:pre-destroy ((this gameplay-debug-screen))
(with-slots (world pack) this
(dispose world)
(dispose-resource-pack pack)))
(defmethod gk:act ((this gameplay-debug-screen))
(with-slots (world) this
;; (format t "~&player-shooting?: ~A~%" (shooting-p (player-of world)))
(observe-world world)))
(defmethod gk:draw ((this gameplay-debug-screen))
(with-slots (world) this
(render world)
(draw-player-life-bar (player-of world) (gk:vec2 10 125))
))
;;; input handling
(defmethod gk.input:button-pressed ((this gameplay-debug-screen) (button (eql :d)))
(with-slots (world) this
(move-right (player-of world))))
(defmethod gk.input:button-released ((this gameplay-debug-screen) (button (eql :d)))
(with-slots (world) this
(stop-move-right (player-of world))))
(defmethod gk.input:button-pressed ((this gameplay-debug-screen) (button (eql :a)))
(with-slots (world) this
(move-left (player-of world))))
(defmethod gk.input:button-released ((this gameplay-debug-screen) (button (eql :a)))
(with-slots (world) this
(stop-move-left (player-of world))))
(defmethod gk.input:button-released ((this gameplay-debug-screen) (button (eql :space)))
(with-slots (world) this
(jump-player (player-of world))))
(defmethod gk.input:button-released ((this gameplay-debug-screen) (button (eql :escape)))
(gk.fsm:transition-to 'loading-screen :pack 'main-menu-resources
:next-state 'main-menu))
(defmethod gk.input:button-pressed ((this gameplay-debug-screen) (button (eql :enter)))
(with-slots (world) this
(start-shooting (player-of world))
(shoot (player-of world))))
(defmethod gk.input:button-released ((this gameplay-debug-screen) (button (eql :enter)))
(with-slots (world) this
(stop-shooting (player-of world))))
(defmethod gk.input:button-pressed ((this gameplay-debug-screen) (button (eql :j)))
(with-slots (world) this
(start-shooting (player-of world))
(shoot (player-of world))))
(defmethod gk.input:button-released ((this gameplay-debug-screen) (button (eql :j)))
(with-slots (world) this
(stop-shooting (player-of world))))
| 3,900 | Common Lisp | .lisp | 84 | 40.130952 | 89 | 0.663487 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | ac6439c5add9e6839f14a44d2d62c4144d8511c12b2171509e9138f91bfd49a9 | 39,638 | [
-1
] |
39,639 | dialogue.lisp | borodust_decent-game/src/debug/dialogue.lisp | (cl:in-package :decent-game)
(defdialogue (:debug-dialogue
(:choices :debug-choice-1 "Doh!"
:debug-dialogue-cont "Huh?"
:debug-choice-3 "Duh..."))
"This is a debug dialogue.
Best one right?")
(defdialogue (:debug-dialogue-cont
(:choices :debug-start-game "Okay, fine, but
get me to the game"
:debug-dialogue "No, take me back"))
"I'm pretty sure this one is
better. Huehuehue")
(defun debug-print-dialogue-event (event &key &allow-other-keys)
(format t "~&Event triggered: ~A" event)
(finish-output))
(defun debug-transition-to-game (event &key &allow-other-keys)
(declare (ignore event))
(gk.fsm:transition-to 'init-gameplay-debug-screen))
(defclass dialogue-debug-screen (state-input-handler) ())
(defmethod gk:post-initialize ((this dialogue-debug-screen))
(subscribe-to-event :debug-choice-1 'debug-print-dialogue-event)
(subscribe-to-event :debug-choice-3 'debug-print-dialogue-event)
(subscribe-to-event :debug-start-game 'debug-transition-to-game)
(gk.fsm:transition-to 'dialogue-screen :event :debug-dialogue))
;;; input handling
(defmethod gk.input:button-released ((this dialogue-debug-screen) (button (eql :escape)))
(gk.fsm:transition-to 'loading-screen :pack 'main-menu-resources
:next-state 'main-menu))
| 1,396 | Common Lisp | .lisp | 29 | 41 | 89 | 0.670362 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 86d18b8c9baa7c6e161aac9cd456cdcea84f0836d61f9e285f988e4050fde749 | 39,639 | [
-1
] |
39,640 | animation.lisp | borodust_decent-game/src/debug/animation.lisp | (cl:in-package :decent-game)
(define-animation background-area-0 (asset-path "img/backgrounds/area-0/background-area-0.png") :frames 1)
(define-resource-pack animation-debug-resources (player-resources
alien-stinger-0-resources
alien-shooter-0-resources)
'background-area-0)
;;;
;;; INIT
;;;
(defclass init-animation-debug-screen () ())
(defmethod gk:post-initialize ((this init-animation-debug-screen))
(gk.fsm:transition-to 'loading-screen :pack 'animation-debug-resources
:next-state 'animation-debug-screen))
;;;
;;; ANIMATION
;;;
(defclass animation-debug-screen (state-input-handler)
((pack :initarg :pack)))
(defmethod gk:pre-destroy ((this animation-debug-screen))
(with-slots (pack) this
(dispose-resource-pack pack)))
(defmethod gk:draw ((this animation-debug-screen))
(let ((time (bodge-util:real-time-seconds)))
(draw-animation 'background-area-0 time +zero-pos+)
(draw-animation 'player-jump-right time +zero-pos+)
(draw-animation 'player-jumping-right time (gk:add +zero-pos+ (gk:vec2 32 0)))
(draw-animation 'player-falling-right time (gk:add +zero-pos+ (gk:vec2 64 0)))
(draw-animation 'player-run-right time (gk:add +zero-pos+ (gk:vec2 96 0)))
(draw-animation 'player-hurt-right time (gk:add +zero-pos+ (gk:vec2 128 0)))
(draw-animation 'player-slash-right time (gk:add +zero-pos+ (gk:vec2 150 0)))
(draw-animation 'player-shoot-right time (gk:add +zero-pos+ (gk:vec2 182 0)))
(draw-animation 'player-projectile-0-right time (gk:add +zero-pos+ (gk:vec2 224 16)))
(draw-animation 'player-dying-right time (gk:add +zero-pos+ (gk:vec2 182 32)))
(draw-animation 'alien-shooter-0-walk-0 time (gk:add +zero-pos+ (gk:vec2 0 120)))
(draw-animation 'alien-shooter-0-attack-shoot-0 time (gk:add +zero-pos+ (gk:vec2 32 120)))
(draw-animation 'alien-stinger-0-fly-0 time (gk:add +zero-pos+ (gk:vec2 0 64)))
(draw-animation 'alien-stinger-0-attack-sting-0 time (gk:add +zero-pos+ (gk:vec2 32 64)))
))
;;; input handling
(defmethod gk.input:button-released ((this animation-debug-screen) (button (eql :escape)))
(gk.fsm:transition-to 'loading-screen :pack 'main-menu-resources
:next-state 'main-menu))
| 2,400 | Common Lisp | .lisp | 42 | 49.666667 | 107 | 0.655128 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | b91f27b7f87a227d229f6b28d4df1b3c384d7a683d034b7aaf6d970847ee9fed | 39,640 | [
-1
] |
39,641 | main-menu.lisp | borodust_decent-game/src/states/main-menu.lisp | (cl:in-package :decent-game)
(gk:define-sound menu-theme (asset-path "snd/music/intro.wav"))
(gk:define-sound credits-tune (asset-path "snd/music/Hip2BCube_-_P_10.ogg"))
(define-resource-pack main-menu-resources (font-resources)
'menu-theme
'credits-tune)
(defclass main-menu (state-input-handler)
((menu :initform nil)))
(defmethod initialize-instance :after ((this main-menu) &key pack)
(declare (ignore pack))
(with-slots (menu) this
(flet ((%start-game ()
(gk.fsm:transition-to 'init-stage-0))
;; (%gameplay-debug-screen ()
;; (gk.fsm:transition-to 'init-gameplay-debug-screen))
;; (%animation-debug-screen ()
;; (gk.fsm:transition-to 'init-animation-debug-screen))
;; (%dialogue-debug-screen ()
;; (gk.fsm:transition-to 'dialogue-debug-screen))
(%credits-screen ()
(gk.fsm:transition-to 'credits-screen))
(%exit ()
(gk:stop)))
(setf menu (make-instance 'menu :items (list "START GAME" #'%start-game
;; "DEBUG-GAMEPLAY" #'%gameplay-debug-screen
;; "DEBUG-ANIMATION" #'%animation-debug-screen
;; "DEBUG-DIALOGUE" #'%dialogue-debug-screen
"CREDITS" #'%credits-screen
"EXIT" #'%exit))))))
(defmethod gk:post-initialize ((this main-menu))
(gk:play-sound 'menu-theme :looped-p t))
(defmethod gk:pre-destroy ((this main-menu))
(gk:stop-sound 'menu-theme))
;;; Input Handling
(defmethod gk.input:button-pressed ((this main-menu) (key (eql :down)))
(with-slots (menu) this
(select-next-menu-item menu)))
(defmethod gk.input:dpad-changed ((this main-menu) (key (eql :down)))
(with-slots (menu) this
(select-next-menu-item menu)))
(defmethod gk.input:button-pressed ((this main-menu) (key (eql :j)))
(with-slots (menu) this
(select-next-menu-item menu)))
(defmethod gk.input:button-pressed ((this main-menu) (key (eql :up)))
(with-slots (menu) this
(select-prev-menu-item menu)))
(defmethod gk.input:dpad-changed ((this main-menu) (key (eql :up)))
(with-slots (menu) this
(select-prev-menu-item menu)))
(defmethod gk.input:button-pressed ((this main-menu) (key (eql :k)))
(with-slots (menu) this
(select-prev-menu-item menu)))
(defmethod gk.input:button-pressed ((this main-menu) (key (eql :gamepad-a)))
(with-slots (menu) this
(invoke-menu-item-action menu)))
(defmethod gk.input:button-pressed ((this main-menu) (key (eql :enter)))
(with-slots (menu) this
(invoke-menu-item-action menu)))
;;; draw
(defmethod gk:draw ((this main-menu))
(with-slots (menu) this
(gk:draw-rect +zero-pos+ 256 144 :fill-paint +black+)
(gk:with-pushed-canvas ()
(gk:translate-canvas 90 100)
(render menu))))
| 2,992 | Common Lisp | .lisp | 65 | 37.276923 | 97 | 0.604001 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | e5503cf9f780bff6d74deb910c927e9a5605de0537c87f5b692ba7761679de3f | 39,641 | [
-1
] |
39,642 | stage.lisp | borodust_decent-game/src/states/stage.lisp | (cl:in-package :decent-game)
;;;
;;; INIT
;;;
(defclass init-stage (loading-screen) ())
;;;
;;; PREPARE
;;;
(defgeneric provide-world (prepare-stage))
(defclass prepare-stage ()
((pack :initarg :pack :initform (error ":pack missing"))
(stage :initarg :stage :initform (error ":stage missing"))
(level :initarg :level :initform nil)))
(defmethod provide-world ((this prepare-stage))
(with-slots (level) this
(make-world level)))
(defmethod gk:post-initialize :after ((this prepare-stage))
(with-slots (pack stage) this
(gk.fsm:transition-to stage :world (provide-world this) :pack pack)))
;;;
;;; DESTROY
;;;
(defclass destroy-stage ()
((world :initarg :world :initform (error ":world missing"))
(pack :initarg :pack :initform (error ":pack missing"))
(next :initarg :next :initform (error ":next missing"))))
(defmethod gk:post-initialize :after ((this destroy-stage))
(with-slots (world pack next) this
(dispose world)
(dispose-resource-pack pack)
(gk.fsm:transition-to next)))
;;;
;;; PLAY
;;;
(defclass stage (state-input-handler)
((world :initarg :world :initform (error ":world missing") :reader world-of)
(pack :initarg :pack :initform (error ":pack missing"))
(init :initarg :init :initform (error ":init missing"))
(next :initarg :next :initform (error ":next missing"))
(destroy :initarg :destroy :initform (error ":destroy missing"))))
(defun spawn-stinger (spawn &optional count)
(with-slots (world) (gk.fsm:current-state)
(loop repeat (or count 1)
for offset = (gk:vec2 (- (random 20) 10) (- (random 20) 10))
do (spawn-enemy world 'alien-stinger spawn :offset offset))))
(defun spawn-shooter (spawn &optional count)
(with-slots (world) (gk.fsm:current-state)
(loop repeat (or count 1)
for offset = (gk:vec2 (- (random 20) 10) (- (random 20) 10))
do (spawn-enemy world 'alien-shooter spawn :offset offset))))
(defun call-enemy (action &key spawn type count)
(declare (ignore action))
(a:switch (type :test #'equal)
("shooter" (spawn-shooter spawn count))
("stinger" (spawn-stinger spawn count))))
(defun kill-player (action &key)
(declare (ignore action))
(with-slots (init) (gk.fsm:current-state)
(gk.fsm:transition-to init)))
(defun finish-level (action &key)
(declare (ignore action))
(with-slots (next destroy world pack) (gk.fsm:current-state)
(gk.fsm:transition-to destroy :next next :world world :pack pack)))
(defmethod gk:post-initialize :before ((this stage))
(with-slots (world) this
(subscribe-to-event :player-death 'kill-player)
(subscribe-to-event :enemy-call 'call-enemy)
(subscribe-to-event :level-finished 'finish-level)))
(defmethod gk:pre-destroy :after ((this stage))
(with-slots (world pack) this
(unsubscribe-from-event :player-death 'kill-player)
(unsubscribe-from-event :enemy-call 'call-enemy)
(unsubscribe-from-event :level-finished 'finish-level)))
(defmethod gk:act :before ((this stage))
(with-slots (world) this
(observe-world world)))
(defmethod gk:draw :before ((this stage))
(with-slots (world) this
(gk:draw-rect +zero-pos+ 256 144 :fill-paint +black+)
(render world)
(draw-player-life-bar (player-of world) (gk:vec2 10 125))))
;;;
;;; input handling
;;;
(defmethod gk.input:button-released ((this stage) (button (eql :escape)))
(with-slots (world pack) this
(gk.fsm:transition-to 'pause-screen :world world :pack pack)))
(defmethod gk.input:button-pressed ((this stage) (button (eql :d)))
(with-slots (world) this
(move-right (player-of world))))
(defmethod gk.input:button-released ((this stage) (button (eql :d)))
(with-slots (world) this
(stop-move-right (player-of world))))
(defmethod gk.input:button-pressed ((this stage) (button (eql :a)))
(with-slots (world) this
(move-left (player-of world))))
(defmethod gk.input:button-released ((this stage) (button (eql :a)))
(with-slots (world) this
(stop-move-left (player-of world))))
(defmethod gk.input:button-released ((this stage) (button (eql :space)))
(with-slots (world) this
(jump-player (player-of world))))
(defmethod gk.input:button-pressed ((this stage) (button (eql :enter)))
(with-slots (world) this
(start-shooting (player-of world))
(shoot (player-of world))))
(defmethod gk.input:button-released ((this stage) (button (eql :enter)))
(with-slots (world) this
(stop-shooting (player-of world))))
(defmethod gk.input:button-pressed ((this stage) (button (eql :j)))
(with-slots (world) this
(start-shooting (player-of world))
(shoot (player-of world))))
(defmethod gk.input:button-released ((this stage) (button (eql :j)))
(with-slots (world) this
(stop-shooting (player-of world))))
| 4,798 | Common Lisp | .lisp | 116 | 37.741379 | 78 | 0.689201 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | d27be275402b045c01ad4b4213fa9aee77bf302cfd9cf8230642ad65ba28459a | 39,642 | [
-1
] |
39,643 | dialogue.lisp | borodust_decent-game/src/states/dialogue.lisp | (cl:in-package :decent-game)
;;;
;;; OSD
;;;
(defclass gameplay-dialogue ()
((dialogue :initarg :dialogue)))
(defmethod gk:draw ((this gameplay-dialogue)))
;;;
;;; CUTSCENE
;;;
(defclass cutscene-dialogue ()
())
(defmethod gk:draw ((this cutscene-dialogue)))
;;;
;;; DIALOGUE
;;;
(defclass dialogue-screen (state-input-handler)
((dialogue :initform nil)))
(defmethod initialize-instance :after ((this dialogue-screen) &key event)
(with-slots (dialogue) this
(unless event
(error ":event missing"))
(setf dialogue (make-dialogue event))))
(defmethod gk:act ((this dialogue-screen))
(with-slots (dialogue) this
(maintain-dialogue dialogue)))
(defmethod gk:draw ((this dialogue-screen))
(with-slots (dialogue) this
(render dialogue)))
(defmethod gk.input:button-pressed ((this dialogue-screen) (key (eql :up)))
(with-slots (dialogue) this
(select-prev-dialogue-choice dialogue)))
(defmethod gk.input:button-pressed ((this dialogue-screen) (key (eql :down)))
(with-slots (dialogue) this
(select-next-dialogue-choice dialogue)))
(defmethod gk.input:button-pressed ((this dialogue-screen) (key (eql :enter)))
(with-slots (dialogue) this
(invoke-dialogue-choice dialogue)))
| 1,240 | Common Lisp | .lisp | 38 | 29.710526 | 78 | 0.715495 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 9ec0486d264969c077f78e2cc23fe6b732fc34d38ed559ed0c0a771afc853d91 | 39,643 | [
-1
] |
39,644 | credits.lisp | borodust_decent-game/src/states/credits.lisp | (cl:in-package :decent-game)
(defparameter *credits-pos* (gk:vec2 16 124))
(defclass credits-screen (state-input-handler)
((credits-finished-p :initform nil :accessor credits-finished-p)))
(defmethod gk:act ((this credits-screen))
(cond ((and (> (gk:y *credits-pos*) 420)
(not (credits-finished-p this)))
(setf (credits-finished-p this) t))
((not (credits-finished-p this))
(incf (gk:y *credits-pos*) .25))
(t nil)))
(defmethod gk:post-initialize ((this credits-screen))
(gk:play-sound 'credits-tune)
(setf *credits-pos* (gk:vec2 16 124)))
(defmethod gk:pre-destroy ((this credits-screen))
(gk:stop-sound 'credits-tune))
(defmethod gk:draw ((this credits-screen))
(gk:draw-rect +zero-pos+ 256 144 :fill-paint +black+)
(draw-multiline-text "Copyright (C) 2020
decent-username,
Ryan Burnside,
David O'Toole,
readeval,
Pavel Korolev.
Game Director : Pavel Korolev
Development & Engine Director :
Pavel Korolev
Graphics & Level Director :
decent-username
Concept Art & Design :
Ryan Burnside
Assistant Producer and Story :
readeval
Music Director:
readeval
Original Music Score by:
DJXXSS, Tomorrow Mars
Additional Music licensed from:
Austin Coco
Additional testing by:
Plastson"
*credits-pos*
:font (gk:make-font 'pixel-operator 6)
:line-height 8
:fill-color +color-alien-dark+))
(defmethod gk.input:button-pressed ((this credits-screen) (key (eql :down)))
(scroll-down this))
(defmethod gk.input:dpad-changed ((this credits-screen) (key (eql :down)))
(scroll-down this))
(defmethod gk.input:button-pressed ((this credits-screen) (key (eql :j)))
(scroll-down this))
(defmethod gk.input:button-pressed ((this credits-screen) (key (eql :k)))
(scroll-up this))
(defmethod gk.input:button-pressed ((this credits-screen) (key (eql :up)))
(scroll-up this))
(defmethod gk.input:dpad-changed ((this credits-screen) (key (eql :up)))
(scroll-up this))
(defmethod gk.input:button-pressed ((this credits-screen) (key (eql :escape)))
(gk.fsm:transition-to 'main-menu))
(defmethod scroll-up ((this credits-screen))
(decf (gk:y *credits-pos*) 5))
(defmethod scroll-down ((this credits-screen))
(incf (gk:y *credits-pos*) 5))
| 2,335 | Common Lisp | .lisp | 63 | 32.460317 | 78 | 0.688143 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 9ac1fad4b88ab8660c67a3fa7bf7b28cd6f05c6d3eca54e1b8cf83d8fc7b4c8d | 39,644 | [
-1
] |
39,645 | base-loading-screen.lisp | borodust_decent-game/src/states/base-loading-screen.lisp | (cl:in-package :decent-game)
(defgeneric on-load (state))
(defclass base-loading-screen (state-input-handler)
((pack-name :initarg :pack :initform (error ":pack missing"))
(pack :initform nil :reader pack-of)
(prepared-percentage :initform 100 ; 100 is the default, because if no
; resources are specified, there's nothing
; to load
:documentation "Indicated what percentage of the resources has already benn loaded.")))
(defmethod gk:post-initialize ((this base-loading-screen))
(with-slots (pack-name pack) this
(unless pack-name
(error ":pack-name must not be nil"))
(setf pack (load-resource-pack pack-name))))
(defmethod gk:act ((this base-loading-screen))
(with-slots (pack prepared-percentage) this
(let ((count (pack-prepared-count pack))
(total (pack-total-count pack)))
(setf prepared-percentage (truncate (* (if (> total 0)
(/ count total)
1)
100)))
(when (= count total)
(on-load this)))))
| 1,212 | Common Lisp | .lisp | 24 | 36.583333 | 111 | 0.558002 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | c3fd350eaacf8bba77236a97fe3b45eb094ce501ab4342a6930d91962a617b03 | 39,645 | [
-1
] |
39,646 | loading.lisp | borodust_decent-game/src/states/loading.lisp | (cl:in-package :decent-game)
(gk:define-image loading-screen-bar-overlay (asset-path "img/hud/loading-screen-bar-overlay.png")
:use-nearest-interpolation t)
(define-animation loading-screen-animation (asset-path "img/hud/loading-screen-anim-sprite-sheet.png")
:frames 12)
(define-resource-pack loading-screen-resources ()
'loading-screen-animation
'loading-screen-bar-overlay
'bold-pixel-operator)
(defclass loading-screen (base-loading-screen)
((next-state :initform (error ":next-state missing") :initarg :next-state)))
(defmethod gk:draw ((this loading-screen))
(with-slots (prepared-percentage) this
(gk:draw-rect +zero-pos+ 256 144 :fill-paint +black+)
(gk:with-pushed-canvas ()
(draw-loading-bar prepared-percentage (gk:vec2 8 8) :bar-height 16 :bar-width 240)
(gk:draw-image +zero-pos+ 'loading-screen-bar-overlay))
(gk:with-pushed-canvas ()
(gk:translate-canvas 9 10)
(gk:scale-canvas 0.5 0.5)
(gk:draw-text (format nil "~A%" prepared-percentage)
+zero-pos+
:fill-color +black+
:font (gk:make-font 'bold-pixel-operator 24)))
(gk:with-pushed-canvas ()
(gk:translate-canvas 112 56)
(draw-animation 'loading-screen-animation (now) +zero-pos+))))
(defmethod on-load ((this loading-screen))
(with-slots (next-state) this
(gk.fsm:transition-to next-state :pack (pack-of this))))
| 1,429 | Common Lisp | .lisp | 30 | 41.7 | 102 | 0.686825 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | e617d47d0ac9e1a1407b505cd961642d175cfbdd672d5cd7b17e711c46f6f66e | 39,646 | [
-1
] |
39,647 | pause.lisp | borodust_decent-game/src/states/pause.lisp | (cl:in-package :decent-game)
(defclass pause-screen (state-input-handler)
((world :initarg :world :initform (error ":world missing") :reader world-of)
(pack :initarg :pack :initform (error ":pack missing"))
(menu :initform nil)))
(defmethod initialize-instance :after ((this pause-screen) &key)
(with-slots (menu pack world) this
(flet ((%resume-stage ()
(gk.fsm:transition-to 'stage-0 :world world :pack pack))
(%restart-stage ()
(gk.fsm:transition-to 'init-stage-0))
(%main-menu ()
(gk.fsm:transition-to 'loading-screen :pack 'main-menu-resources
:next-state 'main-menu))
(%exit ()
(gk:stop)))
(setf menu (make-instance 'menu :items (list "RESUME STAGE" #'%resume-stage
"RESTART STAGE" #'%restart-stage
"MAIN MENU" #'%main-menu
"EXIT" #'%exit))))))
;;; Input Handling
(defmethod gk.input:button-pressed ((this pause-screen) (key (eql :down)))
(with-slots (menu) this
(select-next-menu-item menu)))
(defmethod gk.input:dpad-changed ((this pause-screen) (key (eql :down)))
(with-slots (menu) this
(select-next-menu-item menu)))
(defmethod gk.input:button-pressed ((this pause-screen) (key (eql :j)))
(with-slots (menu) this
(select-next-menu-item menu)))
(defmethod gk.input:button-pressed ((this pause-screen) (key (eql :up)))
(with-slots (menu) this
(select-prev-menu-item menu)))
(defmethod gk.input:dpad-changed ((this pause-screen) (key (eql :up)))
(with-slots (menu) this
(select-prev-menu-item menu)))
(defmethod gk.input:button-pressed ((this pause-screen) (key (eql :k)))
(with-slots (menu) this
(select-prev-menu-item menu)))
(defmethod gk.input:button-pressed ((this pause-screen) (key (eql :enter)))
(with-slots (menu) this
(invoke-menu-item-action menu)))
;;; draw
(defmethod gk:draw ((this pause-screen))
(with-slots (menu world) this
(render world)
(gk:with-pushed-canvas ()
(gk:translate-canvas 60 24)
(gk:draw-rect +zero-pos+ 140 100
:fill-paint (alphacolor .8 +black+)
:stroke-paint (alphacolor .5 +color-alien-dark+)
:thickness 4)
(gk:with-pushed-canvas ()
(gk:translate-canvas 26 100)
(render menu)))))
| 2,498 | Common Lisp | .lisp | 55 | 35.781818 | 83 | 0.589765 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 6a4bd9766e60fa6f4e844512a7f133e6525aea37d00726dacc7ab7e6036d294f | 39,647 | [
-1
] |
39,648 | init.lisp | borodust_decent-game/src/states/init.lisp | (cl:in-package :decent-game)
(defclass init-screen (base-loading-screen) ()
(:default-initargs :pack 'loading-screen-resources))
(defmethod on-load ((this init-screen))
(gk.fsm:transition-to 'loading-screen
:pack 'main-menu-resources
:next-state 'main-menu))
(defmethod gk:draw ((this init-screen))
(gk:draw-rect +zero-pos+ 256 144 :fill-paint +black+))
| 415 | Common Lisp | .lisp | 9 | 38.333333 | 56 | 0.651629 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 564d621c00cb347ff9da8bad3287d12e5a18f694c686f95d6b603151893410cf | 39,648 | [
-1
] |
39,649 | stage.lisp | borodust_decent-game/src/states/stage-2/stage.lisp | (cl:in-package :decent-game)
(gk:define-sound boss-tune (asset-path "snd/music/gigamegasuuperbossbeaty.ogg"))
(define-level stage-2 (asset-path "tld/stage-2/stage.sxp")
(stage-2-tilesheet (asset-path "tld/stage-2/tiles.png") "tiles.png")
(boss-stage-2-tilesheet (asset-path "tld/stage-2/tileset-1-with-alpha.png") "tileset-1-with-alpha.png"))
(define-resource-pack stage-2-resources (player-resources
boss-resources)
(level-resources 'stage-2)
'boss-tune)
;;;
;;; INIT
;;;
(defclass init-stage-2 (init-stage)
()
(:default-initargs :pack 'stage-2-resources :next-state 'prepare-stage-2))
;;;
;;; PREPARE
;;;
(defclass prepare-stage-2 (prepare-stage)
()
(:default-initargs :level 'stage-2
:stage 'stage-2))
(defmethod gk:post-initialize ((this prepare-stage-2))
(gk:play-sound 'boss-tune :looped-p t))
;;;
;;; STAGE 2
;;;
(defclass stage-2 (stage)
()
(:default-initargs :init 'init-stage-2
:next 'credits-screen
:destroy 'destroy-stage-2))
(defmethod gk:act ((this stage-2))
(unless (boss-exists-p (world-of this))
(trigger-event :level-finished)))
(defmethod gk:draw ((this stage-2))
(draw-boss-life-bar (get-boss-of (world-of this)) (gk:vec2 156 126)))
(defmethod gk:post-initialize ((this stage-2))
(spawn-enemy (world-of this) 'boss "boss"))
;;;
;;; DESTROY
;;;
(defclass destroy-stage-2 (destroy-stage)
())
(defmethod gk:post-initialize ((this destroy-stage-2))
(gk:stop-sound 'boss-tune))
| 1,555 | Common Lisp | .lisp | 46 | 29.282609 | 106 | 0.659718 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | f46f0a0d05ce9f53267a3698eefefddbfa1db0d903356a1542874bdae5f48c0a | 39,649 | [
-1
] |
39,650 | stage.lisp | borodust_decent-game/src/states/stage-0/stage.lisp | (cl:in-package :decent-game)
(gk:define-sound gameplay-tune (asset-path "snd/music/combat-zone.ogg"))
(define-level stage-0 (asset-path "tld/stage-0/stage.sxp")
(stage-0-tilesheet (asset-path "tld/stage-0/tiles.png") "tiles.png"))
(define-resource-pack stage-0-resources (player-resources
alien-shooter-0-resources
alien-stinger-0-resources)
(level-resources 'stage-0)
'gameplay-tune)
;;;
;;; INIT
;;;
(defclass init-stage-0 (init-stage)
()
(:default-initargs :pack 'stage-0-resources :next-state 'prepare-stage-0))
;;;
;;; PREPARE
;;;
(defclass prepare-stage-0 (prepare-stage)
()
(:default-initargs :level 'stage-0
:stage 'stage-0))
(defmethod gk:post-initialize ((this prepare-stage-0))
(gk:play-sound 'gameplay-tune :looped-p t))
;;;
;;; STAGE 0
;;;
(defclass stage-0 (stage)
()
(:default-initargs :init 'init-stage-0
:next 'init-stage-2
:destroy 'destroy-stage-0))
;;;
;;; DESTROY
;;;
(defclass destroy-stage-0 (destroy-stage)
())
(defmethod gk:post-initialize ((this destroy-stage-0))
(gk:stop-sound 'gameplay-tune))
| 1,208 | Common Lisp | .lisp | 39 | 25.205128 | 76 | 0.626736 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 89d00696094add92a6d2051289cc011db29960b33ca03f9617c5ef419636a112 | 39,650 | [
-1
] |
39,651 | exporter.lisp | borodust_decent-game/tiled/exporter.lisp | (uiop:define-package :decent-game.tiled
(:use :cl :cffi :cffi-c-ref)
(:export #:convert))
(cl:in-package :decent-game.tiled)
(declaim (special *properties*
*objects*
*map*))
(defcallback parse-property :void ((property :pointer) (data :pointer))
(declare (ignore data))
(c-val ((property %tmx:property))
(let ((type (property :type)))
(push (list (property :name)
(c-let ((value %tmx:property-value :from (property :value)))
(case type
(:int (value :integer))
(:bool (unless (= (value :boolean) 0) t))
(:float (value :decimal))
(:color (value :color))
(:string (value :string))
(:file (value :file)))))
*properties*))))
(defun parse-properties (properties)
(let (*properties*)
(unless (null-pointer-p properties)
(%tmx:property-foreach properties
(callback parse-property)
(null-pointer)))
*properties*))
(defun parse-layer-content (content)
(c-let ((tmx %tmx:map :from *map*))
(c-val ((content (:union %tmx:layer-content)))
(list :gids (loop for i from 0 below (* (tmx :width) (tmx :height))
collect (content :gids * i))))))
(defun parse-poly-shape (content)
(c-val ((content %tmx:shape))
(list :points (loop for i from 0 below (content :points-len)
collect (list (content :points * i * 0)
(content :points * i * 1))))))
(defun parse-text (content)
(declare (ignore content)))
(defun parse-objects (head)
(loop for object = head then (c-ref object %tmx:object :next)
until (null-pointer-p object)
collect (c-val ((object %tmx:object))
(let ((kind (object :obj-type)))
(list* :id (object :id)
:kind kind
:name (object :name)
:type (object :type)
:position (list (object :x) (object :y))
:width (object :width)
:height (object :height)
:rotation (object :rotation)
:properties (parse-properties (object :properties))
(case kind
(:polygon (parse-poly-shape (object :content :shape)))
(:polyline (parse-poly-shape (object :content :shape)))
(:tile (list :gid (object :content :gid)))
(:text (parse-text (object :content :text)))))))))
(defun parse-object-group-content (content)
(c-val ((content (:union %tmx:layer-content)))
(c-let ((object-group %tmx:object-group :from (content :objgr)))
(list :objects (parse-objects (object-group :head))))))
(defun parse-layer (layer)
(c-val ((layer %tmx:layer))
(let ((type (layer :type)))
(list* :type type
:name (layer :name)
:properties (parse-properties (layer :properties))
(case type
(:layer (parse-layer-content (layer :content)))
(:objgr (parse-object-group-content (layer :content))))))))
(defun parse-image (image)
(unless (null-pointer-p image)
(c-val ((image %tmx:image))
(list :source (image :source)
:width (image :width)
:height (image :height)))))
(defun parse-tile (tile)
(unless (null-pointer-p tile)
(c-val ((tile %tmx:tile))
(list :id (tile :id)
:type (tile :type)
:position (list (tile :ul-x) (tile :ul-y))
:image (parse-image (tile :image))
:properties (parse-properties (tile :properties))))))
(defun parse-tiles (tiles count)
(unless (or (null-pointer-p tiles) (= count 0))
(c-val ((tiles (:pointer %tmx:tile)))
(loop for i from 0 below count
unless (null-pointer-p (tiles i))
collect (parse-tile (tiles i))))))
(defun parse-tileset (tileset gid-offset)
(c-val ((tileset %tmx:tileset))
(list :name (tileset :name)
:tile-width (tileset :tile-width)
:tile-height (tileset :tile-height)
:offset (list (tileset :x-offset) (tileset :y-offset))
:spacing (tileset :spacing)
:margin (tileset :margin)
:image (parse-image (tileset :image))
:tiles (loop for i from 0 below (tileset :tilecount)
unless (null-pointer-p (tileset :tiles * i))
collect (list (+ i gid-offset)
(parse-tile (tileset :tiles * i))))
:properties (parse-properties (tileset :properties)))))
(defun parse-map (tmx)
(c-val ((tmx %tmx:map))
(let ((*map* (tmx &)))
(list :layers (unless (null-pointer-p (tmx :ly-head))
(loop for layer = (tmx :ly-head) then (c-ref layer %tmx:layer :next)
until (null-pointer-p layer)
collect (parse-layer layer)))
:tilesets (unless (null-pointer-p (tmx :ts-head))
(loop for item = (tmx :ts-head) then (c-ref item %tmx:tileset-list :next)
until (null-pointer-p item)
collect (c-val ((item %tmx:tileset-list))
(parse-tileset (item :tileset) (item :firstgid)))))
:width (tmx :width)
:height (tmx :height)
:tile-width (tmx :tile-width)
:tile-height (tmx :tile-height)
:properties (parse-properties (tmx :properties))))))
(defun convert (source-file target-file)
(let ((tmx (%tmx:load (uiop:native-namestring source-file))))
(when (null-pointer-p tmx)
(error "Failed to load tmx map from ~A: ~A"
source-file (%tmx:strerr)))
(unwind-protect
(with-open-file (out target-file :direction :output :if-exists :supersede)
(prin1 (parse-map tmx) out))
(%tmx:map-free tmx))))
| 6,218 | Common Lisp | .lisp | 132 | 33.94697 | 97 | 0.524203 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | a3bc2a788caa6865c84edde130b5f847da06023fe565a5cc417ce528c7c6d4eb | 39,651 | [
-1
] |
39,652 | text-template.lisp | borodust_decent-game/brainstorming/text-template.lisp | (cl:in-package :decent-game)
(defdialogue (:event-0
;; this is the event that triggers this dialogue
;; type can be :osd or :cutscene
;; :osd is the default if no :type is provided
(:type :osd)
;; here's the smallish avatar-like image because :osd
(:image :boss-image-id)
;; dialogue might have choices
;; choices can have predicates that control if particular choice is shown or not
(:choices
;; this choice also uses a predicated user-have-label-p
;; if it returns true - choice is shown, otherwise choice is hidden
(:event-1 :test #'user-have-label-p) "This is the choice 1. This triggers :event-1"
:event-2 "This is the choice 2. This triggers :event-2. See next dialogue"))
"Multiline text goes here.
This is the main text that takes the most space.")
;; several dialogues can be defined in a single file
(defdialogue (:event-2
;; this is the event that triggers this dialogue
(:type :cutscene)
;; here's the full screen image because :cutscene
(:image :fail-screen)
;; if you want for something to happend when user hits enter
;; other than dialogue closing, you need to provide
;; default choice w/o a text
(:choices :event-stop-game))
"Another multiline text goes here.
It is not autoscrolled, and you would need to define a dialogue for each screen of text.")
| 1,591 | Common Lisp | .lisp | 29 | 42.758621 | 98 | 0.604487 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | ffd610f718c21b1cbbf1630af3e01d72de2323e8488162e1324532dacd615e0c | 39,652 | [
-1
] |
39,653 | text-template.lisp | borodust_decent-game/brainstorming/txt/text-template.lisp | ;;;TODO if the code is changed and this doesn't work, i'll just re-do it. lemme know.
;; First cut-scene giving premise
(decent-game:defdialogue (:info-on-start
(:type :cutscene)
;; in order of complexity - pick one
;; hero lying down,hero dying, hero lying with burning city behind
(:image :info-on-start))
"The sounds of battle fade. You are dying. Why is something you just can't remeber. Aliens, humanoids with machine parts, or was it the other way around?")
;; Second screen for early game premise info
(decent-game:defdialogue (:info-on-start-1
(:type :cutscene)
;; in order of complexity - pick one
;; cyborg weapon or device to left, alien weapon or bio-container
(:image :info-on-start-1)
(:choices
(:pick-cyborg :test #'picked-cyborg-p ) "Pick the Cyborg gear"
(:pick-alien :test #'picked-alien-p ) "Pick the Alien tech"
(:human :test #'human-p "Go without unknown enhancements")))
"Perhaps there's some life in You left.
Close-by, a cybernetic gear pack and an alien container.
Pick one or go without?")
;;Boss taunts
(decent-game:defdialogue (:first-enemy-kill ;; TODO cheapest event for boss taunts? Random through game?
(:type :osd)
(:image :boss-image-id)))
"Not You! Again! Let me know when you get tired of dying... Again."
;;; Default template
;;;
(decent-game:defdialogue (:event-0 ;; this is the event that triggers this dialogue
;; type can be :osd or :cutscene
;; :osd is the default if no :type is provided
(:type :osd)
;; here's the smallish avatar-like image because :osd
(:image :boss-image-id)
;; dialogue might have choices
;; choices can have predicates that control if particular choice is shown or not
(:choices
;; this choice also uses a predicated user-have-label-p
;; if it returns true - choice is shown, otherwise choice is hidden
(:event-1 :test #'user-have-label-p) "This is the choice 1. This triggers :event-1"
:event-2 "This is the choice 2. This triggers :event-2. See next dialogue"))
"Multiline text goes here.
This is the main text that takes the most space.")
;; several dialogues can be defined in a single file
(decent-game:defdialogue (:event-2 ;; this is the event that triggers this dialogue
(:type :cutscene)
;; here's the full screen image because :cutscene
(:image :fail-screen)
;; if you want for something to happend when user hits enter
;; other than dialogue closing, you need to provide
;; default choice w/o a text
(:choices :event-stop-game))
"Another multiline text goes here.
It is not autoscrolled, and you would need to define a dialogue for each screen of text.")
; Load Screen - text menu (main-load-screen)
;; Text Info Screen On Game Start describing game premise. (info-on-start)
;; ESC screen - text menu (main-esc-menu)
;; Boss Fight (boss-battle)
;; Final Outcome Text Summary (final-outcome)
;; End Credits (end-credits))
| 3,703 | Common Lisp | .lisp | 60 | 45.85 | 157 | 0.566703 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | e14cece680ba491bd4158baeb8a17c461340a52a3e09cdb06243d1a85f8d71a3 | 39,653 | [
-1
] |
39,654 | decent-game.asd | borodust_decent-game/decent-game.asd | (cl:pushnew :bodge-gl2 cl:*features*)
(asdf:defsystem :decent-game
:description "Spring Lisp Game Jam 2020 entry"
:author "decent-username, Ryan Burnside, David O'Toole, readeval, Pavel Korolev"
:license "GNUv3"
:depends-on (#:alexandria
#:trivial-gamekit
#:trivial-gamekit-fistmachine
#:trivial-gamekit-input-handler
#:cl-bodge/physics
#:cl-bodge/physics/2d
#:cl-tiled)
:pathname "src/"
:serial t
:components ((:file "packages")
(:file "color")
(:file "util")
(:file "timer-util")
(:file "resources")
(:file "physics")
(:file "event")
(:file "spritesheet")
(:file "animation")
(:file "hud")
(:module "objects"
:components ((:file "dialogue")
(:file "menu")
(:file "level")
(:file "world")
(:file "stats")
(:file "hitbox")
(:file "bullet")
(:file "fighter")
(:file "player")
(:module "enemies"
:components ((:file "enemy")
(:file "boss")
(:file "alien")
(:file "alien-stinger")
(:file "alien-shooter")))))
(:module "states"
:components ((:file "base-loading-screen")
(:file "init")
(:file "loading")
(:file "main-menu")
(:file "dialogue")
(:file "replay")
(:file "pause")
(:file "credits")
(:file "stage")
(:module "stage-0"
:components ((:file "stage")))
(:module "stage-2"
:components ((:file "stage")))))
(:file "text")
(:file "main")
(:module "debug"
:components ((:file "animation")
(:file "dialogue")
(:file "gameplay")))))
(asdf:defsystem :decent-game/tiled
:description "Tiled map converter"
:author "Pavel Korolev"
:license "MIT"
:depends-on (#:bodge-tmx :cffi :cffi-c-ref)
:pathname "tiled/"
:serial t
:components ((:file "exporter")))
| 2,798 | Common Lisp | .asd | 68 | 21.735294 | 82 | 0.377615 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 142988bd814168335000b60d72f5904d189903cec6d8335a388bcb739dc4cb5d | 39,654 | [
-1
] |
39,656 | .travis.yml | borodust_decent-game/.travis.yml | language: common-lisp
sudo: false
addons:
apt:
packages:
- zip
env:
global:
- GAMEKIT_SYSTEM_NAME: decent-game
- GAMEKIT_APPLICATION_PACKAGE: decent-game
- GAMEKIT_APPLICATION_MAIN_CLASS: decent-game
- PATH: ~/.bodge/bin/:$PATH
- GAMEKIT_TARGET_PACKAGE: $GAMEKIT_SYSTEM_NAME-x86-64-$TRAVIS_OS_NAME-$TRAVIS_BRANCH.zip
- GAMEKIT_BUILD_DIR: /tmp/$GAMEKIT_SYSTEM_NAME
- secure: "CILXscSAoBEFOlaPuo+3S5Kxl/+g1rDM3B5G5hJO42ig/JASwwid1InNpyLZQWS1C13nOJKpPXlvMn2SQ32zhKvx0dUCOWvKNVwzRG+mK+h8KpI1otKaHCWjPl0DPE6MbUsvdkYkjpyY0ULWx7CxCLgJ7qDnnBA41b99X/O0ikMEE5Ix10T3EHIpAPVlxH+FAnZoywOzx3gRP9+NJpDXx198nkUPM0ptS5Bv1QZiAYBECf3RmVhgvfddYyv1pfVISQTu4UDbCJuOZ/ZtE+BBq43l6JC1dQ733uG8SnR+Z10ISQexi62G8b8ir1J0Iw5NAKxUZBlKqks2NlnhK3JFdGOlDzxsG86H6gderm9IpOEq8E2gvHp5bp2zYyJSqxVA0hcfRi7PhCkckMrIJI+tfZMajx1OPERXlUUtjgFKD4M0VIxvjcguGUCjk99WrKEWfvA8KzshoGEJi2LSQ5VGNYG5JTHO8HzXvo2CXU3t5ylD18thJTZX3q2IKGGJXQsI5Z3n/F+Rj8767HftI6JBAXfIbuUbyj35BNyOZGXUbGuekPNVerNGKUXwo0uumN8agUiEa3IY44E+olHsceixc1MRvF3ogZH+IOaFHvtJvz2gBTfeoQ3F+/dRirymTEouuVohpCnf9IQw84KYKQpkM9olqramzgIQLqoU7KGeL68="
branches:
only:
- "/^v\\d+(\\.\\d+)+$/"
os:
- linux
- osx
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install git-lfs; fi
- curl -L http://bodge.borodust.org/files/install.sh | sh
- git lfs install && git lfs pull
- lisp install-testing-dist
script:
- >
lisp build-gamekit-system
$GAMEKIT_SYSTEM_NAME $GAMEKIT_APPLICATION_PACKAGE $GAMEKIT_APPLICATION_MAIN_CLASS
$TRAVIS_BUILD_DIR
$GAMEKIT_BUILD_DIR
before_deploy:
- mv "$GAMEKIT_BUILD_DIR/$GAMEKIT_SYSTEM_NAME.zip" $GAMEKIT_TARGET_PACKAGE
deploy:
provider: releases
api-key: $GITHUB_TOKEN
file: $GAMEKIT_TARGET_PACKAGE
skip_cleanup: true
overwrite: true
on:
tags: true
| 1,871 | Common Lisp | .l | 44 | 39.454545 | 698 | 0.794829 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 409cbec0c0827e839dc31ac1987135c509725fbf7cbb35ed3afbbb8ae6bdd01e | 39,656 | [
-1
] |
39,657 | .appveyor.yml | borodust_decent-game/.appveyor.yml | image:
- Visual Studio 2017
platform:
- x64
environment:
global:
GAMEKIT_SYSTEM_NAME: decent-game
GAMEKIT_APPLICATION_PACKAGE: decent-game
GAMEKIT_APPLICATION_MAIN_CLASS: decent-game
GAMEKIT_ARTIFACT: $(GAMEKIT_SYSTEM_NAME)-x86-64-windows-$(APPVEYOR_REPO_TAG_NAME).zip
GAMEKIT_BUILD_DIR: $(TMP)\$(GAMEKIT_SYSTEM_NAME)
skip_non_tags: true
branches:
only:
- master
- "/^v\\d+(\\.\\d+)+$/"
install:
- set PATH=C:\msys64\usr\bin\;%PATH%
- pacman --noconfirm -Syu
- pacman --noconfirm -S zip mingw-w64-x86_64-git-lfs
- sh -c "git lfs install && git lfs pull"
- sh -c "curl -L http://bodge.borodust.org/files/install.sh | sh"
- sh -c "$HOME/.bodge/bin/lisp install-testing-dist"
build_script:
- >
sh -c "$HOME/.bodge/bin/lisp build-gamekit-system
%GAMEKIT_SYSTEM_NAME% %GAMEKIT_APPLICATION_PACKAGE% %GAMEKIT_APPLICATION_MAIN_CLASS%
$(cygpath -u '%APPVEYOR_BUILD_FOLDER%')
$(cygpath -u '%GAMEKIT_BUILD_DIR%')"
- mv %GAMEKIT_BUILD_DIR%\%GAMEKIT_SYSTEM_NAME%.zip %GAMEKIT_ARTIFACT%
artifacts:
- path: "%GAMEKIT_ARTIFACT%"
name: release_archive
deploy:
provider: GitHub
release: $(APPVEYOR_REPO_TAG_NAME)
tag: $(APPVEYOR_REPO_TAG_NAME)
description: $(APPVEYOR_REPO_COMMIT_MESSAGE)
auth_token:
secure: Z5XWjDOBlCrmfz3SQAjnLKtdgI5B2b/owJhRPNWYGrI+qwVNbBc4cZiroBZReWP7
artifact: release_archive
force_update: true
draft: false
prerelease: false
on:
appveyor_repo_tag: true
| 1,471 | Common Lisp | .l | 46 | 28.565217 | 89 | 0.711864 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | ebd10a3c8cb3c08f3e4898994c61ebc0c7a400fafd2dbaa375e3f794d122c296 | 39,657 | [
-1
] |
39,696 | tiles.tsx | borodust_decent-game/assets/tld/test/tiles.tsx | <?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.2" tiledversion="1.3.3" name="tiles" tilewidth="8" tileheight="8" tilecount="576" columns="32">
<image source="tiles.png" width="256" height="144"/>
</tileset>
| 220 | Common Lisp | .l | 4 | 53.75 | 115 | 0.689815 | borodust/decent-game | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:45 AM (Europe/Amsterdam) | 4903be64f61f72f61f9dc2bb5ff12ccb24501c9ac5d70dcd4528d5a092af1e1a | 39,696 | [
-1
] |
39,715 | helper.lisp | hwa_lisp-helpers/hunchentoot-helper/helper.lisp | (in-package #:hunchentoot-helper)
;;
;;;; server starter
;;
(defparameter *server* nil)
(defparameter *hunchentoot-log-dir* #p"/tmp")
(defun start-webserver (&optional (port 5000))
(flet ((prefix-log-dir (log-file)
(format nil "~a/~a" *hunchentoot-log-dir* log-file)))
(let ((server
(make-instance 'hunchentoot:easy-acceptor
:port port
:access-log-destination (prefix-log-dir "hunchentoot.log")
:message-log-destination (prefix-log-dir "hunchentoot.log"))))
(setf *server* server)
(hunchentoot:start server))))
;;
;;;; handler definition helper
;;
;;
;; usage example
;;
;; (define-easy-json-handler (handler-delete-base-category
;; :uri "/dealer/delete-base-category"
;; :default-request-type :POST)
;; ((base-category-id :real-name "base-category" :parameter-type 'integer))
;; (action-delete-base-category base-category-id))
;;
;; handler-delete-base-category becomes name of handler, :uri and
;; :default-request-type are definition parameters of handler.
;; ((base-category-id)) are request params bindings for use in &body.
;; action-delete-base-category is defined elsewhere, and returns lisp object
;; that would be encoded as json response to be sent out.
(defmacro define-easy-json-handler (description lambda-list &body body)
(let ((but-last-expr (butlast body))
(last-expr (last body)))
`(hunchentoot:define-easy-handler ,description ,lambda-list
(setf (hunchentoot:content-type*) "application/json")
,@but-last-expr
(cl-json:encode-json-to-string ,@last-expr))))
| 1,696 | Common Lisp | .lisp | 40 | 37.4 | 88 | 0.654336 | hwa/lisp-helpers | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:54 AM (Europe/Amsterdam) | c475a902658517a31ebc78f7cfd4c51d004c6d23199bf907e0d9730f4c5c943f | 39,715 | [
-1
] |
39,716 | helper.lisp | hwa_lisp-helpers/cl-yaml-helper/helper.lisp | (in-package #:cl-yaml-helper)
(defun decode-yaml-from-file (yaml-file)
(cl-yaml:parse yaml-file))
(defgeneric encode-yaml-to-emitter (emitter object))
(defmethod encode-yaml-to-emitter (emitter (object (eql 'nil)))
(yaml.emitter:emit-object emitter object))
(defmethod encode-yaml-to-emitter (emitter (object list))
(yaml.emitter:emit-sequence (emitter)
(loop for el in object
do
(encode-yaml-to-emitter emitter el))))
(defmethod encode-yaml-to-emitter (emitter (object string))
(yaml.emitter:emit-object emitter object))
(defmethod encode-yaml-to-emitter (emitter (object vector))
(yaml.emitter:emit-sequence (emitter)
(loop for el across object
do
(encode-yaml-to-emitter emitter el))))
(defmethod encode-yaml-to-emitter (emitter (object hash-table))
(yaml.emitter:emit-mapping (emitter)
(loop for k being the hash-key using (hash-value v) of object
do
(encode-yaml-to-emitter emitter k)
(encode-yaml-to-emitter emitter v))))
(defmethod encode-yaml-to-emitter (emitter object)
(yaml.emitter:emit-object emitter object))
(defun encode-yaml-to-file (file object)
(with-open-file (stream file :direction :output :if-does-not-exist :create)
(yaml.emitter:with-emitter-to-stream
(emitter stream)
(yaml.emitter:emit-stream (emitter)
(yaml.emitter:emit-document (emitter)
(encode-yaml-to-emitter emitter object))))))
| 1,474 | Common Lisp | .lisp | 33 | 38.757576 | 77 | 0.70021 | hwa/lisp-helpers | 0 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:46:54 AM (Europe/Amsterdam) | b2f79fb8c6295f2c7425fc7cf20a7ee9bd9ce166fb3610b11a521036dd771141 | 39,716 | [
-1
] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.