<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emanuele Feronato &#187; Box2D</title>
	<atom:link href="http://www.emanueleferonato.com/category/box2d/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Thu, 02 Sep 2010 09:32:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Create Box2D levels in a quick with Bison Kick</title>
		<link>http://www.emanueleferonato.com/2010/08/16/create-box2d-levels-in-a-quick-with-bison-kick/</link>
		<comments>http://www.emanueleferonato.com/2010/08/16/create-box2d-levels-in-a-quick-with-bison-kick/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 21:41:38 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3235</guid>
		<description><![CDATA[Some time ago I published a Basic Box2D editor using Flash movieclips. Now it&#8217;s time to show you something way more interesting called Bison Kick by Jacob Schatz who runs the blog jacobschatz.com (bookmark it! It contains a lot of useful information). It&#8217;s an online Box2D editor with live preview. Besides it&#8217;s still under development, [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I published a <a href="http://www.emanueleferonato.com/2010/07/12/basic-box2d-editor-using-flash-movieclips/">Basic Box2D editor using Flash movieclips</a>.</p>
<p>Now it&#8217;s time to show you something way more interesting called <strong><a target = "_blank" href="http://www.jacobschatz.com/bisonkick/">Bison Kick</a></strong> by <strong>Jacob Schatz</strong> who runs the blog <a href="http://jacobschatz.com/" target = "_blank">jacobschatz.com</a> (bookmark it! It contains a lot of useful information).</p>
<p><a target = "_blank" href="http://www.jacobschatz.com/bisonkick/"><img src="/wp-content/uploads/2010/08/bison.png" /></a></p>
<p>It&#8217;s an online Box2D editor with live preview.</p>
<p>Besides it&#8217;s still under development, with more options to be added and a few bugs to be removed, it&#8217;s very fun and simple to use.</p>
<p>I tried to design a level to be used in a game like Totem Destroyer and I managed to export it both in AS3:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">//order: x , y , height, width, rotation, isDynamic, shape, friction,density,restitution,ID </span>
 <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span>
<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">175</span>,<span style="color: #000000; font-weight:bold;">324</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">325</span>,<span style="color: #000000; font-weight:bold;">325</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">375</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">500</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">false</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'ground'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">275</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">300</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">200</span>,<span style="color: #000000; font-weight:bold;">100</span>,<span style="color: #000000; font-weight:bold;">150</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">125</span>,<span style="color: #000000; font-weight:bold;">225</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">125</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">375</span>,<span style="color: #000000; font-weight:bold;">225</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">100</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.25</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'totem'</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#93;</span>;</pre></div></div>

<p>and in XML:<span id="more-3235"></span></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;level&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;175&lt;/xprop&gt;
    &lt;yprop&gt;324&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'normal'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;325&lt;/xprop&gt;
    &lt;yprop&gt;325&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'normal'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;375&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;500&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;false&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'ground'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;275&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;300&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'normal'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;200&lt;/yprop&gt;
    &lt;height&gt;100&lt;/height&gt;
    &lt;width&gt;150&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'normal'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;125&lt;/xprop&gt;
    &lt;yprop&gt;225&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,2,0.5,'heavy'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;125&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,2,0.5,'heavy'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;375&lt;/xprop&gt;
    &lt;yprop&gt;225&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,2,0.5,'heavy'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;50&lt;/yprop&gt;
    &lt;height&gt;100&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.25,0.5,'totem'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
&lt;/level&gt;</pre></div></div>

<p>Then, creating a Box2D world from these data was really easy thanks to the <a href="http://jacobschatz.com/?p=117">snippet of code</a> provided by Jacob:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> 
<span style="color: #000000;">&#123;</span>	
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world<span style="color: #000000; font-weight: bold;">:</span>b2World=<span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world_scale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">30</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> static const <span style="color: #004993;">SQUARE</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;SQUARE&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> static const CIRCLE<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;CIRCLE&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> fixtureDef<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> specialB2Body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> motorOn<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
&nbsp;
		<span style="color: #009900;">//order: x , y , height, width, rotation, isDynamic, shape, friction,density,restitution,ID </span>
 <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span>
<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">175</span>,<span style="color: #000000; font-weight:bold;">324</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">325</span>,<span style="color: #000000; font-weight:bold;">325</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">375</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">500</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">false</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'ground'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">275</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">300</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">200</span>,<span style="color: #000000; font-weight:bold;">100</span>,<span style="color: #000000; font-weight:bold;">150</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">125</span>,<span style="color: #000000; font-weight:bold;">225</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">125</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">375</span>,<span style="color: #000000; font-weight:bold;">225</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">100</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.25</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'totem'</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#93;</span>;		<span style="color: #009900;">//</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> 
		<span style="color: #000000;">&#123;</span>
			debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #004993;">map</span>.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> sx<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sy<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sizerh<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sizerw<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> srot<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sIsDynamic<span style="color: #000000; font-weight: bold;">:*</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sShape<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">6</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sFric<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">7</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sMass<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sRest<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> boxId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#93;</span>;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>sShape == <span style="color: #004993;">SQUARE</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>	
					draw_box<span style="color: #000000;">&#40;</span>sx, sy, sizerw, sizerh, sIsDynamic,srot,sFric,sMass,sRest,boxId<span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>sShape == CIRCLE<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					draw_circle<span style="color: #000000;">&#40;</span>sx, sy, sizerw <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span>, sIsDynamic,srot,sFric,sMass,sRest,boxId<span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, update<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_circle<span style="color: #000000;">&#40;</span>px<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, py<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, r<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">d</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>, rot<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,
		fric<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,mass<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,rest<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,boxId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_body<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span>px <span style="color: #000000; font-weight: bold;">/</span> world_scale, py <span style="color: #000000; font-weight: bold;">/</span> world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span><span style="color: #000000;">&#41;</span> 
			<span style="color: #000000;">&#123;</span>
				my_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #000000;">&#125;</span>
			my_body.<span style="color: #004993;">angle</span> = rot;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_circle<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span>r<span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_fixture.density = mass;
			my_fixture.friction = fric;
			my_fixture.restitution = rest;
			my_fixture.shape=my_circle;
			<span style="color: #6699cc; font-weight: bold;">var</span> world_body<span style="color: #000000; font-weight: bold;">:</span>b2Body = world.CreateBody<span style="color: #000000;">&#40;</span>my_body<span style="color: #000000;">&#41;</span>;
			world_body.CreateFixture<span style="color: #000000;">&#40;</span>my_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_box<span style="color: #000000;">&#40;</span>px<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, py<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, w<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, h<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">d</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>, rot<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,
		fric<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,mass<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,rest<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,boxId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_body<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			my_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span>px <span style="color: #000000; font-weight: bold;">/</span> world_scale, py <span style="color: #000000; font-weight: bold;">/</span> world_scale<span style="color: #000000;">&#41;</span>;
			my_body.<span style="color: #004993;">angle</span> = rot;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span><span style="color: #000000;">&#41;</span> 
			<span style="color: #000000;">&#123;</span>
				my_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box.SetAsBox<span style="color: #000000;">&#40;</span>w<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, h<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_fixture.density = mass;
			my_fixture.friction = fric;
			my_fixture.restitution = rest;
			my_fixture.shape=my_box;
			<span style="color: #6699cc; font-weight: bold;">var</span> world_body<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>my_body<span style="color: #000000;">&#41;</span>;
			world_body.CreateFixture<span style="color: #000000;">&#40;</span>my_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_draw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetSprite<span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.3</span><span style="color: #000000;">&#41;</span>;
			debug_draw.SetDrawScale<span style="color: #000000;">&#40;</span>world_scale<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit<span style="color: #000000;">&#41;</span>;
			world.SetDebugDraw<span style="color: #000000;">&#40;</span>debug_draw<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span>e <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			world.Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">30</span>, <span style="color: #000000; font-weight:bold;">10</span>, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;			
			world.ClearForces<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>&#8230; and this is what you&#8217;ll get:</p>
<p><embed src="/wp-content/uploads/2010/08/bison.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>This the same scene of the screenshot you can see at the beginning of this post.</p>
<p>Next time, I&#8217;ll show you how to generate the same thing reading an external XML, and how to add more features.</p>
<p><a href="/wp-content/uploads/2010/08/bison.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/16/create-box2d-levels-in-a-quick-with-bison-kick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Basic Box2D editor using Flash movieclips</title>
		<link>http://www.emanueleferonato.com/2010/07/12/basic-box2d-editor-using-flash-movieclips/</link>
		<comments>http://www.emanueleferonato.com/2010/07/12/basic-box2d-editor-using-flash-movieclips/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 11:16:20 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3103</guid>
		<description><![CDATA[When you are about to design a level or whatever else in Box2D, you have to face some design issues due to different unit measurements (Flash works with pixels while Box2D uses meters) and the common problems in level design: the need to have a WYSIWYG interface. Some frameworks such as Citrus Engine, have a [...]]]></description>
			<content:encoded><![CDATA[<p>When you are about to design a level or whatever else in Box2D, you have to face some design issues due to different unit measurements (Flash works with pixels while Box2D uses meters) and the common problems in level design: the need to have a <a href="http://en.wikipedia.org/wiki/WYSIWYG" target = "_blank">WYSIWYG</a> interface.</p>
<p>Some frameworks such as <a href="http://www.emanueleferonato.com/2010/03/16/citrus-engine-released-for-free-for-learning/">Citrus Engine</a>, have a built in editor, but what if you are making a Box2D project on your own?</p>
<p>I am making a little Box2D editor to be used in a couple of games I am making, and it&#8217;s based on&#8230; Flash movieclips.</p>
<p>It&#8217;s the easiest solution if you don&#8217;t need a lot of features. The best solution for simple games such as <a href="http://www.emanueleferonato.com/2009/03/06/full-totem-destroyer-prototype/">Totem Destroyer</a>.</p>
<p>It works this way: first, we need a movieclip with a box, centered in its origin:</p>
<p><img src="/wp-content/uploads/2010/07/editor.png" /></p>
<p>Then using this movieclip, we start building the level in another movieclip just adding and transforming the original box movieclip:</p>
<p><img src="/wp-content/uploads/2010/07/editor2.png" /></p>
<p>Finally, we need to tell the movieclip which boxes are static and which ones are dynamic: I am giving a <code>d</code> instance name for dynamic boxes and a <code>s</code> instance name for static boxes.</p>
<p>Then it&#8217;s just actionscript:<span id="more-3103"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> b2ded extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #009900;">// this is the size of the original box movieclip</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> box_original_size<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">40</span>;
		<span style="color: #009900;">// importing the editor movieclip</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> editor<span style="color: #000000; font-weight: bold;">:</span>editor_mc = <span style="color: #0033ff; font-weight: bold;">new</span> editor_mc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world<span style="color: #000000; font-weight: bold;">:</span>b2World=<span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world_scale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">30</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> b2ded<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// placing the editor movieclip in transparency to show its precision</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>editor<span style="color: #000000;">&#41;</span>;
			editor.<span style="color: #004993;">alpha</span>=<span style="color: #000000; font-weight:bold;">0.2</span>
			<span style="color: #009900;">// looping through all children in the editor movieclip</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>;i<span style="color: #000000; font-weight: bold;">&lt;</span>editor.<span style="color: #004993;">numChildren</span>;i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">with</span> <span style="color: #000000;">&#40;</span>editor.<span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #009900;">// calling the function to fraw a Box2D oriented box</span>
					<span style="color: #009900;">// just notice how I use scaleX and scaleY instead of width and height</span>
					<span style="color: #009900;">// because it would give wrong results when dealing with rotated movieclips</span>
					draw_box<span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span>,<span style="color: #004993;">y</span>,box_original_size<span style="color: #000000; font-weight: bold;">*</span><span style="color: #004993;">scaleX</span>,box_original_size<span style="color: #000000; font-weight: bold;">*</span><span style="color: #004993;">scaleY</span>,<span style="color: #004993;">rotation</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">0.0174532925</span>,<span style="color: #004993;">name</span>==<span style="color: #990000;">&quot;d&quot;</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, update<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_box<span style="color: #000000;">&#40;</span>x_origin<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,y_origin<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,box_width<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,box_height<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,<span style="color: #004993;">angle</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,is_dynamic<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_body<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>is_dynamic<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				my_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box.SetAsOrientedBox<span style="color: #000000;">&#40;</span>box_width<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, box_height<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>x_origin<span style="color: #000000; font-weight: bold;">/</span>world_scale,y_origin<span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_fixture.shape=my_box;
			<span style="color: #6699cc; font-weight: bold;">var</span> world_body<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>my_body<span style="color: #000000;">&#41;</span>;
			world_body.CreateFixture<span style="color: #000000;">&#40;</span>my_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_draw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetSprite<span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetDrawScale<span style="color: #000000;">&#40;</span>world_scale<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit<span style="color: #000000;">&#41;</span>;
			world.SetDebugDraw<span style="color: #000000;">&#40;</span>debug_draw<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span>e <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			world.Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
			world.ClearForces<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And this is the result:</p>
<p><embed src="/wp-content/uploads/2010/07/b2ded.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>As you can see I perfectly recreated the Box2D environment I made in the editor movieclip.</p>
<p>Obviously it&#8217;s far from being complete, but you can add more features just playing with instance name, adding attributes such as density, restitution and so on. If I receive a good feedback, I can improve the editor or share the one I am making for my games.</p>
<p><a href="/wp-content/uploads/2010/07/b2ded.zip">Download the source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/07/12/basic-box2d-editor-using-flash-movieclips/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Following a body with the camera in Box2D &#8211; The smart way</title>
		<link>http://www.emanueleferonato.com/2010/05/04/following-a-body-with-the-camera-in-box2d-the-smart-way/</link>
		<comments>http://www.emanueleferonato.com/2010/05/04/following-a-body-with-the-camera-in-box2d-the-smart-way/#comments</comments>
		<pubDate>Tue, 04 May 2010 15:49:50 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2828</guid>
		<description><![CDATA[We are about to create an intelligent camera that will follow a body in Box2D. What&#8217;s the difference between an intelligent camera and a dumb one? Simple&#8230; the intelligent camera follows the object keeping it in the middle of the screen as long as there are enough game area to fill the screen. The dumb [...]]]></description>
			<content:encoded><![CDATA[<p>We are about to create an intelligent camera that will follow a body in Box2D. What&#8217;s the difference between an intelligent camera and a dumb one?</p>
<p>Simple&#8230; the intelligent camera follows the object keeping it in the middle of the screen as long as there are enough game area to fill the screen. The dumb one just keeps the object in the middle of the screen, sometime causing to have just a little part of the game on the screen.</p>
<p>Let me make things clearer with a real world example:</p>
<p><img src="/wp-content/uploads/2010/05/smart01.png" /></p>
<p>In this map, taken from <a href="http://en.wikipedia.org/wiki/Crystal_Kingdom_Dizzy" target = "_blank">Crystal Kingdom Dizzy</a>, the cherry is followed by a smart camera, because the cherry is centered and the game area fills the entire screen.</p>
<p>Now look at this:<span id="more-2828"></span></p>
<p><img src="/wp-content/uploads/2010/05/smart02.png" /></p>
<p>The cherry moved up and the camera followed it in a dumb way: the camera wanted to keep the cherry in the middle of the screen, but doing it will make the game scroll down even if there aren&#8217;t enough game area to fill the entire screen.</p>
<p>An intelligent camera should show the cherry this way:</p>
<p><img src="/wp-content/uploads/2010/05/smart03.png" /></p>
<p>So when the cherry moves in a direction that would make the game scroll away from the screen, the camera has to release it and don&#8217;t keep it in the middle of the screen until there is enough gaming area to fill the entire screen.</p>
<p>How do we apply this concept to the <a href="http://www.emanueleferonato.com/2010/04/29/following-a-body-with-the-camera-in-box2d/">catapult prototype</a>?</p>
<p>This way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> main extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world<span style="color: #000000; font-weight: bold;">:</span>b2World=<span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world_scale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">30</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> the_cannonball_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> catapult_chassis_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> arm_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> left_key_pressed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> right_key_pressed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> following_catapult<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">true</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> bg<span style="color: #000000; font-weight: bold;">:</span>background_mc = <span style="color: #0033ff; font-weight: bold;">new</span> background_mc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bg<span style="color: #000000;">&#41;</span>;
			debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_ground<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_body<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_arm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_motor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_wheels<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_wheel_motors<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_cannonball<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, update<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_DOWN</span>, key_down<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_UP</span>, key_up<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_cannonball<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> cannonball<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> ball<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> cannonball_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cannonball_fixture.shape=ball;
			cannonball_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			cannonball_fixture.density=<span style="color: #000000; font-weight:bold;">20</span>;
			cannonball_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.5</span>;
			the_cannonball_itself=world.CreateBody<span style="color: #000000;">&#40;</span>cannonball<span style="color: #000000;">&#41;</span>;
			the_cannonball_itself.CreateFixture<span style="color: #000000;">&#40;</span>cannonball_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_wheel_motors<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			front_wheel_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, front_wheel_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			front_wheel_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>front_wheel_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			front_wheel_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			rear_wheel_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, rear_wheel_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>rear_wheel_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			rear_wheel_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_wheels<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			rear_wheel.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_shape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_fixture.shape=rear_wheel_shape;
			rear_wheel_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			rear_wheel_fixture.density=<span style="color: #000000; font-weight:bold;">30</span>;
			rear_wheel_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			rear_wheel_body=world.CreateBody<span style="color: #000000;">&#40;</span>rear_wheel<span style="color: #000000;">&#41;</span>;
			rear_wheel_body.CreateFixture<span style="color: #000000;">&#40;</span>rear_wheel_fixture<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">450</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			front_wheel.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_shape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_fixture.shape=front_wheel_shape;
			front_wheel_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			front_wheel_fixture.density=<span style="color: #000000; font-weight:bold;">30</span>;
			front_wheel_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			front_wheel_body=world.CreateBody<span style="color: #000000;">&#40;</span>front_wheel<span style="color: #000000;">&#41;</span>;
			front_wheel_body.CreateFixture<span style="color: #000000;">&#40;</span>front_wheel_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_motor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.enableLimit=<span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, catapult_arm_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>arm_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			arm_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint.SetLimits<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span>,<span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_arm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_arm.allowSleep=<span style="color: #0033ff; font-weight: bold;">false</span>;
			catapult_arm.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">210</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">110</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_arm.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_part_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_part_fixture.shape=arm_part;
			arm_part_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			arm_part_fixture.density=<span style="color: #000000; font-weight:bold;">5</span>;
			arm_part_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> stopper<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			stopper.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">140</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> stopper_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			stopper_fixture.shape=stopper;
			stopper_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			stopper_fixture.density=<span style="color: #000000; font-weight:bold;">10</span>;
			stopper_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			catapult_arm_body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_arm<span style="color: #000000;">&#41;</span>;
			catapult_arm_body.CreateFixture<span style="color: #000000;">&#40;</span>arm_part_fixture<span style="color: #000000;">&#41;</span>;
			catapult_arm_body.CreateFixture<span style="color: #000000;">&#40;</span>stopper_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_body<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_body<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> main_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			main_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">125</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> chassis_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			chassis_fixture.shape=main_part;
			chassis_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			chassis_fixture.density=<span style="color: #000000; font-weight:bold;">50</span>;
			chassis_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> fixed_arm<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			fixed_arm.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> fixed_arm_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			fixed_arm_fixture.shape=fixed_arm;
			fixed_arm_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			fixed_arm_fixture.density=<span style="color: #000000; font-weight:bold;">1</span>;
			fixed_arm_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			catapult_chassis_body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_body<span style="color: #000000;">&#41;</span>;
			catapult_chassis_body.CreateFixture<span style="color: #000000;">&#40;</span>chassis_fixture<span style="color: #000000;">&#41;</span>;
			catapult_chassis_body.CreateFixture<span style="color: #000000;">&#40;</span>fixed_arm_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_ground<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ground.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2500</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box.SetAsBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2500</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> ground_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ground_fixture.shape=my_box;
			ground_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			ground_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box2<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box2.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2485</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">335</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> right_wall_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			right_wall_fixture.shape=my_box2;
			right_wall_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			right_wall_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box3<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box3.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">2485</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">335</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> left_wall_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			left_wall_fixture.shape=my_box3;
			left_wall_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			left_wall_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box4<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box4.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2500</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">670</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> roof_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			roof_fixture.shape=my_box4;
			roof_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			roof_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> the_ground_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>ground<span style="color: #000000;">&#41;</span>;
			the_ground_itself.CreateFixture<span style="color: #000000;">&#40;</span>ground_fixture<span style="color: #000000;">&#41;</span>;
			the_ground_itself.CreateFixture<span style="color: #000000;">&#40;</span>right_wall_fixture<span style="color: #000000;">&#41;</span>;
			the_ground_itself.CreateFixture<span style="color: #000000;">&#40;</span>left_wall_fixture<span style="color: #000000;">&#41;</span>;
			the_ground_itself.CreateFixture<span style="color: #000000;">&#40;</span>roof_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_up<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span> <span style="color: #000000; font-weight: bold;">:</span>
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span> <span style="color: #000000; font-weight: bold;">:</span>
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_down<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span> <span style="color: #000000; font-weight: bold;">:</span>
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">true</span>;
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span> <span style="color: #000000; font-weight: bold;">:</span>
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">true</span>;
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">32</span> <span style="color: #000000; font-weight: bold;">:</span>
					arm_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10000</span><span style="color: #000000;">&#41;</span>;
					following_catapult=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_draw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetSprite<span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetDrawScale<span style="color: #000000;">&#40;</span>world_scale<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit<span style="color: #000000; font-weight: bold;">|</span>b2DebugDraw.e_jointBit<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span>;
			world.SetDebugDraw<span style="color: #000000;">&#40;</span>debug_draw<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> set_motor_speed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> current_speed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>right_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=<span style="color: #000000; font-weight:bold;">1</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>left_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> right_key_pressed<span style="color: #000000; font-weight: bold;">&amp;&amp;!</span> left_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=rear_wheel_revolute_joint.GetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">0.9</span>;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					current_speed=<span style="color: #000000; font-weight:bold;">0</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			rear_wheel_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span>;
			front_wheel_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> pos_x<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> pos_y<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
			set_motor_speed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>following_catapult<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				pos_x=catapult_chassis_body.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">*</span>world_scale;
				pos_y=catapult_chassis_body.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">*</span>world_scale;
			<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
				pos_x=the_cannonball_itself.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">*</span>world_scale;
				pos_y=the_cannonball_itself.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">*</span>world_scale;
			<span style="color: #000000;">&#125;</span>
			pos_x=<span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">-</span>pos_x;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>pos_x<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">4500</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				pos_x=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">4500</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>pos_x<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				pos_x=<span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">x</span>=pos_x;
			pos_y=<span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">-</span>pos_y;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>pos_y<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				pos_y=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">15</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>pos_y<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">285</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				pos_y=<span style="color: #000000; font-weight:bold;">285</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">y</span>=pos_y;
			world.ClearForces<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And this is the result:</p>
<p><embed src="/wp-content/uploads/2010/05/ctp5.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Left and right arrows to move the catapult, spacebar to fire</p>
<p><a href = "/wp-content/uploads/2010/05/ctp5.zip">Download</a> the example and wait for the fully commented source code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/05/04/following-a-body-with-the-camera-in-box2d-the-smart-way/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Following a body with the camera in Box2D</title>
		<link>http://www.emanueleferonato.com/2010/04/29/following-a-body-with-the-camera-in-box2d/</link>
		<comments>http://www.emanueleferonato.com/2010/04/29/following-a-body-with-the-camera-in-box2d/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 03:57:19 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2813</guid>
		<description><![CDATA[If you want to make a good game, a good camera movement is necessary. This time we&#8217;ll learn to follow a Box2D object with the camera. Box2D does not have a &#8220;camera&#8221;, so we will have to move the stage according to body position. This is the same script as Real world catapult using Box2D [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to make a good game, a good camera movement is necessary.</p>
<p>This time we&#8217;ll learn to follow a Box2D object with the camera. Box2D does not have a &#8220;camera&#8221;, so we will have to move the stage according to body position. This is the same script as <a href="http://www.emanueleferonato.com/2010/04/14/real-world-catapult-prototype-using-box2d-–-cleaner-code/">Real world catapult using Box2D &#8211; cleaner code</a>, I just placed a gradient background to help you seeing how the camera is following the objects.</p>
<p>The main idea is following the catapult until it fires the cannonball, then following the cannonball.</p>
<p>This is the result:</p>
<p><embed src="/wp-content/uploads/2010/04/ctp41.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Left and right to move, spacebar to fire</p>
<p>And this is the code:<span id="more-2813"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> main extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world<span style="color: #000000; font-weight: bold;">:</span>b2World=<span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world_scale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">30</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> the_cannonball_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> catapult_chassis_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> arm_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> left_key_pressed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> right_key_pressed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> following_catapult<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">true</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> bg<span style="color: #000000; font-weight: bold;">:</span>background_mc = <span style="color: #0033ff; font-weight: bold;">new</span> background_mc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bg<span style="color: #000000;">&#41;</span>;
			debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_ground<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_body<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_arm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_motor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_wheels<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_wheel_motors<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_cannonball<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, update<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_DOWN</span>, key_down<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_UP</span>, key_up<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_cannonball<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> cannonball<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> ball<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> cannonball_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cannonball_fixture.shape=ball;
			cannonball_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			cannonball_fixture.density=<span style="color: #000000; font-weight:bold;">20</span>;
			cannonball_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.5</span>;
			the_cannonball_itself=world.CreateBody<span style="color: #000000;">&#40;</span>cannonball<span style="color: #000000;">&#41;</span>;
			the_cannonball_itself.CreateFixture<span style="color: #000000;">&#40;</span>cannonball_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_wheel_motors<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			front_wheel_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, front_wheel_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			front_wheel_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>front_wheel_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			front_wheel_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			rear_wheel_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, rear_wheel_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>rear_wheel_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			rear_wheel_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_wheels<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			rear_wheel.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_shape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_fixture.shape=rear_wheel_shape;
			rear_wheel_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			rear_wheel_fixture.density=<span style="color: #000000; font-weight:bold;">30</span>;
			rear_wheel_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			rear_wheel_body=world.CreateBody<span style="color: #000000;">&#40;</span>rear_wheel<span style="color: #000000;">&#41;</span>;
			rear_wheel_body.CreateFixture<span style="color: #000000;">&#40;</span>rear_wheel_fixture<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">450</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			front_wheel.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_shape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_fixture.shape=front_wheel_shape;
			front_wheel_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			front_wheel_fixture.density=<span style="color: #000000; font-weight:bold;">30</span>;
			front_wheel_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			front_wheel_body=world.CreateBody<span style="color: #000000;">&#40;</span>front_wheel<span style="color: #000000;">&#41;</span>;
			front_wheel_body.CreateFixture<span style="color: #000000;">&#40;</span>front_wheel_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_motor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.enableLimit=<span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, catapult_arm_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>arm_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			arm_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint.SetLimits<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span>,<span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_arm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_arm.allowSleep=<span style="color: #0033ff; font-weight: bold;">false</span>;
			catapult_arm.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">210</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">110</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_arm.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_part_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_part_fixture.shape=arm_part;
			arm_part_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			arm_part_fixture.density=<span style="color: #000000; font-weight:bold;">5</span>;
			arm_part_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> stopper<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			stopper.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">140</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> stopper_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			stopper_fixture.shape=stopper;
			stopper_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			stopper_fixture.density=<span style="color: #000000; font-weight:bold;">10</span>;
			stopper_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			catapult_arm_body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_arm<span style="color: #000000;">&#41;</span>;
			catapult_arm_body.CreateFixture<span style="color: #000000;">&#40;</span>arm_part_fixture<span style="color: #000000;">&#41;</span>;
			catapult_arm_body.CreateFixture<span style="color: #000000;">&#40;</span>stopper_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_body<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_body<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> main_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			main_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">125</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> chassis_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			chassis_fixture.shape=main_part;
			chassis_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			chassis_fixture.density=<span style="color: #000000; font-weight:bold;">50</span>;
			chassis_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> fixed_arm<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			fixed_arm.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> fixed_arm_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			fixed_arm_fixture.shape=fixed_arm;
			fixed_arm_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			fixed_arm_fixture.density=<span style="color: #000000; font-weight:bold;">1</span>;
			fixed_arm_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			catapult_chassis_body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_body<span style="color: #000000;">&#41;</span>;
			catapult_chassis_body.CreateFixture<span style="color: #000000;">&#40;</span>chassis_fixture<span style="color: #000000;">&#41;</span>;
			catapult_chassis_body.CreateFixture<span style="color: #000000;">&#40;</span>fixed_arm_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_ground<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ground.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box.SetAsBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">5000</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> ground_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ground_fixture.shape=my_box;
			ground_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			ground_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_ground_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>ground<span style="color: #000000;">&#41;</span>;
			the_ground_itself.CreateFixture<span style="color: #000000;">&#40;</span>ground_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_up<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span> <span style="color: #000000; font-weight: bold;">:</span>
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span> <span style="color: #000000; font-weight: bold;">:</span>
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_down<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span> <span style="color: #000000; font-weight: bold;">:</span>
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">true</span>;
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span> <span style="color: #000000; font-weight: bold;">:</span>
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">true</span>;
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">32</span> <span style="color: #000000; font-weight: bold;">:</span>
					arm_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10000</span><span style="color: #000000;">&#41;</span>;
					following_catapult=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_draw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetSprite<span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetDrawScale<span style="color: #000000;">&#40;</span>world_scale<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit<span style="color: #000000; font-weight: bold;">|</span>b2DebugDraw.e_jointBit<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span>;
			world.SetDebugDraw<span style="color: #000000;">&#40;</span>debug_draw<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> set_motor_speed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> current_speed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>right_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=<span style="color: #000000; font-weight:bold;">1</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>left_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> right_key_pressed<span style="color: #000000; font-weight: bold;">&amp;&amp;!</span> left_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=rear_wheel_revolute_joint.GetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">0.9</span>;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					current_speed=<span style="color: #000000; font-weight:bold;">0</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			rear_wheel_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span>;
			front_wheel_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> pos_x<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> pos_y<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
			set_motor_speed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>following_catapult<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				pos_x=catapult_chassis_body.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">*</span>world_scale;
				pos_y=catapult_chassis_body.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">*</span>world_scale;
			<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
				pos_x=the_cannonball_itself.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">*</span>world_scale;
				pos_y=the_cannonball_itself.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">*</span>world_scale;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">x</span>=<span style="color: #004993;">stage</span>.<span style="color: #004993;">stageWidth</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">-</span>pos_x;
			<span style="color: #004993;">y</span>=<span style="color: #004993;">stage</span>.<span style="color: #004993;">stageHeight</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">-</span>pos_y;
			world.ClearForces<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a href="/wp-content/uploads/2010/04/ctp41.zip">Download the source code</a>. Next time, smarter camera movement and fully commented code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/04/29/following-a-body-with-the-camera-in-box2d/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Quoted on Adobe Edge: April 2010 edition</title>
		<link>http://www.emanueleferonato.com/2010/04/27/quoted-on-adobe-edge-april-2010-edition/</link>
		<comments>http://www.emanueleferonato.com/2010/04/27/quoted-on-adobe-edge-april-2010-edition/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 02:40:20 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2806</guid>
		<description><![CDATA[If you want to read an interesting article about Flash games and physics, I suggest you to point your browser on Developing physics-based games with Adobe Flash Professional by Samuel Asher Rivello. I was quoted in the article, but what makes it really great is the way it will guide you through the creation of [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to read an interesting article about Flash games and physics, I suggest you to point your browser on <a href="http://www.adobe.com/newsletters/edge/april2010/articles/article7/" target = "_blank">Developing physics-based games with Adobe Flash Professional</a> by <strong>Samuel Asher Rivello</strong>.</p>
<p>I was quoted in the article, but what makes it really great is the way it will guide you through the creation of a physics-based game called <strong>StackZ</strong></p>
<p> <a href="http://www.adobe.com/newsletters/edge/april2010/articles/article7/" target = "_blank"><img src="http://www.emanueleferonato.com/wp-content/uploads/2010/04/stackz.jpg" /></a></p>
<p>Also, Samuel has an awesome way to comment the code, a must see for all coders.</p>
<p>Happy reading</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/04/27/quoted-on-adobe-edge-april-2010-edition/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Real world catapult prototype using Box2D – Cleaner code</title>
		<link>http://www.emanueleferonato.com/2010/04/14/real-world-catapult-prototype-using-box2d-%e2%80%93-cleaner-code/</link>
		<comments>http://www.emanueleferonato.com/2010/04/14/real-world-catapult-prototype-using-box2d-%e2%80%93-cleaner-code/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 16:58:47 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2732</guid>
		<description><![CDATA[We got it. After the first catapult prototype and the &#8220;slippery wheels&#8221; sequel, this is a version with realistic movement and a lot cleaner code. To add realistic movement I defined friction and restitution, making useless the CreateFixture2 function and widely using the more appropriate CreateFixture one. This way I have full control on fixtures, [...]]]></description>
			<content:encoded><![CDATA[<p>We got it.</p>
<p>After the <a href="http://www.emanueleferonato.com/2010/04/07/real-world-catapult-prototype-using-box2d/">first catapult prototype</a> and the <a href="http://www.emanueleferonato.com/2010/04/09/real-world-catapult-prototype-using-box2d-adding-wheels/">&#8220;slippery wheels&#8221; sequel</a>, this is a version with realistic movement and a lot cleaner code.</p>
<p>To add realistic movement I defined friction and restitution, making useless the <code>CreateFixture2</code> function and widely using the more appropriate <code>CreateFixture</code> one.</p>
<p>This way I have full control on fixtures, while in the old way I could only define their masses.</p>
<p>This is the result:</p>
<p><embed src="/wp-content/uploads/2010/04/ctp3.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Left and right to move, spacebar to fire<span id="more-2732"></span></p>
<p>And this is the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> main extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world<span style="color: #000000; font-weight: bold;">:</span>b2World=<span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world_scale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">30</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> catapult_chassis_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #6699cc; font-weight: bold;">var</span> arm_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_revolute_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> left_key_pressed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> right_key_pressed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_ground<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_body<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_arm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_catapult_motor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_wheels<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_wheel_motors<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			the_cannonball<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, update<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_DOWN</span>, key_down<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_UP</span>, key_up<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_cannonball<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> cannonball<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> ball<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> cannonball_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cannonball_fixture.shape=ball;
			cannonball_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			cannonball_fixture.density=<span style="color: #000000; font-weight:bold;">20</span>;
			cannonball_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.5</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_cannonball_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>cannonball<span style="color: #000000;">&#41;</span>;
			the_cannonball_itself.CreateFixture<span style="color: #000000;">&#40;</span>cannonball_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_wheel_motors<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			front_wheel_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, front_wheel_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			front_wheel_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>front_wheel_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			front_wheel_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			rear_wheel_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, rear_wheel_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>rear_wheel_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			rear_wheel_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_wheels<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			rear_wheel.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_shape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_fixture.shape=rear_wheel_shape;
			rear_wheel_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			rear_wheel_fixture.density=<span style="color: #000000; font-weight:bold;">30</span>;
			rear_wheel_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			rear_wheel_body=world.CreateBody<span style="color: #000000;">&#40;</span>rear_wheel<span style="color: #000000;">&#41;</span>;
			rear_wheel_body.CreateFixture<span style="color: #000000;">&#40;</span>rear_wheel_fixture<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">450</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			front_wheel.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_shape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_fixture.shape=front_wheel_shape;
			front_wheel_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			front_wheel_fixture.density=<span style="color: #000000; font-weight:bold;">30</span>;
			front_wheel_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			front_wheel_body=world.CreateBody<span style="color: #000000;">&#40;</span>front_wheel<span style="color: #000000;">&#41;</span>;
			front_wheel_body.CreateFixture<span style="color: #000000;">&#40;</span>front_wheel_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_motor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.enableLimit=<span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_chassis_body, catapult_arm_body,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint=world.CreateJoint<span style="color: #000000;">&#40;</span>arm_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			arm_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint.SetLimits<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span>,<span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_arm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_arm.allowSleep=<span style="color: #0033ff; font-weight: bold;">false</span>;
			catapult_arm.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">210</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">110</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_arm.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_part_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_part_fixture.shape=arm_part;
			arm_part_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			arm_part_fixture.density=<span style="color: #000000; font-weight:bold;">5</span>;
			arm_part_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> stopper<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			stopper.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">140</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> stopper_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			stopper_fixture.shape=stopper;
			stopper_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			stopper_fixture.density=<span style="color: #000000; font-weight:bold;">10</span>;
			stopper_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			catapult_arm_body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_arm<span style="color: #000000;">&#41;</span>;
			catapult_arm_body.CreateFixture<span style="color: #000000;">&#40;</span>arm_part_fixture<span style="color: #000000;">&#41;</span>;
			catapult_arm_body.CreateFixture<span style="color: #000000;">&#40;</span>stopper_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_catapult_body<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_body<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> main_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			main_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">125</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> chassis_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			chassis_fixture.shape=main_part;
			chassis_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			chassis_fixture.density=<span style="color: #000000; font-weight:bold;">50</span>;
			chassis_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> fixed_arm<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			fixed_arm.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> fixed_arm_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			fixed_arm_fixture.shape=fixed_arm;
			fixed_arm_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			fixed_arm_fixture.density=<span style="color: #000000; font-weight:bold;">1</span>;
			fixed_arm_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			catapult_chassis_body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_body<span style="color: #000000;">&#41;</span>;
			catapult_chassis_body.CreateFixture<span style="color: #000000;">&#40;</span>chassis_fixture<span style="color: #000000;">&#41;</span>;
			catapult_chassis_body.CreateFixture<span style="color: #000000;">&#40;</span>fixed_arm_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> the_ground<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ground.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box.SetAsBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">15</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> ground_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ground_fixture.shape=my_box;
			ground_fixture.friction=<span style="color: #000000; font-weight:bold;">0.9</span>;
			ground_fixture.restitution=<span style="color: #000000; font-weight:bold;">0.1</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_ground_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>ground<span style="color: #000000;">&#41;</span>;
			the_ground_itself.CreateFixture<span style="color: #000000;">&#40;</span>ground_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_up<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span> <span style="color: #000000; font-weight: bold;">:</span>
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span> <span style="color: #000000; font-weight: bold;">:</span>
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_down<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span> <span style="color: #000000; font-weight: bold;">:</span>
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">true</span>;
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span> <span style="color: #000000; font-weight: bold;">:</span>
					left_key_pressed=<span style="color: #0033ff; font-weight: bold;">true</span>;
					right_key_pressed=<span style="color: #0033ff; font-weight: bold;">false</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">32</span> <span style="color: #000000; font-weight: bold;">:</span>
					arm_revolute_joint.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10000</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_draw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetSprite<span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetDrawScale<span style="color: #000000;">&#40;</span>world_scale<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit<span style="color: #000000; font-weight: bold;">|</span>b2DebugDraw.e_jointBit<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span>;
			world.SetDebugDraw<span style="color: #000000;">&#40;</span>debug_draw<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> set_motor_speed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> current_speed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>right_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=<span style="color: #000000; font-weight:bold;">1</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>left_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> right_key_pressed<span style="color: #000000; font-weight: bold;">&amp;&amp;!</span> left_key_pressed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				current_speed=rear_wheel_revolute_joint.GetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">0.9</span>;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					current_speed=<span style="color: #000000; font-weight:bold;">0</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			rear_wheel_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span>;
			front_wheel_revolute_joint.SetMotorSpeed<span style="color: #000000;">&#40;</span>current_speed<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			set_motor_speed<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
			world.ClearForces<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>No need to download, just cut and paste on the <a href="http://www.emanueleferonato.com/2010/04/07/real-world-catapult-prototype-using-box2d/">first catapult prototype</a>.</p>
<p>Next time, full comments and some other interesting features&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/04/14/real-world-catapult-prototype-using-box2d-%e2%80%93-cleaner-code/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Real world catapult prototype using Box2D &#8211; Adding wheels</title>
		<link>http://www.emanueleferonato.com/2010/04/09/real-world-catapult-prototype-using-box2d-adding-wheels/</link>
		<comments>http://www.emanueleferonato.com/2010/04/09/real-world-catapult-prototype-using-box2d-adding-wheels/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 10:09:56 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2708</guid>
		<description><![CDATA[Did you enjoy the catapult prototype? Here I am with the second part, adding wheels controlled by left and right arrows. Have a look: Now you can move the catapult with left and arrow keys, and shoot with a mouse click If you feel the catapult is running on an icy surface, that&#8217;s because I [...]]]></description>
			<content:encoded><![CDATA[<p>Did you enjoy the <a href="http://www.emanueleferonato.com/2010/04/07/real-world-catapult-prototype-using-box2d/">catapult prototype</a>?</p>
<p>Here I am with the second part, adding wheels controlled by left and right arrows.</p>
<p>Have a look:</p>
<p><embed src="/wp-content/uploads/2010/04/ctp2.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Now you can move the catapult with left and arrow keys, and shoot with a mouse click</p>
<p>If you feel the catapult is running on an icy surface, that&#8217;s because I did not set any friction. I&#8217;ll do it next time, when I&#8217;ll also come with a decent code, meanwhile check this:<span id="more-2708"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> main extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world<span style="color: #000000; font-weight: bold;">:</span>b2World=<span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world_scale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">30</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> arm_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> arm_revolute_joint_def<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_joint_def<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_joint_def<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #6699cc; font-weight: bold;">var</span> catapult_body<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> catapult_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			draw_box<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">400</span>,<span style="color: #000000; font-weight:bold;">2000</span>,<span style="color: #000000; font-weight:bold;">30</span>,<span style="color: #0033ff; font-weight: bold;">false</span>,<span style="color: #990000;">&quot;ground&quot;</span><span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> main_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			main_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">125</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> fixed_arm<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			fixed_arm.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			catapult_itself=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_body<span style="color: #000000;">&#41;</span>;
			catapult_itself.CreateFixture2<span style="color: #000000;">&#40;</span>main_part,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span>;
			catapult_itself.CreateFixture2<span style="color: #000000;">&#40;</span>fixed_arm,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_arm.allowSleep=<span style="color: #0033ff; font-weight: bold;">false</span>;
			catapult_arm.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">210</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">110</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_arm.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> stopper<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			stopper.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">140</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_arm<span style="color: #000000;">&#41;</span>;
			catapult_arm_itself.CreateFixture2<span style="color: #000000;">&#40;</span>arm_part,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
			catapult_arm_itself.CreateFixture2<span style="color: #000000;">&#40;</span>stopper,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			arm_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.enableLimit=<span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_itself, catapult_arm_itself,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint_def=world.CreateJoint<span style="color: #000000;">&#40;</span>arm_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			arm_revolute_joint_def.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint_def.SetLimits<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span>,<span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
			arm_revolute_joint_def.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			rear_wheel.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> rear_wheel_shape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_rear_wheel_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>rear_wheel<span style="color: #000000;">&#41;</span>;
			the_rear_wheel_itself.CreateFixture2<span style="color: #000000;">&#40;</span>rear_wheel_shape,<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			front_wheel.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">450</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			front_wheel.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> front_wheel_shape<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_front_wheel_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>front_wheel<span style="color: #000000;">&#41;</span>;
			the_front_wheel_itself.CreateFixture2<span style="color: #000000;">&#40;</span>front_wheel_shape,<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			front_wheel_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			front_wheel_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_itself, the_front_wheel_itself,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			front_wheel_joint_def=world.CreateJoint<span style="color: #000000;">&#40;</span>front_wheel_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			front_wheel_joint_def.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			rear_wheel_joint.enableMotor=<span style="color: #0033ff; font-weight: bold;">true</span>;
			rear_wheel_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_itself, the_rear_wheel_itself,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			rear_wheel_joint_def=world.CreateJoint<span style="color: #000000;">&#40;</span>rear_wheel_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			rear_wheel_joint_def.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> cannonball<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> ball<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_cannonball_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>cannonball<span style="color: #000000;">&#41;</span>;
			the_cannonball_itself.CreateFixture2<span style="color: #000000;">&#40;</span>ball,<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, update<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>,fire<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_DOWN</span>, key_down<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_down<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span> <span style="color: #000000; font-weight: bold;">:</span>
					rear_wheel_joint_def.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
					front_wheel_joint_def.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span> <span style="color: #000000; font-weight: bold;">:</span>
					rear_wheel_joint_def.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
					front_wheel_joint_def.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">break</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> fire<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			arm_revolute_joint_def.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10000</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_box<span style="color: #000000;">&#40;</span>px,py,w,h,<span style="color: #004993;">d</span>,ud<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ground.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span>px<span style="color: #000000; font-weight: bold;">/</span>world_scale, py<span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				ground.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box.SetAsBox<span style="color: #000000;">&#40;</span>w<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, h<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_fixture.shape=my_box;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_ground_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>ground<span style="color: #000000;">&#41;</span>;
			the_ground_itself.SetUserData<span style="color: #000000;">&#40;</span>ud<span style="color: #000000;">&#41;</span>;
			the_ground_itself.CreateFixture<span style="color: #000000;">&#40;</span>my_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_draw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetSprite<span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetDrawScale<span style="color: #000000;">&#40;</span>world_scale<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit<span style="color: #000000; font-weight: bold;">|</span>b2DebugDraw.e_jointBit<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span>;
			world.SetDebugDraw<span style="color: #000000;">&#40;</span>debug_draw<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			world.Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
			world.ClearForces<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>No need to download anything, just paste the new code in the <a href="http://www.emanueleferonato.com/2010/04/07/real-world-catapult-prototype-using-box2d/">catapult prototype</a> file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/04/09/real-world-catapult-prototype-using-box2d-adding-wheels/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Real world catapult prototype using Box2D</title>
		<link>http://www.emanueleferonato.com/2010/04/07/real-world-catapult-prototype-using-box2d/</link>
		<comments>http://www.emanueleferonato.com/2010/04/07/real-world-catapult-prototype-using-box2d/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 20:44:46 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2680</guid>
		<description><![CDATA[This is an early attempt to simulate a real world catapult using Box2D. Raw and uncommented code, but a lot of useful information about compound objects, revolute joints and motors. This is what you&#8217;ll get: Click with the mouse to shoot the ball. And this is the source code: 1 2 3 4 5 6 [...]]]></description>
			<content:encoded><![CDATA[<p>This is an early attempt to simulate a real world catapult using Box2D.</p>
<p>Raw and uncommented code, but a lot of useful information about <a href="http://www.emanueleferonato.com/2008/12/12/the-magic-of-compound-objects-with-box2d/">compound objects</a>, <a href="http://www.emanueleferonato.com/2009/01/13/box2d-joints-revolute-joint/">revolute joints</a> and <a href="http://www.emanueleferonato.com/2009/01/19/box2d-joints-revolute-joint-building-motors/">motors</a>.</p>
<p>This is what you&#8217;ll get:</p>
<p><embed src="/wp-content/uploads/2010/04/ctp.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Click with the mouse to shoot the ball.<span id="more-2680"></span></p>
<p>And this is the source code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
81
82
83
84
85
86
87
88
89
90
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> main extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world<span style="color: #000000; font-weight: bold;">:</span>b2World=<span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world_scale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">30</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> arm_joint<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> the_joint_itself<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJoint;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			draw_box<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">400</span>,<span style="color: #000000; font-weight:bold;">500</span>,<span style="color: #000000; font-weight:bold;">30</span>,<span style="color: #0033ff; font-weight: bold;">false</span>,<span style="color: #990000;">&quot;ground&quot;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_body<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">350</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> main_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			main_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">125</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> fixed_arm<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			fixed_arm.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_body<span style="color: #000000;">&#41;</span>;
			catapult_itself.CreateFixture2<span style="color: #000000;">&#40;</span>main_part,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span>;
			catapult_itself.CreateFixture2<span style="color: #000000;">&#40;</span>fixed_arm,<span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			catapult_arm.allowSleep = <span style="color: #0033ff; font-weight: bold;">false</span>;
			catapult_arm.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">210</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">110</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			catapult_arm.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> arm_part<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			arm_part.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">150</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> stopper<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			stopper.SetAsOrientedBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">140</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> catapult_arm_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>catapult_arm<span style="color: #000000;">&#41;</span>;
			catapult_arm_itself.CreateFixture2<span style="color: #000000;">&#40;</span>arm_part,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
			catapult_arm_itself.CreateFixture2<span style="color: #000000;">&#40;</span>stopper,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
			arm_joint.enableMotor = <span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.enableLimit = <span style="color: #0033ff; font-weight: bold;">true</span>;
			arm_joint.Initialize<span style="color: #000000;">&#40;</span>catapult_itself, catapult_arm_itself,<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorA=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			arm_joint.localAnchorB=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000; font-weight: bold;">/</span>world_scale,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
			the_joint_itself=world.CreateJoint<span style="color: #000000;">&#40;</span>arm_joint<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2RevoluteJoint;
			the_joint_itself.SetMotorSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span>;
			the_joint_itself.SetLimits<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span>,<span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
			the_joint_itself.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> 
			<span style="color: #6699cc; font-weight: bold;">var</span> cannonball<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			cannonball.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #6699cc; font-weight: bold;">var</span> ball<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_cannonball_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>cannonball<span style="color: #000000;">&#41;</span>;
			the_cannonball_itself.CreateFixture2<span style="color: #000000;">&#40;</span>ball,<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, update<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>,fire<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> fire<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			the_joint_itself.SetMaxMotorTorque<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10000</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_box<span style="color: #000000;">&#40;</span>px,py,w,h,<span style="color: #004993;">d</span>,ud<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef= <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ground.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span>px<span style="color: #000000; font-weight: bold;">/</span>world_scale, py<span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				ground.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box<span style="color: #000000; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_box.SetAsBox<span style="color: #000000;">&#40;</span>w<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, h<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_fixture<span style="color: #000000; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			my_fixture.shape=my_box;
			<span style="color: #6699cc; font-weight: bold;">var</span> the_ground_itself<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>ground<span style="color: #000000;">&#41;</span>;
			the_ground_itself.SetUserData<span style="color: #000000;">&#40;</span>ud<span style="color: #000000;">&#41;</span>;
			the_ground_itself.CreateFixture<span style="color: #000000;">&#40;</span>my_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_draw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetSprite<span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetDrawScale<span style="color: #000000;">&#40;</span>world_scale<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit<span style="color: #000000; font-weight: bold;">|</span>b2DebugDraw.e_jointBit<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span>;
			world.SetDebugDraw<span style="color: #000000;">&#40;</span>debug_draw<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			world.Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
			world.ClearForces<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a href="/wp-content/uploads/2010/04/ctp.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/04/07/real-world-catapult-prototype-using-box2d/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Case study: The Big Adventure &#8211; a Box2D RPG</title>
		<link>http://www.emanueleferonato.com/2010/04/01/case-study-the-big-adventure-a-box2d-rpg/</link>
		<comments>http://www.emanueleferonato.com/2010/04/01/case-study-the-big-adventure-a-box2d-rpg/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 22:20:49 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2644</guid>
		<description><![CDATA[Ok, it&#8217;s not an april fool&#8230; the bulgarian freelancer Krasimir Tsonev really made a Box2D based RPG game called The Big Adventure. And he also built the official game site with all features it needs to attract players: a community, a forum, a ladder, updated news&#8230; really a good job. Now he wants to share [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, it&#8217;s not an april fool&#8230; the <a href="http://www.outset.ws/blog" tatget = "_blank">bulgarian freelancer</a> <strong>Krasimir Tsonev</strong> really made a Box2D based RPG game called <a href="http://thebigadventure.svetsoft.com/" target = "_blank"><strong>The Big Adventure</strong></a>.</p>
<p><a href="http://thebigadventure.svetsoft.com/" target = "_blank"><img src="/wp-content/uploads/2010/04/tba.jpg" /></a></p>
<p>And he also built the official game site with all features it needs to attract players: a community, a forum, a ladder, updated news&#8230; really a good job.</p>
<p>Now he wants to share with us his experience:</p>
<p>&laquo; Actually I wanted to create a RPG game since a long time ago.</p>
<p>I made a little research about what engine to use and now the game is based on Box2D. Your articles helped me a lot in the beginning. Now the game has more than 1200 registered users.</p>
<p>Here it is a short information about the game:<span id="more-2644"></span></p>
<p>I spent the last two months working on it: the main idea was to use the Box2D engine to create a jump n&#8217;run game. But I also wanted to make an RPG so I decided to create towns between the levels.</p>
<p>So to travel between the towns you have to play the jump n&#8217;run game i.e. the Box2D game.</p>
<p>First I created the wrapper of the Box2D engine. You know it&#8217;s a little bit complicated to just start with it. Then created some of the major graphics like those of the heroes, some enemies, collisions among them etc.</p>
<p>One of the coolest features of RPG games is the inventory and the ability to wear something. I really love games like Diablo so I was inspired from them. I made possible to wear weapon, helmet, amulet, armour, gloves, belt, shoes and ring.</p>
<p>It was a little bit difficult to create the inventory actions. Like moving items there and placing them in the specific places. Of course some major things like checking if there is enough space in the inventory, if you are able to place some item in the specific place was also developed.</p>
<p>Invested some time in real time changing of the hero&#8217;s graphic. I.e. if you change your weapon the its graphic is also changed. The player also has some characteristics like strength, dexterity, luck, life, damage, defence.</p>
<p>The items that you are wearing give additional points of course. That wasn&#8217;t enough for me and I made a quest system. The quests can be taken from the taverns in the towns. You can speak with different people that of course have some problems to solve :)</p>
<p>After solving a quest you can get more gold, a new item or experience points. It was easy to create a shop for buying and selling items also. All the items and characteristics of the hero are auto saved every 7 seconds, which means that you can play again tomorrow and nothing of your progresses will be lost.</p>
<p>When I released the game more ideas just popped up in my mind. For example potions that can transform your hero in a mouse, rabbit or bear. The mouse potion is used to be able to go through really tiny places, the rabbit one to jump over a big hole and the bear potion to double your damage points.</p>
<p>Some of the ideas came from people that are playing the game. When I started the forum on the site some of them just suggested things that they would like. For example the marketplace. It&#8217;s a specific place in some of the towns where you can offer items to the other players for a price that you want. Then they can buy your items ;)</p>
<p>Some technical information:</p>
<p>- I used flex (AS3) and FlashDevelop to write the code<br />
- Flash for the graphics<br />
- <a href="http://en.wikipedia.org/wiki/LAMP_(software_bundle)" target = "_blank">LAMP</a> as a backend solution<br />
- Tons of AS3 libraries that I wrote during the last few years also take a part in the project<br />
- the MochiAds, Kongregate, GamesChart and Facebook apis are also integrated &raquo;</p>
<p>I wish Krasimir the best luck with his project and obviously he is invited to update us in a couple of months with some fresh news about the community, the monetization and new projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/04/01/case-study-the-big-adventure-a-box2d-rpg/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creation of a game with Citrus Engine</title>
		<link>http://www.emanueleferonato.com/2010/03/23/creation-of-a-game-with-citrus-engine/</link>
		<comments>http://www.emanueleferonato.com/2010/03/23/creation-of-a-game-with-citrus-engine/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 09:50:00 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2593</guid>
		<description><![CDATA[As said, we&#8217;re going to create a little game with Citrus Engine. Since the engine it&#8217;s ready, we can start with level design. So let&#8217;s open the Citrus Engine Level Architect, included in the package, and let&#8217;s start playing with it. The key of this little tool is the right mouse key. Pressing it will [...]]]></description>
			<content:encoded><![CDATA[<p>As said, we&#8217;re going to create a little game with <a href="http://www.emanueleferonato.com/2010/03/16/citrus-engine-released-for-free-for-learning/">Citrus Engine</a>.</p>
<p>Since the engine it&#8217;s ready, we can start with level design.</p>
<p>So let&#8217;s open the <strong>Citrus Engine Level Architect</strong>, included in the package, and let&#8217;s start playing with it.</p>
<p>The key of this little tool is the right mouse key. Pressing it will open a menu with all available assets.</p>
<p><img src="/wp-content/uploads/2010/03/cit01.png" /></p>
<p>Choose <code>Platform</code> and you will be able to create static Box2D boxes.</p>
<p>Now click anywhere with left mouse button and a black square will appear: that&#8217;s the platform. Drag and adjust it as you want.</p>
<p><img src="/wp-content/uploads/2010/03/cit02.png" /></p>
<p>Don&#8217;t worry about extreme precision: we&#8217;ll retouch it later. Once you placed some platforms, from the right click menu choose and place the hero, a coin and a couple of crates. Crates represent dynamic Box2D objects. This is what I&#8217;ve made:<span id="more-2593"></span></p>
<p><img src="/wp-content/uploads/2010/03/cit03.png" /></p>
<p>Then select <code>File->Save Level As</code> and save your level. Don&#8217;t worry about the path: despite what suggesting in the <a href="http://citrusengine.com/learning" target = "_blank">official docs</a> we won&#8217;t include external XML files. We are making a game to distribute it, so we need a single file.</p>
<p>Edit the created XML file removing this line</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span></pre></div></div>

<p>and eventually rounding the <code>x</code>, <code>y</code>, <code>width</code> and <code>height</code> attributes of your assets.</p>
<p>This is my final XML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #000000; font-weight: bold;">&lt;world</span> <span style="color: #000066;">gameWidth</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">gameHeight</span>=<span style="color: #ff0000;">&quot;400&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Platform</span> <span style="color: #000066;">offsetX</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Platform1&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;385&quot;</span> <span style="color: #000066;">restitution</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">movable</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">friction</span>=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #000066;">offsetY</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">rotation</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">mass</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">artType</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">parallax</span>=<span style="color: #ff0000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Platform</span> <span style="color: #000066;">offsetX</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;485&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Platform2&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">restitution</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">movable</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">friction</span>=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #000066;">offsetY</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">rotation</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;340&quot;</span> <span style="color: #000066;">mass</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">artType</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">parallax</span>=<span style="color: #ff0000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Platform</span> <span style="color: #000066;">offsetX</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;15&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Platform3&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">restitution</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">movable</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">friction</span>=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #000066;">offsetY</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">rotation</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;340&quot;</span> <span style="color: #000066;">mass</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">artType</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">parallax</span>=<span style="color: #ff0000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Platform</span> <span style="color: #000066;">offsetX</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Platform4&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;15&quot;</span> <span style="color: #000066;">restitution</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">movable</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">friction</span>=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #000066;">offsetY</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">rotation</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">mass</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">artType</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">parallax</span>=<span style="color: #ff0000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Hero</span> <span style="color: #000066;">hurtMagnitudeX</span>=<span style="color: #ff0000;">&quot;150&quot;</span> <span style="color: #000066;">maxHealth</span>=<span style="color: #ff0000;">&quot;10000000000&quot;</span> <span style="color: #000066;">friction</span>=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #000066;">acceleration</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">parallax</span>=<span style="color: #ff0000;">&quot;-1&quot;</span> <span style="color: #000066;">jumpHeight</span>=<span style="color: #ff0000;">&quot;360&quot;</span> <span style="color: #000066;">maxSpeedY</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">killBounceHeight</span>=<span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #000066;">hurtMagnitudeY</span>=<span style="color: #ff0000;">&quot;350&quot;</span> <span style="color: #000066;">boost</span>=<span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;33&quot;</span> <span style="color: #000066;">offsetX</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">maxSpeedX</span>=<span style="color: #ff0000;">&quot;180&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Hero1&quot;</span> <span style="color: #000066;">rotation</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">dampY</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">boostDuration</span>=<span style="color: #ff0000;">&quot;26&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;350&quot;</span> <span style="color: #000066;">restitution</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">movable</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;425&quot;</span> <span style="color: #000066;">offsetY</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">hurtInvincibility</span>=<span style="color: #ff0000;">&quot;5000&quot;</span> <span style="color: #000066;">mass</span>=<span style="color: #ff0000;">&quot;1.32&quot;</span> <span style="color: #000066;">artType</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">dampX</span>=<span style="color: #ff0000;">&quot;0.97&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Crate</span> <span style="color: #000066;">offsetX</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;275&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Crate1&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;325&quot;</span> <span style="color: #000066;">restitution</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">movable</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">friction</span>=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #000066;">offsetY</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">rotation</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">mass</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">artType</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">parallax</span>=<span style="color: #ff0000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Crate</span> <span style="color: #000066;">offsetX</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;275&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Crate2&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;225&quot;</span> <span style="color: #000066;">restitution</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">movable</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">friction</span>=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #000066;">offsetY</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">rotation</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">mass</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">artType</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">parallax</span>=<span style="color: #ff0000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Coin</span> <span style="color: #000066;">offsetX</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">destroyDelay</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">parallax</span>=<span style="color: #ff0000;">&quot;-1&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Coin1&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;15&quot;</span> <span style="color: #000066;">mass</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;101&quot;</span> <span style="color: #000066;">restitution</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">artType</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">movable</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">rotation</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;15&quot;</span> <span style="color: #000066;">friction</span>=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;274&quot;</span> <span style="color: #000066;">offsetY</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/world<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Then drop a few AS3 lines:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.citrusengine.core.CitrusEngine;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.blueflamedev.math.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> citrusdemo extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> citrusdemo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> level_xml<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> =
			<span style="color: #000000; font-weight: bold;">&lt;</span>world gameWidth=<span style="color: #990000;">&quot;500&quot;</span> gameHeight=<span style="color: #990000;">&quot;400&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
			  <span style="color: #000000; font-weight: bold;">&lt;</span>Platform offsetX=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;250&quot;</span> id=<span style="color: #990000;">&quot;Platform1&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;500&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;385&quot;</span> restitution=<span style="color: #990000;">&quot;0&quot;</span> movable=<span style="color: #990000;">&quot;false&quot;</span> friction=<span style="color: #990000;">&quot;0.6&quot;</span> offsetY=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">rotation</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;30&quot;</span> mass=<span style="color: #990000;">&quot;0&quot;</span> artType=<span style="color: #990000;">&quot;&quot;</span> parallax=<span style="color: #990000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
			  <span style="color: #000000; font-weight: bold;">&lt;</span>Platform offsetX=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;485&quot;</span> id=<span style="color: #990000;">&quot;Platform2&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;30&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;200&quot;</span> restitution=<span style="color: #990000;">&quot;0&quot;</span> movable=<span style="color: #990000;">&quot;false&quot;</span> friction=<span style="color: #990000;">&quot;0.6&quot;</span> offsetY=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">rotation</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;340&quot;</span> mass=<span style="color: #990000;">&quot;0&quot;</span> artType=<span style="color: #990000;">&quot;&quot;</span> parallax=<span style="color: #990000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
			  <span style="color: #000000; font-weight: bold;">&lt;</span>Platform offsetX=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;15&quot;</span> id=<span style="color: #990000;">&quot;Platform3&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;30&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;200&quot;</span> restitution=<span style="color: #990000;">&quot;0&quot;</span> movable=<span style="color: #990000;">&quot;false&quot;</span> friction=<span style="color: #990000;">&quot;0.6&quot;</span> offsetY=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">rotation</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;340&quot;</span> mass=<span style="color: #990000;">&quot;0&quot;</span> artType=<span style="color: #990000;">&quot;&quot;</span> parallax=<span style="color: #990000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
			  <span style="color: #000000; font-weight: bold;">&lt;</span>Platform offsetX=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;250&quot;</span> id=<span style="color: #990000;">&quot;Platform4&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;500&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;15&quot;</span> restitution=<span style="color: #990000;">&quot;0&quot;</span> movable=<span style="color: #990000;">&quot;false&quot;</span> friction=<span style="color: #990000;">&quot;0.6&quot;</span> offsetY=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">rotation</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;30&quot;</span> mass=<span style="color: #990000;">&quot;0&quot;</span> artType=<span style="color: #990000;">&quot;&quot;</span> parallax=<span style="color: #990000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
			  <span style="color: #000000; font-weight: bold;">&lt;</span>Hero hurtMagnitudeX=<span style="color: #990000;">&quot;150&quot;</span> maxHealth=<span style="color: #990000;">&quot;10000000000&quot;</span> friction=<span style="color: #990000;">&quot;0.6&quot;</span> acceleration=<span style="color: #990000;">&quot;30&quot;</span> parallax=<span style="color: #990000;">&quot;-1&quot;</span> jumpHeight=<span style="color: #990000;">&quot;360&quot;</span> maxSpeedY=<span style="color: #990000;">&quot;500&quot;</span> killBounceHeight=<span style="color: #990000;">&quot;40&quot;</span> hurtMagnitudeY=<span style="color: #990000;">&quot;350&quot;</span> boost=<span style="color: #990000;">&quot;12&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;33&quot;</span> offsetX=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;60&quot;</span> maxSpeedX=<span style="color: #990000;">&quot;180&quot;</span> id=<span style="color: #990000;">&quot;Hero1&quot;</span> <span style="color: #004993;">rotation</span>=<span style="color: #990000;">&quot;0&quot;</span> dampY=<span style="color: #990000;">&quot;1&quot;</span> boostDuration=<span style="color: #990000;">&quot;26&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;350&quot;</span> restitution=<span style="color: #990000;">&quot;0&quot;</span> movable=<span style="color: #990000;">&quot;true&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;425&quot;</span> offsetY=<span style="color: #990000;">&quot;0&quot;</span> hurtInvincibility=<span style="color: #990000;">&quot;5000&quot;</span> mass=<span style="color: #990000;">&quot;1.32&quot;</span> artType=<span style="color: #990000;">&quot;&quot;</span> dampX=<span style="color: #990000;">&quot;0.97&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
			  <span style="color: #000000; font-weight: bold;">&lt;</span>Crate offsetX=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;275&quot;</span> id=<span style="color: #990000;">&quot;Crate1&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;325&quot;</span> restitution=<span style="color: #990000;">&quot;0&quot;</span> movable=<span style="color: #990000;">&quot;true&quot;</span> friction=<span style="color: #990000;">&quot;0.6&quot;</span> offsetY=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">rotation</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100&quot;</span> mass=<span style="color: #990000;">&quot;1&quot;</span> artType=<span style="color: #990000;">&quot;&quot;</span> parallax=<span style="color: #990000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
			  <span style="color: #000000; font-weight: bold;">&lt;</span>Crate offsetX=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;275&quot;</span> id=<span style="color: #990000;">&quot;Crate2&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;225&quot;</span> restitution=<span style="color: #990000;">&quot;0&quot;</span> movable=<span style="color: #990000;">&quot;true&quot;</span> friction=<span style="color: #990000;">&quot;0.6&quot;</span> offsetY=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">rotation</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100&quot;</span> mass=<span style="color: #990000;">&quot;1&quot;</span> artType=<span style="color: #990000;">&quot;&quot;</span> parallax=<span style="color: #990000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
			  <span style="color: #000000; font-weight: bold;">&lt;</span>Coin offsetX=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;&quot;</span> destroyDelay=<span style="color: #990000;">&quot;500&quot;</span> parallax=<span style="color: #990000;">&quot;-1&quot;</span> id=<span style="color: #990000;">&quot;Coin1&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;15&quot;</span> mass=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;101&quot;</span> restitution=<span style="color: #990000;">&quot;0&quot;</span> artType=<span style="color: #990000;">&quot;&quot;</span> movable=<span style="color: #990000;">&quot;false&quot;</span> <span style="color: #004993;">rotation</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;15&quot;</span> friction=<span style="color: #990000;">&quot;0.6&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;274&quot;</span> offsetY=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;/</span>world<span style="color: #000000; font-weight: bold;">&gt;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> ce<span style="color: #000000; font-weight: bold;">:</span>CitrusEngine=CitrusEngine.getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ce.initialize<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;
			ce.camera.debugDraw=<span style="color: #0033ff; font-weight: bold;">true</span>;
			ce.physics.gravity=<span style="color: #0033ff; font-weight: bold;">new</span> MathVector<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">900</span><span style="color: #000000;">&#41;</span>;
			ce.<span style="color: #004993;">loop</span>.run<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;
			ce.manager.createSet<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Level 1&quot;</span>,<span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span>level_xml<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Lines 7-17</strong>: Importing the XML</p>
<p><strong>Lines 18-19</strong>: Initializing the engine</p>
<p><strong>Line 20</strong>: Turning on debug draw</p>
<p><strong>Line 21</strong>: Defining the gravity. I found <code>MathVector(0,900)</code> very similar to <code>b2Vec(0,10)</code></p>
<p><strong>Line 22</strong>: Starting the simulation</p>
<p><strong>Line 23</strong>: Loading the XML level</p>
<p>And that&#8217;s it:</p>
<p><embed src="/wp-content/uploads/2010/03/citrusdemo.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Move your hero with arrow keys and jump with spacebar. Try to get the coin.</p>
<p><a href="/wp-content/uploads/2010/03/citrusdemo.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/03/23/creation-of-a-game-with-citrus-engine/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
