<?xml version="1.0" encoding="utf-8" ?>
<c2eventsheet>
    <!--All the 'name' attributes are ignored by Construct 2 - they are there for readability only.-->
    <name>evGame</name>
    <events>
        <variable constant="1" name="MAX_DISTANCE" sid="932086744101398" static="0" type="number">100</variable>
        <variable constant="1" name="MAX_AIM_SIZE" sid="408009433931944" static="0" type="number">100</variable>
        <variable constant="1" name="TILE_SIDE" sid="694895118394719" static="0" type="number">32</variable>
        <variable constant="1" name="MAX_IMPULSE" sid="511459539147201" static="0" type="number">20</variable>
        <variable constant="0" name="sessionId" sid="662634306465221" static="0" type="number">0</variable>
        <variable constant="0" name="level" sid="671164638821024" static="0" type="number">0</variable>
        <event-block sid="458832686389344">
            <conditions>
                <condition id="-2" name="On start of layout" sid="936162339797174" type="System" />
            </conditions>
            <actions>
                <action behavior="Physics" id="27" name="Set enabled" sid="315817809862857" type="tmCollisions">
                    <param id="0" name="Mode">0</param>
                </action>
                <action behavior="Physics" id="12" name="Set world gravity" sid="301837004186579" type="PhysicalObjects">
                    <param id="0" name="Gravity">0</param>
                </action>
                <action id="-3" name="Create object" sid="805715788202673" type="System">
                    <param id="0" name="Object to create">btnRestart</param>
                    <param id="1" name="Layer">0</param>
                    <param id="2" name="X">LayoutWidth - 60</param>
                    <param id="3" name="Y">LayoutHeight - 60</param>
                </action>
            </actions>
            <sub-events>
                <event-block sid="964114241094490">
                    <conditions>
                        <condition id="-33" name="Pick by comparison" sid="917555928220559" type="System">
                            <param id="0" name="Object">spCueBall</param>
                            <param id="1" name="Expression">spCueBall.IID</param>
                            <param id="2" name="Comparison">0</param>
                            <param id="3" name="Value">0</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="-3" name="Create object" sid="955210719639272" type="System">
                            <param id="0" name="Object to create">spTouchArea</param>
                            <param id="1" name="Layer">0</param>
                            <param id="2" name="X">spCueBall.X</param>
                            <param id="3" name="Y">spCueBall.Y</param>
                        </action>
                        <action id="-25" name="Move to bottom" sid="155870293096495" type="spTouchArea" />
                    </actions>
                </event-block>
                <event-block sid="941883325365889">
                    <conditions>
                        <condition id="-14" name="Compare variable" sid="222157336332109" type="System">
                            <param id="0" name="Variable">sessionId</param>
                            <param id="1" name="Comparison">0</param>
                            <param id="2" name="Value">0</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="-9" name="Set value" sid="113866038053752" type="System">
                            <param id="0" name="Variable">sessionId</param>
                            <param id="1" name="Value">random(1000000000000000000000)</param>
                        </action>
                        <action id="14" name="Log" sid="596010330962062" type="Browser">
                            <param id="0" name="Type">0</param>
                            <param id="1" name="Message">&quot;SESSION #&quot; &amp; sessionId</param>
                        </action>
                    </actions>
                </event-block>
                <event-block sid="276981107905452">
                    <conditions />
                    <actions>
                        <action id="0" name="Request URL" sid="963139406670842" type="AJAX">
                            <param id="0" name="Tag">&quot;logStart&quot;</param>
                            <param id="1" name="URL">&quot;http://gamelab.rf.gd/particles/php/log.php?msg=&quot; &amp; sessionId &amp; &quot;%09&quot; &amp; Browser.ExecJS(&quot;new Date().getTime();&quot;) &amp; &quot;%09&quot; &amp; level &amp; &quot;%09START&quot;</param>
                        </action>
                        <action id="14" name="Log" sid="732741257363402" type="Browser">
                            <param id="0" name="Type">0</param>
                            <param id="1" name="Message">&quot;Logging start...&quot;</param>
                        </action>
                    </actions>
                </event-block>
                <event-block sid="693470164312351">
                    <conditions>
                        <condition id="-12" name="Repeat" sid="227186362839397" type="System">
                            <param id="0" name="Count">4</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="14" name="Log" sid="999669931771183" type="Browser">
                            <param id="0" name="Type">0</param>
                            <param id="1" name="Message">loopindex * 90 &amp; &quot;: &quot; &amp; sin(loopindex * 90) &amp; &quot;,&quot; &amp; cos(loopindex * 90)</param>
                        </action>
                    </actions>
                </event-block>
                <event-block sid="236655500841587">
                    <conditions>
                        <condition id="-10" name="For" sid="639878102516906" type="System">
                            <param id="0" name="Name">&quot;tileMapX&quot;</param>
                            <param id="1" name="Start index">0</param>
                            <param id="2" name="End index">floor(tmCollisions.Width / TILE_SIDE) - 1</param>
                        </condition>
                    </conditions>
                    <actions />
                    <sub-events>
                        <event-block sid="235027785683171">
                            <conditions>
                                <condition id="-10" name="For" sid="119935087826936" type="System">
                                    <param id="0" name="Name">&quot;tileMapY&quot;</param>
                                    <param id="1" name="Start index">0</param>
                                    <param id="2" name="End index">floor(tmCollisions.Height / TILE_SIDE) - 1</param>
                                </condition>
                            </conditions>
                            <actions />
                            <sub-events>
                                <event-block sid="460648997257023">
                                    <conditions>
                                        <condition id="0" name="Compare tile at" sid="367598992742758" type="tmCollisions">
                                            <param id="0" name="Tile X">loopindex(&quot;tileMapX&quot;)</param>
                                            <param id="1" name="Tile Y">loopindex(&quot;tileMapY&quot;)</param>
                                            <param id="2" name="Comparison">0</param>
                                            <param id="3" name="Tile">7</param>
                                        </condition>
                                    </conditions>
                                    <actions>
                                        <action id="1" name="Set tile" sid="690004621096249" type="tmFiller">
                                            <param id="0" name="Tile X">loopindex(&quot;tileMapX&quot;)</param>
                                            <param id="1" name="Tile Y">loopindex(&quot;tileMapY&quot;)</param>
                                            <param id="2" name="Tile">7</param>
                                            <param id="3" name="State">0</param>
                                        </action>
                                        <action id="0" name="Erase tile" sid="644917303135702" type="tmCollisions">
                                            <param id="0" name="Tile X">loopindex(&quot;tileMapX&quot;)</param>
                                            <param id="1" name="Tile Y">loopindex(&quot;tileMapY&quot;)</param>
                                        </action>
                                    </actions>
                                </event-block>
                                <event-block sid="961361778551477">
                                    <conditions>
                                        <condition id="-8" name="Compare two values" sid="498627402911234" type="System">
                                            <param id="0" name="First value">loopindex(&quot;tileMapX&quot;)</param>
                                            <param id="1" name="Comparison">0</param>
                                            <param id="2" name="Second value">floor(tmCollisions.Width / TILE_SIDE)  - 1</param>
                                        </condition>
                                        <condition id="-8" name="Compare two values" sid="700325921185958" type="System">
                                            <param id="0" name="First value">loopindex(&quot;tileMapY&quot;)</param>
                                            <param id="1" name="Comparison">0</param>
                                            <param id="2" name="Second value">floor(tmCollisions.Height / TILE_SIDE)  - 1</param>
                                        </condition>
                                    </conditions>
                                    <actions>
                                        <action id="-16" name="Wait" sid="430609766987085" type="System">
                                            <param id="0" name="Seconds">0.01</param>
                                        </action>
                                        <action behavior="Physics" id="27" name="Set enabled" sid="549902685323271" type="tmCollisions">
                                            <param id="0" name="Mode">1</param>
                                        </action>
                                    </actions>
                                </event-block>
                            </sub-events>
                        </event-block>
                    </sub-events>
                </event-block>
                <event-block sid="357342168527557">
                    <conditions>
                        <condition id="5" inverted="1" name="Is tag playing" sid="477665552741111" type="Audio">
                            <param id="0" name="Tag">&quot;bg-music&quot;</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="0" name="Play" sid="338130597808204" type="Audio">
                            <param id="0" name="Audio file">bg-music</param>
                            <param id="2" name="Loop">1</param>
                            <param id="3" name="Volume">-5</param>
                            <param id="1" name="Tag (optional)">&quot;bg-music&quot;</param>
                        </action>
                    </actions>
                </event-block>
            </sub-events>
        </event-block>
        <event-block sid="512402512499401">
            <conditions>
                <condition id="-8" name="Is boolean instance variable set" sid="991370718877905" type="spCueBall">
                    <param id="0" name="Instance variable">aiming</param>
                </condition>
            </conditions>
            <actions>
                <action id="-8" name="Set angle" sid="809227694398764" type="spAim">
                    <param id="0" name="Angle">angle(Touch.X, Touch.Y, spCueBall.X, spCueBall.Y)</param>
                </action>
                <action id="-5" name="Set width" sid="327497912218841" type="spAim">
                    <param id="0" name="Width">min(1, distance(Touch.X, Touch.Y, spCueBall.X, spCueBall.Y) / MAX_DISTANCE) * MAX_AIM_SIZE</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="552219731480241">
            <conditions>
                <condition id="3" name="On touched object" sid="627779495791742" type="Touch">
                    <param id="0" name="Object">spTouchArea</param>
                </condition>
            </conditions>
            <actions />
            <sub-events>
                <event-block sid="230812240481819">
                    <conditions>
                        <condition id="-33" name="Pick by comparison" sid="190678515517834" type="System">
                            <param id="0" name="Object">spCueBall</param>
                            <param id="1" name="Expression">spCueBall.IID</param>
                            <param id="2" name="Comparison">0</param>
                            <param id="3" name="Value">0</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="-13" name="Set boolean" sid="852071862152876" type="spCueBall">
                            <param id="0" name="Instance variable">aiming</param>
                            <param id="1" name="Value">1</param>
                        </action>
                        <action id="-3" name="Create object" sid="850371770156441" type="System">
                            <param id="0" name="Object to create">spAim</param>
                            <param id="1" name="Layer">2</param>
                            <param id="2" name="X">spCueBall.X</param>
                            <param id="3" name="Y">spCueBall.Y</param>
                        </action>
                    </actions>
                </event-block>
            </sub-events>
        </event-block>
        <event-block sid="451674348259078">
            <conditions>
                <condition id="11" name="On Nth touch end" sid="399127473813581" type="Touch">
                    <param id="0" name="Touch number">0</param>
                </condition>
                <condition id="-8" name="Is boolean instance variable set" sid="831592921445007" type="spCueBall">
                    <param id="0" name="Instance variable">aiming</param>
                </condition>
            </conditions>
            <actions>
                <action behavior="Physics" id="5" name="Apply impulse at angle" sid="207841936876637" type="spCueBall">
                    <param id="0" name="Impulse">min(1, distance(Touch.X, Touch.Y, spCueBall.X, spCueBall.Y) / MAX_DISTANCE) * MAX_IMPULSE</param>
                    <param id="1" name="Angle">angle(Touch.X, Touch.Y, spCueBall.X, spCueBall.Y)</param>
                    <param id="2" name="Image point">0</param>
                </action>
                <action id="-9" name="Destroy" sid="433488647561901" type="spAim" />
                <action id="-9" name="Destroy" sid="752355647516688" type="spTouchArea" />
                <action id="-13" name="Set boolean" sid="627952171043282" type="spCueBall">
                    <param id="0" name="Instance variable">aiming</param>
                    <param id="1" name="Value">0</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="569851632349661">
            <conditions>
                <condition id="0" name="On collision with another object" sid="234935957453007" type="spHole">
                    <param id="0" name="Object">spGoalBall</param>
                </condition>
            </conditions>
            <actions>
                <action behavior="Physics" id="27" name="Set enabled" sid="582323563763192" type="PhysicalObjects">
                    <param id="0" name="Mode">0</param>
                </action>
                <action id="-4" name="Set position to another object" sid="896565523194270" type="spGoalBall">
                    <param id="0" name="Object">spHole</param>
                    <param id="1" name="Image point (optional)">0</param>
                </action>
                <action id="5" name="Set frame" sid="822742356766037" type="spHole">
                    <param id="0" name="Frame number">1</param>
                </action>
                <action id="0" name="Request URL" sid="206513835469685" type="AJAX">
                    <param id="0" name="Tag">&quot;logVictory&quot;</param>
                    <param id="1" name="URL">&quot;http://gamelab.rf.gd/particles/php/log.php?msg=&quot; &amp; sessionId &amp; &quot;%09&quot; &amp; Browser.ExecJS(&quot;new Date().getTime();&quot;) &amp; &quot;%09&quot; &amp; level &amp; &quot;%09WIN&quot;</param>
                </action>
                <action id="14" name="Log" sid="797092130571831" type="Browser">
                    <param id="0" name="Type">0</param>
                    <param id="1" name="Message">&quot;Logging end...&quot;</param>
                </action>
                <action id="0" name="Play" sid="450621978504647" type="Audio">
                    <param id="0" name="Audio file">level_end</param>
                    <param id="2" name="Loop">0</param>
                    <param id="3" name="Volume">0</param>
                    <param id="1" name="Tag (optional)">&quot;&quot;</param>
                </action>
            </actions>
            <sub-events>
                <event-block sid="437688246338944">
                    <conditions>
                        <condition id="-10" name="For" sid="427495005869163" type="System">
                            <param id="0" name="Name">&quot;tileMapX&quot;</param>
                            <param id="1" name="Start index">0</param>
                            <param id="2" name="End index">floor(tmCollisions.Width / TILE_SIDE) - 1</param>
                        </condition>
                    </conditions>
                    <actions />
                    <sub-events>
                        <event-block sid="337368048668179">
                            <conditions>
                                <condition id="-10" name="For" sid="632412504165231" type="System">
                                    <param id="0" name="Name">&quot;tileMapY&quot;</param>
                                    <param id="1" name="Start index">0</param>
                                    <param id="2" name="End index">floor(tmCollisions.Height / TILE_SIDE) - 1</param>
                                </condition>
                            </conditions>
                            <actions>
                                <action id="1" name="Set tile" sid="451041801075435" type="tmCollisions">
                                    <param id="0" name="Tile X">loopindex(&quot;tileMapX&quot;)</param>
                                    <param id="1" name="Tile Y">loopindex(&quot;tileMapY&quot;)</param>
                                    <param id="2" name="Tile">tmCollisions.TileAt(loopindex(&quot;tileMapX&quot;), loopindex(&quot;tileMapY&quot;)) + 18</param>
                                    <param id="3" name="State">0</param>
                                </action>
                            </actions>
                            <sub-events>
                                <event-block sid="624209624414077">
                                    <conditions>
                                        <condition id="-8" name="Compare two values" sid="843054410421366" type="System">
                                            <param id="0" name="First value">loopindex(&quot;tileMapX&quot;)</param>
                                            <param id="1" name="Comparison">0</param>
                                            <param id="2" name="Second value">floor(tmCollisions.Width / TILE_SIDE)  - 1</param>
                                        </condition>
                                        <condition id="-8" name="Compare two values" sid="332806301482840" type="System">
                                            <param id="0" name="First value">loopindex(&quot;tileMapY&quot;)</param>
                                            <param id="1" name="Comparison">0</param>
                                            <param id="2" name="Second value">floor(tmCollisions.Height / TILE_SIDE)  - 1</param>
                                        </condition>
                                    </conditions>
                                    <actions>
                                        <action id="-16" name="Wait" sid="551134284085962" type="System">
                                            <param id="0" name="Seconds">2</param>
                                        </action>
                                        <action id="-10" name="Add to" sid="207115327215555" type="System">
                                            <param id="0" name="Variable">level</param>
                                            <param id="1" name="Value">1</param>
                                        </action>
                                        <action id="-25" name="Go to layout (by name)" sid="989803143058404" type="System">
                                            <param id="0" name="Layout">&quot;layLevel&quot; &amp; level</param>
                                        </action>
                                    </actions>
                                </event-block>
                            </sub-events>
                        </event-block>
                    </sub-events>
                </event-block>
            </sub-events>
        </event-block>
        <event-block sid="738611480865995">
            <conditions>
                <condition id="0" name="On collision with another object" sid="169819319267659" type="spCueBall">
                    <param id="0" name="Object">PhysicalObjects</param>
                </condition>
                <condition id="-7" name="Compare instance variable" sid="135330707880621" type="PhysicalObjects">
                    <param id="0" name="Instance variable">state</param>
                    <param id="1" name="Comparison">5</param>
                    <param id="2" name="Value">0</param>
                </condition>
            </conditions>
            <actions>
                <action id="0" name="Play" sid="270513394236630" type="Audio">
                    <param id="0" name="Audio file">ball_impact</param>
                    <param id="2" name="Loop">0</param>
                    <param id="3" name="Volume">0</param>
                    <param id="1" name="Tag (optional)">&quot;&quot;</param>
                </action>
                <action id="-10" name="Set value" sid="518584347736146" type="PhysicalObjects">
                    <param id="0" name="Instance variable">state</param>
                    <param id="1" name="Value">1</param>
                </action>
                <action id="-10" name="Set value" sid="750471623944464" type="spCueBall">
                    <param id="0" name="Instance variable">state</param>
                    <param id="1" name="Value">0</param>
                </action>
                <action id="-16" name="Wait" sid="203190549627477" type="System">
                    <param id="0" name="Seconds">0.1</param>
                </action>
                <action id="0" name="Spawn another object" sid="698625519467860" type="spCueBall">
                    <param id="0" name="Object">ptcDestroyBall</param>
                    <param id="1" name="Layer">2</param>
                    <param id="2" name="Image point">0</param>
                </action>
                <action id="-9" name="Destroy" sid="997190148298886" type="spCueBall" />
            </actions>
        </event-block>
        <event-block sid="573816756509038">
            <conditions>
                <condition id="-11" name="For Each" sid="731163109463910" type="System">
                    <param id="0" name="Object">PhysicalObjects</param>
                </condition>
            </conditions>
            <actions />
            <sub-events>
                <event-block sid="696523431122695">
                    <conditions>
                        <condition id="-7" name="Compare instance variable" sid="738264167376055" type="PhysicalObjects">
                            <param id="0" name="Instance variable">state</param>
                            <param id="1" name="Comparison">0</param>
                            <param id="2" name="Value">0</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="5" name="Set frame" sid="993239407647058" type="PhysicalObjects">
                            <param id="0" name="Frame number">0</param>
                        </action>
                    </actions>
                </event-block>
                <event-block sid="379246718537549">
                    <conditions>
                        <condition id="-22" name="Else" sid="700832135366871" type="System" />
                        <condition id="-7" name="Compare instance variable" sid="285196883021667" type="PhysicalObjects">
                            <param id="0" name="Instance variable">state</param>
                            <param id="1" name="Comparison">0</param>
                            <param id="2" name="Value">1</param>
                        </condition>
                    </conditions>
                    <actions>
                        <action id="5" name="Set frame" sid="878507219398342" type="PhysicalObjects">
                            <param id="0" name="Frame number">1</param>
                        </action>
                    </actions>
                </event-block>
            </sub-events>
        </event-block>
        <event-block disabled="1" sid="814986800590465">
            <conditions />
            <actions>
                <action id="-10" name="Add to" sid="225029649336611" type="System">
                    <param id="0" name="Variable">level</param>
                    <param id="1" name="Value">1</param>
                </action>
                <action id="-25" name="Go to layout (by name)" sid="898286076025803" type="System">
                    <param id="0" name="Layout">&quot;layLevel&quot; &amp; level</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="238869045079802">
            <conditions>
                <condition id="3" name="On touched object" sid="463220468027276" type="Touch">
                    <param id="0" name="Object">btnRestart</param>
                </condition>
            </conditions>
            <actions>
                <action id="5" name="Set frame" sid="136583480759383" type="btnRestart">
                    <param id="0" name="Frame number">1</param>
                </action>
                <action id="-16" name="Wait" sid="301590756143358" type="System">
                    <param id="0" name="Seconds">0.5</param>
                </action>
                <action id="5" name="Set frame" sid="986877158036994" type="btnRestart">
                    <param id="0" name="Frame number">0</param>
                </action>
                <action id="-26" name="Restart layout" sid="722414935263340" type="System" />
            </actions>
        </event-block>
        <event-block sid="281217822969847">
            <conditions>
                <condition id="1" name="Is overlapping another object" sid="929587604622871" type="PhysicalObjects">
                    <param id="0" name="Object">areaRamp</param>
                </condition>
            </conditions>
            <actions>
                <action behavior="Physics" id="15" name="Set velocity" sid="243336842465850" type="PhysicalObjects">
                    <param id="0" name="X component">PhysicalObjects.Physics.VelocityX + cos(areaRamp.Angle) * 5</param>
                    <param id="1" name="Y component">PhysicalObjects.Physics.VelocityY + sin(areaRamp.Angle) * 5</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="865919121219818">
            <conditions>
                <condition id="0" name="On collision with another object" sid="566415819363045" type="PhysicalObjects">
                    <param id="0" name="Object">areaDamage</param>
                </condition>
            </conditions>
            <actions>
                <action behavior="Physics" id="15" name="Set velocity" sid="782315968641239" type="PhysicalObjects">
                    <param id="0" name="X component">0</param>
                    <param id="1" name="Y component">0</param>
                </action>
                <action id="-16" name="Wait" sid="867686991809707" type="System">
                    <param id="0" name="Seconds">0.5</param>
                </action>
                <action id="0" name="Spawn another object" sid="108115394085220" type="PhysicalObjects">
                    <param id="0" name="Object">ptcDestroyBall</param>
                    <param id="1" name="Layer">2</param>
                    <param id="2" name="Image point">0</param>
                </action>
                <action id="-9" name="Destroy" sid="790268589816434" type="PhysicalObjects" />
                <action id="0" name="Play" sid="472283692457364" type="Audio">
                    <param id="0" name="Audio file">ball_trapped</param>
                    <param id="2" name="Loop">0</param>
                    <param id="3" name="Volume">0</param>
                    <param id="1" name="Tag (optional)">&quot;&quot;</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="751243433060555">
            <conditions>
                <condition id="1" name="Is overlapping another object" sid="640248392875145" type="PhysicalObjects">
                    <param id="0" name="Object">areaDamage</param>
                </condition>
            </conditions>
            <actions>
                <action id="-3" name="Set position" sid="731707098219064" type="PhysicalObjects">
                    <param id="0" name="X">areaDamage.X + random(-5,5)</param>
                    <param id="1" name="Y">areaDamage.Y + random(-5,5)</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="703175070576305">
            <conditions>
                <condition id="-18" name="On created" sid="964374890358274" type="areaDamage" />
            </conditions>
            <actions>
                <action id="-29" name="Move to object" sid="881907557098892" type="areaDamage">
                    <param id="0" name="Where">0</param>
                    <param id="1" name="Object">tmCollisions</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="223958068423494">
            <conditions>
                <condition id="-18" name="On created" sid="289797247129362" type="areaRamp" />
            </conditions>
            <actions>
                <action id="-29" name="Move to object" sid="244567046786546" type="areaRamp">
                    <param id="0" name="Where">0</param>
                    <param id="1" name="Object">tmCollisions</param>
                </action>
            </actions>
        </event-block>
        <event-block sid="146475074313261">
            <conditions>
                <condition id="-18" name="On created" sid="290707348919984" type="guiLevelText" />
            </conditions>
            <actions>
                <action id="5" name="Set web font" sid="452098089588423" type="guiLevelText">
                    <param id="0" name="Family name">&quot;chintzy_cpu_brkregular&quot;</param>
                    <param id="1" name="CSS URL">&quot;stylesheet.css&quot;</param>
                </action>
            </actions>
        </event-block>
    </events>
</c2eventsheet>
