From: Javier Sancho Date: Thu, 19 Jan 2017 19:19:29 +0000 (+0100) Subject: Quit game support X-Git-Url: https://git.jsancho.org/?p=gacela.git;a=commitdiff_plain;h=475d22be2375535402165d3373fae03a028886f2 Quit game support --- 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 index 0000000..903a6a5 --- /dev/null +++ b/examples/02-event-driven-programming/02-event-driven-programming.scm @@ -0,0 +1,22 @@ +#!/usr/bin/env guile +!# + +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2017 by Javier Sancho Fernandez +;;; +;;; 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 . + +(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 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 index 0000000..9efd8e1 --- /dev/null +++ b/gacela/event.scm @@ -0,0 +1,37 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2017 by Javier Sancho Fernandez +;;; +;;; 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 (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*)))) diff --git a/gacela/game.scm b/gacela/game.scm index dad0412..dd7886c 100644 --- a/gacela/game.scm +++ b/gacela/game.scm @@ -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