;;; Lisparuga ;;; Copyright © 2020 David Thompson ;;; ;;; Lisparuga 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. ;;; ;;; Lisparuga 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 Lisparuga. If not, see . ;;; Commentary: ;; ;; Game container. Handles all the state, logic, and rendering for ;; the game itself. ;; ;;; Code: (define-module (lisparuga game) #:use-module (chickadee) #:use-module (chickadee math) #:use-module (chickadee math easings) #:use-module (chickadee math rect) #:use-module (chickadee math vector) #:use-module (chickadee render color) #:use-module (chickadee render particles) #:use-module (chickadee render texture) #:use-module (chickadee scripting) #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (lisparuga actor) #:use-module (lisparuga asset) #:use-module (lisparuga bullets) #:use-module (lisparuga config) #:use-module (lisparuga enemy) #:use-module (lisparuga node) #:use-module (lisparuga node-2d) #:use-module (lisparuga player) #:use-module (oop goops) #:export ( steer-player start-player-shooting stop-player-shooting toggle-player-polarity fire-player-homing-missiles spawn-enemies start-stage stop-stage game-over? complete?)) ;;(define-asset clouds (load-image (scope-asset "images/clouds.png"))) (define-asset player-bullet-atlas (load-tile-atlas (scope-asset "images/player-bullets.png") 16 16)) (define-asset enemy-bullet-atlas (load-tile-atlas (scope-asset "images/enemy-bullets.png") 24 24)) (define-asset explosion-texture (load-image (scope-asset "images/explosion.png"))) ;; nodes needed: ;; scrolling background (define-class () (player-control? #:accessor player-control? #:init-value #f) (complete? #:accessor complete? #:init-value #f) (skip-tutorial? #:accessor skip-tutorial? #:init-value #f) (stage-script #:accessor stage-script #:init-value #f)) (define-method (reset (game )) (set! (player-control? game) #f) (set! (complete? game) #f) (reset (& game player)) (for-each detach (children (& game enemies))) (let ((battle-report (& game battle-report))) (and battle-report (detach battle-report)))) (define-method (initialize (game ) initargs) (next-method) (set! (views game) ;; Game happens on a 160x240 pixel screen. (list (make #:camera (make #:width 160 #:height 240) #:area (make-rect 80 0 160 240) #:clear-color (make-color 0.0 0.0 0.0 1.0))))) (define-method (on-boot (game )) (let* ((player-bullets (make #:name 'player-bullets #:rank 2 #:capacity 500 #:texture-atlas player-bullet-atlas)) (player (make-player player-bullets)) (enemy-bullets (make #:name 'enemy-bullets #:rank 5 #:capacity 1000 #:texture-atlas enemy-bullet-atlas)) (explosions (make #:name 'explosions #:rank 3 #:particles (make-particles 1000 #:texture (asset-ref explosion-texture) #:end-color (make-color 1.0 1.0 1.0 0.0) #:speed-range (vec2 0.5 5.0) #:lifetime 12))) (ui (make #:name 'ui #:rank 999))) (set! (rank player) 1) (attach-to game ;; (make ;; #:name 'clouds ;; #:rank 0 ;; #:texture clouds) player player-bullets (make #:name 'enemies #:rank 4) explosions enemy-bullets ui) ;; Setup UI elements ;; TODO: Move this out of here. (attach-to ui (make