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

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

Anonymous wiki edit for IP [178.15.24.98]: indentation fixes

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 {{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
93Colors in doodle are represented as simple lists representing RGBA
94values 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
103Initialises the internal state and createas a window with the given
104dimensions and title.
105
106<procedure>(show!)</procedure>
107
108Causes a redraw of the window.
109
110<procedure>(clear-screen!)</procedure>
111
112Fills the screen with the {{current-background}} color.
113
114<procedure>(rectangle x y width height color)</procedure>
115
116Draws a rectangle at the given coordinates {{(x, y)}} with the
117dimensions {{width}} and {{height}}. The border is drawn in {{color}}.
118
119<procedure>(filled-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
123{{color}}. The rectangle also is filled with {{color}}.
124
125<procedure>(circle x y diameter color)</procedure>
126
127Draws 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
132Draws a circle at the point defined by {{(x,y)}} with the given
133{{diameter}} and {{color}}. The border is drawn in {{color}}. The
134circle is filled in {{color}} too.
135
136<procedure>(draw-line x1 y1 x2 y2 #!key (color solid-white) (style #:solid))</procedure>
137
138Draw a line between the two points {{(x1,y1)}} and {{(x2,y2)}} in the
139given 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
144Sets the font to {{font}}, given {{size}} and {{color}}. {{font}} is a
145string representing the font's name. Every X11 TTF font is applicable.
146
147<procedure>(text x y text #!key (align #:left))</procedure>
148
149Print the given text in one line starting on point
150{{(x,y)}}. Alignment can be changed with the {{align}}
151parameter. Supported alignment values are {{#:left}}, {{#:center}} and
152{{#:right}}.
153
154<procedure>(save-screenshot filename)</procedure>
155
156Saves the current screen content to a file called {{filename}} as a
157portable network graphics (PNG). It is up to the user to provide an
158appropriate extension to the filename.
159
160===== Parameters
161
162<parameter>(font-color)</parameter>
163
164Holds the current font color.
165
166<parameter>(font-size)</parameter>
167
168Holds the current font-size.
169
170<parameter>(current-background)</parameter>
171
172Holds 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.
Note: See TracBrowser for help on using the repository browser.