├── .DS_Store ├── .gitignore ├── .project ├── .settings └── com.appcelerator.titanium.mobile.prefs ├── CHANGELOG.txt ├── LICENSE ├── LICENSE.txt ├── README ├── Resources ├── .DS_Store ├── app.js ├── images │ ├── .DS_Store │ ├── ball.png │ ├── ball@2x.png │ ├── bg.png │ ├── bg@2x.png │ ├── bumper10.png │ ├── bumper10@2x.png │ ├── bumper50.png │ ├── bumper50@2x.png │ ├── flipper_l.png │ ├── flipper_l@2x.png │ ├── flipper_r.png │ ├── flipper_r@2x.png │ ├── gamebg.png │ ├── gamebg@2x.png │ ├── spring.png │ └── spring@2x.png ├── iphone │ ├── Default-Landscape.png │ ├── Default-Portrait.png │ ├── Default.png │ ├── Default@2x.png │ ├── appicon.png │ └── pinball_icon_57.png ├── ui.js └── world.js ├── build └── .DS_Store ├── manifest └── tiapp.xml /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | .DS_Store 3 | .project 4 | .settings 5 | build/iphone/* 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | pinball 4 | 5 | 6 | 7 | 8 | 9 | com.appcelerator.titanium.core.builder 10 | 11 | 12 | 13 | 14 | com.aptana.ide.core.unifiedBuilder 15 | 16 | 17 | 18 | 19 | 20 | com.appcelerator.titanium.mobile.nature 21 | com.aptana.projects.webnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/com.appcelerator.titanium.mobile.prefs: -------------------------------------------------------------------------------- 1 | #Tue Sep 06 16:57:52 EDT 2011 2 | MOBILE_PROJECT_SDK_VERSION=1.7.2 3 | eclipse.preferences.version=1 4 | -------------------------------------------------------------------------------- /CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | Place your change log text here. This file will be incorporated with your app at package time. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2009 Appcelerator, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | (or the full text of the license is below) 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | 18 | 19 | Apache License 20 | Version 2.0, January 2004 21 | http://www.apache.org/licenses/ 22 | 23 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 24 | 25 | 1. Definitions. 26 | 27 | "License" shall mean the terms and conditions for use, reproduction, 28 | and distribution as defined by Sections 1 through 9 of this document. 29 | 30 | "Licensor" shall mean the copyright owner or entity authorized by 31 | the copyright owner that is granting the License. 32 | 33 | "Legal Entity" shall mean the union of the acting entity and all 34 | other entities that control, are controlled by, or are under common 35 | control with that entity. For the purposes of this definition, 36 | "control" means (i) the power, direct or indirect, to cause the 37 | direction or management of such entity, whether by contract or 38 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 39 | outstanding shares, or (iii) beneficial ownership of such entity. 40 | 41 | "You" (or "Your") shall mean an individual or Legal Entity 42 | exercising permissions granted by this License. 43 | 44 | "Source" form shall mean the preferred form for making modifications, 45 | including but not limited to software source code, documentation 46 | source, and configuration files. 47 | 48 | "Object" form shall mean any form resulting from mechanical 49 | transformation or translation of a Source form, including but 50 | not limited to compiled object code, generated documentation, 51 | and conversions to other media types. 52 | 53 | "Work" shall mean the work of authorship, whether in Source or 54 | Object form, made available under the License, as indicated by a 55 | copyright notice that is included in or attached to the work 56 | (an example is provided in the Appendix below). 57 | 58 | "Derivative Works" shall mean any work, whether in Source or Object 59 | form, that is based on (or derived from) the Work and for which the 60 | editorial revisions, annotations, elaborations, or other modifications 61 | represent, as a whole, an original work of authorship. For the purposes 62 | of this License, Derivative Works shall not include works that remain 63 | separable from, or merely link (or bind by name) to the interfaces of, 64 | the Work and Derivative Works thereof. 65 | 66 | "Contribution" shall mean any work of authorship, including 67 | the original version of the Work and any modifications or additions 68 | to that Work or Derivative Works thereof, that is intentionally 69 | submitted to Licensor for inclusion in the Work by the copyright owner 70 | or by an individual or Legal Entity authorized to submit on behalf of 71 | the copyright owner. For the purposes of this definition, "submitted" 72 | means any form of electronic, verbal, or written communication sent 73 | to the Licensor or its representatives, including but not limited to 74 | communication on electronic mailing lists, source code control systems, 75 | and issue tracking systems that are managed by, or on behalf of, the 76 | Licensor for the purpose of discussing and improving the Work, but 77 | excluding communication that is conspicuously marked or otherwise 78 | designated in writing by the copyright owner as "Not a Contribution." 79 | 80 | "Contributor" shall mean Licensor and any individual or Legal Entity 81 | on behalf of whom a Contribution has been received by Licensor and 82 | subsequently incorporated within the Work. 83 | 84 | 2. Grant of Copyright License. Subject to the terms and conditions of 85 | this License, each Contributor hereby grants to You a perpetual, 86 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 87 | copyright license to reproduce, prepare Derivative Works of, 88 | publicly display, publicly perform, sublicense, and distribute the 89 | Work and such Derivative Works in Source or Object form. 90 | 91 | 3. Grant of Patent License. Subject to the terms and conditions of 92 | this License, each Contributor hereby grants to You a perpetual, 93 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 94 | (except as stated in this section) patent license to make, have made, 95 | use, offer to sell, sell, import, and otherwise transfer the Work, 96 | where such license applies only to those patent claims licensable 97 | by such Contributor that are necessarily infringed by their 98 | Contribution(s) alone or by combination of their Contribution(s) 99 | with the Work to which such Contribution(s) was submitted. If You 100 | institute patent litigation against any entity (including a 101 | cross-claim or counterclaim in a lawsuit) alleging that the Work 102 | or a Contribution incorporated within the Work constitutes direct 103 | or contributory patent infringement, then any patent licenses 104 | granted to You under this License for that Work shall terminate 105 | as of the date such litigation is filed. 106 | 107 | 4. Redistribution. You may reproduce and distribute copies of the 108 | Work or Derivative Works thereof in any medium, with or without 109 | modifications, and in Source or Object form, provided that You 110 | meet the following conditions: 111 | 112 | (a) You must give any other recipients of the Work or 113 | Derivative Works a copy of this License; and 114 | 115 | (b) You must cause any modified files to carry prominent notices 116 | stating that You changed the files; and 117 | 118 | (c) You must retain, in the Source form of any Derivative Works 119 | that You distribute, all copyright, patent, trademark, and 120 | attribution notices from the Source form of the Work, 121 | excluding those notices that do not pertain to any part of 122 | the Derivative Works; and 123 | 124 | (d) If the Work includes a "NOTICE" text file as part of its 125 | distribution, then any Derivative Works that You distribute must 126 | include a readable copy of the attribution notices contained 127 | within such NOTICE file, excluding those notices that do not 128 | pertain to any part of the Derivative Works, in at least one 129 | of the following places: within a NOTICE text file distributed 130 | as part of the Derivative Works; within the Source form or 131 | documentation, if provided along with the Derivative Works; or, 132 | within a display generated by the Derivative Works, if and 133 | wherever such third-party notices normally appear. The contents 134 | of the NOTICE file are for informational purposes only and 135 | do not modify the License. You may add Your own attribution 136 | notices within Derivative Works that You distribute, alongside 137 | or as an addendum to the NOTICE text from the Work, provided 138 | that such additional attribution notices cannot be construed 139 | as modifying the License. 140 | 141 | You may add Your own copyright statement to Your modifications and 142 | may provide additional or different license terms and conditions 143 | for use, reproduction, or distribution of Your modifications, or 144 | for any such Derivative Works as a whole, provided Your use, 145 | reproduction, and distribution of the Work otherwise complies with 146 | the conditions stated in this License. 147 | 148 | 5. Submission of Contributions. Unless You explicitly state otherwise, 149 | any Contribution intentionally submitted for inclusion in the Work 150 | by You to the Licensor shall be under the terms and conditions of 151 | this License, without any additional terms or conditions. 152 | Notwithstanding the above, nothing herein shall supersede or modify 153 | the terms of any separate license agreement you may have executed 154 | with Licensor regarding such Contributions. 155 | 156 | 6. Trademarks. This License does not grant permission to use the trade 157 | names, trademarks, service marks, or product names of the Licensor, 158 | except as required for reasonable and customary use in describing the 159 | origin of the Work and reproducing the content of the NOTICE file. 160 | 161 | 7. Disclaimer of Warranty. Unless required by applicable law or 162 | agreed to in writing, Licensor provides the Work (and each 163 | Contributor provides its Contributions) on an "AS IS" BASIS, 164 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 165 | implied, including, without limitation, any warranties or conditions 166 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 167 | PARTICULAR PURPOSE. You are solely responsible for determining the 168 | appropriateness of using or redistributing the Work and assume any 169 | risks associated with Your exercise of permissions under this License. 170 | 171 | 8. Limitation of Liability. In no event and under no legal theory, 172 | whether in tort (including negligence), contract, or otherwise, 173 | unless required by applicable law (such as deliberate and grossly 174 | negligent acts) or agreed to in writing, shall any Contributor be 175 | liable to You for damages, including any direct, indirect, special, 176 | incidental, or consequential damages of any character arising as a 177 | result of this License or out of the use or inability to use the 178 | Work (including but not limited to damages for loss of goodwill, 179 | work stoppage, computer failure or malfunction, or any and all 180 | other commercial damages or losses), even if such Contributor 181 | has been advised of the possibility of such damages. 182 | 183 | 9. Accepting Warranty or Additional Liability. While redistributing 184 | the Work or Derivative Works thereof, You may choose to offer, 185 | and charge a fee for, acceptance of support, warranty, indemnity, 186 | or other liability obligations and/or rights consistent with this 187 | License. However, in accepting such obligations, You may act only 188 | on Your own behalf and on Your sole responsibility, not on behalf 189 | of any other Contributor, and only if You agree to indemnify, 190 | defend, and hold each Contributor harmless for any liability 191 | incurred by, or claims asserted against, such Contributor by reason 192 | of your accepting any such warranty or additional liability. 193 | 194 | END OF TERMS AND CONDITIONS 195 | 196 | APPENDIX: How to apply the Apache License to your work. 197 | 198 | To apply the Apache License to your work, attach the following 199 | boilerplate notice, with the fields enclosed by brackets "[]" 200 | replaced with your own identifying information. (Don't include 201 | the brackets!) The text should be enclosed in the appropriate 202 | comment syntax for the file format. We also recommend that a 203 | file or class name and description of purpose be included on the 204 | same "printed page" as the copyright notice for easier 205 | identification within third-party archives. 206 | 207 | Copyright [yyyy] [name of copyright owner] 208 | 209 | Licensed under the Apache License, Version 2.0 (the "License"); 210 | you may not use this file except in compliance with the License. 211 | You may obtain a copy of the License at 212 | 213 | http://www.apache.org/licenses/LICENSE-2.0 214 | 215 | Unless required by applicable law or agreed to in writing, software 216 | distributed under the License is distributed on an "AS IS" BASIS, 217 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 218 | See the License for the specific language governing permissions and 219 | limitations under the License. -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Place your license text here. This file will be incorporated with your app at package time. -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Welcome to your Appcelerator Titanium Mobile Project 2 | 3 | This is a blank project. Start by editing your application's app.js to 4 | make your first mobile project using Titanium. 5 | 6 | 7 | 8 | ---------------------------------- 9 | Stuff our legal folk make us say: 10 | 11 | Appcelerator, Appcelerator Titanium and associated marks and logos are 12 | trademarks of Appcelerator, Inc. 13 | 14 | Titanium is Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved. 15 | 16 | Titanium is licensed under the Apache Public License (Version 2). Please 17 | see the LICENSE file for the full license. 18 | 19 | -------------------------------------------------------------------------------- /Resources/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/.DS_Store -------------------------------------------------------------------------------- /Resources/app.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var app = { 4 | balls : 3, 5 | plungerY : 550, 6 | hScore : Ti.App.Properties.getInt('high_score') || 0, 7 | 8 | MAX_IMPULSE : 1500, 9 | 10 | isIn : function(obj, a) { 11 | var i = a.length; 12 | while (i--) { 13 | if (a[i] === obj) { 14 | return true; 15 | } 16 | } 17 | return false; 18 | } 19 | }; 20 | 21 | var box2d = require("ti.box2d"); 22 | 23 | Ti.include('world.js', 'ui.js'); 24 | 25 | app.ui.startGame(); 26 | app.ui.createStartWindow().open(); -------------------------------------------------------------------------------- /Resources/images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/.DS_Store -------------------------------------------------------------------------------- /Resources/images/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/ball.png -------------------------------------------------------------------------------- /Resources/images/ball@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/ball@2x.png -------------------------------------------------------------------------------- /Resources/images/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/bg.png -------------------------------------------------------------------------------- /Resources/images/bg@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/bg@2x.png -------------------------------------------------------------------------------- /Resources/images/bumper10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/bumper10.png -------------------------------------------------------------------------------- /Resources/images/bumper10@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/bumper10@2x.png -------------------------------------------------------------------------------- /Resources/images/bumper50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/bumper50.png -------------------------------------------------------------------------------- /Resources/images/bumper50@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/bumper50@2x.png -------------------------------------------------------------------------------- /Resources/images/flipper_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/flipper_l.png -------------------------------------------------------------------------------- /Resources/images/flipper_l@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/flipper_l@2x.png -------------------------------------------------------------------------------- /Resources/images/flipper_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/flipper_r.png -------------------------------------------------------------------------------- /Resources/images/flipper_r@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/flipper_r@2x.png -------------------------------------------------------------------------------- /Resources/images/gamebg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/gamebg.png -------------------------------------------------------------------------------- /Resources/images/gamebg@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/gamebg@2x.png -------------------------------------------------------------------------------- /Resources/images/spring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/spring.png -------------------------------------------------------------------------------- /Resources/images/spring@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/images/spring@2x.png -------------------------------------------------------------------------------- /Resources/iphone/Default-Landscape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/iphone/Default-Landscape.png -------------------------------------------------------------------------------- /Resources/iphone/Default-Portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/iphone/Default-Portrait.png -------------------------------------------------------------------------------- /Resources/iphone/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/iphone/Default.png -------------------------------------------------------------------------------- /Resources/iphone/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/iphone/Default@2x.png -------------------------------------------------------------------------------- /Resources/iphone/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/iphone/appicon.png -------------------------------------------------------------------------------- /Resources/iphone/pinball_icon_57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/Resources/iphone/pinball_icon_57.png -------------------------------------------------------------------------------- /Resources/ui.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | app.ui = { 3 | overlay : Ti.UI.createView({ 4 | backgroundColor : 'transparent' 5 | }) 6 | }; 7 | 8 | app.ui.createStartWindow = function() { 9 | 10 | var modal = Ti.UI.createWindow({ 11 | backgroundImage: '/images/bg.png' 12 | }); 13 | 14 | var instructions = Ti.UI.createLabel({ 15 | top:50, 16 | width:300, 17 | height:20, 18 | color:'white', 19 | text: 'Instructions', 20 | textAlign: 'center', 21 | font: {fontSize:25, fontWeight:'bold'} 22 | }); 23 | 24 | modal.add(instructions); 25 | 26 | var message = Ti.UI.createLabel({ 27 | top:85, 28 | width:300, 29 | height:'auto', 30 | color:'white', 31 | font: {fontWeight:'bold'}, 32 | text: 'Plunger - Tap the screen anywhere and hold, release to shoot the ball.\n\nFlippers - Tap the screen on the right or left side, to flip the right or left flipper.\n\nHigh Score - The high score is saved through closing the app to keep a running high score.' 33 | }); 34 | modal.add(message); 35 | 36 | var newGame = Ti.UI.createButton({ 37 | title : 'New Game', 38 | width : 200, 39 | height : 40, 40 | bottom : 20 41 | }); 42 | modal.add(newGame); 43 | 44 | newGame.addEventListener('click', function() { 45 | app.world.ball.SetTransform({ 46 | posX : 300, 47 | posY : 420 48 | }); 49 | app.world.ball.setAwake(true); 50 | 51 | app.balls = 3; 52 | app.ui.ballsRemaining.text = 'Balls: 2'; 53 | score = 0; 54 | app.ui.scoreBoard.text = 'Score: 0'; 55 | 56 | modal.close(); 57 | }); 58 | return modal; 59 | } 60 | 61 | app.ui.createGame = function() { 62 | 63 | var window = Ti.UI.createWindow({ 64 | backgroundImage : '/images/gamebg.png', 65 | fullscreen : true 66 | }); 67 | 68 | window.gameBoard = Ti.UI.createView({ 69 | height : 440, 70 | bottom : 0, 71 | backgroundColor : 'transparent' 72 | }); 73 | window.add(window.gameBoard); 74 | 75 | app.ui.ballsRemaining = Ti.UI.createLabel({ 76 | top : 0, 77 | left : 0, 78 | height : 20, 79 | width : 'auto', 80 | color : 'white', 81 | text : 'Balls: 2' 82 | }); 83 | window.add(app.ui.ballsRemaining); 84 | 85 | app.ui.scoreBoard = Ti.UI.createLabel({ 86 | top : 0, 87 | right : 0, 88 | height : 20, 89 | width : 'auto', 90 | color : 'white', 91 | text : 'Score: 0' 92 | }); 93 | window.add(app.ui.scoreBoard); 94 | 95 | app.ui.highScore = Ti.UI.createLabel({ 96 | top : 0, 97 | left : 65, 98 | height : 20, 99 | width : 'auto', 100 | color : 'white', 101 | text : 'High Score: ' + app.hScore 102 | }); 103 | window.add(app.ui.highScore); 104 | 105 | window.add(app.ui.overlay); 106 | 107 | return window; 108 | }; 109 | 110 | app.ui.startGame = function() { 111 | 112 | var win = app.ui.createGame(); 113 | win.open(); 114 | 115 | var world = app.createWorld(win.gameBoard); 116 | world.start(); 117 | 118 | }; 119 | })(); 120 | -------------------------------------------------------------------------------- /Resources/world.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | app.world = { 4 | nodes : [] 5 | }; 6 | 7 | app.createWorld = function(gameBoard) { 8 | 9 | // create the world, using view as the surface 10 | var world = box2d.createWorld(gameBoard); 11 | 12 | // This will be used to shoot the ball "harder" the longer the user holds the plunger 13 | var impulseIntervul, impulse = 1, score = 0; 14 | 15 | // Set the gravity so that the ball "falls" correctly 16 | world.setGravity(0.0, -5.91); 17 | 18 | var nodeSettings = { 19 | backgroundImage : "/images/bumper1000.png", 20 | borderRadius : 15, 21 | width : 30, 22 | height : 30, 23 | }; 24 | 25 | var node = [{ 26 | left : 35, 27 | top : 105 28 | }, { 29 | left : 130, 30 | top : 75 31 | }, { 32 | left : 210, 33 | top : 105 34 | }, { 35 | left : 55, 36 | top : 200 37 | }, { 38 | left : 190, 39 | top : 200 40 | }]; 41 | 42 | for( i = 0; i < node.length; i++) { 43 | 44 | nodeSettings.left = node[i].left; 45 | nodeSettings.top = node[i].top; 46 | nodeSettings.backgroundImage = (i % 2 == 0) ? '/images/bumper10.png' : '/images/bumper50.png'; 47 | nodeSettings.hit_value = (i % 2 == 0) ? 10 : 50; 48 | 49 | app.world.nodes[i] = world.addBody(Ti.UI.createView(nodeSettings), { 50 | radius : 15, 51 | density : 10.0, 52 | friction : 0.3, 53 | restitution : 1.5, 54 | type : "static" 55 | }); 56 | 57 | } 58 | 59 | app.world.rightWall = world.addBody(Ti.UI.createView({ 60 | backgroundColor : "transparent", 61 | width : 1, 62 | right : 4, 63 | height : 440, 64 | bottom : 0 65 | }), { 66 | density : 12.0, 67 | friction : 0.3, 68 | restitution : 0.4, 69 | type : "static" 70 | }); 71 | 72 | app.world.leftWall = world.addBody(Ti.UI.createView({ 73 | backgroundColor : "transparent", 74 | width : 2, 75 | left : 1, 76 | height : 440, 77 | bottom : 0 78 | }), { 79 | density : 10.0, 80 | friction : 0.3, 81 | restitution : 0.4, 82 | type : "static" 83 | }); 84 | 85 | app.world.topWall = world.addBody(Ti.UI.createView({ 86 | backgroundColor : "transparent", 87 | width : 310, 88 | height : 2, 89 | top : 0 90 | }), { 91 | density : 12.0, 92 | friction : 0.3, 93 | restitution : 0.4, 94 | type : "static" 95 | }); 96 | 97 | app.world.wallCorner = world.addBody(Ti.UI.createView({ 98 | backgroundColor : "transparent", 99 | width : 160, 100 | height : 2, 101 | left : 0, 102 | top : 10 103 | }), { 104 | density : 10.0, 105 | friction : 0.3, 106 | restitution : 0.4, 107 | type : "static" 108 | }); 109 | app.world.wallCorner.setAngle(0.2); 110 | 111 | app.world.LsideDeflector = world.addBody(Ti.UI.createView({ 112 | backgroundColor : "transparent", 113 | width : 40, 114 | left : 8, 115 | height : 2, 116 | top : 280 117 | }), { 118 | density : 10.0, 119 | friction : 0.3, 120 | restitution : 0.4, 121 | type : "static" 122 | }); 123 | app.world.LsideDeflector.setAngle(-0.7); 124 | 125 | app.world.RsideDeflector = world.addBody(Ti.UI.createView({ 126 | backgroundColor : "transparent", 127 | width : 40, 128 | right : 45, 129 | height : 2, 130 | top : 280 131 | }), { 132 | density : 10.0, 133 | friction : 0.3, 134 | restitution : 0.4, 135 | type : "static" 136 | }); 137 | app.world.RsideDeflector.setAngle(0.7); 138 | 139 | // add body to the world 140 | app.world.shoot = world.addBody(Ti.UI.createView({ 141 | backgroundColor : "transparent", 142 | width : 2, 143 | right : 38, 144 | height : 362, 145 | bottom : 0 146 | }), { 147 | density : 1.0, 148 | friction : 0.1, 149 | restitution : 0.1, 150 | type : "static" 151 | }); 152 | 153 | app.world.shootHook = world.addBody(Ti.UI.createView({ 154 | backgroundColor : "transparent", 155 | height : 4, 156 | width : 40, 157 | bottom : 372, 158 | right : 37 159 | }), { 160 | density : 12.0, 161 | friction : 0.3, 162 | restitution : 0.4, 163 | type : "static" 164 | }); 165 | app.world.shootHook.setAngle(-0.60); 166 | 167 | // add body to the world 168 | app.world.plunger = world.addBody(Ti.UI.createView({ 169 | backgroundImage : "/images/spring.png", 170 | width : 32, 171 | right : 7, 172 | height : 35, 173 | bottom : 0 174 | }), { 175 | density : 10.0, 176 | friction : 0.3, 177 | restitution : 0.4, 178 | type : "static" 179 | }); 180 | 181 | // add body to the world 182 | app.world.deflector = world.addBody(Ti.UI.createView({ 183 | backgroundColor : "transparent", 184 | width : 50, 185 | right : -10, 186 | height : 2, 187 | top : 15 188 | }), { 189 | density : 5.0, 190 | friction : 0.3, 191 | restitution : 0.4, 192 | type : "static" 193 | }); 194 | app.world.deflector.setAngle(-1); 195 | 196 | // add body to the world 197 | app.world.gutterRight = world.addBody(Ti.UI.createView({ 198 | backgroundColor : "transparent", 199 | width : 5, 200 | right : 75, 201 | height : 15, 202 | bottom : 50 203 | }), { 204 | density : 10.0, 205 | friction : 0.3, 206 | restitution : 0.4, 207 | type : "static" 208 | }); 209 | app.world.gutterRight.setAngle(0.25); 210 | 211 | // add body to the world 212 | app.world.gutterLeft = world.addBody(Ti.UI.createView({ 213 | backgroundColor : "transparent", 214 | width : 5, 215 | left : 40, 216 | height : 15, 217 | bottom : 50 218 | }), { 219 | density : 10.0, 220 | friction : 0.3, 221 | restitution : 0.4, 222 | type : "static" 223 | }); 224 | app.world.gutterLeft.setAngle(-0.25); 225 | 226 | // add body to the world 227 | app.world.flipperRight = world.addBody(Ti.UI.createView({ 228 | backgroundImage : "/images/flipper_r.png", 229 | width : 66, 230 | right : 55, 231 | height : 21, 232 | bottom : 10 233 | }), { 234 | density : 10.0, 235 | friction : 0.3, 236 | restitution : 1.0, 237 | type : "dynamic" 238 | }); 239 | 240 | app.world.flipperRightmoter = world.createJoint(app.world.flipperRight, app.world.gutterRight, { 241 | enableLimit : true, 242 | upperAngle : 0.44, 243 | lowerAngle : 0.01, 244 | enableMotor : true, 245 | maxMotorTorque : 26000, 246 | motorSpeed : -100, 247 | jointPoint : 1.4, 248 | basePoint : -1.8, 249 | collideConnected : false 250 | }); 251 | 252 | // add body to the world 253 | app.world.flipperLeft = world.addBody(Ti.UI.createView({ 254 | backgroundImage : "/images/flipper_l.png", 255 | width : 66, 256 | left : 10, 257 | height : 21, 258 | bottom : 10 259 | }), { 260 | density : 10.0, 261 | friction : 0.3, 262 | restitution : 1.0, 263 | type : "dynamic" 264 | }); 265 | 266 | app.world.flipperLeftmoter = world.createJoint(app.world.flipperLeft, app.world.gutterLeft, { 267 | enableLimit : true, 268 | upperAngle : 0.01, 269 | lowerAngle : -0.44, 270 | enableMotor : true, 271 | maxMotorTorque : 26000, 272 | motorSpeed : 100, 273 | jointPoint : -1.4, 274 | basePoint : 1.8, 275 | collideConnected : false 276 | }); 277 | 278 | // add the ball body to the world 279 | app.world.ball = world.addBody(Ti.UI.createView({ 280 | backgroundImage : "/images/ball.png", 281 | borderRadius : 15, 282 | width : 27, 283 | height : 27, 284 | right : 8, 285 | bottom : 50, 286 | shootMe : true 287 | }), { 288 | radius : 15, 289 | density : 11.0, 290 | friction : 0.9, 291 | restitution : 0.4, 292 | type : "dynamic" 293 | }); 294 | 295 | // This element is our "hole" we add this so we can control the collision of the ball 296 | // with an element below the flippers, this will be used to reset the ball 297 | app.world.hole = world.addBody(Ti.UI.createView({ 298 | backgroundColor : "transparent", 299 | width : 286, 300 | left : 0, 301 | height : 5, 302 | bottom : 0 303 | }), { 304 | density : 7.0, 305 | friction : 0.3, 306 | restitution : 0.4, 307 | type : "static" 308 | }); 309 | 310 | world.addEventListener("collision", function(e) { 311 | //Ti.API.info(e); 312 | if(e.phase == "begin") { 313 | 314 | // Interactions 315 | switch(e.a) { 316 | case app.world.hole : 317 | app.balls--; 318 | 319 | if(app.balls > 0) { 320 | app.ui.ballsRemaining.text = 'Balls: ' + (app.balls - 1); 321 | 322 | // setting the ball to awake false then back before/after moving it, removes all momentum the body had 323 | app.world.ball.setAwake(false); 324 | app.world.ball.SetTransform({ 325 | posX : 300, 326 | posY : 400 327 | }); 328 | app.world.ball.setAwake(true); 329 | } else { 330 | 331 | var modal = app.ui.createStartWindow(); 332 | 333 | modal.open(); 334 | 335 | if(score > app.hScore) { 336 | alert('YOU BEAT THE HIGH SCORE!!'); 337 | } else { 338 | alert("Game over!"); 339 | } 340 | 341 | // save the high score 342 | if(score > app.hScore) { 343 | Ti.App.Properties.setInt('high_score', score); 344 | 345 | app.hScore = score; 346 | 347 | app.ui.highScore.text = 'High Score: ' + app.hScore; 348 | 349 | } 350 | 351 | app.world.ball.setAwake(false); 352 | } 353 | break; 354 | case app.world.plunger: 355 | 356 | //mark that its ready to shoot 357 | app.world.ball.view.shootMe = true; 358 | break; 359 | } 360 | 361 | //Score 362 | if(app.isIn(e.a, app.world.nodes)) { 363 | score = score + e.a.view.hit_value; 364 | 365 | app.ui.scoreBoard.text = 'Score: ' + score; 366 | 367 | } 368 | } 369 | }); 370 | 371 | app.ui.overlay.addEventListener('touchstart', function(e) { 372 | // make sure we are playing :) 373 | world.start(); 374 | 375 | // Flip the flipper 376 | if(e.x > 160) { 377 | app.world.flipperRightmoter.setMotorSpeed(1000); 378 | } else { 379 | app.world.flipperLeftmoter.setMotorSpeed(-1000); 380 | } 381 | 382 | if(app.world.ball.view.shootMe) { 383 | impulseIntervul = setInterval(function() { 384 | impulse = impulse + 150; 385 | 386 | if(impulse >= app.MAX_IMPULSE) { 387 | impulse = app.MAX_IMPULSE; 388 | } else { 389 | app.plungerY = app.plungerY + 2; 390 | app.world.plunger.SetTransform({ 391 | posX : 297, 392 | posY : app.plungerY 393 | }); 394 | } 395 | 396 | }, 300); 397 | } 398 | }); 399 | 400 | app.ui.overlay.addEventListener('touchend', function(e) { 401 | 402 | app.world.flipperRightmoter.setMotorSpeed(-1000); 403 | app.world.flipperLeftmoter.setMotorSpeed(1000); 404 | 405 | if(app.world.ball.view.shootMe) { 406 | 407 | // FIRE THE GUN!!!! 408 | app.world.ball.applyLinearImpulse([0, impulse], [19, 2]); 409 | 410 | //READY THE PLUNGER!!!! 411 | clearInterval(impulseIntervul); 412 | impulse = 1; 413 | 414 | //BATTLE STATIONS!!! 415 | app.plungerY = 550; 416 | app.world.plunger.SetTransform({ 417 | posX : 297, 418 | posY : app.plungerY 419 | }); 420 | 421 | // ...mark ball as shot 422 | app.world.ball.view.shootMe = false; 423 | } 424 | }); 425 | return world; 426 | }; 427 | })(); 428 | -------------------------------------------------------------------------------- /build/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/sample-tiball/6e64ad9858fcac355cc810feed889457f8eedbba/build/.DS_Store -------------------------------------------------------------------------------- /manifest: -------------------------------------------------------------------------------- 1 | #appname:TiBall 2 | #publisher:Appcelerator Developer Relations 3 | #url:http://developer.appcelerator.com 4 | #image:appicon.png 5 | #appid:com.appcelerator.tiball 6 | #desc:Basic Pinball game using the box2d module. Currently only for iPhone. 7 | #type:mobile 8 | #guid:5f663b2f-4f76-484a-974c-30ee4872b736 9 | -------------------------------------------------------------------------------- /tiapp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | true 6 | false 7 | false 8 | false 9 | 10 | com.appcelerator.tiball 11 | TiBall 12 | 1.0 13 | Appcelerator Developer Relations 14 | http://developer.appcelerator.com 15 | Basic Pinball game using the box2d module. Currently only for iPhone. 16 | 2011 by Appcelerator Inc 17 | pinball_icon_57.png 18 | false 19 | false 20 | default 21 | false 22 | false 23 | false 24 | true 25 | 5f663b2f-4f76-484a-974c-30ee4872b736 26 | 27 | 28 | Ti.UI.PORTRAIT 29 | 30 | 31 | Ti.UI.PORTRAIT 32 | Ti.UI.UPSIDE_PORTRAIT 33 | Ti.UI.LANDSCAPE_LEFT 34 | Ti.UI.LANDSCAPE_RIGHT 35 | 36 | 37 | 38 | 39 | ti.box2d 40 | 41 | 42 | --------------------------------------------------------------------------------