1 | [[tags: egg]] |
---|
2 | |
---|
3 | == doodle - A minimal game 'framework'. |
---|
4 | |
---|
5 | [[toc:]] |
---|
6 | |
---|
7 | === Description |
---|
8 | |
---|
9 | A minimal game 'framework' inspired by [[http://love2d.org/|löve]]. |
---|
10 | |
---|
11 | '''This is still a work in progress and subject to change!''' |
---|
12 | |
---|
13 | === Author |
---|
14 | |
---|
15 | [[/users/christian-kellermann|Christian Kellermann]] |
---|
16 | |
---|
17 | === Requirements |
---|
18 | |
---|
19 | Requires the [[miscmacros]], [[cairo]] and [[sdl]] extensions. |
---|
20 | |
---|
21 | === General program flow of a doodle |
---|
22 | |
---|
23 | A program creates a window, called a 'doodle' here and registers for |
---|
24 | any of these three events: world-inits, world-ends and |
---|
25 | world-changes. world-inits is called upon the first iteration of the |
---|
26 | event loop, world-ends last and world-changes for every iteration. |
---|
27 | |
---|
28 | world-inits and world-ends are thunks, whereas world-changes has the |
---|
29 | following signature: |
---|
30 | |
---|
31 | <procedure>(world-changes (lambda (event dt escape-continuation) ...)</procedure> |
---|
32 | |
---|
33 | ; event : holds the occured event of this loop iteration |
---|
34 | ; dt : holds the time delta between the last and this iteration |
---|
35 | ; escape-continuation : holds the continuation that will exit the loop |
---|
36 | |
---|
37 | Please see below for a detailed list of supported {{event}} symbols. |
---|
38 | |
---|
39 | {{dt}} is a flonum which can be used to adjust speed of animations for |
---|
40 | example. |
---|
41 | |
---|
42 | The game loop is started with the {{(run-event-loop)}} procedure. |
---|
43 | Usually the game loop will run as fast as it can unless the keyword |
---|
44 | parameter {{minimum-wait}} has been given which adds that minimum |
---|
45 | delay between iterations. |
---|
46 | |
---|
47 | === API Documentation |
---|
48 | |
---|
49 | This egg is still under development; the API might change a bit in |
---|
50 | future versions. |
---|
51 | |
---|
52 | ==== Event loop |
---|
53 | ===== Procedures |
---|
54 | <procedure>(run-event-loop #!key (run-in-background #f) (minimum-wait 0))</procedure> |
---|
55 | |
---|
56 | Starts the event loop and runs {{world-inits}}. If |
---|
57 | {{run-in-background}} is #t a new thread is started. Within the event |
---|
58 | loop the procedure given with {{world-changes}} is called with the |
---|
59 | time delta of the last call and the events that occured. If |
---|
60 | {{minimum-wait}} is given and the delta is smaller than |
---|
61 | {{minimum-wait}} the thread will sleep for the remaining |
---|
62 | time. {{minimum-wait}} takes a value in milliseconds. |
---|
63 | |
---|
64 | ===== Parameters |
---|
65 | <parameter>(world-inits (lambda () ...))</parameter> |
---|
66 | |
---|
67 | A thunk that is called once when the event loop is started. |
---|
68 | |
---|
69 | <parameter>(world-ends (lambda () ...))</parameter> |
---|
70 | |
---|
71 | A thunk that is called once when the even loop is exited. |
---|
72 | |
---|
73 | <parameter>(world-changes (lambda (event dt exit-continuation) ...))</parameter> |
---|
74 | |
---|
75 | A procedure that gets called every iteration of the event loop. The |
---|
76 | {{event}} parameter holds the event, {{dt}} is the time difference in |
---|
77 | milliseconds between the last and current |
---|
78 | iteration. {{exit-continuation}} can be used to jump out of the |
---|
79 | event-loop. |
---|
80 | |
---|
81 | ===== Events |
---|
82 | |
---|
83 | One event is a list containing information about the individual |
---|
84 | event. There are currently 3 types of handled events: |
---|
85 | |
---|
86 | ; quit : The quit event has the following form {{(quit)}}. |
---|
87 | ; key events : The first element of the list is either the symbol {{pressed}} or {{released}} followed by either the integer for the key code or the symbols {{up}}, {{down}}, {{left}} or {{right}} representing cursor keys. |
---|
88 | ; unknown : This will list all other events. The list contains the symbol {{unknown}} and the SDL event type. See the SDL egg documentation for hints on what this may be. |
---|
89 | |
---|
90 | ==== Drawing |
---|
91 | ===== Colors |
---|
92 | |
---|
93 | Colors in doodle are represented as simple lists representing RGBA |
---|
94 | values one number each. Currently there are two predefined colors: |
---|
95 | |
---|
96 | ; solid-black : {{(0 0 0 1)}} |
---|
97 | ; solid-white : {{(1 1 1 1)}} |
---|
98 | |
---|
99 | ===== Procedures |
---|
100 | |
---|
101 | <procedure>(new-doodle #!key (width 680) (height 460) (title "Doodle") (background solid-black) (fullscreen #f))</procedure> |
---|
102 | |
---|
103 | Initialises the internal state and createas a window with the given |
---|
104 | dimensions and title. |
---|
105 | |
---|
106 | <procedure>(show!)</procedure> |
---|
107 | |
---|
108 | Causes a redraw of the window. |
---|
109 | |
---|
110 | <procedure>(clear-screen!)</procedure> |
---|
111 | |
---|
112 | Fills the screen with the {{current-background}} color. |
---|
113 | |
---|
114 | <procedure>(rectangle x y width height color)</procedure> |
---|
115 | |
---|
116 | Draws a rectangle at the given coordinates {{(x, y)}} with the |
---|
117 | dimensions {{width}} and {{height}}. The border is drawn in {{color}}. |
---|
118 | |
---|
119 | <procedure>(filled-rectangle x y width height color)</procedure> |
---|
120 | |
---|
121 | Draws a rectangle at the given coordinates {{(x, y)}} with the |
---|
122 | dimensions {{width}} and {{height}}. The border is drawn in |
---|
123 | {{color}}. The rectangle also is filled with {{color}}. |
---|
124 | |
---|
125 | <procedure>(circle x y diameter color)</procedure> |
---|
126 | |
---|
127 | Draws a circle at the point defined by {{(x,y)}} with the given |
---|
128 | {{diameter}} and {{color}}. The border is drawn in {{color}}. |
---|
129 | |
---|
130 | <procedure>(filled-circle x y diameter color)</procedure> |
---|
131 | |
---|
132 | Draws a circle at the point defined by {{(x,y)}} with the given |
---|
133 | {{diameter}} and {{color}}. The border is drawn in {{color}}. The |
---|
134 | circle is filled in {{color}} too. |
---|
135 | |
---|
136 | <procedure>(draw-line x1 y1 x2 y2 #!key (color solid-white) (style #:solid))</procedure> |
---|
137 | |
---|
138 | Draw a line between the two points {{(x1,y1)}} and {{(x2,y2)}} in the |
---|
139 | given style. Valid {{style}}s are either {{#:solid}} (the default) or |
---|
140 | {{#:dashed}} for dashed lines. The line is drawn in {{color}}. |
---|
141 | |
---|
142 | <procedure>(set-font! font size color)</procedure> |
---|
143 | |
---|
144 | Sets the font to {{font}}, given {{size}} and {{color}}. {{font}} is a |
---|
145 | string representing the font's name. Every X11 TTF font is applicable. |
---|
146 | |
---|
147 | <procedure>(text x y text #!key (align #:left))</procedure> |
---|
148 | |
---|
149 | Print the given text in one line starting on point |
---|
150 | {{(x,y)}}. Alignment can be changed with the {{align}} |
---|
151 | parameter. Supported alignment values are {{#:left}}, {{#:center}} and |
---|
152 | {{#:right}}. |
---|
153 | |
---|
154 | <procedure>(save-screenshot filename)</procedure> |
---|
155 | |
---|
156 | Saves the current screen content to a file called {{filename}} as a |
---|
157 | portable network graphics (PNG). It is up to the user to provide an |
---|
158 | appropriate extension to the filename. |
---|
159 | |
---|
160 | ===== Parameters |
---|
161 | |
---|
162 | <parameter>(font-color)</parameter> |
---|
163 | |
---|
164 | Holds the current font color. |
---|
165 | |
---|
166 | <parameter>(font-size)</parameter> |
---|
167 | |
---|
168 | Holds the current font-size. |
---|
169 | |
---|
170 | <parameter>(current-background)</parameter> |
---|
171 | |
---|
172 | Holds the current background color. |
---|
173 | |
---|
174 | ==== Collision detection |
---|
175 | |
---|
176 | *sprites* |
---|
177 | |
---|
178 | <procedure>add-sprite!</procedure> |
---|
179 | |
---|
180 | <procedure>check-for-collisions</procedure> |
---|
181 | |
---|
182 | <procedure>make-sprite</procedure> |
---|
183 | |
---|
184 | <procedure>remove-sprite!</procedure> |
---|
185 | |
---|
186 | <procedure>update-sprite!</procedure> |
---|
187 | |
---|
188 | ==== Example |
---|
189 | |
---|
190 | <enscript highlight="scheme"> |
---|
191 | </enscript> |
---|
192 | |
---|
193 | === Changelog |
---|
194 | |
---|
195 | ; 0.1 : Initial version |
---|
196 | |
---|
197 | === License |
---|
198 | |
---|
199 | Copyright (c) 2012, Christian Kellermann |
---|
200 | All rights reserved. |
---|
201 | |
---|
202 | Redistribution and use in source and binary forms, with or without |
---|
203 | modification, are permitted provided that the following conditions |
---|
204 | are met: |
---|
205 | |
---|
206 | Redistributions of source code must retain the above copyright |
---|
207 | notice, this list of conditions and the following disclaimer. |
---|
208 | |
---|
209 | Redistributions in binary form must reproduce the above |
---|
210 | copyright notice, this list of conditions and the following |
---|
211 | disclaimer in the documentation and/or other materials provided |
---|
212 | with the distribution. |
---|
213 | |
---|
214 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
215 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
216 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
---|
217 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
---|
218 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
---|
219 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
220 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
---|
221 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
222 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
---|
223 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
224 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
---|
225 | OF THE POSSIBILITY OF SUCH DAMAGE. |
---|