summaryrefslogtreecommitdiff
path: root/apple-town-fair
diff options
context:
space:
mode:
Diffstat (limited to 'apple-town-fair')
-rw-r--r--apple-town-fair/assets.scm35
-rw-r--r--apple-town-fair/common.scm60
-rw-r--r--apple-town-fair/config.scm25
-rw-r--r--apple-town-fair/splash.scm95
4 files changed, 215 insertions, 0 deletions
diff --git a/apple-town-fair/assets.scm b/apple-town-fair/assets.scm
new file mode 100644
index 0000000..1f9b15e
--- /dev/null
+++ b/apple-town-fair/assets.scm
@@ -0,0 +1,35 @@
+;;; Copyright © 2022 David Thompson <davet@gnu.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+(define-module (apple-town-fair assets)
+ #:use-module (catbird asset)
+ #:export (monogram-font
+ chickadee-image))
+
+(define (scope-datadir file-name)
+ (let ((prefix (or (getenv "APPLE_TOWN_FAIR_DATADIR") (getcwd))))
+ (string-append prefix "/" file-name)))
+
+(define (font-file file-name)
+ (scope-datadir (string-append "assets/fonts/" file-name)))
+
+(define (image-file file-name)
+ (scope-datadir (string-append "assets/images/" file-name)))
+
+(define (audio-file file-name)
+ (scope-datadir (string-append "assets/audio/" file-name)))
+
+(define-font monogram-font (font-file "monogram_extended.ttf") 12)
+(define-image chickadee-image (image-file "chickadee.png"))
diff --git a/apple-town-fair/common.scm b/apple-town-fair/common.scm
new file mode 100644
index 0000000..5fe5bb3
--- /dev/null
+++ b/apple-town-fair/common.scm
@@ -0,0 +1,60 @@
+;;; Copyright © 2022 David Thompson <davet@gnu.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+(define-module (apple-town-fair common)
+ #:use-module (apple-town-fair config)
+ #:use-module (chickadee)
+ #:use-module (chickadee graphics color)
+ #:use-module (chickadee graphics path)
+ #:use-module (chickadee math vector)
+ #:use-module (chickadee scripting)
+ #:use-module (oop goops)
+ #:use-module (catbird scene)
+ #:use-module (catbird node)
+ #:use-module (catbird node-2d)
+ #:export (steps
+ full-screen-rectangle
+ fade-in
+ fade-out))
+
+(define (steps n)
+ (* n (current-timestep)))
+
+(define (full-screen-rectangle color)
+ (with-style ((fill-color color))
+ (fill
+ (rectangle (vec2 0.0 0.0) %game-width %game-height))))
+
+(define (black-alpha alpha)
+ (make-color 0.0 0.0 0.0 alpha))
+
+(define (fade scene start-alpha end-alpha duration)
+ (let ((bg (make <canvas>
+ #:rank 999
+ #:painter (full-screen-rectangle
+ (black-alpha start-alpha)))))
+ (attach-to scene bg)
+ (tween duration start-alpha end-alpha
+ (lambda (a)
+ (set! (painter bg)
+ (full-screen-rectangle
+ (black-alpha a)))))
+ (detach bg)))
+
+(define-method (fade-in (scene <scene>) duration)
+ (fade scene 1.0 0.0 duration))
+
+(define-method (fade-out (scene <scene>) duration)
+ (fade scene 0.0 1.0 duration))
diff --git a/apple-town-fair/config.scm b/apple-town-fair/config.scm
new file mode 100644
index 0000000..7bf7a5b
--- /dev/null
+++ b/apple-town-fair/config.scm
@@ -0,0 +1,25 @@
+;;; Copyright © 2022 David Thompson <davet@gnu.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+(define-module (apple-town-fair config)
+ #:export (%window-width
+ %window-height
+ %game-width
+ %game-height))
+
+(define %window-width 960)
+(define %window-height 720)
+(define %game-width 320)
+(define %game-height 240)
diff --git a/apple-town-fair/splash.scm b/apple-town-fair/splash.scm
new file mode 100644
index 0000000..8a1b0e3
--- /dev/null
+++ b/apple-town-fair/splash.scm
@@ -0,0 +1,95 @@
+;;; Copyright © 2022 David Thompson <davet@gnu.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+(define-module (apple-town-fair splash)
+ #:use-module (apple-town-fair assets)
+ #:use-module (apple-town-fair config)
+ #:use-module (apple-town-fair common)
+ #:use-module (chickadee graphics color)
+ #:use-module (chickadee graphics path)
+ #:use-module (chickadee math vector)
+ #:use-module (chickadee scripting)
+ #:use-module (oop goops)
+ #:use-module (catbird)
+ #:use-module (catbird camera)
+ #:use-module (catbird kernel)
+ #:use-module (catbird mode)
+ #:use-module (catbird node)
+ #:use-module (catbird node-2d)
+ #:use-module (catbird region)
+ #:use-module (catbird scene)
+ #:export (launch-game))
+
+(define-class <splash-mode> (<major-mode>))
+
+(define %text-color (rgb #x181425))
+(define %background-color white)
+
+(define-method (on-enter (mode <splash-mode>))
+ (let ((scene (parent mode)))
+ (attach-to scene
+ (make <canvas>
+ #:painter
+ (with-style ((fill-color %background-color))
+ (fill
+ (rectangle (vec2 0.0 0.0) %game-width %game-height))))
+ (make <sprite>
+ #:texture chickadee-image
+ #:position (vec2 (/ %game-width 2.0)
+ (/ %game-height 2.0))
+ #:origin (vec2 8.0 8.0)
+ #:scale (vec2 4.0 4.0))
+ (make <label>
+ #:rank 1
+ #:position (vec2 (/ %game-width 2.0) 70.5)
+ #:font monogram-font
+ #:color %text-color
+ #:align 'center
+ #:vertical-align 'center
+ #:text "Made with Chickadee")
+ (make <label>
+ #:rank 1
+ #:position (vec2 (/ %game-width 2.0) 50.5)
+ #:font monogram-font
+ #:color %text-color
+ #:align 'center
+ #:vertical-align 'center
+ #:text "https://dthompson.us/projects/chickadee.html"))
+ (run-script scene
+ (unless (getenv "SKIP_SPLASH")
+ (fade-in scene 1.0)
+ (sleep 1.0)
+ (fade-out scene 1.0))
+ (let ((new-scene (make <scene>))
+ (region (car (all-regions))))
+ ;;(replace-scene region (make-game-scene))
+ #t))))
+
+(define (launch-game)
+ (set! *random-state* (random-state-from-platform))
+ (run-catbird
+ (lambda ()
+ (let ((region (create-full-region))
+ (scene (make <scene>)))
+ (take-controller-focus 0 region)
+ (replace-scene region scene)
+ (replace-major-mode scene (make <splash-mode>))
+ (set! (camera region)
+ (make <camera-2d>
+ #:width %game-width
+ #:height %game-height))))
+ #:width %window-width
+ #:height %window-height
+ #:title "Apple Town Fair"))