]> git.jsancho.org Git - gacela.git/commitdiff
Quit game support
authorJavier Sancho <jsf@jsancho.org>
Thu, 19 Jan 2017 19:19:29 +0000 (20:19 +0100)
committerJavier Sancho <jsf@jsancho.org>
Thu, 19 Jan 2017 19:19:29 +0000 (20:19 +0100)
examples/02-event-driven-programming/02-event-driven-programming.scm [new file with mode: 0644]
examples/02-event-driven-programming/x.bmp [new file with mode: 0755]
gacela/event.scm [new file with mode: 0644]
gacela/game.scm

diff --git a/examples/02-event-driven-programming/02-event-driven-programming.scm b/examples/02-event-driven-programming/02-event-driven-programming.scm
new file mode 100644 (file)
index 0000000..903a6a5
--- /dev/null
@@ -0,0 +1,22 @@
+#!/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))
+
+(run-scene (import-bitmap "x.bmp"))
diff --git a/examples/02-event-driven-programming/x.bmp b/examples/02-event-driven-programming/x.bmp
new file mode 100755 (executable)
index 0000000..9633a7e
Binary files /dev/null and b/examples/02-event-driven-programming/x.bmp differ
diff --git a/gacela/event.scm b/gacela/event.scm
new file mode 100644 (file)
index 0000000..9efd8e1
--- /dev/null
@@ -0,0 +1,37 @@
+;;; 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/>.
+
+
+(define-module (gacela event)
+  #:use-module ((sdl2 events) #:prefix sdl2:)
+  #:export (process-events
+           quit?))
+
+
+(define *current-events* '())
+
+(define (poll-events)
+  (let ((event (sdl2:poll-event)))
+    (cond (event
+          (cons event (poll-events)))
+         (else
+          '()))))
+
+(define (process-events)
+  (set! *current-events* (poll-events)))
+
+(define (quit?)
+  (not (null? (filter (lambda (e) (sdl2:quit-event? e)) *current-events*))))
index dad04126bbd1812ea0ef7b92f4810fb49d33ab9f..dd7886cc150e5f230bf3ed5c3c97318c0aa8f4da 100644 (file)
@@ -17,6 +17,7 @@
 
 (define-module (gacela game)
   #:use-module (gacela math)
+  #:use-module (gacela event)
   #:use-module ((sdl2) #:prefix sdl2:)
   #:use-module ((sdl2 render) #:prefix sdl2:)
   #:use-module ((sdl2 surface) #:prefix sdl2:)
@@ -72,7 +73,7 @@ unused accumulator time."
        (cond ((>= ticks max-ticks-per-frame)
               lag)
              ((>= lag tick-interval)
-                                       ;(process-events)
+              (process-events)
                                        ;(agenda-tick!)
               (iter (- lag tick-interval) (1+ ticks)))
              (else