--- /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))
+
+(display-scene
+ (window ((resolution '(640 480)))
+ (bitmap "hello-world.bmp")))
--- /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 counter-quit #f)
+(let ((n 0))
+ (set! counter-quit
+ (lambda ()
+ (set! n (+ n 1))
+ (format #t "Quit clicked ~a times !!~%" n)
+ (if (> n 2)
+ (stop-game)))))
+
+(display-scene
+ (window ((resolution '(640 480))
+ (when-quit counter-quit))
+ (bitmap "x.bmp")))
;;; First example
-(run-scene (import-bitmap "hello_world.bmp"))
-
-(define red (import-bitmap "red.bmp"))
+(define red (bitmap "red.bmp"))
(define left-right-red (move-xy wiggle 0 red))
(run-scene left-right-red)
-(define blue (import-bitmap "blue.bmp"))
+(define blue (bitmap "blue.bmp"))
(define up-down-blue (move-xy 0 waggle blue))
(run-scene up-down-blue)
(begin
(define %public-modules
'((gacela image)
+ (gacela game)
(gacela math)
- (gacela scene)))
+ (gacela scene)
+ (gacela window)))
(for-each (let ((i (module-public-interface (current-module))))
(lambda (m)
--- /dev/null
+;;; 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*))))
(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:)
#:use-module ((sdl2 video) #:prefix sdl2:)
#:use-module (gl)
#:use-module (srfi srfi-11)
- #:export (play-game
+ #:export (start-game
+ stop-game
%sdl-renderer))
(define* (run-game-loop scene #:key
(frame-rate 60)
(tick-rate 60)
- (max-ticks-per-frame 4))
+ (max-ticks-per-frame 4)
+ (when-quit #f))
"Run the game loop. SCENE is a signal which contains the current
scene renderer procedure. FRAME-RATE specifies the optimal number of
frames to draw SCENE per second. TICK-RATE specifies the optimal game
(cond ((>= ticks max-ticks-per-frame)
lag)
((>= lag tick-interval)
- ;(process-events)
+ (process-events)
+ (if (and (quit?) (procedure? when-quit))
+ (when-quit))
;(agenda-tick!)
(iter (- lag tick-interval) (1+ ticks)))
(else
(set! %gl-context (sdl2:make-gl-context %sdl-window))
(sdl2:set-gl-swap-interval! 'vsync))
-(define* (open-window #:key (title "Untitled") (resolution '(640 480)) (fullscreen? #f))
+(define (open-window title resolution fullscreen?)
(sdl2:set-window-title! %sdl-window title)
(sdl2:set-window-size! %sdl-window resolution)
(sdl2:set-window-fullscreen! %sdl-window fullscreen?)
(sdl2:hide-window! %sdl-window)
(sdl2:sdl-quit))
-(define (play-game scene)
+(define* (start-game scene #:key
+ (title "Untitled")
+ (resolution '(640 480))
+ (fullscreen? #f)
+ (when-quit (lambda () (stop-game))))
(init-window)
- (open-window)
- (run-game-loop scene)
+ (open-window title resolution fullscreen?)
+ (run-game-loop scene #:when-quit when-quit)
(close-window))
+
+(define (stop-game)
+ (stop-game-loop))
#:use-module ((sdl2 image) #:prefix sdl2:)
#:use-module ((sdl2 render) #:prefix sdl2:)
#:use-module ((sdl2 surface) #:prefix sdl2:)
- #:export (import-bitmap
+ #:export (bitmap
move-xy))
-(define (import-bitmap filename)
+(define (bitmap filename)
(make-scene
"bitmap"
(let ((image (sdl2:load-image filename))
(define (display-scene scene . args)
(apply (scene-procedure scene) args))
-(define (run-scene scene)
- (play-game
- (scene-procedure scene)))
+(define (run-scene scene . args)
+ (apply start-game
+ (cons (scene-procedure scene) args)))
--- /dev/null
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2016 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 window)
+ #:use-module (gacela scene)
+ #:export (window))
+
+
+(define-syntax window
+ (lambda (x)
+ (syntax-case x ()
+ ((_ ((property-name property-value) ...) scene)
+ #'(make-scene
+ "window"
+ (lambda ()
+ (apply run-scene (cons scene
+ (append (list (symbol->keyword 'property-name) property-value)
+ ...)))))))))