(in-package :uxul-world)
+(defparameter *zoom-ash* -1)
+(defmacro zoom-trans (x) `(ash ,x *zoom-ash*))
+
(defparameter *graphics-table* nil)
;; the functions may assume that the contents of a graphics-file -
;; graphics with an equivalent path any time you load an image.
(defclass animation (xy-coordinates)
- ((images :initarg :images
- :initform (make-array (list 0) :element-type 'sdl:surface)
- :accessor images
-; :type (simple-array 'sdl:surface (*))
- :documentation "Array with the images")
+ (
+;; (images :initarg :images
+;; :initform (make-array (list 0) :element-type 'sdl:surface)
+;; :accessor images
+;; ; :type (simple-array 'sdl:surface (*))
+;; :documentation "Array with the images")
+ (images-2x :initarg :images-2x
+ :initform (make-array (list 0) :element-type 'sdl:surface)
+ :accessor images-2x
+ :documentation "Array of double-sized images")
+ (images-1x :initarg :images-1x
+ :initform (make-array (list 0) :element-type 'sdl:surface)
+ :accessor images-1x
+ :documentation "Array of normal-sized images")
+ (images-.5x :initarg :images-.5x
+ :initform (make-array (list 0) :element-type 'sdl:surface)
+ :accessor images-.5x
+ :documentation "Array of half-sized images")
+ (images-.25x :initarg :images-.25x
+ :initform (make-array (list 0) :element-type 'sdl:surface)
+ :accessor images-.25x
+ :documentation "Array of quarter-sized images")
(sprite-image-number :initform 0
:initarg :sprite-image-number
:accessor sprite-image-number
animations. For any animation created from a file by the api from
below, this will refer to an animation in the *graphics-table*." )))
+(defmethod images ((obj animation))
+ (cond
+ ((= *zoom-ash* 0)
+ (images-2x obj))
+ ((= *zoom-ash* -1)
+ (images-1x obj))
+ ((= *zoom-ash* -2)
+ (images-.5x obj))
+ ((= *zoom-ash* -3)
+ (images-.25x obj))))
+
+
(defmethod draw ((obj animation))
(when (not (<= (sprite-delay obj) 0)) ;<=, because -a means "paused,
;but a is the delay when
(setf (sprite-image-number obj) (mod (+ 1 (sprite-image-number obj)) (length (images obj))))))
(when (visible obj)
(sdl:draw-surface-at-* (elt (images obj) (sprite-image-number obj))
- (+ *current-translation-x* (round (x obj)))
- (+ *current-translation-y* (round (y obj))))))
+ (zoom-trans (+ *current-translation-x* (round (x obj))))
+ (zoom-trans (+ *current-translation-y* (round (y obj)))))))
;additional methods to make life easier
(defmethod pause ((obj animation))
"Create an animation from the list of animation-names given in the
images-variable."
(make-instance 'animation
- :images (mapcar
- #'(lambda (x)
- (sdl:convert-surface :surface (sdl-image:load-image
- x
- :image-type :PNG :alpha 1 )))
- image-list)
+ :images-2x (mapcar
+ #'(lambda (x)
+ (sdl:convert-surface :surface (sdl-image:load-image
+ (car x)
+ :image-type :PNG :alpha 1 )))
+ image-list)
+ :images-1x (mapcar
+ #'(lambda (x)
+ (sdl:convert-surface :surface (sdl-image:load-image
+ (cadr x)
+ :image-type :PNG :alpha 1 )))
+ image-list)
+ :images-.5x (mapcar
+ #'(lambda (x)
+ (sdl:convert-surface :surface (sdl-image:load-image
+ (caddr x)
+ :image-type :PNG :alpha 1 )))
+ image-list)
+ :images-.25x (mapcar
+ #'(lambda (x)
+ (sdl:convert-surface :surface (sdl-image:load-image
+ (cadddr x)
+ :image-type :PNG :alpha 1 )))
+ image-list)
:sprite-delay frame-skip))
\ No newline at end of file
(in-package :uxul-world)
(defun draw-background (x-trans y-trans)
- (let ((ani3 (car (images (make-animation 0 |background_test_layer_3|))))
- (ani2 (car (images (make-animation 0 |background_test_layer_2|)))))
+ ;; (let ((ani3 (car (images (make-animation 0 |background_test_layer_3|))))
+;; (ani2 (car (images (make-animation 0 |background_test_layer_2|)))))
- (loop for i from -1 to 16
- do (loop for j from -1 to 12
- do (progn
- (sdl:draw-surface-at-* ani2
- (+ (* i 64) (round
- (mod (/ x-trans 4) 64)))
- (+ (* j 64) (round
- (mod (/ y-trans 4) 64)))))))
- (loop for i from -1 to 16
- do (loop for j from -1 to 12
- do
- (sdl:draw-surface-at-* ani3
- (+ (* 64 i) (round
- (mod (/ x-trans 2) 64)))
- (+ (* 64 j) (round
- (mod (/ y-trans 2) 64))))))))
+;; (loop for i from -1 to 16
+;; do (loop for j from -1 to 12
+;; do (progn
+;; (sdl:draw-surface-at-* ani2
+;; (+ (* i 64) (round
+;; (mod (/ x-trans 4) 64)))
+;; (+ (* j 64) (round
+;; (mod (/ y-trans 4) 64)))))))
+;; (loop for i from -1 to 16
+;; do (loop for j from -1 to 12
+;; do
+;; (sdl:draw-surface-at-* ani3
+;; (+ (* 64 i) (round
+;; (mod (/ x-trans 2) 64)))
+;; (+ (* 64 j) (round
+;; (mod (/ y-trans 2) 64)))))))
+ )
(defmethod draw ((obj room))
(let ((*current-translation-x*
(- 800 (width obj)))
(T
(- 400 (x (graphic-centralizer obj)))))|#
- (- 400 (x (graphic-centralizer obj)))
+ (- (ash 400 (- *zoom-ash*)) (x (graphic-centralizer obj)))
)
(*current-translation-y*
#|(cond
(- 600 (height obj)))
(T
(- 300 (y (graphic-centralizer obj)))))|#
- (- 300 (y (graphic-centralizer obj)))
+ (- (ash 300 (- *zoom-ash*)) (y (graphic-centralizer obj)))
))
(draw-background *current-translation-x* *current-translation-y*)
(dolist (image (get-objects obj 'uxul-world::game-object))
(defun si (var val)
(setf (symbol-value (intern var)) val))
-(defun init-file (file)
- "Load a file into a Variable. Access with |filename| (without .png
-and path)."
- (si (pathname-name file)
- (with-open-file (in file :element-type '(unsigned-byte 8))
- (let* ((length (file-length in))
- (content (make-array (list length)
- :element-type '(unsigned-byte 8)
- :adjustable nil)))
- (read-sequence content in)
- content))))
-
-(defun file-relevant-p (file)
+
+(defun stretch-image (x y img)
+ "Call ImageMagick to resize that file to 64x64."
+ (lisp-magick:with-magick-wand (mywand)
+ (lisp-magick::magick-read-image-blob mywand img)
+ (lisp-magick::magick-resize-image mywand x y #x00000000 1d0)
+ (lisp-magick::magick-set-format mywand "png")
+ (lisp-magick::magick-get-image-blob mywand)))
+
+(defun ash-sized-image (img a)
+ "Calculate an image of half of the size."
+ (lisp-magick:with-magick-wand (mywand)
+ (lisp-magick::magick-read-image-blob mywand img)
+ (let
+ ((w (lisp-magick::magick-get-image-width mywand))
+ (h (lisp-magick::magick-get-image-height mywand)))
+ (lisp-magick::magick-resize-image mywand
+ (max 1 (floor (/ w a))) (max 1 (floor (/ h a))) ;; no ash here ...
+ #x00000000 1d0)
+ (lisp-magick::magick-set-format mywand "png")
+ (lisp-magick::magick-get-image-blob mywand))))
+
+(defun all-sizes (img)
+ (list img
+ (ash-sized-image img 2)
+ (ash-sized-image img 4)
+ (ash-sized-image img 8)))
+
+
+;; (defun init-file (file)
+;; "Load a file into a Variable. Access with |filename| (without .png
+;; and path)."
+;; (si (pathname-name file)
+;; (stretched-image
+;; (with-open-file (in file :element-type '(unsigned-byte 8))
+;; (let* ((length (file-length in))
+;; (content (make-array (list length)
+;; :element-type '(unsigned-byte 8)
+;; :adjustable nil)))
+;; (read-sequence content in)
+;; content)))))
+
+(defun init-png-file (file)
+ "Load an image file into a Variable. Set |filename| (without .png
+and path) to a list with all sizes of that image."
+ (si (pathname-name file)
+ (all-sizes
+ (with-open-file (in file :element-type '(unsigned-byte 8))
+ (let* ((length (file-length in))
+ (content (make-array (list length)
+ :element-type '(unsigned-byte 8)
+ :adjustable nil)))
+ (read-sequence content in)
+ content)))))
+
+(defun png-p (file)
"Is the file relevant for initialization? So far only .png-files are
relevant."
(string= (pathname-type file) "png"))
-(defun init-files ()
- "Load the relevant files into variables"
+(defun init-png-files ()
(cl-fad:walk-directory
(asdf:component-pathname (asdf:find-system :uxul-world))
- #'init-file :test #'file-relevant-p))
+ #'init-png-file :test #'png-p))
+
+(defun init-files ()
+ "Load the relevant files into variables"
+ (init-png-files))
(init-files)
\ No newline at end of file
(defun old-draw-rectangle (obj &key (r 0) (g 0) (b 0))
- (sdl:draw-rectangle-* (+ *current-translation-x* (x obj))
- (+ *current-translation-y* (y obj))
- (width obj)
- (height obj)
+ (declare (type game-object obj))
+ (sdl:draw-rectangle-* (zoom-trans (+ *current-translation-x* (x obj)))
+ (zoom-trans (+ *current-translation-y* (y obj)))
+ (zoom-trans (width obj))
+ (zoom-trans (height obj))
:color (sdl:color :r r :g g :b b)))
((animation-translation :initarg :animation-translation
:accessor animation-translation
:initform (make-xy 0 0)
- :documentation "The translation of the animation")
+ :documentation "The translation of the
+ animation (in double zoom).")
(animation :initarg :animation
:accessor animation
:documentation "The animation of this object")
(+ (y obj) (height obj) (y bounds))
(- *current-translation-x*)
(- *current-translation-y*)
- (- +screen-width+ *current-translation-x*)
- (- +screen-height+ *current-translation-y*))
- T)))
+ (- (ash +screen-width+ (- *zoom-ash*)) *current-translation-x*)
+ (- (ash +screen-height+ (- *zoom-ash*)) *current-translation-y*))
+ T))
+)
"Start the Game: Call room-function for getting the room-object to
run. Music is ignored so far. 15-fps makes only every second frame be
drawn (for very slow computers)"
+ (sdl:set-video-driver "directx")
(sdl:with-init (sdl:sdl-init-video sdl:sdl-init-audio)
(sdl:window +screen-width+ +screen-height+
:title-caption "Uxul World"
(cond
((sdl:key= key :SDL-KEY-ESCAPE)
(sdl:push-quit-event))
+ ((sdl:key= key :SDL-KEY-O)
+ (setf *zoom-ash*
+ (max -3 (1- *zoom-ash*))))
+ ((sdl:key= key :SDL-KEY-I)
+ (setf *zoom-ash*
+ (min 0 (1+ *zoom-ash*))))
(T
(on-key-down *current-room* key))))
(:key-up-event (:key key)
--- /dev/null
+;; Copyright 2010 Christoph Senjak\r
+\r
+(in-package :uxul-world)\r
+\r
+;; "Binding" for the "convert"-Program\r
+\r
+(defparameter *convert* #P"C:\\Program Files (x86)\\ImageMagick-6.6.2-Q16\\convert.exe")\r
+\r
+(defun run-convert (arguments in)\r
+ "Return output of convert"\r
+ (let* ((p (sb-ext:run-program *convert* arguments\r
+ :wait nil\r
+ :input :stream\r
+ :output :stream))\r
+ (pin (sb-ext:process-input p))\r
+ (pou (sb-ext:process-output p))\r
+ (ret '()))\r
+ (loop for byte across in do\r
+ (progn\r
+ (format t "doing~%")\r
+ (write-byte byte pin)\r
+ (loop while (listen pou) do\r
+ ;; this read should never fail and never be eof\r
+ (format t "reading 1~%")\r
+ (push (read-byte pou) ret))))\r
+ (format t "finishing out, closing~%")\r
+ (finish-output pin)\r
+ (close pin)\r
+ (let ((c 0))\r
+ (loop while (setf c (read-byte pou nil nil)) do\r
+ (format t "reading 2~%")\r
+ (push c ret)))\r
+ ret))\r
+\r
+(defun resize-image (bytes x y)\r
+ (run-convert (list "-scale" (format nil "~dx~d" x y) "-" "-") bytes))
\ No newline at end of file
:version "No Release Yet"
:author "Christoph Senjak <firstName.secondName at googlemail.com>"
:license "Copyright 2009 Christoph Senjak."
- :depends-on (#:lispbuilder-sdl #:closer-mop
+ :depends-on (#:lispbuilder-sdl #:lisp-magick
+ #:closer-mop
#:cl-fad
#:lispbuilder-sdl-image)
:components ((:file "uxul-world")