summaryrefslogtreecommitdiff
path: root/README.org
blob: 460abf6a062f84cb359a4b7d80dbf75a644be7ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
* guile-2d

  Guile-2d is a 2D game programming library for GNU Guile. It is a
  layer above SDL and OpenGL that provides abstractions for common 2D
  game programming requirements such as:

  - Sprites
  - Animation
  - Tilesets
  - Tile maps
  - Scene graph
  - Input handling
  - Scripting

** Inspiration
   Every programming language should have a fun, easy to use 2D game
   library. Guile-2d draws it's inspiration from great
   libraries/frameworks such as [[http://love2d.org][LÖVE]], [[http://pygame.org][Pygame]], and [[http://pyglet.org][Pyglet]].

** Example
   Here is the simplest Guile-2d application (so far).

   #+BEGIN_SRC scheme
    (use-modules ((sdl sdl) #:prefix SDL:)
                 (figl gl)
                 (2d sprite)
                 (2d game-loop)
                 (2d window))

    (define window-width 800)
    (define window-height 600)
    (define sprite #f)

    (define (key-down key)
      (display key) (newline)
      (case key
        ;; Quit program when ESCAPE or Q is pressed.
        ;; For now we have to use the SDL keycodes, but not for long!
        ((SDLK_ESCAPE SDLK_q)
         (close-window)
         (quit))))

    ;; Draw our sprite
    (define (render)
      (draw-sprite sprite))

    ;; Register callbacks.
    (set-render-callback (lambda () (render)))
    (set-key-down-callback (lambda (key) (key-down key)))

    ;; Open the window.
    (open-window window-width window-height)

    ;; Load a sprite and center it on the screen.
    ;; Must be done AFTER opening the window.
    (set! sprite (load-sprite "sprite.png" #:position (vector (/ window-width 2)
                                                              (/ window-height 2))))

    ;; Start the game loop.
    ;; The render callback will be called through this procedure.
    (run-game-loop)
   #+END_SRC

** REPL Driven Development
   The read-eval-print-loop present in Guile allows you to develop
   your game while it is running! This allows you to see in real time
   what your changes do to the game without having to restart the
   program every time.

   ** This section needs to be completed. **

** Dependencies

   - [[https://gitorious.org/guile-figl/guile-figl][guile-figl]]
   - [[https://www.gnu.org/software/guile-sdl/index.html][guile-sdl]]
   - SDL 1.2

** License

   GNU LGPL v3