Removed some boilerplate.
[uxul-world.git] / animation.lisp
index 20fce5b..f2825aa 100755 (executable)
@@ -1,6 +1,6 @@
-;;; Copyright 2009 Christoph Senjak
+;;; Copyright 2009-2011 Christoph Senjak
 
-;; Basic definitions for animations. Needs lispbuilder-sdl.
+;; Basic definitions for animations.
 
 (in-package :uxul-world)
 
 ;; 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")
+   (full-widths :initarg :full-widths
+               :initform (make-array (list 0))
+               :accessor full-widths
+               :documentation "Widths of images")
+   (full-heights :initarg :full-heights
+               :initform (make-array (list 0))
+               :accessor full-heights
+               :documentation "Heights of images")
+   (images :initarg :images
+          :initform (make-array (list 0))
+          :accessor images
+          :documentation "Array of images")
    (sprite-image-number :initform 0
                        :initarg :sprite-image-number
                        :accessor sprite-image-number
@@ -65,9 +78,11 @@ below, this will refer to an animation in the *graphics-table*." )))
       (setf (already-jumped obj) 0)
       (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))))))
+    (make-quad (elt (images obj) (sprite-image-number obj))
+              (round (x obj))
+              (round (y obj))
+              (elt (full-widths obj) (sprite-image-number obj))
+              (elt (full-heights obj) (sprite-image-number obj)))))
 
 ;additional methods to make life easier
 (defmethod pause ((obj animation))
@@ -94,28 +109,13 @@ below, this will refer to an animation in the *graphics-table*." )))
   "rewind the animation"
   (setf (slot-value obj 'sprite-image-number) 0))
 
-#|(defun load-png-image (filename)
-  (sdl-image:load-image (gethash filename *file-table*) :image-type :PNG :alpha 1 )) ;; :alpha t))
-
-(defun hashed-load-image (filename)
-  "loads an image by its filename, if it wasnt loaded yet. returns a
-reference, if the current filename already exists."
-  (let ((ret (gethash filename *graphics-table* nil)))
-    (cond
-      (ret ret)
-      (T
-       (setf ret (load-png-image filename))
-       (setf (gethash filename *graphics-table*) ret)
-       ret))))|#
-
 (defun make-animation (frame-skip &rest image-list)
   "Create an animation from the list of animation-names given in the
 images-variable."
+  ;(format t "make-animation is being called~%")
   (make-instance 'animation
-                :images (mapcar
-                         #'(lambda (x)
-                             (sdl:convert-surface :surface (sdl-image:load-image
-                              x
-                              :image-type :PNG :alpha 1 )))
+                :full-widths (mapcar #'bmp-width image-list)
+                :full-heights (mapcar #'bmp-height image-list)
+                :images (mapcar #'load-bmp-blob-into-texture
                                 image-list)
                 :sprite-delay frame-skip))
\ No newline at end of file