;;; The Inevitable Game ;;; Copyright © 2018 Ricardo Wurmus ;;; ;;; 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 ;;; . (define-module (characters) #:use-module (chickadee math rect) #:use-module (chickadee math vector) #:use-module (chickadee render color) #:use-module (chickadee render font) #:use-module (chickadee render shapes) #:use-module (chickadee render texture) #:use-module (chickadee render tiled) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (ice-9 match) #:use-module (engine assets) #:use-module (engine node) #:use-module (engine node-2d) #:use-module (oop goops) #:export ( conversations accepted-messages speaking? velocity walk-speed direction hitbox load-atlas walk)) (define-class () (conversations #:accessor conversations #:init-keyword #:conversations) (accepted-messages #:accessor accepted-messages #:init-form '((hello "Hello there!"))) (speaking? #:accessor speaking? #:init-form #f) (velocity #:getter velocity #:init-form (vec2 0.0 0.0)) (walk-speed #:accessor walk-speed #:init-form 0.8) (direction #:accessor direction #:init-form '(idle)) (hitbox #:getter hitbox #:init-form (make-rect 8.0 0.0 16.0 16.0))) (define (load-atlas file-name tile-width tile-height) (split-texture (load-image file-name) tile-width tile-height)) (define-method (walk (character ) directions . rest) (let ((stop? (member 'stop rest))) (unless (and (equal? (direction character) directions) (not stop?)) (let ((sprite (child-ref character 'sprite)) (speed (if stop? 0.0 (walk-speed character)))) (change-animation sprite (last directions)) (for-each (lambda (dir) (case dir ((right) (set-vec2-x! (velocity character) speed)) ((left) (set-vec2-x! (velocity character) (* -1.0 speed))) ((up) (set-vec2-y! (velocity character) speed)) ((down) (set-vec2-y! (velocity character) (* -1.0 speed))) ((idle) (set-vec2-x! (velocity character) 0.0) (set-vec2-y! (velocity character) 0.0) (change-animation sprite (case (last (direction character)) ((right) 'idle-right) ((left) 'idle-left) ((up) 'idle-back) ((down) 'idle-front)))))) directions) (set! (direction character) directions)))))