1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.2.1" />
7 <style type=
"text/css">
9 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
11 border: 1px solid red;
16 margin: 1em 5% 1em 5%;
21 text-decoration: underline
;
39 h1
, h2
, h3
, h4
, h5
, h6
{
41 font-family: sans-serif
;
48 border-bottom: 2px solid silver
;
51 border-bottom: 2px solid silver
;
61 border: 1px solid silver
;
76 font-family: sans-serif
;
83 font-family: sans-serif
;
87 font-family: sans-serif
;
89 border-top: 2px solid silver
;
95 padding-bottom: 0.5em;
99 padding-bottom: 0.5em;
103 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
104 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
105 div
.admonitionblock
{
108 margin-bottom: 1.5em;
110 div
.admonitionblock
{
112 margin-bottom: 2.5em;
115 div
.content
{ /* Block element content. */
119 /* Block element titles. */
120 div
.title
, caption
.title
{
121 font-family: sans-serif
;
125 margin-bottom: 0.5em;
131 td div
.title:first-child
{
134 div
.content div
.title:first-child
{
137 div
.content
+ div
.title
{
141 div
.sidebarblock
> div
.content
{
143 border: 1px solid silver
;
150 div
.listingblock
> div
.content
{
151 border: 1px solid silver
;
156 div
.quoteblock
> div
.content
{
163 div
.verseblock
+ div
.attribution
{
167 div
.admonitionblock
.icon
{
171 text-decoration: underline
;
173 padding-right: 0.5em;
175 div
.admonitionblock td
.content
{
177 border-left: 2px solid silver
;
180 div
.exampleblock
> div
.content
{
181 border-left: 2px solid silver
;
185 div
.verseblock div
.content
{
189 div
.imageblock div
.content
{ padding-left: 0; }
190 div
.imageblock img
{ border: 1px solid silver
; }
191 span
.image img
{ border-style: none
; }
195 margin-bottom: 0.8em;
207 list-style-position: outside
;
210 list-style-type: lower-alpha
;
213 div
.tableblock
> table
{
214 border: 3px solid
#527bbd;
217 font-family: sans-serif
;
226 margin-bottom: 0.8em;
234 padding-right: 0.8em;
241 div#footer-badges
{ display: none
; }
246 font-family: sans-serif
;
250 margin-bottom: 0.1em;
253 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
269 /* Workarounds for IE6's broken and incomplete CSS2. */
271 div
.sidebar-content
{
273 border: 1px solid silver
;
276 div
.sidebar-title
, div
.image-title
{
277 font-family: sans-serif
;
280 margin-bottom: 0.5em;
283 div
.listingblock div
.content
{
284 border: 1px solid silver
;
289 div
.quoteblock-content
{
293 div
.exampleblock-content
{
294 border-left: 2px solid silver
;
298 /* IE6 sets dynamically generated links as visited. */
299 div#toc
a:visited
{ color: blue
; }
301 <script type=
"text/javascript">
303 window
.onload = function(){generateToc(2)}
304 /* Author: Mihai Bazon, September 2002
305 * http://students.infoiasi.ro/~mishoo
307 * Table Of Content generator
310 * Feel free to use this script under the terms of the GNU General Public
311 * License, as long as you do not remove or alter this notice.
314 /* modified by Troy D. Hanson, September 2006. License: GPL */
315 /* modified by Stuart Rackham, October 2006. License: GPL */
317 function getText(el
) {
319 for (var i
= el
.firstChild
; i
!= null; i
= i
.nextSibling
) {
320 if (i
.nodeType
== 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
322 else if (i
.firstChild
!= null)
328 function TocEntry(el
, text
, toclevel
) {
331 this.toclevel
= toclevel
;
334 function tocEntries(el
, toclevels
) {
335 var result
= new Array
;
336 var re
= new RegExp('[hH]([2-'+(toclevels
+1)+'])');
337 // Function that scans the DOM tree for header elements (the DOM2
338 // nodeIterator API would be a better technique but not supported by all
340 var iterate = function (el
) {
341 for (var i
= el
.firstChild
; i
!= null; i
= i
.nextSibling
) {
342 if (i
.nodeType
== 1 /* Node.ELEMENT_NODE */) {
343 var mo
= re
.exec(i
.tagName
)
345 result
[result
.length
] = new TocEntry(i
, getText(i
), mo
[1]-1);
354 // This function does the work. toclevels = 1..4.
355 function generateToc(toclevels
) {
356 var toc
= document
.getElementById("toc");
357 var entries
= tocEntries(document
.getElementsByTagName("body")[0], toclevels
);
358 for (var i
= 0; i
< entries
.length
; ++i
) {
359 var entry
= entries
[i
];
360 if (entry
.element
.id
== "")
361 entry
.element
.id
= "toc" + i
;
362 var a
= document
.createElement("a");
363 a
.href
= "#" + entry
.element
.id
;
364 a
.appendChild(document
.createTextNode(entry
.text
));
365 var div
= document
.createElement("div");
367 div
.className
= "toclevel" + entry
.toclevel
;
368 toc
.appendChild(div
);
373 <title>EventManager Class Reference
</title>
377 <h1>EventManager Class Reference
</h1>
379 <div id=
"toctitle">Table of Contents
</div>
380 <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.
</b></p></noscript>
383 <h2>1. Attributes
</h2>
384 <div class=
"sectionbody">
385 <p><em>Italics
</em> means private (in the sense that they shouldn't be set manually).
</p>
386 <div class=
"tableblock">
389 cellspacing=
"0" cellpadding=
"4">
405 <strong>keyboard
</strong>
416 keyboard pressed events
424 keyboard release events
429 <strong>mouse
</strong>
456 mouse released events
461 <strong>joystick
</strong>
472 joystick axis motion events
480 joystick ball motion events
488 joystick hat motion events
496 joystick button pressed events
504 joystick button released events
568 <div class=
"sectionbody">
569 <div class=
"tableblock">
572 cellspacing=
"0" cellpadding=
"4">
599 processes all pending events
606 <h2>3. Event Function Prototypes
</h2>
607 <div class=
"sectionbody">
608 <div class=
"tableblock">
611 cellspacing=
"0" cellpadding=
"4">
630 function(x, y, xrel, yrel)
654 function(axis, axis_value)
662 function(ball, xrel, yrel)
670 function(hat, hat_value)
702 <div class=
"sectionbody">
703 <p>Joysticks and joystick buttons start numbering at
1, not
0.
</p>
706 <div class=
"sectionbody">
707 <div class=
"listingblock">
708 <div class=
"content"><!-- Generator: GNU source-highlight 2.4
710 http://www.lorenzobettini.it
711 http://www.gnu.org/software/src-highlite -->
712 <pre><tt><span style=
"font-style: italic"><span style=
"color: #9A1900">--create a new EventManager
</span></span>
713 evman
<span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #000000">EventManager:new
</span></span><span style=
"color: #990000">()
</span>
715 <span style=
"font-style: italic"><span style=
"color: #9A1900">--add an event to exit when ESC is pressed
</span></span>
716 <span style=
"font-style: italic"><span style=
"color: #9A1900">-- assumes main loop is controlled by variable
"done"</span></span>
717 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>ESCAPE
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> done
<span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">true
</span></span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
719 <span style=
"font-style: italic"><span style=
"color: #9A1900">--events to control a player object's movement
</span></span>
720 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>UP
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>y_vel
<span style=
"color: #990000">=
</span> <span style=
"color: #990000">-
</span><span style=
"color: #993399">1</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
721 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>DOWN
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>y_vel
<span style=
"color: #990000">=
</span> <span style=
"color: #993399">1</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
722 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>LEFT
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>x_vel
<span style=
"color: #990000">=
</span> <span style=
"color: #990000">-
</span><span style=
"color: #993399">1</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
723 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>RIGHT
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>x_vel
<span style=
"color: #990000">=
</span> <span style=
"color: #993399">1</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
725 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>released
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>UP
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>y_vel
<span style=
"color: #990000">=
</span> <span style=
"color: #993399">0</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
726 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>released
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>DOWN
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>y_vel
<span style=
"color: #990000">=
</span> <span style=
"color: #993399">0</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
727 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>released
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>LEFT
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>x_vel
<span style=
"color: #990000">=
</span> <span style=
"color: #993399">0</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
728 evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>released
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>RIGHT
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>x_vel
<span style=
"color: #990000">=
</span> <span style=
"color: #993399">0</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
730 <span style=
"font-style: italic"><span style=
"color: #9A1900">--EventManager for a fictional menu object
</span></span>
731 menu_evman
<span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #000000">EventManager:new
</span></span><span style=
"color: #990000">()
</span>
732 menu_evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>UP
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> menu
<span style=
"color: #990000">.
</span><span style=
"font-weight: bold"><span style=
"color: #000000">next_item
</span></span><span style=
"color: #990000">()
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
733 menu_evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>DOWN
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> menu
<span style=
"color: #990000">.
</span><span style=
"font-weight: bold"><span style=
"color: #000000">prev_item
</span></span><span style=
"color: #990000">()
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
734 menu_evman
<span style=
"color: #990000">.
</span>keyboard
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>Keys
<span style=
"color: #990000">.
</span>RETURN
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> menu
<span style=
"color: #990000">.
</span><span style=
"font-weight: bold"><span style=
"color: #000000">execute
</span></span><span style=
"color: #990000">()
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
736 <span style=
"font-style: italic"><span style=
"color: #9A1900">--Controlling a player with the mouse
</span></span>
737 <span style=
"font-style: italic"><span style=
"color: #9A1900">-- assume there exists a player:set_pos(x,y) method
</span></span>
739 <span style=
"font-style: italic"><span style=
"color: #9A1900">--wrapper function for player:set_pos(x,y)
</span></span>
740 <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span> <span style=
"font-weight: bold"><span style=
"color: #000000">move_player
</span></span><span style=
"color: #990000">(
</span>x
<span style=
"color: #990000">,
</span>y
<span style=
"color: #990000">)
</span>
741 <span style=
"font-weight: bold"><span style=
"color: #000000">player:set_pos
</span></span><span style=
"color: #990000">(
</span>x
<span style=
"color: #990000">,
</span>y
<span style=
"color: #990000">)
</span>
742 <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
744 evman
<span style=
"color: #990000">.
</span>mouse
<span style=
"color: #990000">.
</span>motion
<span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #000000">move_player
</span></span><span style=
"color: #990000">(
</span>x
<span style=
"color: #990000">,
</span>y
<span style=
"color: #990000">)
</span>
745 evman
<span style=
"color: #990000">.
</span>mouse
<span style=
"color: #990000">.
</span>pressed
<span style=
"color: #990000">[
</span>MouseButton
<span style=
"color: #990000">.
</span>BUTTON_LEFT
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>firing
<span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">true
</span></span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
746 evman
<span style=
"color: #990000">.
</span>mouse
<span style=
"color: #990000">.
</span>released
<span style=
"color: #990000">[
</span>MouseButton
<span style=
"color: #990000">.
</span>BUTTON_LEFT
<span style=
"color: #990000">]
</span> <span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> player
<span style=
"color: #990000">.
</span>firing
<span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">false
</span></span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
748 <span style=
"font-style: italic"><span style=
"color: #9A1900">--quitting (assumes main loop is controlled by done variable)
</span></span>
749 evman
<span style=
"color: #990000">.
</span>quit
<span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">function
</span></span><span style=
"color: #990000">()
</span> done
<span style=
"color: #990000">=
</span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">true
</span></span> <span style=
"font-weight: bold"><span style=
"color: #0000FF">end
</span></span>
751 </tt></pre></div></div>
754 <div id=
"footer-text">
755 Last updated
18-Aug-
2007 19:
41:
58 EDT