Skip to content

Commit

Permalink
Merge pull request #5 from metayan/continue-refactoring
Browse files Browse the repository at this point in the history
Continue refactoring
  • Loading branch information
TatriX authored Jan 8, 2022
2 parents 865902d + bfa61c4 commit f06f635
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
15 changes: 8 additions & 7 deletions 14/tutorial-14.lisp → 14-animated-sprites-and-vsync.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(defpackage #:sdl2-tutorial-14
(:use :common-lisp)
(:export :main))
(defpackage #:sdl2-tutorial-14-animated-sprites-and-vsync
(:use :cl)
(:export :run)
(:import-from :sdl2-tutorial-utils :asset-pathname))

(in-package :sdl2-tutorial-14)
(in-package #:sdl2-tutorial-14-animated-sprites-and-vsync)

(defparameter *screen-width* 640)
(defparameter *screen-height* 480)
Expand Down Expand Up @@ -54,7 +55,7 @@
(defmacro with-window-renderer ((window renderer) &body body)
`(sdl2:with-init (:video)
(sdl2:with-window (,window
:title "SDL2 Tutorial"
:title "SDL2 Tutorial 14"
:w *screen-width*
:h *screen-height*
:flags '(:shown))
Expand All @@ -70,10 +71,10 @@
(defmacro clamp-decf (x delta)
`(setf ,x (clamp (- ,x ,delta))))

(defun main()
(defun run ()
(with-window-renderer (window renderer)
(sdl2-image:init '(:png))
(let ((spritesheet-tex (load-texture-from-file renderer "14/character.png"))
(let ((spritesheet-tex (load-texture-from-file renderer (asset-pathname "assets/14/character.png")))
(clip (sdl2:make-rect 0 0 64 96))
(sprite-frames 4)
(current-sprite-frame 0)
Expand Down
15 changes: 8 additions & 7 deletions 15/tutorial-15.lisp → 15-rotation-and-flipping.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(defpackage #:sdl2-tutorial-15
(:use :common-lisp)
(:export :main))
(defpackage #:sdl2-tutorial-15-rotation-and-flipping
(:use :cl)
(:export :run)
(:import-from :sdl2-tutorial-utils :asset-pathname))

(in-package :sdl2-tutorial-15)
(in-package #:sdl2-tutorial-15-rotation-and-flipping)

(defparameter *screen-width* 640)
(defparameter *screen-height* 480)
Expand Down Expand Up @@ -51,17 +52,17 @@
(defmacro with-window-renderer ((window renderer) &body body)
`(sdl2:with-init (:video)
(sdl2:with-window (,window
:title "SDL2 Tutorial"
:title "SDL2 Tutorial 15"
:w *screen-width*
:h *screen-height*
:flags '(:shown))
(sdl2:with-renderer (,renderer ,window :index -1 :flags '(:accelerated))
,@body))))

(defun main()
(defun run ()
(with-window-renderer (window renderer)
(sdl2-image:init '(:png))
(let ((texture (load-texture-from-file renderer "15/arrow.png"))
(let ((texture (load-texture-from-file renderer (asset-pathname "assets/15/arrow.png")))
(flip :none)
(degrees 0)
(delta 60))
Expand Down
25 changes: 16 additions & 9 deletions 16/tutorial-16.lisp → 16-true-type-fonts.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(defpackage #:sdl2-tutorial-16
(:use :common-lisp)
(:export :main))
(defpackage #:sdl2-tutorial-16-true-type-fonts
(:use :cl)
(:export :run)
(:import-from :sdl2-tutorial-utils :asset-pathname))

(in-package :sdl2-tutorial-16)
(in-package #:sdl2-tutorial-16-true-type-fonts)

(defparameter *screen-width* 640)
(defparameter *screen-height* 480)
Expand All @@ -23,6 +24,10 @@
:accessor tex-texture
:initform nil)))

(defun free-tex (tex)
(with-slots (texture) tex
(sdl2:destroy-texture texture)))

(defun load-texture-from-file (renderer filename)
(let ((tex (make-instance 'tex :renderer renderer)))
(with-slots (renderer texture width height) tex
Expand All @@ -46,7 +51,7 @@
(defun set-color (tex r g b)
(sdl2:set-texture-color-mod (tex-texture tex) r g b))

(defun render (tex x y &key clip angle center flip)
(defun render (tex x y &key clip angle center (flip :none))
(with-slots (renderer texture width height) tex
(sdl2:render-copy-ex renderer
texture
Expand All @@ -62,18 +67,18 @@
(defmacro with-window-renderer ((window renderer) &body body)
`(sdl2:with-init (:video)
(sdl2:with-window (,window
:title "SDL2 Tutorial"
:title "SDL2 Tutorial 16"
:w *screen-width*
:h *screen-height*
:flags '(:shown))
(sdl2:with-renderer (,renderer ,window :index -1 :flags '(:accelerated))
,@body))))

(defun main()
(defun run ()
(with-window-renderer (window renderer)
(sdl2-image:init '(:png))
(sdl2-ttf:init)
(setf *font* (sdl2-ttf:open-font "16/Pacifico.ttf" 28))
(setf *font* (sdl2-ttf:open-font (asset-pathname "assets/16/Pacifico.ttf") 28))
(let ((texture (load-texture-from-text renderer "The quick brown fox jumps over the lazy dog")))
(sdl2:with-event-loop (:method :poll)
(:quit () t)
Expand All @@ -83,6 +88,8 @@
(render texture
(round (/ (- *screen-width* (tex-width texture)) 2))
(round (/ (- *screen-height* (tex-height texture)) 2)))
(sdl2:render-present renderer))))
(sdl2:render-present renderer)))
;; clean up
(free-tex texture))
(sdl2-ttf:quit)
(sdl2-image:quit)))
File renamed without changes
File renamed without changes
File renamed without changes.
6 changes: 3 additions & 3 deletions sdl2-tutorial.asd
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
(:file "11-clip-rendering-and-sprite-sheets")
(:file "12-color-modulation")
(:file "13-alpha-blending")
(:file "14/tutorial-14")
(:file "15/tutorial-15")
(:file "16/tutorial-16"))
(:file "14-animated-sprites-and-vsync")
(:file "15-rotation-and-flipping")
(:file "16-true-type-fonts"))
:in-order-to ((test-op (test-op "sdl2-tutorial/tests"))))


Expand Down

0 comments on commit f06f635

Please sign in to comment.