--- /dev/null
+#!/usr/bin/env guile
+!#
+
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2017 by Javier Sancho Fernandez <jsf at jsancho dot 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/>.
+
+(use-modules (gacela))
+
+
+(define get-pressed-scene #f)
+
+(set! get-pressed-scene
+ (let* ((up (bitmap "up.bmp"))
+ (down (bitmap "down.bmp"))
+ (left (bitmap "left.bmp"))
+ (right (bitmap "right.bmp"))
+ (press (bitmap "press.bmp"))
+ (actived press))
+ (lambda ()
+ (if (any-key-down?)
+ (cond ((key-down? 'up)
+ (set! actived up))
+ ((key-down? 'down)
+ (set! actived down))
+ ((key-down? 'left)
+ (set! actived left))
+ ((key-down? 'right)
+ (set! actived right))
+ (else
+ (set! actived press))))
+ actived)))
+
+(define press (bitmap "press.bmp"))
+
+(display-scene
+ (window ((resolution '(640 480)))
+ (lambda ()
+ (display-scene (get-pressed-scene)))))
(eval-when (eval load compile)
(begin
(define %public-modules
- '((gacela image)
+ '((gacela event)
+ (gacela image)
(gacela game)
(gacela math)
(gacela scene)
(define-module (gacela event)
#:use-module ((sdl2 events) #:prefix sdl2:)
#:export (process-events
- quit?))
+ quit-event?
+ key-events
+ any-key-down?
+ any-key-up?
+ key-down?
+ key-up?))
(define *current-events* '())
(define (process-events)
(set! *current-events* (poll-events)))
-(define (quit?)
+(define (quit-event?)
(not (null? (filter (lambda (e) (sdl2:quit-event? e)) *current-events*))))
+
+(define (key-events)
+ (filter (lambda (e) (sdl2:keyboard-event? e)) *current-events*))
+
+(define (any-key-down?)
+ (let loop ((events *current-events*))
+ (if (null? events)
+ #f
+ (or (sdl2:keyboard-down-event? (car events))
+ (loop (cdr events))))))
+
+(define (any-key-up?)
+ (let loop ((events *current-events*))
+ (if (null? events)
+ #f
+ (or (sdl2:keyboard-up-event? (car events))
+ (loop (cdr events))))))
+
+(define (key-down? key)
+ (let ((ke (filter
+ (lambda (e)
+ (and (sdl2:keyboard-down-event? e)
+ (equal? (sdl2:keyboard-event-key e) key)))
+ *current-events*)))
+ (not (null? ke))))
+
+(define (key-up? key)
+ (let ((ke (filter
+ (lambda (e)
+ (and (sdl2:keyboard-up-event? e)
+ (equal? (sdl2:keyboard-event-key e) key)))
+ *current-events*)))
+ (not (null? ke))))
lag)
((>= lag tick-interval)
(process-events)
- (if (and (quit?) (procedure? when-quit))
+ (if (and (quit-event?) (procedure? when-quit))
(when-quit))
;(agenda-tick!)
(iter (- lag tick-interval) (1+ ticks)))
;;; Scene Procedures
(define (display-scene scene . args)
- (apply (scene-procedure scene) args))
+ (apply
+ (if (scene? scene)
+ (scene-procedure scene)
+ scene)
+ args))
(define (run-scene scene . args)
(apply start-game
- (cons (scene-procedure scene) args)))
+ (cons
+ (if (scene? scene)
+ (scene-procedure scene)
+ scene)
+ args)))
;;; Gacela, a GNU Guile extension for fast games development
-;;; Copyright (C) 2016 by Javier Sancho Fernandez <jsf at jsancho dot org>
+;;; Copyright (C) 2017 by Javier Sancho Fernandez <jsf at jsancho dot 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