diff options
author | Ricardo Wurmus <rekado@elephly.net> | 2019-07-12 23:07:32 +0200 |
---|---|---|
committer | Ricardo Wurmus <rekado@elephly.net> | 2019-07-12 23:07:32 +0200 |
commit | c8de1a94ed00d8c6f304c2edb73e3a2419b0ce9b (patch) | |
tree | c7f7db5cd355f9f590af8fbb61e6a4b2db665fab | |
parent | bc3d81c004e7edfc2ea7449968eaaf44c8806b88 (diff) |
Update to Chickadee 0.4.0.
* characters/lorenzo.scm (default-shader): Remove.
(lorenzo): Use #:tint instead of #:shader; hide shadow when dead.
* engine/node-2d.scm (<sprite>): Replace SHADER field with TINT.
(draw <sprite>): Remove SHADER case.
* engine/node.scm (run-node): Use RUN-GAME instead of RUN-GAME/SDL.
* scenes/death.scm (ghost-shader): Remove.
(populate): Use DEAD? keyword instead of SHADER.
-rw-r--r-- | characters/lorenzo.scm | 66 | ||||
-rw-r--r-- | engine/node-2d.scm | 14 | ||||
-rw-r--r-- | engine/node.scm | 49 | ||||
-rw-r--r-- | scenes/death.scm | 42 |
4 files changed, 51 insertions, 120 deletions
diff --git a/characters/lorenzo.scm b/characters/lorenzo.scm index 8a59e72..8c8971f 100644 --- a/characters/lorenzo.scm +++ b/characters/lorenzo.scm @@ -1,5 +1,5 @@ ;;; The Inevitable Game -;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net> +;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net> ;;; ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as @@ -18,7 +18,6 @@ (define-module (characters lorenzo) #:use-module (chickadee render texture) #:use-module (chickadee render color) - #:use-module (chickadee render shader) #:use-module (chickadee math rect) #:use-module (chickadee math vector) #:use-module (engine assets) @@ -40,34 +39,6 @@ player-atlas)) -;; Copied from (chickadee render sprite) -(define default-shader - (delay - (strings->shader - " -#version 130 - -in vec2 position; -in vec2 tex; -out vec2 frag_tex; -uniform mat4 mvp; - -void main(void) { - frag_tex = tex; - gl_Position = mvp * vec4(position.xy, 0.0, 1.0); -} -" - " -#version 130 - -in vec2 frag_tex; -uniform sampler2D color_texture; - -void main (void) { - gl_FragColor = texture2D(color_texture, frag_tex); -} -"))) - (define-class <player> (<character>) (previous-key-presses #:accessor previous-key-presses #:init-form (list)) (selecting-message? #:accessor selecting-message? #:init-form #f) @@ -84,7 +55,7 @@ void main (void) { (define* (lorenzo #:key (position (vec2 0 0)) - (shader default-shader)) + (dead? #f)) (make <player> #:name 'player #:position position @@ -93,7 +64,9 @@ void main (void) { (make <animated-sprite> #:name 'sprite #:atlas player-atlas - #:shader shader + #:tint (if dead? + (make-color 1.0 1.0 1.0 0.5) + (make-color 1.0 1.0 1.0 1.0)) #:animations '((idle-right . #(24 24 24 24 24 39 39 39 39 39)) (idle-left . #(32 32 32 32 32 31 31 31 31 31)) (idle-front . #(8 8 8 8 8 0 0 0 0 0)) @@ -104,17 +77,18 @@ void main (void) { (down . #(9 8 10 8))) #:current-animation 'idle-front #:frame-duration 10) - ;; Simple player shadow. This should better be done - ;; with a single ellipse shader. - (let ((color (make-color 0 0 0 0.2))) - (map (lambda (n x w) - (make <filled-rect> - #:region (make-rect 0.0 0.0 w 1.0) - #:position (vec2 x (- 2 n)) - #:color color)) - ;; position in the stack - (iota 5) - ;; x offsets - (list 12 10 8 10 12) - ;; widths - (list 8 12 16 12 8)))))) + (if dead? '() + ;; Simple player shadow. This should better be done + ;; with a single ellipse shader. + (let ((color (make-color 0 0 0 0.2))) + (map (lambda (n x w) + (make <filled-rect> + #:region (make-rect 0.0 0.0 w 1.0) + #:position (vec2 x (- 2 n)) + #:color color)) + ;; position in the stack + (iota 5) + ;; x offsets + (list 12 10 8 10 12) + ;; widths + (list 8 12 16 12 8))))))) diff --git a/engine/node-2d.scm b/engine/node-2d.scm index 163a798..3de1597 100644 --- a/engine/node-2d.scm +++ b/engine/node-2d.scm @@ -303,17 +303,13 @@ (define-class <sprite> (<node-2d>) (texture #:accessor texture #:init-keyword #:texture) - (shader #:accessor shader #:init-keyword #:shader #:init-form #f)) + (tint #:accessor tint #:init-keyword #:tint #:init-form white)) (define-method (draw (sprite <sprite>) alpha) - (if (shader sprite) - (draw-sprite* (asset-ref (texture sprite)) - (texture-gl-rect (texture sprite)) - (world-matrix sprite) - #:shader (force (shader sprite))) - (draw-sprite* (asset-ref (texture sprite)) - (texture-gl-rect (texture sprite)) - (world-matrix sprite)))) + (draw-sprite* (asset-ref (texture sprite)) + (texture-gl-rect (texture sprite)) + (world-matrix sprite) + #:tint (tint sprite))) (define-class <animated-sprite> (<sprite>) (atlas #:accessor atlas #:init-keyword #:atlas) diff --git a/engine/node.scm b/engine/node.scm index 5f2434b..b62d6e4 100644 --- a/engine/node.scm +++ b/engine/node.scm @@ -1,6 +1,6 @@ ;;; Lisp Game Jam 2018 ;;; Copyright © 2018 David Thompson <davet@gnu.org> -;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net> +;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net> ;;; ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as @@ -17,6 +17,7 @@ ;;; <http://www.gnu.org/licenses/>. (define-module (engine node) + #:use-module (chickadee) #:use-module (chickadee sdl) #:use-module (chickadee math matrix) #:use-module (chickadee math quaternion) @@ -229,26 +230,26 @@ one." (window-height 480) window-fullscreen? (update-hz 60)) - (run-game/sdl #:window-title window-title - #:window-width window-width - #:window-height window-height - #:window-fullscreen? window-fullscreen? - #:update-hz update-hz - #:load - (lambda () - (set-root-node! (make-root-node))) - #:draw - (cut draw/children *root-node* <>) - #:update - (cut update/children *root-node* <>) - #:quit - (lambda () - (visit-while (cut on-quit <>) *root-node*)) - #:key-press - (lambda (key sc mods repeat?) - (visit-while (cut on-key-press <> key mods repeat?) - *root-node*)) - #:text-input - (lambda (text) - (visit-while (cut on-text-edit <> text) - *root-node*)))) + (run-game #:window-title window-title + #:window-width window-width + #:window-height window-height + #:window-fullscreen? window-fullscreen? + #:update-hz update-hz + #:load + (lambda () + (set-root-node! (make-root-node))) + #:draw + (cut draw/children *root-node* <>) + #:update + (cut update/children *root-node* <>) + #:quit + (lambda () + (visit-while (cut on-quit <>) *root-node*)) + #:key-press + (lambda (key sc mods repeat?) + (visit-while (cut on-key-press <> key mods repeat?) + *root-node*)) + #:text-input + (lambda (text) + (visit-while (cut on-text-edit <> text) + *root-node*)))) diff --git a/scenes/death.scm b/scenes/death.scm index 301db14..07e3b8c 100644 --- a/scenes/death.scm +++ b/scenes/death.scm @@ -24,7 +24,6 @@ #:use-module (chickadee render color) #:use-module (chickadee render font) #:use-module (chickadee render texture) - #:use-module (chickadee render shader) #:use-module (chickadee render tiled) #:use-module (chickadee scripting) #:use-module (engine assets) @@ -125,45 +124,6 @@ quite short.")) (set! *random-state* (random-state-from-platform)) -;; This shader renders the texture after blending each pixel with a -;; 0.1 opacity pixel, thereby rendering everything with increased -;; transparency. -(define ghost-shader - (delay - (strings->shader - " -#version 130 - -in vec2 position; -in vec2 tex; -out vec2 frag_tex; -uniform mat4 mvp; - -void main(void) { - frag_tex = tex; - gl_Position = mvp * vec4(position.xy, 0.0, 1.0); -} -" - " -#version 130 - -in vec2 frag_tex; -uniform sampler2D color_texture; - -void main (void) { - vec4 original = texture2D(color_texture, frag_tex); - vec4 g; - - g = vec4(1, 1, 1, 0.1); - g = mix(g, original, 0.5); - gl_FragColor = vec4(original.rgb, min(g.a,original.a)); - if (gl_FragColor.a < 0.5) - { - discard; - } -} -"))) - (define-method (populate (death <death>)) (cons (let* ((text (list-ref texts (random (length texts)))) @@ -191,7 +151,7 @@ void main (void) { #:region (make-rect 0.0 0.0 %width %height) #:color (make-color 0.125 0.09 0.161 0)) (let ((player (lorenzo #:position (vec2 40.0 70.0) - #:shader ghost-shader))) + #:dead? #t))) (set! (visible? player) #f) (set! (walk-speed player) 0.3) player) |