source: project/wiki/eggref/4/doodle @ 25831

Last change on this file since 25831 was 25831, checked in by svnwiki, 9 years ago

Anonymous wiki edit for IP [178.15.24.98]: Fix procedure definition markup

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