Skip to content
Browse files

Implemented a local loopback socket client, so you don't need a live …

…node.js server running to debug animation & collisision detection client code
  • Loading branch information...
1 parent 6db4f3e commit da01f62c458d2d2184c476d98fe2faab69f7c27b @dylanbeattie committed Jun 5, 2011
View
209 .idea/workspace.xml
@@ -2,22 +2,113 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="7317696f-fc4e-428e-a525-03340f4ecdb5" name="Default" comment="Removed all hardcoded references to &quot;localhost&quot;. server.js will now listen on all available IPs on the specified port, and the KaboomClient passes window.location.hostname and window.location.port into the SocketClient init() routine. This means Kaboom now runs cleanly on remote servers.">
- <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/KaboomJS.iml" />
- <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/encodings.xml" />
- <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/misc.xml" />
- <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/modules.xml" />
- <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/vcs.xml" />
+ <change type="DELETED" beforePath="Q:\KaboomJS\client.js" afterPath="" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/BOMBPAL.jpg" afterPath="$PROJECT_DIR$/etc/BOMBPAL.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/BOMBDUDE.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/BOMBDUDE.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/BONUS.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/BONUS.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/CREDBAR.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/CREDBAR.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/DRAW.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/DRAW.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD0.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD0.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD1.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD1.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD10.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD10.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD2.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD2.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD3.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD3.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD4.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD4.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD5.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD5.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD6.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD6.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD7.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD7.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD8.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD8.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD9.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/FIELD9.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE0.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE0.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE1.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE1.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE2.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE2.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE3.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE3.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE4.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE4.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE5.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE5.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE6.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/GLUE6.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/HSLOGO.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/HSLOGO.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/IPLOGO.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/IPLOGO.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/JERM.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/JERM.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/KURT.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/KURT.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/KURTHEAD.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/KURTHEAD.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/MAINMENU.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/MAINMENU.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWBAD.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWBAD.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWBOMB.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWBOMB.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWDISEA.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWDISEA.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWEBOLA.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWEBOLA.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWFAST.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWFAST.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWFLAME.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWFLAME.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWGOLD.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWGOLD.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWGRAB.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWGRAB.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWJELLY.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWJELLY.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWKICK.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWKICK.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWPUNCH.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWPUNCH.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWRAND.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWRAND.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWSKATE.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWSKATE.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWSLOW.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWSLOW.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWSPOOG.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWSPOOG.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/POWTRIG.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/POWTRIG.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/QALOGO.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/QALOGO.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/RESULTS.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/RESULTS.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/ROULETTE.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/ROULETTE.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/TEAM0.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/TEAM0.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/TEAM1.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/TEAM1.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/TITLE.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/TITLE.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY0.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY0.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY1.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY1.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY2.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY2.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY3.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY3.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY4.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY4.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY5.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY5.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY6.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY6.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY7.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY7.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY8.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY8.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY9.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/VICTORY9.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/RawResources/Graphics/WINZ.jpg" afterPath="$PROJECT_DIR$/etc/RawResources/Graphics/WINZ.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/sounds/bomb.mp3" afterPath="$PROJECT_DIR$/etc/sounds/bomb.mp3" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/sounds/bomb.wav" afterPath="$PROJECT_DIR$/etc/sounds/bomb.wav" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/sounds/die1.mp3" afterPath="$PROJECT_DIR$/etc/sounds/die1.mp3" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/sounds/die1.wav" afterPath="$PROJECT_DIR$/etc/sounds/die1.wav" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/sounds/menu.mp3" afterPath="$PROJECT_DIR$/etc/sounds/menu.mp3" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/sounds/menu.wav" afterPath="$PROJECT_DIR$/etc/sounds/menu.wav" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/blank.png" afterPath="$PROJECT_DIR$/public/images/blank.png" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/bomb.png" afterPath="$PROJECT_DIR$/public/images/bomb.png" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/clear4way.png" afterPath="$PROJECT_DIR$/public/images/clear4way.png" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/destroyable-block.png" afterPath="$PROJECT_DIR$/public/images/destroyable-block.png" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/field0.jpg" afterPath="$PROJECT_DIR$/public/images/field0.jpg" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/player-1.png" afterPath="$PROJECT_DIR$/public/images/player-1.png" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/player-2.png" afterPath="$PROJECT_DIR$/public/images/player-2.png" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/player-3.png" afterPath="$PROJECT_DIR$/public/images/player-3.png" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/player-4.png" afterPath="$PROJECT_DIR$/public/images/player-4.png" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/images/solid-block.png" afterPath="$PROJECT_DIR$/public/images/solid-block.png" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/data/level.txt" afterPath="$PROJECT_DIR$/data/level.txt" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/etc/client_hax.txt" afterPath="$PROJECT_DIR$/etc/client_hax.txt" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/broadcaster.js" afterPath="$PROJECT_DIR$/lib/broadcaster.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/package.json" afterPath="$PROJECT_DIR$/package.json" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/css/bomber.css" afterPath="$PROJECT_DIR$/public/css/bomber.css" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/index.html" afterPath="$PROJECT_DIR$/public/index.html" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/game/kaboom.game.js" afterPath="$PROJECT_DIR$/public/js/game/kaboom.game.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/game/kaboom.player.js" afterPath="$PROJECT_DIR$/public/js/game/kaboom.player.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/game/kaboom.renderer.js" afterPath="$PROJECT_DIR$/public/js/game/kaboom.renderer.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/game/level.js" afterPath="$PROJECT_DIR$/public/js/game/level.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/libs/jquery-1.6.1.js" afterPath="$PROJECT_DIR$/public/js/libs/jquery-1.6.1.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/libs/json2.js" afterPath="$PROJECT_DIR$/public/js/libs/json2.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/libs/key_status.js" afterPath="$PROJECT_DIR$/public/js/libs/key_status.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/libs/socket.io.min.js" afterPath="$PROJECT_DIR$/public/js/libs/socket.io.min.js" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/levelTest.htm" afterPath="$PROJECT_DIR$/public/levelTest.htm" />
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/server/config.json" afterPath="$PROJECT_DIR$/server/config.json" />
</list>
<list id="07e85f89-abd1-48f0-9afd-84fa67e279d7" name="Failed commit: Default" comment="Removed all hardcoded references to &quot;localhost&quot;. server.js will now listen on all available IPs on the specified port, and the KaboomClient passes window.location.hostname and window.location.port into the SocketClient init() routine. This means Kaboom now runs cleanly on remote servers.">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/game/client.js" afterPath="$PROJECT_DIR$/public/js/game/client.js" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/game/kaboom.socket.js" afterPath="$PROJECT_DIR$/public/js/game/kaboom.socket.js" />
- <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/js/libs/jquery.hotkeys.js" afterPath="$PROJECT_DIR$/public/js/libs/jquery.hotkeys.js" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/server.js" afterPath="$PROJECT_DIR$/server.js" />
</list>
<ignored path="KaboomJS.iws" />
<ignored path=".idea/workspace.xml" />
- <file path="$PROJECT_DIR$/public/js/libs/jquery.hotkeys.js" changelist="7317696f-fc4e-428e-a525-03340f4ecdb5" time="1307269364867" ignored="false" />
+ <file path="$PROJECT_DIR$/server.js" changelist="7317696f-fc4e-428e-a525-03340f4ecdb5" time="1307269827519" ignored="true" />
+ <file path="$PROJECT_DIR$/public/js/game/kaboom.socket.js" changelist="7317696f-fc4e-428e-a525-03340f4ecdb5" time="1307280853960" ignored="true" />
+ <file path="$PROJECT_DIR$/public/js/game/client.js" changelist="7317696f-fc4e-428e-a525-03340f4ecdb5" time="1307280647328" ignored="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -37,19 +128,10 @@
</component>
<component name="FileEditorManager">
<leaf>
- <file leaf-file-name="index.html" pinned="false" current="false" current-in-tab="false">
- <entry file="file://$PROJECT_DIR$/public/index.html">
- <provider selected="true" editor-type-id="text-editor">
- <state line="24" column="49" selection-start="607" selection-end="607" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
- </file>
- <file leaf-file-name="kaboom.game.js" pinned="false" current="false" current-in-tab="false">
- <entry file="file://$PROJECT_DIR$/public/js/game/kaboom.game.js">
+ <file leaf-file-name="server.js" pinned="false" current="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/server.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="35" column="0" selection-start="1080" selection-end="1080" vertical-scroll-proportion="0.0">
+ <state line="19" column="0" selection-start="573" selection-end="573" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -58,43 +140,34 @@
<file leaf-file-name="client.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/public/js/game/client.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="84" column="34" selection-start="1541" selection-end="1541" vertical-scroll-proportion="0.0">
+ <state line="75" column="0" selection-start="1443" selection-end="1443" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
- <file leaf-file-name="kaboom.socket.js" pinned="false" current="false" current-in-tab="false">
+ <file leaf-file-name="kaboom.socket.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/public/js/game/kaboom.socket.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="17" column="27" selection-start="509" selection-end="509" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
- </file>
- <file leaf-file-name="kaboom.player.js" pinned="false" current="false" current-in-tab="false">
- <entry file="file://$PROJECT_DIR$/public/js/game/kaboom.player.js">
- <provider selected="true" editor-type-id="text-editor">
- <state line="40" column="15" selection-start="896" selection-end="896" vertical-scroll-proportion="0.0">
+ <state line="11" column="26" selection-start="332" selection-end="332" vertical-scroll-proportion="0.3566553">
<folding />
</state>
</provider>
</entry>
</file>
- <file leaf-file-name="level.js" pinned="false" current="false" current-in-tab="false">
- <entry file="file://$PROJECT_DIR$/public/js/game/level.js">
+ <file leaf-file-name="kaboom.game.js" pinned="false" current="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/public/js/game/kaboom.game.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
+ <state line="11" column="2" selection-start="317" selection-end="317" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
- <file leaf-file-name="server.js" pinned="false" current="true" current-in-tab="true">
- <entry file="file://$PROJECT_DIR$/server.js">
+ <file leaf-file-name="level.txt" pinned="false" current="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/data/level.txt">
<provider selected="true" editor-type-id="text-editor">
- <state line="10" column="25" selection-start="388" selection-end="388" vertical-scroll-proportion="0.3492647">
+ <state line="13" column="0" selection-start="234" selection-end="234" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -121,9 +194,9 @@
<option value="$PROJECT_DIR$/public/js/game/kaboom.player.js" />
<option value="$PROJECT_DIR$/public/js/game/level.js" />
<option value="$PROJECT_DIR$/public/js/game/kaboom.game.js" />
+ <option value="$PROJECT_DIR$/server.js" />
<option value="$PROJECT_DIR$/public/js/game/client.js" />
<option value="$PROJECT_DIR$/public/js/game/kaboom.socket.js" />
- <option value="$PROJECT_DIR$/server.js" />
</list>
</option>
</component>
@@ -221,6 +294,20 @@
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
+ <PATH>
+ <PATH_ELEMENT>
+ <option name="myItemId" value="KaboomJS" />
+ <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
+ </PATH_ELEMENT>
+ <PATH_ELEMENT>
+ <option name="myItemId" value="KaboomJS" />
+ <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
+ </PATH_ELEMENT>
+ <PATH_ELEMENT>
+ <option name="myItemId" value="data" />
+ <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
+ </PATH_ELEMENT>
+ </PATH>
</subPane>
</pane>
</panes>
@@ -286,23 +373,23 @@
</servers>
</component>
<component name="ToolWindowManager">
- <frame x="-8" y="-8" width="1696" height="1004" extended-state="6" />
+ <frame x="-1688" y="-8" width="1696" height="1066" extended-state="6" />
<editor active="false" />
<layout>
- <window_info id="Messages" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32902467" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
+ <window_info id="Messages" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32858709" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Phing Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
+ <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.56626505" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
<window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
- <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.21187997" sideWeight="0.6709753" order="0" side_tool="false" content_ui="tabs" />
+ <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.21187997" sideWeight="0.67141294" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
- <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.27144536" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
+ <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25301206" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
- <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
@@ -333,7 +420,7 @@
<option name="CHECK_COMMIT_MESSAGE_SPELLING" value="true" />
<option name="DEFAULT_PATCH_EXTENSION" value="patch" />
<option name="FORCE_NON_EMPTY_COMMENT" value="false" />
- <option name="LAST_COMMIT_MESSAGE" value="Removed all hardcoded references to &quot;localhost&quot;. server.js will now listen on all available IPs on the specified port, and the KaboomClient passes window.location.hostname and window.location.port into the SocketClient init() routine. This means Kaboom now runs cleanly on remote servers." />
+ <option name="LAST_COMMIT_MESSAGE" value="Implemented a MockSocket fallback so if the client can't connect to a remote socket server, it'll use a local loopback server instead.&#10;" />
<option name="MAKE_NEW_CHANGELIST_ACTIVE" value="true" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_FILES_UP_TO_DATE_BEFORE_COMMIT" value="false" />
@@ -351,6 +438,7 @@
<MESSAGE value="Implemented copyStateFrom on game, level and player objects for syncing state between clients and server." />
<MESSAGE value="Null reference checking before syncing level state on kaboom.game.js" />
<MESSAGE value="Removed all hardcoded references to &quot;localhost&quot;. server.js will now listen on all available IPs on the specified port, and the KaboomClient passes window.location.hostname and window.location.port into the SocketClient init() routine. This means Kaboom now runs cleanly on remote servers." />
+ <MESSAGE value="Implemented a MockSocket fallback so if the client can't connect to a remote socket server, it'll use a local loopback server instead.&#10;" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
@@ -363,45 +451,54 @@
</entry>
<entry file="file://$PROJECT_DIR$/public/index.html">
<provider selected="true" editor-type-id="text-editor">
- <state line="24" column="49" selection-start="607" selection-end="607" vertical-scroll-proportion="0.0">
+ <state line="24" column="49" selection-start="607" selection-end="607" vertical-scroll-proportion="0.1">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/public/js/game/kaboom.game.js">
+ <entry file="file://$PROJECT_DIR$/public/js/game/level.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="35" column="0" selection-start="1080" selection-end="1080" vertical-scroll-proportion="0.0" />
+ <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/js/game/kaboom.player.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="40" column="15" selection-start="896" selection-end="896" vertical-scroll-proportion="0.0">
+ <state line="47" column="21" selection-start="1003" selection-end="1003" vertical-scroll-proportion="0.22428331">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/public/js/game/level.js">
+ <entry file="file://$PROJECT_DIR$/server.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
+ <state line="19" column="0" selection-start="573" selection-end="573" vertical-scroll-proportion="0.0">
+ <folding />
+ </state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/public/js/game/client.js">
+ <entry file="file://$PROJECT_DIR$/public/js/game/kaboom.game.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="84" column="34" selection-start="1541" selection-end="1541" vertical-scroll-proportion="0.0">
+ <state line="11" column="2" selection-start="317" selection-end="317" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/public/js/game/kaboom.socket.js">
+ <entry file="file://$PROJECT_DIR$/data/level.txt">
<provider selected="true" editor-type-id="text-editor">
- <state line="17" column="27" selection-start="509" selection-end="509" vertical-scroll-proportion="0.0">
+ <state line="13" column="0" selection-start="234" selection-end="234" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
- <entry file="file://$PROJECT_DIR$/server.js">
+ <entry file="file://$PROJECT_DIR$/public/js/game/client.js">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="75" column="0" selection-start="1443" selection-end="1443" vertical-scroll-proportion="0.0">
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/public/js/game/kaboom.socket.js">
<provider selected="true" editor-type-id="text-editor">
- <state line="10" column="25" selection-start="388" selection-end="388" vertical-scroll-proportion="0.3492647">
+ <state line="11" column="26" selection-start="332" selection-end="332" vertical-scroll-proportion="0.3566553">
<folding />
</state>
</provider>
View
50 client.js
@@ -1,50 +0,0 @@
-var socket,
- levelData;
-
-$(function() {
- $("#join").click(function() {
- initSocket();
- });
-});
-
-var initSocket = function() {
- socket = new io.Socket("localhost", {port: 5678, transports: ["websocket", "flashsocket"]});
-
- // EVENTS
- // connect, connecting, connect_failed, message, close,
- // disconnect, reconnect, reconnecting, reconnect_failed
-
- // WebSocket connection successful
- socket.on("connect", function() {
- console.log("Connected");
- var msg = JSON.stringify({type: "join"});
- socket.send(msg);
- });
-
- // WebSocket connection failed
- socket.on("connect_failed", function() {
- console.log("Connect failed");
-
- });
-
- // WebSocket disconnection
- socket.on("disconnect", function() {
- console.log("Disconnected");
-
- });
-
- // WebSocket message received
- socket.on("message", function(data) {
- var msg = JSON.parse(data);
-
- if (msg.type) {
- switch (msg.type) {
- case "welcome":
- levelData = msg.level;
- break;
- };
- };
- });
-
- socket.connect();
-};
View
26 data/level.txt
@@ -1,13 +1,13 @@
-*****************
-*1 * 4*
-* *
-** *
-* *
-* *
-* *
-* *-* *-* *
-* *
-* *
-* *
-*3 2*
-*****************
+*****************
+*1 * 4*
+* *
+** *
+* *
+* *
+* *
+* *-* *-* *
+* *
+* *
+* *
+*3 2*
+*****************
View
14 etc/client_hax.txt
@@ -1,8 +1,8 @@
-
-
-window.kaboomClient = the CLIENT INSTANCE that's running your game.
-
-
-$(function() {
- $("document".bind("keydown", window.kaboomClient.handleKeyDown.bind(window
+
+
+window.kaboomClient = the CLIENT INSTANCE that's running your game.
+
+
+$(function() {
+ $("document".bind("keydown", window.kaboomClient.handleKeyDown.bind(window
}
View
82 lib/broadcaster.js
@@ -1,41 +1,41 @@
-var _ = require('base');
-var sys = require('sys');
-var EventEmitter = require('events').EventEmitter;
-
-var Broadcaster = function(){
- var self = this;
- this.clients = {};
-
- function broadcast(message, fromJSON) {
- message = fromJSON ? JSON.stringify(message) : message;
- for(var id in self.clients) {
- self.clients[id].send(message);
- }
- }
-
- this.on('broadcast-json', function(message){
- broadcast(message, true);
- });
-
- this.on('broadcast', function(msg){ broadcast(msg) });
-
- EventEmitter.call(this);
-}
-
-sys.inherits(Broadcaster, EventEmitter);
-
-Broadcaster.prototype.addClient = function(c) {
- var uuid = _.uuid();
- c._kaboomUid = uuid;
- this.clients[uuid] = c;
-}
-
-Broadcaster.prototype.removeClient = function(c) {
- var self = this;
- return function() {
- delete self.clients[c._kaboomUid];
- }
-}
-
-var broadcaster = new Broadcaster();
-exports.broadcaster = broadcaster
+var _ = require('base');
+var sys = require('sys');
+var EventEmitter = require('events').EventEmitter;
+
+var Broadcaster = function(){
+ var self = this;
+ this.clients = {};
+
+ function broadcast(message, fromJSON) {
+ message = fromJSON ? JSON.stringify(message) : message;
+ for(var id in self.clients) {
+ self.clients[id].send(message);
+ }
+ }
+
+ this.on('broadcast-json', function(message){
+ broadcast(message, true);
+ });
+
+ this.on('broadcast', function(msg){ broadcast(msg) });
+
+ EventEmitter.call(this);
+}
+
+sys.inherits(Broadcaster, EventEmitter);
+
+Broadcaster.prototype.addClient = function(c) {
+ var uuid = _.uuid();
+ c._kaboomUid = uuid;
+ this.clients[uuid] = c;
+}
+
+Broadcaster.prototype.removeClient = function(c) {
+ var self = this;
+ return function() {
+ delete self.clients[c._kaboomUid];
+ }
+}
+
+var broadcaster = new Broadcaster();
+exports.broadcaster = broadcaster
View
16 package.json
@@ -1,8 +1,8 @@
-{ "name" : "KaboomJS"
-, "version" : "0.0.1"
-, "description" : ""
-, "scripts" : { "start" : "node server.js" }
-, "dependencies" : { "socket.io" : "0.6.18"
- , "faye" : "0.6.0"
- , "express" : "2.3.10"
- , "log4js" : "0.2.5"}}
+{ "name" : "KaboomJS"
+, "version" : "0.0.1"
+, "description" : ""
+, "scripts" : { "start" : "node server.js" }
+, "dependencies" : { "socket.io" : "0.6.18"
+ , "faye" : "0.6.0"
+ , "express" : "2.3.10"
+ , "log4js" : "0.2.5"}}
View
158 public/css/bomber.css
@@ -1,80 +1,80 @@
-
-body {
- font-family: helvetica;
- font-size: 1.5em;
- background: black;
- color: #ccc;
-}
-
-#container {
- position: absolute;
- width: 816px;
- height: 624px;
- margin: 5px;
- padding: 10px;
- z-index: 0;
-}
-
-#arena, #playerLayer {
- position: absolute;
- width: 816px;
- height: 624px;
- z-index: 10;
-}
-
-#playerLayer {
- z-index: 20;
-}
-
-#holding {
- position: absolute;
- left: 860px;
- width: 48px;
- height: 624px;
- z-index: 20;
-}
-
-.row {
- background: beige;
-}
-
-.tile {
- background: transparent;
-}
-
-.player {
- float: left;
- width: 36px;
- height: 72px;
- z-index: 40;
-}
-
-#player_1 {
- background: url(../images/player-1.png);
-}
-
-#player_2 {
- background: url(../images/player-2.png);
-}
-
-#player_3 {
- background: url(../images/player-3.png);
-}
-
-#player_4 {
- background: url(../images/player-4.png);
-}
-
-.boundingBox {
- border: 1px solid red;
- position: absolute;
- z-index: 100;
-}
-
-.boundingBox.player {
- border: 1px solid green;
-}
-
-.intersecting {
- background: rgba(0, 0, 255, 0.5);
+
+body {
+ font-family: helvetica;
+ font-size: 1.5em;
+ background: black;
+ color: #ccc;
+}
+
+#container {
+ position: absolute;
+ width: 816px;
+ height: 624px;
+ margin: 5px;
+ padding: 10px;
+ z-index: 0;
+}
+
+#arena, #playerLayer {
+ position: absolute;
+ width: 816px;
+ height: 624px;
+ z-index: 10;
+}
+
+#playerLayer {
+ z-index: 20;
+}
+
+#holding {
+ position: absolute;
+ left: 860px;
+ width: 48px;
+ height: 624px;
+ z-index: 20;
+}
+
+.row {
+ background: beige;
+}
+
+.tile {
+ background: transparent;
+}
+
+.player {
+ float: left;
+ width: 36px;
+ height: 72px;
+ z-index: 40;
+}
+
+#player_1 {
+ background: url(../images/player-1.png);
+}
+
+#player_2 {
+ background: url(../images/player-2.png);
+}
+
+#player_3 {
+ background: url(../images/player-3.png);
+}
+
+#player_4 {
+ background: url(../images/player-4.png);
+}
+
+.boundingBox {
+ border: 1px solid red;
+ position: absolute;
+ z-index: 100;
+}
+
+.boundingBox.player {
+ border: 1px solid green;
+}
+
+.intersecting {
+ background: rgba(0, 0, 255, 0.5);
}
View
90 public/index.html
@@ -1,46 +1,46 @@
-<!doctype html>
-
-<html>
- <head>
- <title>KaboomJS</title>
- <link rel="stylesheet" type="text/css" href="css/bomber.css" media="screen" />
- </head>
-
- <body>
- <a id="join" href="#">Join</a>
-
- <div id="container">
- <div id="arena"></div>
- <div id="playerLayer"></div>
- <div id="holding"></div>
- </div>
-
-
-
- <script src="js/libs/jquery-1.6.1.js"></script>
- <script src="js/libs/socket.io.min.js"></script>
- <script src="js/libs/jquery.hotkeys.js"></script>
- <script src="js/libs/key_status.js"></script>
- <script src="js/libs/json2.js"></script>
- <script src="js/game/client.js"></script>
- <script src="js/game/kaboom.socket.js"></script>
- <script src="js/game/kaboom.game.js"></script>
- <script src="js/game/kaboom.player.js"></script>
- <script src="js/game/kaboom.renderer.js"></script>
- <script src="js/game/level.js"></script>
- <script type="text/javascript">
- $(function(){
- var client = new KaboomClient({fps: 30});
- client.init();
-
- $('#join').click(function(){
- client.join();
- });
-
- });
-
-
- </script>
-
- </body>
+<!doctype html>
+
+<html>
+ <head>
+ <title>KaboomJS</title>
+ <link rel="stylesheet" type="text/css" href="css/bomber.css" media="screen" />
+ </head>
+
+ <body>
+ <a id="join" href="#">Join</a>
+
+ <div id="container">
+ <div id="arena"></div>
+ <div id="playerLayer"></div>
+ <div id="holding"></div>
+ </div>
+
+
+
+ <script src="js/libs/jquery-1.6.1.js"></script>
+ <script src="js/libs/socket.io.min.js"></script>
+ <script src="js/libs/jquery.hotkeys.js"></script>
+ <script src="js/libs/key_status.js"></script>
+ <script src="js/libs/json2.js"></script>
+ <script src="js/game/client.js"></script>
+ <script src="js/game/kaboom.socket.js"></script>
+ <script src="js/game/kaboom.game.js"></script>
+ <script src="js/game/kaboom.player.js"></script>
+ <script src="js/game/kaboom.renderer.js"></script>
+ <script src="js/game/level.js"></script>
+ <script type="text/javascript">
+ $(function(){
+ var client = new KaboomClient({fps: 30});
+ client.init();
+
+ $('#join').click(function(){
+ client.join();
+ });
+
+ });
+
+
+ </script>
+
+ </body>
</html>
View
17 public/js/game/client.js
@@ -71,7 +71,7 @@ KaboomClient.prototype = {
notifyPlayerChanged: function(){
- this.socket.playerChangedDirection(player);
+ if (this.socket) this.socket.playerChangedDirection(player);
},
draw : function(){
@@ -81,12 +81,17 @@ KaboomClient.prototype = {
join: function(){
console.log('Joining...');
- this.socket = new KaboomSocket();
- this.socket.init(this, window.location.hostname, window.location.port);
- this.socket.join();
-
+ try {
+ this.socket = new KaboomSocket();
+ this.socket.init(this, window.location.hostname, window.location.port);
+ } catch(e) {
+ console.log("Socket init failed - using local mode");
+ this.socket = new MockSocket();
+ this.socket.init(this);
+ }
+ this.socket.join();
},
-
+
gameSuccessfullyJoined : function(gameState, playerState){
console.log('Creating game...');
window.game = new KaboomGame();
View
550 public/js/game/kaboom.game.js
@@ -1,275 +1,275 @@
-/**
- * Created by JetBrains WebStorm.
- * User: dylanbeattie
- * Date: 04/06/2011
- * Time: 15:07
- * To change this template use File | Settings | File Templates.
- */
-
-if (typeof require == "function") {
- var KaboomPlayer = require("./kaboom.player").KaboomPlayer;
- var Position = require("./kaboom.player").Position;
-};
-
-var KaboomGame = function (levelMap) {
- this.level = new Level(levelMap);
- this.players = [];
- this.DISTANCE = 5;
- this.TILE_SIZE = 48;
-};
-
-KaboomGame.prototype = {
-
- copyStateFrom : function(gameState) {
- this.DISTANCE = gameState.DISTANCE;
- this.TILE_SIZE = gameState.TILE_SIZE;
- this.level = this.level || new Level();
- this.level.copyStateFrom(gameState.level);
- for (var i = 0; i < gameState.players.length; i++) {
- var sourcePlayer = gameState.players[i];
- if (sourcePlayer) {
- var targetPlayer = this.findPlayer(gameState.players[i]) || this.addPlayer(new KaboomPlayer());
- targetPlayer.copyStateFrom(gameState.players[i]);
- }
- }
- },
-
- /* Finds the player instance within THIS game representing the same player as the supplied player */
- findPlayer : function(player) {
- for(var i = 0; i < this.players.length; i++) {
- if (this.players[i].name == player.name) return(this.players[i]);
- }
- },
-
- playerChangedVelocity : function(player) {
- /* TODO: find the GAME player matching the supplied player and
- update their position and velocity with those from the
- supplied player.
- */
- },
-
- addPlayer : function(player) {
- this.players.push(player);
- return(player);
- },
-
- removePlayer: function(player) {
- /* TODO: Find and free the player slot used by the specified player */
- /* TODO: remember to set the corresponding spawn point.player back to null */
- },
-
- createPlayer : function() {
- var spawn = this.level.getFirstEmptySpawnPoint();
- var that=this;
- if (spawn == null) return(null);
- var player = new KaboomPlayer(spawn.number, "Player " + spawn.number, that.tilesToPixels(spawn.position));
- console.log(player);
- this.players[spawn.number - 1] = player;
- console.log(spawn.number, this.players);
- spawn.player = player;
- return player;
- },
-
- tilesToPixels : function(position) {
- var pixelX = position.x * this.TILE_SIZE;
- var pixelY = position.y * this.TILE_SIZE;
-
- return new Position(pixelX, pixelY);
- },
-
- pixelsToTiles : function(position) {
- var tileX = Math.floor(position.x/this.TILE_SIZE);
- var tileY = Math.floor(position.y/this.TILE_SIZE);
-
- return new Position(tileX, tileY);
- },
-
-
- update: function() {
- var game = this;
- /* For each player, assume they have moved DISTANCE in their own velocity */
- this.players.forEach(function(p, idx) {
- if (p != null) {
- var newPos = new Position(
- p.position.x + game.DISTANCE * p.velocity.dx,
- p.position.y + game.DISTANCE * p.velocity.dy
- );
-
- var playerRect = new Rectangle(newPos.y, newPos.x, 48, 48);
- var canMove = true;
-
- game.level.forEachIntersectingTile(playerRect, game, function(tile) {
- if (tile.solid) {
- canMove = false;
- }
- });
-
- if (canMove) {
- p.position = newPos;
- }
- }
- });
- }
-};
-
-if (typeof exports == "object") {
- exports.KaboomGame = KaboomGame;
-};
-
-TileType = {
- Solid: 0,
- Destroyable: 1,
- Blank: 2
-};
-
-function Level(initialTileMap) {
-
- /*this.rows = 13;
- this.cols = 17;*/
-
- this.rows = [];
- this.spawns = [];
-
- this.copyStateFrom = function(that) {
- this.rows = that.rows.map(function(row) {
- return row.map(function(cell) {
- return new Tile(cell.solid, cell.tileType, cell.row, cell.col);
- });
- });
- this.spawns = that.spawns;
- }
-
- this.forEachIntersectingTile = function(rect, game, callback) {
- $(this.rows).each(function(ri, row) {
- $(row).each(function(ti, tile) {
- tile.isIntersecting = false;
- if (rect.intersects(tile.getBounds(game))) {
- tile.isIntersecting = true;
- callback(tile);
- }
- });
- });
- };
-
- this.parseLevel = function(tileMap) {
- var r, c;
- var entry;
- var index;
- var spawn, spawnNum = 0;
- var solid, tileType;
-
- var row = [];
-
- for (var i = 0; i < tileMap.length; i++) {
- var tileChar = tileMap[i];
-
- switch (tileChar) {
- case '\n':
- this.rows.push(row);
- row = [];
- continue;
- case "*":
- tileType = TileType.Solid;
- solid = true;
- spawn = false;
- break;
- case "-":
- tileType = TileType.Destroyable;
- solid = true;
- spawn = false
- break;
- case " ":
- tileType = TileType.Blank;
- solid = false;
- spawn = false;
- break;
- case "1":
- tileType = TileType.Blank;
- solid = false;
- spawn = true;
- spawnNum = 1;
- break;
- case "2":
- tileType = TileType.Blank;
- solid = false;
- spawn = true;
- spawnNum = 2;
- break;
- case "3":
- tileType = TileType.Blank;
- solid = false;
- spawn = true;
- spawnNum = 3;
- break;
- case "4":
- tileType = TileType.Blank;
- solid = false;
- spawn = true;
- spawnNum = 4;
- break;
- default:
- console.log(entry);
- }
-
- if (spawn) {
- this.spawns.push(new Spawn(spawnNum, row.length, this.rows.length));
- }
-
- row.push(new Tile(solid, tileType, this.rows.length, row.length));
- };
-
- if (row.length > 0) {
- this.rows.push(row);
- }
- }
-
-
- if (initialTileMap) {
- this.parseLevel(initialTileMap);
- }
-
- this.getFirstEmptySpawnPoint = function()
- {
- for(var i = 0; i < this.spawns.length; i++) {
- var spawn = this.spawns[i];
- if (spawn.player == null) return(spawn);
- }
- }
-}
-
-function Tile (solid, tileType, row, col) {
- this.solid = solid;
- this.tileType = tileType;
- this.row = row;
- this.col = col;
- this.getBounds = function(game) {
- return new Rectangle(this.col * game.TILE_SIZE, this.row * game.TILE_SIZE, game.TILE_SIZE, game.TILE_SIZE);
- }
-};
-
-function Spawn (num, x, y) {
- this.number = num;
- this.position = new Position(x,y);
- this.player = null;
-}
-
-function Rectangle(x, y, width, height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- this.left = x;
- this.top = y;
- this.right = this.left + width;
- this.bottom = this.top + height;
- this.pointIntersects = function(point) {
- return point.x >= this.left && point.x < this.right &&
- point.y >= this.top && point.y < this.bottom;
- };
- this.intersects = function(that) {
- return this.pointIntersects({x: that.top, y: that.left}) ||
- this.pointIntersects({x: that.top, y: that.right}) ||
- this.pointIntersects({x: that.bottom, y: that.left}) ||
- this.pointIntersects({x: that.bottom, y: that.right});
- };
-};
+/**
+ * Created by JetBrains WebStorm.
+ * User: dylanbeattie
+ * Date: 04/06/2011
+ * Time: 15:07
+ * To change this template use File | Settings | File Templates.
+ */
+
+if (typeof require == "function") {
+ var KaboomPlayer = require("./kaboom.player").KaboomPlayer;
+ var Position = require("./kaboom.player").Position;
+};
+
+var KaboomGame = function (levelMap) {
+ this.level = new Level(levelMap);
+ this.players = [];
+ this.DISTANCE = 5;
+ this.TILE_SIZE = 48;
+};
+
+KaboomGame.prototype = {
+
+ copyStateFrom : function(gameState) {
+ this.DISTANCE = gameState.DISTANCE;
+ this.TILE_SIZE = gameState.TILE_SIZE;
+ this.level = this.level || new Level();
+ this.level.copyStateFrom(gameState.level);
+ for (var i = 0; i < gameState.players.length; i++) {
+ var sourcePlayer = gameState.players[i];
+ if (sourcePlayer) {
+ var targetPlayer = this.findPlayer(gameState.players[i]) || this.addPlayer(new KaboomPlayer());
+ targetPlayer.copyStateFrom(gameState.players[i]);
+ }
+ }
+ },
+
+ /* Finds the player instance within THIS game representing the same player as the supplied player */
+ findPlayer : function(player) {
+ for(var i = 0; i < this.players.length; i++) {
+ if (this.players[i].name == player.name) return(this.players[i]);
+ }
+ },
+
+ playerChangedVelocity : function(player) {
+ /* TODO: find the GAME player matching the supplied player and
+ update their position and velocity with those from the
+ supplied player.
+ */
+ },
+
+ addPlayer : function(player) {
+ this.players.push(player);
+ return(player);
+ },
+
+ removePlayer: function(player) {
+ /* TODO: Find and free the player slot used by the specified player */
+ /* TODO: remember to set the corresponding spawn point.player back to null */
+ },
+
+ createPlayer : function() {
+ var spawn = this.level.getFirstEmptySpawnPoint();
+ var that=this;
+ if (spawn == null) return(null);
+ var player = new KaboomPlayer(spawn.number, "Player " + spawn.number, that.tilesToPixels(spawn.position));
+ console.log(player);
+ this.players[spawn.number - 1] = player;
+ console.log(spawn.number, this.players);
+ spawn.player = player;
+ return player;
+ },
+
+ tilesToPixels : function(position) {
+ var pixelX = position.x * this.TILE_SIZE;
+ var pixelY = position.y * this.TILE_SIZE;
+
+ return new Position(pixelX, pixelY);
+ },
+
+ pixelsToTiles : function(position) {
+ var tileX = Math.floor(position.x/this.TILE_SIZE);
+ var tileY = Math.floor(position.y/this.TILE_SIZE);
+
+ return new Position(tileX, tileY);
+ },
+
+
+ update: function() {
+ var game = this;
+ /* For each player, assume they have moved DISTANCE in their own velocity */
+ this.players.forEach(function(p, idx) {
+ if (p != null) {
+ var newPos = new Position(
+ p.position.x + game.DISTANCE * p.velocity.dx,
+ p.position.y + game.DISTANCE * p.velocity.dy
+ );
+
+ var playerRect = new Rectangle(newPos.y, newPos.x, 48, 48);
+ var canMove = true;
+
+ game.level.forEachIntersectingTile(playerRect, game, function(tile) {
+ if (tile.solid) {
+ canMove = false;
+ }
+ });
+
+ if (canMove) {
+ p.position = newPos;
+ }
+ }
+ });
+ }
+};
+
+if (typeof exports == "object") {
+ exports.KaboomGame = KaboomGame;
+};
+
+TileType = {
+ Solid: 0,
+ Destroyable: 1,
+ Blank: 2
+};
+
+function Level(initialTileMap) {
+
+ /*this.rows = 13;
+ this.cols = 17;*/
+
+ this.rows = [];
+ this.spawns = [];
+
+ this.copyStateFrom = function(that) {
+ this.rows = that.rows.map(function(row) {
+ return row.map(function(cell) {
+ return new Tile(cell.solid, cell.tileType, cell.row, cell.col);
+ });
+ });
+ this.spawns = that.spawns;
+ }
+
+ this.forEachIntersectingTile = function(rect, game, callback) {
+ $(this.rows).each(function(ri, row) {
+ $(row).each(function(ti, tile) {
+ tile.isIntersecting = false;
+ if (rect.intersects(tile.getBounds(game))) {
+ tile.isIntersecting = true;
+ callback(tile);
+ }
+ });
+ });
+ };
+
+ this.parseLevel = function(tileMap) {
+ var r, c;
+ var entry;
+ var index;
+ var spawn, spawnNum = 0;
+ var solid, tileType;
+
+ var row = [];
+
+ for (var i = 0; i < tileMap.length; i++) {
+ var tileChar = tileMap[i];
+
+ switch (tileChar) {
+ case '\n':
+ this.rows.push(row);
+ row = [];
+ continue;
+ case "*":
+ tileType = TileType.Solid;
+ solid = true;
+ spawn = false;
+ break;
+ case "-":
+ tileType = TileType.Destroyable;
+ solid = true;
+ spawn = false
+ break;
+ case " ":
+ tileType = TileType.Blank;
+ solid = false;
+ spawn = false;
+ break;
+ case "1":
+ tileType = TileType.Blank;
+ solid = false;
+ spawn = true;
+ spawnNum = 1;
+ break;
+ case "2":
+ tileType = TileType.Blank;
+ solid = false;
+ spawn = true;
+ spawnNum = 2;
+ break;
+ case "3":
+ tileType = TileType.Blank;
+ solid = false;
+ spawn = true;
+ spawnNum = 3;
+ break;
+ case "4":
+ tileType = TileType.Blank;
+ solid = false;
+ spawn = true;
+ spawnNum = 4;
+ break;
+ default:
+ console.log(entry);
+ }
+
+ if (spawn) {
+ this.spawns.push(new Spawn(spawnNum, row.length, this.rows.length));
+ }
+
+ row.push(new Tile(solid, tileType, this.rows.length, row.length));
+ };
+
+ if (row.length > 0) {
+ this.rows.push(row);
+ }
+ }
+
+
+ if (initialTileMap) {
+ this.parseLevel(initialTileMap);
+ }
+
+ this.getFirstEmptySpawnPoint = function()
+ {
+ for(var i = 0; i < this.spawns.length; i++) {
+ var spawn = this.spawns[i];
+ if (spawn.player == null) return(spawn);
+ }
+ }
+}
+
+function Tile (solid, tileType, row, col) {
+ this.solid = solid;
+ this.tileType = tileType;
+ this.row = row;
+ this.col = col;
+ this.getBounds = function(game) {
+ return new Rectangle(this.col * game.TILE_SIZE, this.row * game.TILE_SIZE, game.TILE_SIZE, game.TILE_SIZE);
+ }
+};
+
+function Spawn (num, x, y) {
+ this.number = num;
+ this.position = new Position(x,y);
+ this.player = null;
+}
+
+function Rectangle(x, y, width, height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.left = x;
+ this.top = y;
+ this.right = this.left + width;
+ this.bottom = this.top + height;
+ this.pointIntersects = function(point) {
+ return point.x >= this.left && point.x < this.right &&
+ point.y >= this.top && point.y < this.bottom;
+ };
+ this.intersects = function(that) {
+ return this.pointIntersects({x: that.top, y: that.left}) ||
+ this.pointIntersects({x: that.top, y: that.right}) ||
+ this.pointIntersects({x: that.bottom, y: that.left}) ||
+ this.pointIntersects({x: that.bottom, y: that.right});
+ };
+};
View
168 public/js/game/kaboom.player.js
@@ -1,84 +1,84 @@
-/**
- * Created by JetBrains WebStorm.
- * User: dylanbeattie
- * Date: 04/06/2011
- * Time: 15:08
- * To change this template use File | Settings | File Templates.
- */
-
-var KaboomPlayer = function(id, name, position, velocity) {
- /* Player.name must be unique and can be used to determine equality */
- this.id = id;
- this.name = name;
- this.position = position || new Position(0,0);
- this.velocity = velocity || new Velocity(0,0);
- this.getBounds = function(game) {
- return new Rectangle(this.position.x, this.position.y, game.TILE_SIZE, game.TILE_SIZE);
- };
-};
-
-Position = function(x, y) {
- this.x = x;
- this.y = y;
-};
-
-function Velocity(dx, dy) {
- this.dx = dx;
- this.dy = dy;
-};
-
-KaboomPlayer.prototype = {
-
- goLeft: function(){
- if(this.velocity.dx != -1){
- this.velocity.dx = -1;
- return true;
- }
- return false;
- },
-
- goRight: function(){
- if (this.velocity.dx != 1) {
- this.velocity.dx = 1;
- return true;
- }
- return false;
- },
-
- goUp: function(){
- if(this.velocity.dy != -1){
- this.velocity.dy = -1;
- return true;
- }
- return false;
- },
-
- goDown: function(){
- if(this.velocity.dy != 1){
- this.velocity.dy = 1;
- return true;
- }
- return false;
- },
-
- horizontalStop: function(){
- this.velocity.dx = 0;
- },
-
- verticalStop: function(){
- this.velocity.dy = 0;
- },
-
- copyStateFrom : function(that) {
- this.id = that.id;
- this.name = that.name;
- this.position = new Position(that.position.x, that.position.y);
- this.velocity = new Velocity(that.velocity.dx, that.velocity.dy);
- return this;
- }
-};
-
-if (typeof exports == "object") {
- exports.KaboomPlayer = KaboomPlayer;
- exports.Position = Position;
-};
+/**
+ * Created by JetBrains WebStorm.
+ * User: dylanbeattie
+ * Date: 04/06/2011
+ * Time: 15:08
+ * To change this template use File | Settings | File Templates.
+ */
+
+var KaboomPlayer = function(id, name, position, velocity) {
+ /* Player.name must be unique and can be used to determine equality */
+ this.id = id;
+ this.name = name;
+ this.position = position || new Position(0,0);
+ this.velocity = velocity || new Velocity(0,0);
+ this.getBounds = function(game) {
+ return new Rectangle(this.position.x, this.position.y, game.TILE_SIZE, game.TILE_SIZE);
+ };
+};
+
+Position = function(x, y) {
+ this.x = x;
+ this.y = y;
+};
+
+function Velocity(dx, dy) {
+ this.dx = dx;
+ this.dy = dy;
+};
+
+KaboomPlayer.prototype = {
+
+ goLeft: function(){
+ if(this.velocity.dx != -1){
+ this.velocity.dx = -1;
+ return true;
+ }
+ return false;
+ },
+
+ goRight: function(){
+ if (this.velocity.dx != 1) {
+ this.velocity.dx = 1;
+ return true;
+ }
+ return false;
+ },
+
+ goUp: function(){
+ if(this.velocity.dy != -1){
+ this.velocity.dy = -1;
+ return true;
+ }
+ return false;
+ },
+
+ goDown: function(){
+ if(this.velocity.dy != 1){
+ this.velocity.dy = 1;
+ return true;
+ }
+ return false;
+ },
+
+ horizontalStop: function(){
+ this.velocity.dx = 0;
+ },
+
+ verticalStop: function(){
+ this.velocity.dy = 0;
+ },
+
+ copyStateFrom : function(that) {
+ this.id = that.id;
+ this.name = that.name;
+ this.position = new Position(that.position.x, that.position.y);
+ this.velocity = new Velocity(that.velocity.dx, that.velocity.dy);
+ return this;
+ }
+};
+
+if (typeof exports == "object") {
+ exports.KaboomPlayer = KaboomPlayer;
+ exports.Position = Position;
+};
View
280 public/js/game/kaboom.renderer.js
@@ -1,140 +1,140 @@
-KaboomPlayer.prototype.showBoundingBox = function(layer, game) {
- var boundingBox = $('#player_'+this.id+'_boundingBox');
- if (boundingBox.length == 0) {
- boundingBox = $('<div id="player_'+this.id+'_boundingBox" class="boundingBox player" />');
- layer.append(boundingBox);
- }
-
- var bounds = this.getBounds(game);
- boundingBox.css({
- top: bounds.top + 'px',
- left: bounds.left + 'px',
- width: bounds.width + 'px',
- height: bounds.height + 'px'
- });
-};
-
-Tile.prototype.showBoundingBox = function(layer, game) {
- var boundingBox = $('#tile_'+this.row+'x'+this.col+'_boundingBox');
- if (boundingBox.length == 0) {
- boundingBox = $('<div id="tile_'+this.row+'x'+this.col+'_boundingBox" class="boundingBox" />');
- layer.append(boundingBox);
- }
-
- var bounds = this.getBounds(game);
- boundingBox.css({
- top: bounds.top + 'px',
- left: bounds.left + 'px',
- width: bounds.width + 'px',
- height: bounds.height + 'px'
- });
-
- if (this.isIntersecting) {
- boundingBox.addClass('intersecting');
- } else {
- boundingBox.removeClass('intersecting');
- }
-};
-
-function KaboomRenderer(opts) {
- var game = opts.game;
- this.itemImages = ["images/solid-block.png",
- "images/destroyable-block.png",
- "images/blank.png" ];
- this.initialise = function() {
- var level = game.level;
-
- // create tiles
- for (var row = 0; row < level.rows.length; row++) {
- var rowDiv = $('<div class="row" style="position:absolute;top:'+row*game.TILE_SIZE+'px;height:'+game.TILE_SIZE+'px;width:'+game.TILE_SIZE*level.rows[row].length+'px" />');
-
- for (var tileIndex = 0; tileIndex < level.rows[row].length; tileIndex++) {
- var tile = level.rows[row][tileIndex];
- var tileDiv = $('<div id="tile_' + row + '_' + tileIndex + '" class="tile" style="position:absolute;height:' + game.TILE_SIZE + 'px;width:'+game.TILE_SIZE+'px;top:0;left:'+tileIndex * game.TILE_SIZE+'px" />');
-
- if (tile != null) {
- tileDiv.css('background', 'url(' + this.itemImages[tile.tileType] + ')');
- }
-
- rowDiv.append(tileDiv);
- }
-
- opts.arena.append(rowDiv);
- }
-
- // create players
- for (var player = 0; player < game.players.length; player++) {
- this.createPlayer(player + 1);
- }
- };
-
- this.createPlayer = function(num) {
- var playerDiv = $('<div id="player_' + num + '" class="player" />');
-
- opts.holding.append(playerDiv);
- };
-
- this.updatePlayerLocations = function() {
- for (var i = 0; i < game.players.length; i++) {
- var player = game.players[i];
-
- if (player != null) {
- if (opts.showBoundingBoxes) {
- player.showBoundingBox(opts.playerLayer, game);
- }
-
- var playerDiv = $('#player_' + (i + 1));
-
- if (!playerDiv.data('isInPlay')) {
- opts.playerLayer.append(playerDiv);
- playerDiv.data('isInPlay', true);
- }
-
- if (playerDiv.data('y') != player.position.y && playerDiv.data('x') != player.position.x) {
- var y = player.position.y - 32;
- var x = player.position.x + 8;
- playerDiv.css({
- position: 'absolute',
- top: y + 'px',
- left: x + 'px'
- });
- playerDiv.data('x', x);
- playerDiv.data('y', y);
- }
- }
- }
- };
-
- this.updateItems = function() {
- for (var rowIndex = 0; rowIndex < game.level.rows.length; rowIndex++) {
- for (var tileIndex = 0; tileIndex < game.level.rows[rowIndex].length; tileIndex++) {
- var tile = game.level.rows[rowIndex][tileIndex];
- var tileDiv = $('#tile_' + rowIndex + '_' + tileIndex);
-
- var url = null;
-
- if (tile == null) {
- url = 'url(images/blank.png)';
- } else {
- url = 'url(' + this.itemImages[tile.tileType] + ')';
- }
-
- if (tileDiv.data('background') != url) {
- tileDiv.css('background', url);
- tileDiv.data('background', url);
- }
-
- if (opts.showBoundingBoxes) {
- tile.showBoundingBox(opts.playerLayer, game);
- }
- }
- }
- };
-
- this.update = function() {
- this.updatePlayerLocations();
- this.updateItems();
- };
-
- this.initialise();
-}
+KaboomPlayer.prototype.showBoundingBox = function(layer, game) {
+ var boundingBox = $('#player_'+this.id+'_boundingBox');
+ if (boundingBox.length == 0) {
+ boundingBox = $('<div id="player_'+this.id+'_boundingBox" class="boundingBox player" />');
+ layer.append(boundingBox);
+ }
+
+ var bounds = this.getBounds(game);
+ boundingBox.css({
+ top: bounds.top + 'px',
+ left: bounds.left + 'px',
+ width: bounds.width + 'px',
+ height: bounds.height + 'px'
+ });
+};
+
+Tile.prototype.showBoundingBox = function(layer, game) {
+ var boundingBox = $('#tile_'+this.row+'x'+this.col+'_boundingBox');
+ if (boundingBox.length == 0) {
+ boundingBox = $('<div id="tile_'+this.row+'x'+this.col+'_boundingBox" class="boundingBox" />');
+ layer.append(boundingBox);
+ }
+
+ var bounds = this.getBounds(game);
+ boundingBox.css({
+ top: bounds.top + 'px',
+ left: bounds.left + 'px',
+ width: bounds.width + 'px',
+ height: bounds.height + 'px'
+ });
+
+ if (this.isIntersecting) {
+ boundingBox.addClass('intersecting');
+ } else {
+ boundingBox.removeClass('intersecting');
+ }
+};
+
+function KaboomRenderer(opts) {
+ var game = opts.game;
+ this.itemImages = ["images/solid-block.png",
+ "images/destroyable-block.png",
+ "images/blank.png" ];
+ this.initialise = function() {
+ var level = game.level;
+
+ // create tiles
+ for (var row = 0; row < level.rows.length; row++) {
+ var rowDiv = $('<div class="row" style="position:absolute;top:'+row*game.TILE_SIZE+'px;height:'+game.TILE_SIZE+'px;width:'+game.TILE_SIZE*level.rows[row].length+'px" />');
+
+ for (var tileIndex = 0; tileIndex < level.rows[row].length; tileIndex++) {
+ var tile = level.rows[row][tileIndex];
+ var tileDiv = $('<div id="tile_' + row + '_' + tileIndex + '" class="tile" style="position:absolute;height:' + game.TILE_SIZE + 'px;width:'+game.TILE_SIZE+'px;top:0;left:'+tileIndex * game.TILE_SIZE+'px" />');
+
+ if (tile != null) {
+ tileDiv.css('background', 'url(' + this.itemImages[tile.tileType] + ')');
+ }
+
+ rowDiv.append(tileDiv);
+ }
+
+ opts.arena.append(rowDiv);
+ }
+
+ // create players
+ for (var player = 0; player < game.players.length; player++) {
+ this.createPlayer(player + 1);
+ }
+ };
+
+ this.createPlayer = function(num) {
+ var playerDiv = $('<div id="player_' + num + '" class="player" />');
+
+ opts.holding.append(playerDiv);
+ };
+
+ this.updatePlayerLocations = function() {
+ for (var i = 0; i < game.players.length; i++) {
+ var player = game.players[i];
+
+ if (player != null) {
+ if (opts.showBoundingBoxes) {
+ player.showBoundingBox(opts.playerLayer, game);
+ }
+
+ var playerDiv = $('#player_' + (i + 1));
+
+ if (!playerDiv.data('isInPlay')) {
+ opts.playerLayer.append(playerDiv);
+ playerDiv.data('isInPlay', true);
+ }
+
+ if (playerDiv.data('y') != player.position.y && playerDiv.data('x') != player.position.x) {
+ var y = player.position.y - 32;
+ var x = player.position.x + 8;
+ playerDiv.css({
+ position: 'absolute',
+ top: y + 'px',
+ left: x + 'px'
+ });
+ playerDiv.data('x', x);
+ playerDiv.data('y', y);
+ }
+ }
+ }
+ };
+
+ this.updateItems = function() {
+ for (var rowIndex = 0; rowIndex < game.level.rows.length; rowIndex++) {
+ for (var tileIndex = 0; tileIndex < game.level.rows[rowIndex].length; tileIndex++) {
+ var tile = game.level.rows[rowIndex][tileIndex];
+ var tileDiv = $('#tile_' + rowIndex + '_' + tileIndex);
+
+ var url = null;
+
+ if (tile == null) {
+ url = 'url(images/blank.png)';
+ } else {
+ url = 'url(' + this.itemImages[tile.tileType] + ')';
+ }
+
+ if (tileDiv.data('background') != url) {
+ tileDiv.css('background', url);
+ tileDiv.data('background', url);
+ }
+
+ if (opts.showBoundingBoxes) {
+ tile.showBoundingBox(opts.playerLayer, game);
+ }
+ }
+ }
+ };
+
+ this.update = function() {
+ this.updatePlayerLocations();
+ this.updateItems();
+ };
+
+ this.initialise();
+}
View
53 public/js/game/kaboom.socket.js
@@ -1,3 +1,40 @@
+function MockSocket() {
+ this.client = null;
+ this.levelMap = "*****************\n"
+ +"*1 * 4*\n"
+ +"* *\n"
+ +"* *\n"
+ +"* *\n"
+ +"* *\n"
+ +"* *\n"
+ +"* *-* *-* *\n"
+ +"* *\n"
+ +"* *\n"
+ +"* *\n"
+ +"*****************";
+}
+
+MockSocket.prototype = {
+ init : function(client) {
+ this.client = client;
+ },
+
+ join : function(){
+ var game = new KaboomGame(this.levelMap);
+ var player = game.createPlayer();
+ this.client.gameSuccessfullyJoined(game, player);
+ },
+
+ playerChangedDirection : function(player) {
+ },
+
+ playerDroppedBomb : function(player) {
+ },
+
+ playerDied : function(player) {
+ }
+}
+
function KaboomSocket() {
this.client = null;
this.socket = null;
@@ -61,18 +98,20 @@ KaboomSocket.prototype = {
},
playerChangedDirection : function(player) {
- var msg = JSON.stringify({type: "player_changed_direction", player: player});
- this.socket.send(msg);
+ this.sendPlayerUpdate("player_changed_direction", player);
},
playerDroppedBomb : function(player) {
- var msg = JSON.stringify({type: "player_dropped_bomb", player: player});
- this.socket.msg();
+ this.sendPlayerUpdate("player_dropped_bomb", player);
},
playerDied : function(player) {
- var msg = JSON.stringify({type: "player_died", player: player});
- this.socket.msg();
- }
+ this.sendPlayerUpdate("player_died", player);
+ },
+
+ sendPlayerUpdate : function(type, player) {
+ var msg = JSON.stringify({type: type, player: player});
+ this.socket.send(msg);
+ }
};
View
17,870 public/js/libs/jquery-1.6.1.js
8,935 additions, 8,935 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
958 public/js/libs/json2.js
@@ -1,480 +1,480 @@
-/*
- http://www.JSON.org/json2.js
- 2011-02-23
-
- Public Domain.
-
- NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-
- See http://www.JSON.org/js.html
-
-
- This code should be minified before deployment.
- See http://javascript.crockford.com/jsmin.html
-
- USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
- NOT CONTROL.
-
-
- This file creates a global JSON object containing two methods: stringify
- and parse.
-
- JSON.stringify(value, replacer, space)
- value any JavaScript value, usually an object or array.
-
- replacer an optional parameter that determines how object
- values are stringified for objects. It can be a
- function or an array of strings.
-
- space an optional parameter that specifies the indentation
- of nested structures. If it is omitted, the text will
- be packed without extra whitespace. If it is a number,
- it will specify the number of spaces to indent at each
- level. If it is a string (such as '\t' or '&nbsp;'),
- it contains the characters used to indent at each level.
-
- This method produces a JSON text from a JavaScript value.
-
- When an object value is found, if the object contains a toJSON
- method, its toJSON method will be called and the result will be
- stringified. A toJSON method does not serialize: it returns the
- value represented by the name/value pair that should be serialized,
- or undefined if nothing should be serialized. The toJSON method
- will be passed the key associated with the value, and this will be
- bound to the value
-
- For example, this would serialize Dates as ISO strings.
-
- Date.prototype.toJSON = function (key) {
- function f(n) {
- // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
-
- return this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z';
- };
-
- You can provide an optional replacer method. It will be passed the
- key and value of each member, with this bound to the containing
- object. The value that is returned from your method will be
- serialized. If your method returns undefined, then the member will
- be excluded from the serialization.
-
- If the replacer parameter is an array of strings, then it will be
- used to select the members to be serialized. It filters the results
- such that only members with keys listed in the replacer array are
- stringified.
-
- Values that do not have JSON representations, such as undefined or