Skip to content
Browse files

reorganizing files, refactoring, updating libraries

  • Loading branch information...
1 parent 038512d commit 29a60ea9fd91ddf17a41edaeb4d39a7d13613a72 @collinhover committed Oct 29, 2012
Showing with 1,044 additions and 742 deletions.
  1. 0 LICENSE → LICENSE.md
  2. +0 −24 TODO.md
  3. 0 src/web/asset/{model → }/Banana_Leaf_Door.js
  4. 0 src/web/asset/{model → }/Bed.js
  5. 0 src/web/asset/{model → }/Cloud_001.js
  6. 0 src/web/asset/{model → }/Cloud_002.js
  7. 0 src/web/asset/{model → }/Grass_Clump_001.js
  8. 0 src/web/asset/{model → }/Grass_Clump_002.js
  9. 0 src/web/asset/{model → }/Grass_Line_001.js
  10. 0 src/web/asset/{model → }/Grass_Line_002.js
  11. 0 src/web/asset/{model → }/Hero.js
  12. 0 src/web/asset/{model → }/Hut.js
  13. 0 src/web/asset/{model → }/Hut_Hill.js
  14. 0 src/web/asset/{model → }/Hut_Steps.js
  15. 0 src/web/asset/{model → }/Kukui_Tree.js
  16. 0 src/web/asset/{model → }/Kukui_Trees.js
  17. 0 src/web/asset/{model → }/Palm_Tree.js
  18. 0 src/web/asset/{model → }/Palm_Trees.js
  19. 0 src/web/asset/{model → }/Plant_Dirt_Mound.js
  20. 0 src/web/asset/{model → }/Plant_Pineapple.js
  21. 0 src/web/asset/{model → }/Plant_Rock.js
  22. 0 src/web/asset/{model → }/Plant_Rock_Blue.js
  23. 0 src/web/asset/{model → }/Plant_Rock_Purple.js
  24. 0 src/web/asset/{model → }/Plant_Seed.js
  25. 0 src/web/asset/{model → }/Plant_Taro.js
  26. 0 src/web/asset/{model → }/Puzzle_Basics_Abilities.js
  27. 0 src/web/asset/{model → }/Puzzle_Basics_Abilities_Grid.js
  28. 0 src/web/asset/{model → }/Puzzle_Rolling_Hills.js
  29. 0 src/web/asset/{model → }/Puzzle_Rolling_Hills_Grid.js
  30. 0 src/web/asset/{model → }/Puzzle_Rolling_Hills_Toggle.js
  31. 0 src/web/asset/{model → }/Puzzle_Tutorial.js
  32. 0 src/web/asset/{model → }/Puzzle_Tutorial_Grid.js
  33. 0 src/web/asset/{model → }/Puzzle_Tutorial_Toggle.js
  34. 0 src/web/asset/{model → }/Sun.js
  35. 0 src/web/asset/{model → }/Surfboard.js
  36. 0 src/web/asset/{model → }/Volcano_Large.js
  37. 0 src/web/asset/{model → }/Volcano_Rocks_001.js
  38. 0 src/web/asset/{model → }/Volcano_Rocks_002.js
  39. 0 src/web/asset/{model → }/Volcano_Rocks_003.js
  40. 0 src/web/asset/{model → }/Volcano_Rocks_004.js
  41. 0 src/web/asset/{model → }/Volcano_Rocks_005.js
  42. 0 src/web/asset/{model → }/Volcano_Small.js
  43. 0 src/web/asset/{model → }/Whale.js
  44. 0 src/web/asset/{texture → }/dirt_128.jpg
  45. 0 src/web/asset/{texture → }/light_ray.png
  46. 0 src/web/asset/{texture → }/skybox_world_negx.jpg
  47. 0 src/web/asset/{texture → }/skybox_world_negy.jpg
  48. 0 src/web/asset/{texture → }/skybox_world_negz.jpg
  49. 0 src/web/asset/{texture → }/skybox_world_posx.jpg
  50. 0 src/web/asset/{texture → }/skybox_world_posy.jpg
  51. 0 src/web/asset/{texture → }/skybox_world_posz.jpg
  52. 0 src/web/asset/{texture → }/water_512.png
  53. 0 src/web/asset/{texture → }/water_world_512.png
  54. +5 −5 src/web/index.html
  55. +5 −14 src/web/js/kaiopua/Kaiopua.js
  56. +5 −5 src/web/js/kaiopua/Kaiopua_DEPRECATED.js
  57. +57 −37 src/web/js/kaiopua/core/Character.js
  58. +49 −49 src/web/js/kaiopua/core/Game_DEPRECATED.js
  59. +13 −4 src/web/js/kaiopua/core/Morphs.js
  60. +6 −37 src/web/js/kaiopua/core/Player.js
  61. +2 −2 src/web/js/kaiopua/env/Cloud.js
  62. +1 −1 src/web/js/kaiopua/env/Water.js
  63. +41 −41 src/web/js/kaiopua/env/WorldIsland.js
  64. +1 −1 src/web/js/kaiopua/farming/Dirt.js
  65. +31 −3 src/web/js/kaiopua/physics/Obstacle.js
  66. +206 −0 src/web/js/kaiopua/physics/ObstacleDamaging.js
  67. +126 −0 src/web/js/kaiopua/physics/ObstacleSlippery.js
  68. +43 −36 src/web/js/kaiopua/physics/Physics.js
  69. +29 −267 src/web/js/kaiopua/physics/RigidBody.js
  70. +0 −137 src/web/js/kaiopua/physics/SlipperyObstacle.js
  71. +280 −0 src/web/js/kaiopua/physics/Velocity.js
  72. +12 −12 src/web/js/kaiopua/puzzles/GridElementLibrary.js
  73. +16 −16 src/web/js/kaiopua/puzzles/PuzzleLibrary.js
  74. +7 −7 src/web/js/kaiopua/sections/Intro.js
  75. +17 −8 src/web/js/kaiopua/sections/Launcher.js
  76. +1 −2 src/web/js/kaiopua/ui/UIQueue.js
  77. +3 −3 src/web/js/kaiopua/utils/ObjectHelper.js
  78. +5 −8 src/web/js/kaiopua/utils/RayHelper.js
  79. +63 −3 src/web/js/kaiopua/utils/VectorHelper.js
  80. +6 −6 src/web/js/lib/hammer.custom.js
  81. +0 −9 src/web/js/lib/less-1.3.0.min.js
  82. +9 −0 src/web/js/lib/less-1.3.1.min.js
  83. +4 −0 src/web/js/lib/modernizr-2.6.2.min.js
  84. +0 −4 src/web/js/lib/modernizr.2.5.3.min.js
  85. +1 −1 src/web/js/lib/three/ThreeOctree.min.js
View
0 LICENSE → LICENSE.md
File renamed without changes.
View
24 TODO.md
@@ -1,24 +0,0 @@
-# TODO
-
-#### Collin
-* Remove cache-busting from loading for distribution version
-* Complete INDEX.html meta tags & supporting info
- * google-site-verification
- * favicon
- * apple-touch-icon
- * google analytics
- * Facebook metadata icon/thumbnail
- * Facebook share url to domain name
- * Twitter share url to domain name
-* Get domain name and hosting
-* Physics - fix
-* Plants interactions
-* Advanced plants
-* Inventory of seeds
-* Puzzle win state + rewards
-* Ambient occlusion
-
-#### Sound Artist
-* Speak to others about getting a sound artist to join
-* Sound effects
-* Environment music
View
0 src/web/asset/model/Banana_Leaf_Door.js → src/web/asset/Banana_Leaf_Door.js
File renamed without changes.
View
0 src/web/asset/model/Bed.js → src/web/asset/Bed.js
File renamed without changes.
View
0 src/web/asset/model/Cloud_001.js → src/web/asset/Cloud_001.js
File renamed without changes.
View
0 src/web/asset/model/Cloud_002.js → src/web/asset/Cloud_002.js
File renamed without changes.
View
0 src/web/asset/model/Grass_Clump_001.js → src/web/asset/Grass_Clump_001.js
File renamed without changes.
View
0 src/web/asset/model/Grass_Clump_002.js → src/web/asset/Grass_Clump_002.js
File renamed without changes.
View
0 src/web/asset/model/Grass_Line_001.js → src/web/asset/Grass_Line_001.js
File renamed without changes.
View
0 src/web/asset/model/Grass_Line_002.js → src/web/asset/Grass_Line_002.js
File renamed without changes.
View
0 src/web/asset/model/Hero.js → src/web/asset/Hero.js
File renamed without changes.
View
0 src/web/asset/model/Hut.js → src/web/asset/Hut.js
File renamed without changes.
View
0 src/web/asset/model/Hut_Hill.js → src/web/asset/Hut_Hill.js
File renamed without changes.
View
0 src/web/asset/model/Hut_Steps.js → src/web/asset/Hut_Steps.js
File renamed without changes.
View
0 src/web/asset/model/Kukui_Tree.js → src/web/asset/Kukui_Tree.js
File renamed without changes.
View
0 src/web/asset/model/Kukui_Trees.js → src/web/asset/Kukui_Trees.js
File renamed without changes.
View
0 src/web/asset/model/Palm_Tree.js → src/web/asset/Palm_Tree.js
File renamed without changes.
View
0 src/web/asset/model/Palm_Trees.js → src/web/asset/Palm_Trees.js
File renamed without changes.
View
0 src/web/asset/model/Plant_Dirt_Mound.js → src/web/asset/Plant_Dirt_Mound.js
File renamed without changes.
View
0 src/web/asset/model/Plant_Pineapple.js → src/web/asset/Plant_Pineapple.js
File renamed without changes.
View
0 src/web/asset/model/Plant_Rock.js → src/web/asset/Plant_Rock.js
File renamed without changes.
View
0 src/web/asset/model/Plant_Rock_Blue.js → src/web/asset/Plant_Rock_Blue.js
File renamed without changes.
View
0 src/web/asset/model/Plant_Rock_Purple.js → src/web/asset/Plant_Rock_Purple.js
File renamed without changes.
View
0 src/web/asset/model/Plant_Seed.js → src/web/asset/Plant_Seed.js
File renamed without changes.
View
0 src/web/asset/model/Plant_Taro.js → src/web/asset/Plant_Taro.js
File renamed without changes.
View
0 ...eb/asset/model/Puzzle_Basics_Abilities.js → src/web/asset/Puzzle_Basics_Abilities.js
File renamed without changes.
View
0 ...set/model/Puzzle_Basics_Abilities_Grid.js → ...web/asset/Puzzle_Basics_Abilities_Grid.js
File renamed without changes.
View
0 src/web/asset/model/Puzzle_Rolling_Hills.js → src/web/asset/Puzzle_Rolling_Hills.js
File renamed without changes.
View
0 .../asset/model/Puzzle_Rolling_Hills_Grid.js → src/web/asset/Puzzle_Rolling_Hills_Grid.js
File renamed without changes.
View
0 ...sset/model/Puzzle_Rolling_Hills_Toggle.js → src/web/asset/Puzzle_Rolling_Hills_Toggle.js
File renamed without changes.
View
0 src/web/asset/model/Puzzle_Tutorial.js → src/web/asset/Puzzle_Tutorial.js
File renamed without changes.
View
0 src/web/asset/model/Puzzle_Tutorial_Grid.js → src/web/asset/Puzzle_Tutorial_Grid.js
File renamed without changes.
View
0 ...web/asset/model/Puzzle_Tutorial_Toggle.js → src/web/asset/Puzzle_Tutorial_Toggle.js
File renamed without changes.
View
0 src/web/asset/model/Sun.js → src/web/asset/Sun.js
File renamed without changes.
View
0 src/web/asset/model/Surfboard.js → src/web/asset/Surfboard.js
File renamed without changes.
View
0 src/web/asset/model/Volcano_Large.js → src/web/asset/Volcano_Large.js
File renamed without changes.
View
0 src/web/asset/model/Volcano_Rocks_001.js → src/web/asset/Volcano_Rocks_001.js
File renamed without changes.
View
0 src/web/asset/model/Volcano_Rocks_002.js → src/web/asset/Volcano_Rocks_002.js
File renamed without changes.
View
0 src/web/asset/model/Volcano_Rocks_003.js → src/web/asset/Volcano_Rocks_003.js
File renamed without changes.
View
0 src/web/asset/model/Volcano_Rocks_004.js → src/web/asset/Volcano_Rocks_004.js
File renamed without changes.
View
0 src/web/asset/model/Volcano_Rocks_005.js → src/web/asset/Volcano_Rocks_005.js
File renamed without changes.
View
0 src/web/asset/model/Volcano_Small.js → src/web/asset/Volcano_Small.js
File renamed without changes.
View
0 src/web/asset/model/Whale.js → src/web/asset/Whale.js
File renamed without changes.
View
0 src/web/asset/texture/dirt_128.jpg → src/web/asset/dirt_128.jpg
File renamed without changes
View
0 src/web/asset/texture/light_ray.png → src/web/asset/light_ray.png
File renamed without changes
View
0 src/web/asset/texture/skybox_world_negx.jpg → src/web/asset/skybox_world_negx.jpg
File renamed without changes
View
0 src/web/asset/texture/skybox_world_negy.jpg → src/web/asset/skybox_world_negy.jpg
File renamed without changes
View
0 src/web/asset/texture/skybox_world_negz.jpg → src/web/asset/skybox_world_negz.jpg
File renamed without changes
View
0 src/web/asset/texture/skybox_world_posx.jpg → src/web/asset/skybox_world_posx.jpg
File renamed without changes
View
0 src/web/asset/texture/skybox_world_posy.jpg → src/web/asset/skybox_world_posy.jpg
File renamed without changes
View
0 src/web/asset/texture/skybox_world_posz.jpg → src/web/asset/skybox_world_posz.jpg
File renamed without changes
View
0 src/web/asset/texture/water_512.png → src/web/asset/water_512.png
File renamed without changes
View
0 src/web/asset/texture/water_world_512.png → src/web/asset/water_world_512.png
File renamed without changes
View
10 src/web/index.html
@@ -54,12 +54,12 @@
<!-- LESS -->
<link rel="stylesheet/less" type="text/css" href="css/styles.less">
- <script src="js/lib/less-1.3.0.min.js" type="text/javascript"></script>
+ <script src="js/lib/less-1.3.1.min.js" type="text/javascript"></script>
<!-- CSS -->
<!-- setup javascript only -->
- <script src="js/lib/modernizr.2.5.3.min.js"></script>
+ <script src="js/lib/modernizr-2.6.2.min.js"></script>
<!-- Prompt IE 6 users to install Chrome Frame. Remove this if you want to support IE 6.
chromium.org/developers/how-tos/chrome-frame-getting-started -->
@@ -856,13 +856,13 @@ <h1 class="hero-type"><span class="puzzle-active-numShapesChosen">0</span> <smal
<div id="puzzleActiveMapGrid" class="well container-center grid-gutterless">
<div class="row">
<a href="#" class="span1">
- <img src="asset/texture/dirt_128.jpg" alt="" class="iconk">
+ <img src="asset/dirt_128.jpg" alt="" class="iconk">
</a>
<a href="#" class="span1">
- <img src="asset/texture/dirt_128.jpg" alt="" class="iconk">
+ <img src="asset/dirt_128.jpg" alt="" class="iconk">
</a>
<a href="#" class="span1">
- <img src="asset/texture/dirt_128.jpg" alt="" class="iconk">
+ <img src="asset/dirt_128.jpg" alt="" class="iconk">
</a>
</div>
</div>
View
19 src/web/js/kaiopua/Kaiopua.js
@@ -16,9 +16,7 @@ var KAIOPUA = (function (main) {
shared.originLink = window.location.pathname.toString();
shared.pathToIcons = 'img/';
- shared.pathToAssets = 'asset/';
- shared.pathToModels = shared.pathToAssets + 'model/';
- shared.pathToTextures = shared.pathToAssets + 'texture/';
+ shared.pathToAsset = 'asset/';
shared.frameRateMax = 60;
shared.frameRateMin = 20;
@@ -106,9 +104,7 @@ var KAIOPUA = (function (main) {
"js/kaiopua/sections/Launcher.js"
],
assetsGameExtras = [
- "js/kaiopua/sections/Intro.js",
- "js/kaiopua/core/Player.js",
- { path: "asset/model/Hero.js", type: 'model' }
+ "js/kaiopua/sections/Intro.js"
];
/*===================================================
@@ -566,16 +562,10 @@ var KAIOPUA = (function (main) {
=====================================================*/
- function init_ready ( intro, p ) {
+ function init_ready ( intro ) {
console.log('GAME: ready');
_Intro = intro;
- _Player = p;
-
- shared.player = new _Player.Instance( {
- geometry: "asset/model/Hero.js"
- } );
- shared.player.controllable = true;
$( '#buttonStart' ).on( 'tap', start );
$( '#buttonExitGame' ).on( 'tap', stop );
@@ -2652,7 +2642,8 @@ var KAIOPUA = (function (main) {
function asset_path_cascade( path ) {
- var cascade,
+ var i, l,
+ cascade,
part,
dotIndex;
View
10 src/web/js/kaiopua/Kaiopua_DEPRECATED.js
@@ -96,11 +96,11 @@ var KAIOPUA = (function (main) {
// shared
shared.pointers = [];
shared.originLink = window.location.pathname.toString();
- shared.pathToAssets = 'asset/';
- shared.pathToModules = shared.pathToAssets + 'modules/';
- shared.pathToModels = shared.pathToAssets + 'model/';
- shared.pathToIcons = shared.pathToAssets + 'icons/';
- shared.pathToTextures = shared.pathToAssets + 'texture/';
+ shared.pathToAsset = 'asset/';
+ shared.pathToModules = shared.pathToAsset + 'modules/';
+ shared.pathToModels = shared.pathToAsset + 'model/';
+ shared.pathToIcons = shared.pathToAsset + 'icons/';
+ shared.pathToAsset = shared.pathToAsset + 'texture/';
shared.frameRateMax = 60;
shared.frameRateMin = 20;
View
94 src/web/js/kaiopua/core/Character.js
@@ -161,12 +161,12 @@
tweenShow = _ObjectHelper.tween( this.material, { opacity: 1 }, {
start: false,
- time: durationPerTween
+ duration: durationPerTween
} );
tweenHide = _ObjectHelper.tween( this.material, { opacity: stats.invulnerabilityOpacityMin }, {
start: false,
- time: durationPerTween
+ duration: durationPerTween
} );
tweenHide.chain( tweenShow.chain( tweenHide ) ).start();
@@ -176,7 +176,7 @@
else {
_ObjectHelper.tween( this.material, { opacity: 1 }, {
- time: durationPerTween,
+ duration: durationPerTween,
onComplete: function () {
me.material.transparent = false;
@@ -328,7 +328,7 @@
var state = this.state,
stats = this.options.stats;
console.log( this, ' trying to hurt for ', damage, ', invulnerable? ', state.invulnerable );
- if ( state.invulnerable !== true && state.dead !== true ) {
+ if ( state.invulnerable !== true && state.dead !== true && main.is_number( damage ) && damage > 0 ) {
this.health -= damage;
@@ -347,6 +347,8 @@
}
+ return true;
+
}
}
@@ -400,7 +402,7 @@
this.material.transparent = true;
_ObjectHelper.tween( this.material, { opacity: 0 }, {
- time: durations.decay,
+ duration: durations.decay,
delay: durations.decayDelay,
onComplete: function () {
@@ -670,7 +672,7 @@
velocityGravityForceDelta,
velocityMovement,
velocityMovementForceDelta,
- velocityMovementForceLength,
+ velocityMovementForceRotatedLength,
velocityMovementDamping,
dragCoefficient,
terminalVelocity,
@@ -778,7 +780,6 @@
jumpMoveDamping = jump.moveDamping;
velocityMovement = rigidBody.velocityMovement;
- velocityMovementForce = velocityMovement.force;
velocityMovementForceDelta = velocityMovement.forceDelta;
velocityGravity = rigidBody.velocityGravity;
velocityGravityForceDelta = velocityGravity.forceDelta;
@@ -790,6 +791,28 @@
jump.timeAfterNotGrounded += timeDelta;
+ // air control
+
+ if ( grounded === false && jump.timeAfterNotGrounded >= jumpTimeAfterNotGroundedMax ) {
+
+ if ( typeof jump.movementChangeLayer === 'undefined' ) {
+
+ jump.movementChangeLayer = _ObjectHelper.temporary_change( velocityMovement, {
+ damping: new THREE.Vector3( jumpMoveDamping, jumpMoveDamping, jumpMoveDamping ),
+ speedDelta: new THREE.Vector3( jumpAirControl, jumpAirControl, jumpAirControl )
+ } );
+
+ }
+
+ }
+ else if ( typeof jump.movementChangeLayer !== 'undefined' ) {
+
+ _ObjectHelper.revert_change( velocityMovement, jump.movementChangeLayer );
+
+ jump.movementChangeLayer = undefined;
+
+ }
+
// if falling but not jumping
if ( jump.active === false && jump.timeAfterNotGrounded >= jumpTimeAfterNotGroundedMax && grounded === false ) {
@@ -841,11 +864,6 @@
velocityGravity.reset();
- jump.movementChangeLayer = _ObjectHelper.temporary_change( velocityMovement, {
- damping: new THREE.Vector3( jumpMoveDamping, jumpMoveDamping, jumpMoveDamping ),
- speedDelta: new THREE.Vector3( jumpAirControl, jumpAirControl, jumpAirControl )
- } );
-
}
// play jump
@@ -878,8 +896,6 @@
if ( grounded === true && jump.active !== false ) {
- _ObjectHelper.revert_change( velocityMovement, jump.movementChangeLayer );
-
this.stop_jumping();
if ( jump.timeAfterNotGrounded >= jumpTimeAfterNotGroundedMax ) {
@@ -904,58 +920,62 @@
// movement
- velocityMovementForceDelta.copy( moveDir );
-
- if ( state.movingHorizontal && jump.active === true ) {
+ if ( sliding !== true ) {
- velocityMovementForceDelta.z += jumpSpeedStart * jump.moveSpeedMod;
+ moveDir.multiplyScalar( moveSpeed );
- }
-
- velocityMovementForceDelta.multiplyScalar( moveSpeed );
-
- // moving backwards?
-
- if ( velocityMovementForceDelta.z < 0 ) {
+ if ( state.movingHorizontal && jump.active === true ) {
+
+ moveDir.z += jumpSpeedStart * jump.moveSpeedMod;
+
+ }
- state.movingBack = true;
+ velocityMovementForceDelta.addSelf( moveDir );
- }
- else if ( velocityMovementForceDelta.z > 0 ) {
+ // moving backwards?
- state.movingBack = false;
+ if ( moveDir.z < 0 ) {
+
+ state.movingBack = true;
+
+ }
+ else if ( moveDir.z > 0 ) {
+
+ state.movingBack = false;
+
+ }
}
- // get movement force
-
- velocityMovementForceLength = velocityMovement.force.length() / timeDeltaMod;
-
// walk/run/idle
if ( jump.active === false && grounded === true ) {
+ // get movement force
+
+ velocityMovementForceRotatedLength = velocityMovement.forceRotated.length() / timeDeltaMod;
+
// walk / run cycles
- if ( velocityMovementForceLength > 0 || sliding === true ) {
+ if ( velocityMovementForceRotatedLength > 0 || sliding === true ) {
// get approximate terminal velocity based on acceleration (moveVec) and damping
// helps morphs play faster if character is moving faster, or slower if moving slower
- // TODO: move equation into physics module
+ // TODO: account for really low damping (0.95+)
velocityMovementDamping = velocityMovement.damping.z;
dragCoefficient = ( 0.33758 * Math.pow( velocityMovementDamping, 2 ) ) + ( -0.67116 * velocityMovementDamping ) + 0.33419;
terminalVelocity = Math.round( Math.sqrt( ( 2 * Math.abs( velocityMovement.force.z * 0.5 ) ) / dragCoefficient ) ) * 0.5;
- playSpeedModifier = terminalVelocity / Math.round( velocityMovementForceLength );
+ playSpeedModifier = terminalVelocity / Math.round( velocityMovementForceRotatedLength );
if ( main.is_number( playSpeedModifier ) !== true ) {
playSpeedModifier = 1;
}
- if ( velocityMovementForceLength >= move.runThreshold ) {
+ if ( velocityMovementForceRotatedLength >= move.runThreshold ) {
this.morphs.play( 'run', { duration: durations.run * playSpeedModifier, loop: true, solo: true, durationClear: durations.clearSolo, reverse: state.movingBack } );
View
98 src/web/js/kaiopua/core/Game_DEPRECATED.js
@@ -95,55 +95,55 @@
"js/kaiopua/farming/Planting.js",
"js/kaiopua/farming/Dirt.js",
"js/kaiopua/sections/Intro.js",
- { path: "asset/model/Whale.js", type: 'model' },
- { path: "asset/model/Hero.js", type: 'model' },
- { path: "asset/model/Sun.js", type: 'model' },
- { path: "asset/model/Cloud_001.js", type: 'model' },
- { path: "asset/model/Cloud_002.js", type: 'model' },
- { path: "asset/model/Hut.js", type: 'model' },
- { path: "asset/model/Hut_Hill.js", type: 'model' },
- { path: "asset/model/Hut_Steps.js", type: 'model' },
- { path: "asset/model/Bed.js", type: 'model' },
- { path: "asset/model/Banana_Leaf_Door.js", type: 'model' },
- { path: "asset/model/Surfboard.js", type: 'model' },
- { path: "asset/model/Grass_Clump_001.js", type: 'model' },
- { path: "asset/model/Grass_Clump_002.js", type: 'model' },
- { path: "asset/model/Grass_Line_001.js", type: 'model' },
- { path: "asset/model/Grass_Line_002.js", type: 'model' },
- { path: "asset/model/Palm_Tree.js", type: 'model' },
- { path: "asset/model/Palm_Trees.js", type: 'model' },
- { path: "asset/model/Kukui_Tree.js", type: 'model' },
- { path: "asset/model/Kukui_Trees.js", type: 'model' },
- { path: "asset/model/Plant_Dirt_Mound.js", type: 'model' },
- { path: "asset/model/Plant_Seed.js", type: 'model' },
- { path: "asset/model/Plant_Taro.js", type: 'model' },
- { path: "asset/model/Plant_Pineapple.js", type: 'model' },
- { path: "asset/model/Plant_Rock.js", type: 'model' },
- { path: "asset/model/Plant_Rock_Purple.js", type: 'model' },
- { path: "asset/model/Plant_Rock_Blue.js", type: 'model' },
- { path: "asset/model/Volcano_Large.js", type: 'model' },
- { path: "asset/model/Volcano_Small.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_001.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_002.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_003.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_004.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_005.js", type: 'model' },
- { path: "asset/model/Puzzle_Tutorial.js", type: 'model' },
- { path: "asset/model/Puzzle_Tutorial_Grid.js", type: 'model' },
- { path: "asset/model/Puzzle_Tutorial_Toggle.js", type: 'model' },
- { path: "asset/model/Puzzle_Rolling_Hills.js", type: 'model' },
- { path: "asset/model/Puzzle_Rolling_Hills_Grid.js", type: 'model' },
- { path: "asset/model/Puzzle_Rolling_Hills_Toggle.js", type: 'model' },
- { path: "asset/model/Puzzle_Basics_Abilities.js", type: 'model' },
- { path: "asset/model/Puzzle_Basics_Abilities_Grid.js", type: 'model' },
- "asset/texture/skybox_world_posx.jpg",
- "asset/texture/skybox_world_negx.jpg",
- "asset/texture/skybox_world_posy.jpg",
- "asset/texture/skybox_world_negy.jpg",
- "asset/texture/skybox_world_posz.jpg",
- "asset/texture/skybox_world_negz.jpg",
- "asset/texture/water_world_512.png",
- "asset/texture/dirt_128.jpg"
+ { path: shared.pathToAsset + "Whale.js", type: 'model' },
+ { path: shared.pathToAsset + "Hero.js", type: 'model' },
+ { path: shared.pathToAsset + "Sun.js", type: 'model' },
+ { path: shared.pathToAsset + "Cloud_001.js", type: 'model' },
+ { path: shared.pathToAsset + "Cloud_002.js", type: 'model' },
+ { path: shared.pathToAsset + "Hut.js", type: 'model' },
+ { path: shared.pathToAsset + "Hut_Hill.js", type: 'model' },
+ { path: shared.pathToAsset + "Hut_Steps.js", type: 'model' },
+ { path: shared.pathToAsset + "Bed.js", type: 'model' },
+ { path: shared.pathToAsset + "Banana_Leaf_Door.js", type: 'model' },
+ { path: shared.pathToAsset + "Surfboard.js", type: 'model' },
+ { path: shared.pathToAsset + "Grass_Clump_001.js", type: 'model' },
+ { path: shared.pathToAsset + "Grass_Clump_002.js", type: 'model' },
+ { path: shared.pathToAsset + "Grass_Line_001.js", type: 'model' },
+ { path: shared.pathToAsset + "Grass_Line_002.js", type: 'model' },
+ { path: shared.pathToAsset + "Palm_Tree.js", type: 'model' },
+ { path: shared.pathToAsset + "Palm_Trees.js", type: 'model' },
+ { path: shared.pathToAsset + "Kukui_Tree.js", type: 'model' },
+ { path: shared.pathToAsset + "Kukui_Trees.js", type: 'model' },
+ { path: shared.pathToAsset + "Plant_Dirt_Mound.js", type: 'model' },
+ { path: shared.pathToAsset + "Plant_Seed.js", type: 'model' },
+ { path: shared.pathToAsset + "Plant_Taro.js", type: 'model' },
+ { path: shared.pathToAsset + "Plant_Pineapple.js", type: 'model' },
+ { path: shared.pathToAsset + "Plant_Rock.js", type: 'model' },
+ { path: shared.pathToAsset + "Plant_Rock_Purple.js", type: 'model' },
+ { path: shared.pathToAsset + "Plant_Rock_Blue.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Large.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Small.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_001.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_002.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_003.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_004.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_005.js", type: 'model' },
+ { path: shared.pathToAsset + "Puzzle_Tutorial.js", type: 'model' },
+ { path: shared.pathToAsset + "Puzzle_Tutorial_Grid.js", type: 'model' },
+ { path: shared.pathToAsset + "Puzzle_Tutorial_Toggle.js", type: 'model' },
+ { path: shared.pathToAsset + "Puzzle_Rolling_Hills.js", type: 'model' },
+ { path: shared.pathToAsset + "Puzzle_Rolling_Hills_Grid.js", type: 'model' },
+ { path: shared.pathToAsset + "Puzzle_Rolling_Hills_Toggle.js", type: 'model' },
+ { path: shared.pathToAsset + "Puzzle_Basics_Abilities.js", type: 'model' },
+ { path: shared.pathToAsset + "Puzzle_Basics_Abilities_Grid.js", type: 'model' },
+ shared.pathToAsset + "skybox_world_posx.jpg",
+ shared.pathToAsset + "skybox_world_negx.jpg",
+ shared.pathToAsset + "skybox_world_posy.jpg",
+ shared.pathToAsset + "skybox_world_negy.jpg",
+ shared.pathToAsset + "skybox_world_posz.jpg",
+ shared.pathToAsset + "skybox_world_negz.jpg",
+ shared.pathToAsset + "water_world_512.png",
+ shared.pathToAsset + "dirt_128.jpg"
],
loadingHeader = 'Hold on, we need some stuff from Hawaii...',
loadingTips = [
View
17 src/web/js/kaiopua/core/Morphs.js
@@ -155,8 +155,7 @@
function play ( name, parameters ) {
- var i, l,
- names = this.names,
+ var names = this.names,
name,
maps,
map,
@@ -192,9 +191,19 @@
}
- else if ( parameters && typeof parameters.callback === 'function' ) {
+ else if ( parameters ) {
+
+ if ( parameters.solo === true ) {
+
+ this.clear_all( { duration: parameters.durationClear } );
+
+ }
- parameters.callback();
+ if ( typeof parameters.callback === 'function' ) {
+
+ parameters.callback();
+
+ }
}
View
43 src/web/js/kaiopua/core/Player.js
@@ -12,7 +12,6 @@
assetPath = "js/kaiopua/core/Player.js",
_Player = {},
_Character,
- _Planting,
_MathHelper,
_KeyHelper,
_SceneHelper,
@@ -29,7 +28,6 @@
data: _Player,
requirements: [
"js/kaiopua/core/Character.js",
- "js/kaiopua/farming/Planting.js",
"js/kaiopua/utils/MathHelper.js",
"js/kaiopua/utils/KeyHelper.js",
"js/kaiopua/utils/SceneHelper.js",
@@ -46,13 +44,12 @@
=====================================================*/
- function init_internal ( c, pl, mh, kh, sh, oh, rh ) {
+ function init_internal ( c, mh, kh, sh, oh, rh ) {
console.log('internal player');
// assets
_Character = c;
- _Planting = pl;
_MathHelper = mh;
_KeyHelper = kh;
_SceneHelper = sh;
@@ -220,7 +217,7 @@
parameters.name = 'Hero';
parameters.geometry = parameters.geometry || new THREE.CubeGeometry( 50, 100, 50 );
- parameters.material = parameters.material || new THREE.MeshLambertMaterial( { color: 0xFFF7E0, ambient: 0xFFF7E0, vertexColors: THREE.VertexColors } );
+ parameters.center = true;
parameters.physics = parameters.physics || {};
parameters.physics.bodyType = 'capsule';
@@ -410,32 +407,6 @@
}
} );
- // planting
-
- this.planting = new _Planting.Instance( {
- affectUI: true
- } );
-
- this.actions.add( 'pointer', {
- eventCallbacks: {
- // TODO: replace tap planting select with general select
- //tap: [ $.proxy( this.planting.select_puzzle, this.planting ), $.proxy( this.planting.select_plant, this.planting ) ],
- hold: $.proxy( this.planting.activate_puzzle, this.planting ),
- dragstart: $.proxy( this.planting.activate_plant, this.planting ),
- drag: $.proxy( this.planting.step, this.planting ),
- dragend: $.proxy( this.planting.complete, this.planting ),
- doubletap: $.proxy( this.planting.delete_plant, this.planting )
- },
- deactivateCallbacks: $.proxy( this.planting.stop, this.planting ),
- activeCheck: function () {
- return me.planting.started;
- },
- options: {
- priority: 2,
- silencing: true
- }
- } );
-
}
/*===================================================
@@ -584,14 +555,12 @@
if ( this.state.enabled === true || isAlwaysAvailable ) {
- parameters = {
- event: e,
- allowDefault: isAlwaysAvailable || main.paused
- };
-
// perform action
- this.actions.execute( keyNameActual, state, parameters );
+ this.actions.execute( keyNameActual, state, {
+ event: e,
+ allowDefault: isAlwaysAvailable || main.paused
+ } );
}
View
4 src/web/js/kaiopua/env/Cloud.js
@@ -23,8 +23,8 @@
data: _Cloud,
requirements: [
"js/kaiopua/core/Model.js",
- { path: "asset/model/Cloud_001.js", type: 'model' },
- { path: "asset/model/Cloud_002.js", type: 'model' }
+ { path: shared.pathToAsset + "Cloud_001.js", type: 'model' },
+ { path: shared.pathToAsset + "Cloud_002.js", type: 'model' }
],
callbacksOnReqs: init_internal,
wait: true
View
2 src/web/js/kaiopua/env/Water.js
@@ -25,7 +25,7 @@
requirements: [
"js/kaiopua/core/Model.js",
"js/kaiopua/utils/ObjectHelper.js",
- shared.pathToTextures + "water_512.png"
+ shared.pathToAsset + "water_512.png"
],
callbacksOnReqs: init_internal,
wait: true
View
82 src/web/js/kaiopua/env/WorldIsland.js
@@ -32,30 +32,30 @@
"js/kaiopua/env/Water.js",
"js/kaiopua/env/Sky.js",
"js/kaiopua/utils/PhysicsHelper.js",
- { path: "asset/model/Whale.js", type: 'model' },
- { path: "asset/model/Sun.js", type: 'model' },
- { path: "asset/model/Hut.js", type: 'model' },
- { path: "asset/model/Hut_Hill.js", type: 'model' },
- { path: "asset/model/Hut_Steps.js", type: 'model' },
- { path: "asset/model/Bed.js", type: 'model' },
- { path: "asset/model/Banana_Leaf_Door.js", type: 'model' },
- { path: "asset/model/Surfboard.js", type: 'model' },
- { path: "asset/model/Grass_Clump_001.js", type: 'model' },
- { path: "asset/model/Grass_Clump_002.js", type: 'model' },
- { path: "asset/model/Grass_Line_001.js", type: 'model' },
- { path: "asset/model/Grass_Line_002.js", type: 'model' },
- { path: "asset/model/Palm_Tree.js", type: 'model' },
- { path: "asset/model/Palm_Trees.js", type: 'model' },
- { path: "asset/model/Kukui_Tree.js", type: 'model' },
- { path: "asset/model/Kukui_Trees.js", type: 'model' },
- { path: "asset/model/Volcano_Large.js", type: 'model' },
- { path: "asset/model/Volcano_Small.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_001.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_002.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_003.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_004.js", type: 'model' },
- { path: "asset/model/Volcano_Rocks_005.js", type: 'model' },
- shared.pathToTextures + "water_world_512.png"
+ { path: shared.pathToAsset + "Whale.js", type: 'model' },
+ { path: shared.pathToAsset + "Sun.js", type: 'model' },
+ { path: shared.pathToAsset + "Hut.js", type: 'model' },
+ { path: shared.pathToAsset + "Hut_Hill.js", type: 'model' },
+ { path: shared.pathToAsset + "Hut_Steps.js", type: 'model' },
+ { path: shared.pathToAsset + "Bed.js", type: 'model' },
+ { path: shared.pathToAsset + "Banana_Leaf_Door.js", type: 'model' },
+ { path: shared.pathToAsset + "Surfboard.js", type: 'model' },
+ { path: shared.pathToAsset + "Grass_Clump_001.js", type: 'model' },
+ { path: shared.pathToAsset + "Grass_Clump_002.js", type: 'model' },
+ { path: shared.pathToAsset + "Grass_Line_001.js", type: 'model' },
+ { path: shared.pathToAsset + "Grass_Line_002.js", type: 'model' },
+ { path: shared.pathToAsset + "Palm_Tree.js", type: 'model' },
+ { path: shared.pathToAsset + "Palm_Trees.js", type: 'model' },
+ { path: shared.pathToAsset + "Kukui_Tree.js", type: 'model' },
+ { path: shared.pathToAsset + "Kukui_Trees.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Large.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Small.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_001.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_002.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_003.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_004.js", type: 'model' },
+ { path: shared.pathToAsset + "Volcano_Rocks_005.js", type: 'model' },
+ shared.pathToAsset + "water_world_512.png"
],
callbacksOnReqs: init_internal,
wait: true
@@ -112,7 +112,7 @@
// body
me.parts.body = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Whale.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Whale.js"),
physics: {
bodyType: 'mesh',
gravitySource: true
@@ -147,15 +147,15 @@
// water
me.parts.waterRing = new _Water.Instance( {
- wavesTexture: shared.pathToTextures + "water_world_512.png"
+ wavesTexture: shared.pathToAsset + "water_world_512.png"
} );
me.add( me.parts.waterRing );
// sun/moon
me.parts.sun = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Sun.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Sun.js"),
material: new THREE.MeshBasicMaterial( { shading: THREE.NoShading, vertexColors: THREE.VertexColors } ),
physics: {
bodyType: 'mesh',
@@ -242,7 +242,7 @@
// hill for home
me.parts.hill = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Hut_Hill.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Hut_Hill.js"),
physics: {
bodyType: 'mesh'
},
@@ -254,7 +254,7 @@
// steps
me.parts.steps = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Hut_Steps.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Hut_Steps.js"),
physics: {
bodyType: 'mesh'
},
@@ -266,7 +266,7 @@
// hut
me.parts.hut = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Hut.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Hut.js"),
physics: {
bodyType: 'mesh'
},
@@ -278,7 +278,7 @@
// banana leaf door
me.parts.bananaLeafDoor = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Banana_Leaf_Door.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Banana_Leaf_Door.js"),
center: true,
side: THREE.DoubleSide
});
@@ -288,7 +288,7 @@
// surfboard
me.parts.surfboard = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Surfboard.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Surfboard.js"),
center: true
});
@@ -307,7 +307,7 @@
// volcano large
me.parts.volcanoLarge = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Volcano_Large.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Volcano_Large.js"),
physics: {
bodyType: 'mesh'
},
@@ -319,7 +319,7 @@
// volcano small
me.parts.volcanoSmall = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Volcano_Small.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Volcano_Small.js"),
physics: {
bodyType: 'mesh'
},
@@ -331,7 +331,7 @@
// volcano rocks
me.parts.volcanoRocks001 = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Volcano_Rocks_001.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Volcano_Rocks_001.js"),
physics: {
bodyType: 'mesh'
},
@@ -341,7 +341,7 @@
me.parts.volcano.add( me.parts.volcanoRocks001 );
me.parts.volcanoRocks002 = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Volcano_Rocks_002.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Volcano_Rocks_002.js"),
physics: {
bodyType: 'mesh'
},
@@ -351,7 +351,7 @@
me.parts.volcano.add( me.parts.volcanoRocks002 );
me.parts.volcanoRocks003 = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Volcano_Rocks_003.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Volcano_Rocks_003.js"),
physics: {
bodyType: 'mesh'
},
@@ -361,7 +361,7 @@
me.parts.volcano.add( me.parts.volcanoRocks003 );
me.parts.volcanoRocks004 = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Volcano_Rocks_004.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Volcano_Rocks_004.js"),
physics: {
bodyType: 'mesh'
},
@@ -371,7 +371,7 @@
me.parts.volcano.add( me.parts.volcanoRocks004 );
me.parts.volcanoRocks005 = new _Model.Instance({
- geometry: main.get_asset_data("asset/model/Volcano_Rocks_005.js"),
+ geometry: main.get_asset_data(shared.pathToAsset + "Volcano_Rocks_005.js"),
physics: {
bodyType: 'mesh'
},
@@ -393,15 +393,15 @@
// kukui trees
me.parts.kukuiTrees = new _Model.Instance({
- geometry: "asset/model/Kukui_Trees.js",
+ geometry: shared.pathToAsset + "Kukui_Trees.js",
});
me.parts.trees.add( me.parts.kukuiTrees );
// palm trees
me.parts.palmTrees = new _Model.Instance({
- geometry: "asset/model/Palm_Trees.js",
+ geometry: shared.pathToAsset + "Palm_Trees.js",
});
me.parts.trees.add( me.parts.palmTrees );
View
2 src/web/js/kaiopua/farming/Dirt.js
@@ -23,7 +23,7 @@
data: _Dirt,
requirements: [
"js/kaiopua/puzzles/GridModule.js",
- shared.pathToTextures + 'dirt_128.jpg'
+ shared.pathToAsset + 'dirt_128.jpg'
],
callbacksOnReqs: init_internal,
wait: true
View
34 src/web/js/kaiopua/physics/Obstacle.js
@@ -65,7 +65,7 @@
// properties
- this.affected = [];
+ this.affecting = [];
}
@@ -77,13 +77,41 @@
function affect ( object ) {
- return main.array_cautious_add( this.affected, object );
+ var affected,
+ index;
+
+ index = main.index_of_property( this.affecting, 'object', object );
+
+ if ( index === -1 ) {
+
+ affected = {
+ object: object
+ };
+
+ this.affecting.push( affected );
+
+ }
+ else {
+
+ affected = this.affecting[ index ];
+
+ }
+
+ return affected;
}
function unaffect ( object ) {
- return main.array_cautious_remove( this.affected, object );
+ var index;
+
+ index = main.index_of_property( this.affecting, 'object', object );
+
+ if ( index !== -1 ) {
+
+ return this.affecting.splice( index, 1 )[ 0 ];
+
+ }
}
View
206 src/web/js/kaiopua/physics/ObstacleDamaging.js
@@ -0,0 +1,206 @@
+/*
+ *
+ * ObstacleDamaging.js
+ * Obstacle that damages anything running into it.
+ *
+ * @author Collin Hover / http://collinhover.com/
+ *
+ */
+(function (main) {
+
+ var shared = main.shared = main.shared || {},
+ assetPath = "js/kaiopua/physics/ObstacleDamaging.js",
+ _ObstacleDamaging = {},
+ _Obstacle,
+ _ObjectHelper;
+
+ /*===================================================
+
+ public properties
+
+ =====================================================*/
+
+ main.asset_register( assetPath, {
+ data: _ObstacleDamaging,
+ requirements: [
+ "js/kaiopua/physics/Obstacle.js",
+ "js/kaiopua/utils/ObjectHelper.js"
+ ],
+ callbacksOnReqs: init_internal,
+ wait: true
+ });
+
+ /*===================================================
+
+ internal init
+
+ =====================================================*/
+
+ function init_internal ( ob, oh ) {
+ console.log('internal ObstacleDamaging', _ObstacleDamaging);
+ // modules
+
+ _Obstacle = ob;
+ _ObjectHelper = oh;
+
+ // properties
+
+ _ObstacleDamaging.options = {
+ damage: 1,
+ pushback: {
+ speedStart: 4,
+ speedEnd: 0,
+ duration: 200
+ },
+ effects: {
+ speedDelta: 0
+ }
+ };
+
+ // instance
+
+ _ObstacleDamaging.Instance = ObstacleDamaging;
+ _ObstacleDamaging.Instance.prototype = new _Obstacle.Instance();
+ _ObstacleDamaging.Instance.prototype.constructor = _ObstacleDamaging.Instance;
+ _ObstacleDamaging.Instance.prototype.supr = _Obstacle.Instance.prototype;
+
+ _ObstacleDamaging.Instance.prototype.affect = affect;
+ _ObstacleDamaging.Instance.prototype.unaffect = unaffect;
+
+ }
+
+ /*===================================================
+
+ instance
+
+ =====================================================*/
+
+ function ObstacleDamaging ( parameters ) {
+
+ parameters = parameters || {};
+ parameters.options = $.extend( true, {}, _ObstacleDamaging.options, parameters.options );
+
+ // prototype constructor
+
+ _Obstacle.Instance.call( this, parameters );
+
+ // utility
+
+ this.effects = {
+ speedDelta: new THREE.Vector3( 1, 1, 1 ).multiplyScalar( this.options.effects.speedDelta )
+ };
+
+ }
+
+ /*===================================================
+
+ affect
+
+ =====================================================*/
+
+ function affect ( object, parameters ) {
+
+ var me = this,
+ numAffected = this.affecting.length,
+ affected = _ObstacleDamaging.Instance.prototype.supr.affect.apply( this, arguments ),
+ options = this.options,
+ pushback = options.pushback,
+ affected,
+ velocity,
+ damaged,
+ rigidBody,
+ collision;
+
+ parameters = parameters || {};
+ velocity = parameters.velocity;
+
+ // damage
+
+ if ( typeof object.hurt === 'function' && affected.cooldown !== true ) {
+
+ damaged = object.hurt( options.damage );
+
+ // start pushback when damaged
+
+ collision = velocity.collision;
+ rigidBody = object.rigidBody;
+
+ if ( damaged === true && collision && typeof rigidBody !== 'undefined' ) {
+
+ affected.cooldown = true;
+
+ // effect change
+
+ if ( typeof affected.change !== 'undefined' ) {
+
+ _ObjectHelper.revert_change( rigidBody.velocityMovement, affected.change );
+ delete affected.change;
+
+ }
+
+ if ( affected.collision !== collision ) {
+
+ affected.change = _ObjectHelper.temporary_change( rigidBody.velocityMovement, this.effects );
+
+ }
+
+ affected.collision = collision;
+
+ // collision normal is local to collision object, i.e. this
+
+ affected.pushbackDelta = affected.collision.normal.clone();
+ this.matrixWorld.rotateAxis( affected.pushbackDelta );
+
+ // reset movement velocity
+
+ rigidBody.velocityMovement.clear();
+ rigidBody.velocityMovement.dampingPre.set( 1, 1, 1 );
+
+ // tween pushback speed
+
+ affected.tweenFrom = { speed: pushback.speedStart };
+ affected.tweenTo = { speed: pushback.speedEnd };
+
+ _ObjectHelper.tween( affected.tweenFrom, affected.tweenTo, {
+ duration: pushback.duration,
+ onUpdate: function () {
+
+ // apply pushback to force rotated
+
+ affected.pushbackDelta.multiplyScalar( affected.tweenFrom.speed );
+
+ rigidBody.velocityMovement.forceRotated.addSelf( affected.pushbackDelta );
+
+ },
+ onComplete: function () {
+
+ affected.cooldown = false;
+
+ me.unaffect( object );
+
+ }
+ });
+
+ }
+
+ }
+
+ return affected;
+
+ }
+
+ function unaffect ( object ) {
+
+ var affected = _ObstacleDamaging.Instance.prototype.supr.unaffect.apply( this, arguments );
+
+ if ( typeof affected !== 'undefined' ) {
+
+ _ObjectHelper.revert_change( object.rigidBody.velocityMovement, affected.change );
+
+ }
+
+ return affected;
+
+ }
+
+} ( KAIOPUA ) );
View
126 src/web/js/kaiopua/physics/ObstacleSlippery.js
@@ -0,0 +1,126 @@
+/*
+ *
+ * ObstacleSlippery.js
+ * Obstacle that is slippery to walk on, such as ice.
+ *
+ * @author Collin Hover / http://collinhover.com/
+ *
+ */
+(function (main) {
+
+ var shared = main.shared = main.shared || {},
+ assetPath = "js/kaiopua/physics/ObstacleSlippery.js",
+ _ObstacleSlippery = {},
+ _Obstacle,
+ _ObjectHelper;
+
+ /*===================================================
+
+ public properties
+
+ =====================================================*/
+
+ main.asset_register( assetPath, {
+ data: _ObstacleSlippery,
+ requirements: [
+ "js/kaiopua/physics/Obstacle.js",
+ "js/kaiopua/utils/ObjectHelper.js"
+ ],
+ callbacksOnReqs: init_internal,
+ wait: true
+ });
+
+ /*===================================================
+
+ internal init
+
+ =====================================================*/
+
+ function init_internal ( ob, oh ) {
+ console.log('internal ObstacleSlippery', _ObstacleSlippery);
+ // modules
+
+ _Obstacle = ob;
+ _ObjectHelper = oh;
+
+ // properties
+
+ _ObstacleSlippery.options = {
+ effects: {
+ damping: 0.97,
+ speedDelta: 0.1
+ }
+ };
+
+ // instance
+
+ _ObstacleSlippery.Instance = ObstacleSlippery;
+ _ObstacleSlippery.Instance.prototype = new _Obstacle.Instance();
+ _ObstacleSlippery.Instance.prototype.constructor = _ObstacleSlippery.Instance;
+ _ObstacleSlippery.Instance.prototype.supr = _Obstacle.Instance.prototype;
+
+ _ObstacleSlippery.Instance.prototype.affect = affect;
+ _ObstacleSlippery.Instance.prototype.unaffect = unaffect;
+
+ }
+
+ /*===================================================
+
+ instance
+
+ =====================================================*/
+
+ function ObstacleSlippery ( parameters ) {
+
+ parameters = parameters || {};
+ parameters.options = $.extend( true, {}, _ObstacleSlippery.options, parameters.options );
+
+ // prototype constructor
+
+ _Obstacle.Instance.call( this, parameters );
+
+ // properties
+
+ this.effects = {
+ damping: new THREE.Vector3( 1, 1, 1 ).multiplyScalar( this.options.effects.damping ),
+ speedDelta: new THREE.Vector3( 1, 1, 1 ).multiplyScalar( this.options.effects.speedDelta )
+ };
+
+ }
+
+ /*===================================================
+
+ affect
+
+ =====================================================*/
+
+ function affect ( object ) {
+
+ var numAffected = this.affecting.length,
+ affected = _ObstacleSlippery.Instance.prototype.supr.affect.apply( this, arguments );
+
+ if ( this.affecting.length !== numAffected ) {
+
+ affected.change = _ObjectHelper.temporary_change( object.rigidBody.velocityMovement, this.effects );
+
+ }
+
+ return affected;
+
+ }
+
+ function unaffect ( object ) {
+
+ var affected = _ObstacleSlippery.Instance.prototype.supr.unaffect.apply( this, arguments );
+
+ if ( typeof affected !== 'undefined' ) {
+
+ _ObjectHelper.revert_change( object.rigidBody.velocityMovement, affected.change );
+
+ }
+
+ return affected;
+
+ }
+
+} ( KAIOPUA ) );
View
79 src/web/js/kaiopua/physics/Physics.js
@@ -16,6 +16,7 @@
_RayHelper,
_MathHelper,
_VectorHelper,
+ _ObjectHelper,
_PhysicsHelper;
/*===================================================
@@ -32,6 +33,7 @@
"js/kaiopua/utils/MathHelper.js",
"js/kaiopua/utils/VectorHelper.js",
"js/kaiopua/utils/RayHelper.js",
+ "js/kaiopua/utils/ObjectHelper.js",
"js/kaiopua/utils/PhysicsHelper.js",
"js/lib/three/ThreeOctree.min.js"
],
@@ -45,14 +47,15 @@
=====================================================*/
- function init_internal ( rb, ob, mh, vh, rh, ph ) {
+ function init_internal ( rb, ob, mh, vh, rh, oh, ph ) {
console.log('internal physics');
_RigidBody = rb;
_Obstacle = ob;
_MathHelper = mh;
_VectorHelper = vh;
_RayHelper = rh;
+ _ObjectHelper = oh;
_PhysicsHelper = ph;
// instance
@@ -89,12 +92,11 @@
this.utilVec31Update = new THREE.Vector3();
this.utilVec32Update = new THREE.Vector3();
this.utilVec33Update = new THREE.Vector3();
- this.utilVec34Update = new THREE.Vector3();
- this.utilVec35Update = new THREE.Vector3();
this.utilVec31Apply = new THREE.Vector3();
this.utilVec31Velocity = new THREE.Vector3();
this.utilVec32Velocity = new THREE.Vector3();
this.utilVec33Velocity = new THREE.Vector3();
+ this.utilVec34Velocity = new THREE.Vector3();
this.utilQ1Velocity = new THREE.Quaternion();
// octree
@@ -272,6 +274,8 @@
j, k,
rigidBody,
mesh,
+ gravityBody,
+ gravityMesh,
gravityOrigin = this.utilVec31Update,
gravityMagnitude = this.utilVec32Update,
gravityUp = this.utilVec33Update,
@@ -382,12 +386,12 @@
intersectionAlt,
intersectionJump,
intersectionDouble,
- angle,
- angleInverted,
- normalOfIntersected,
direction = this.utilVec31Velocity,
axisInitial = this.utilVec32Velocity,
axisDown = this.utilVec33Velocity,
+ angle,
+ angleInverted,
+ normalOfIntersected = this.utilVec34Velocity,
angleFixCollisionQ,
moveForceRotated,
obstacle,
@@ -399,9 +403,9 @@
// if moving / movable
- if ( rigidBody.dynamic !== true || force.isZero() === true ) {
+ if ( rigidBody.dynamic !== true || forceRotated.isZero() === true ) {
- velocity.reset();
+ velocity.clear();
return;
@@ -414,7 +418,7 @@
// get length
- forceLength = force.length();
+ forceLength = forceRotated.length();
// get bounding radius
//boundingRadius = rigidBody.radius;
@@ -436,28 +440,32 @@
intersection = _RayHelper.raycast( intersectionParameters );
- // jumping needs a pre-application check in opposite direction of velocity to ensure the intersection application does not force rigid body through ground
-
- if ( forGravity && intersection && mesh.jumping === true ) {
-
- // reverse force
+ if ( forGravity && intersection ) {
- forceRotated.multiplyScalar( -1 );
+ // jumping needs a pre-application check in opposite direction of velocity to ensure the intersection application does not force rigid body through ground
- intersectionJump = _RayHelper.raycast( intersectionParameters );
-
- // clear force
-
- if ( intersectionJump ) {
-
- forceRotated.set( 0, 0, 0 );
+ if ( mesh.jumping === true ) {
- }
- // revert force, jump is safe
- else {
+ // reverse force
forceRotated.multiplyScalar( -1 );
+ intersectionJump = _RayHelper.raycast( intersectionParameters );
+
+ // clear force
+
+ if ( intersectionJump ) {
+
+ forceRotated.set( 0, 0, 0 );
+
+ }
+ // revert force, jump is safe
+ else {
+
+ forceRotated.multiplyScalar( -1 );
+
+ }
+
}
}
@@ -467,15 +475,15 @@
clear = apply_velocity.call( this, position, velocity, intersection, forceLength, boundingRadius, true );
// gravity offsets may allow character to walk up steep walls
- // check intersection normal vs normal of velocity, and compare angle between to velocity.collisionAngleThreshold
+ // check intersection normal vs normal of velocity, and compare angle between to velocity.options.collisionAngleThreshold
- if ( intersection && velocity.collisionAngleThreshold < _RigidBody.collisionAngleThresholdMax ) {
+ if ( intersection && velocity.options.collisionAngleThreshold < velocity.options.collisionAngleThresholdMax ) {
direction.copy( forceRotated ).normalize();
// normal is local to object intersected, so rotate normal accordingly
- normalOfIntersected = intersection.normal;
+ normalOfIntersected.copy( intersection.normal );
intersection.object.matrixWorld.rotateAxis( normalOfIntersected );
// invert the angle between velocity direction and normal of intersected
@@ -484,7 +492,7 @@
angle = _VectorHelper.angle_between_vectors( direction, normalOfIntersected );
angleInverted = ( Math.PI - angle );
- if ( angleInverted >= velocity.collisionAngleThreshold ) {
+ if ( angleInverted >= velocity.options.collisionAngleThreshold ) {
// pre damp movement force, if movement force rotated and normal of intersected are in opposite directions ( dot < 0 )
// this should allow characters to continue to walk over small objects with bad angles
@@ -495,7 +503,7 @@
if ( moveForceRotated.dot( normalOfIntersected ) < 0 ) {
- rigidBody.velocityMovement.dampingPre.multiplyScalar( rigidBody.velocityMovement.dampingDecay );
+ rigidBody.velocityMovement.dampingPre.multiplyScalar( rigidBody.velocityMovement.options.dampingDecay );
// if this velocity and movement velocity intersecting something, assume a large object with bad angle
@@ -511,15 +519,15 @@
// revert movement pre damping
else {
- rigidBody.velocityMovement.dampingPre.set( 1, 1, 1 );
+ _VectorHelper.clamp_scalar( rigidBody.velocityMovement.dampingPre.addScalar( 1 - rigidBody.velocityMovement.options.dampingDecay ), 0, 1 );
}
}
// if inverted angle is below max
- if ( angleInverted < _RigidBody.collisionAngleThresholdMax ) {
+ if ( angleInverted < velocity.options.collisionAngleThresholdMax ) {
// find axis perpendicular to normal of intersected and in general direction of velocity
@@ -580,7 +588,7 @@
velocity.obstacle = obstacle;
- obstacle.affect( mesh );
+ obstacle.affect( mesh, { velocity: velocity } );
}
@@ -592,12 +600,11 @@
if ( angleFixCollisionQ instanceof THREE.Quaternion !== true ) {
- rigidBody.velocityMovement.dampingPre.set( 1, 1, 1 );
+ _VectorHelper.clamp_scalar( rigidBody.velocityMovement.dampingPre.addScalar( 1 - rigidBody.velocityMovement.options.dampingDecay ), 0, 1 );
}
}
-
// sliding
if ( angleFixCollisionQ instanceof THREE.Quaternion && intersectionDouble !== true && !intersectionAlt ) {
@@ -615,7 +622,7 @@
if ( clear === true ) {
- velocity.reset();
+ velocity.clear();
}
else {
View
296 src/web/js/kaiopua/physics/RigidBody.js
@@ -11,6 +11,7 @@
var shared = main.shared = main.shared || {},
assetPath = "js/kaiopua/physics/RigidBody.js",
_RigidBody = {},
+ _Velocity,
_VectorHelper,
_RayHelper,
_ObjectHelper,
@@ -26,6 +27,7 @@
main.asset_register( assetPath, {
data: _RigidBody,
requirements: [
+ "js/kaiopua/physics/Velocity.js",
"js/kaiopua/utils/VectorHelper.js",
"js/kaiopua/utils/RayHelper.js",
"js/kaiopua/utils/ObjectHelper.js",
@@ -41,19 +43,17 @@
=====================================================*/
- function init_internal ( vh, rh, oh, sh ) {
+ function init_internal ( vel, vh, rh, oh, sh ) {
console.log('internal Rigid Body', _RigidBody);
+ _Velocity = vel;
_VectorHelper = vh;
_RayHelper = rh;
_ObjectHelper = oh;
_SceneHelper = sh;
// properties
- _RigidBody.damping = 0.97;
- _RigidBody.dampingDecay = 0.95;
_RigidBody.offsetPct = 0.4;
- _RigidBody.collisionAngleThresholdMax = Math.PI * 0.5;
_RigidBody.gravityCollisionAngleThreshold = Math.PI * 0.3;
_RigidBody.lerpDelta = 0.1;
_RigidBody.lerpDeltaGravityChange = 0;
@@ -66,6 +66,10 @@
_RigidBody.gravityBodyChangeForceMod = 0.5;
_RigidBody.gravityBodyChangeMagnitude = new THREE.Vector3( 0, -0.1, 0 );
+ // functions
+
+ _RigidBody.extract_parent_gravity_body = extract_parent_gravity_body;
+
// instance
_RigidBody.Instance = RigidBody;
@@ -90,6 +94,10 @@
get : function () { return this.velocityGravity.sliding }
});
+ Object.defineProperty( _RigidBody.Instance.prototype, 'collisions', {
+ get : function () { return { gravity: this.velocityGravity.collision, movement: this.velocityMovement.collision } }
+ });
+
Object.defineProperty( _RigidBody.Instance.prototype, 'radiusGravity', {
get : function () {
@@ -153,8 +161,6 @@
this.utilVec36GravityBody = new THREE.Vector3();
this.utilVec31Bounds = new THREE.Vector3();
this.utilQ1Bounds = new THREE.Quaternion();
- this.utilQ1Relative= new THREE.Quaternion();
- this.utilMat41Relative = new THREE.Matrix4();
// handle parameters
@@ -344,32 +350,36 @@
offsetPct = parameters.offsetPct || _RigidBody.offsetPct;
- this.velocityMovement = new VelocityTracker( {
+ this.velocityMovement = new _Velocity.Instance( {
rigidBody: this,
- forceLengthMax: parameters.movementForceLengthMax,
- damping: parameters.movementDamping,
- dampingDecay: parameters.movementDampingDecay,
- collisionAngleThreshold: parameters.movementCollisionAngleThreshold,
relativeTo: this.mesh,
offsets: parameters.movementOffsets || [
new THREE.Vector3( -width * offsetPct, 0, 0 ), // left waist side
new THREE.Vector3( width * offsetPct, 0, 0 ), // right waist side
new THREE.Vector3( 0, height * offsetPct, 0 ) // near head
- ]
+ ],
+ options: {
+ damping: parameters.movementDamping,
+ dampingDecay: parameters.movementDampingDecay,
+ collisionAngleThreshold: parameters.movementCollisionAngleThreshold,
+ forceLengthMax: parameters.movementForceLengthMax
+ }
} );
- this.velocityGravity = new VelocityTracker( {
+ this.velocityGravity = new _Velocity.Instance( {
rigidBody: this,
- forceLengthMax: parameters.gravityForceLengthMax,
- damping: parameters.gravityDamping,
- dampingDecay: parameters.gravityDampingDecay,
- collisionAngleThreshold: parameters.gravityCollisionAngleThreshold || _RigidBody.gravityCollisionAngleThreshold,
offsets: parameters.gravityOffsets || [
new THREE.Vector3( -width * offsetPct, 0, -depth * offsetPct ),
new THREE.Vector3( width * offsetPct, 0, -depth * offsetPct ),
new THREE.Vector3( width * offsetPct, 0, depth * offsetPct ),
new THREE.Vector3( -width * offsetPct, 0, depth * offsetPct )
- ]
+ ],
+ options: {
+ damping: parameters.gravityDamping,
+ dampingDecay: parameters.gravityDampingDecay,
+ collisionAngleThreshold: parameters.gravityCollisionAngleThreshold || _RigidBody.gravityCollisionAngleThreshold,
+ forceLengthMax: parameters.gravityForceLengthMax
+ }
} );
// safety net
@@ -423,200 +433,6 @@
/*===================================================
- velocity
-
- =====================================================*/
-
- function VelocityTracker ( parameters ) {
-
- var i, l,
- offsets,
- offset;
-
- // handle parameters
-
- parameters = parameters || {};
-
- parameters.damping = parameters.damping || _RigidBody.damping;
-
- // properties
-
- this.rigidBody = parameters.rigidBody;
- this.force = new THREE.Vector3();
- this.forceRotated = new THREE.Vector3();
- this.forceApplied = new THREE.Vector3();
- this.forceRecentMax = new THREE.Vector3();
- this.forceDelta = new THREE.Vector3();
- this.forceLengthMax = parameters.forceLengthMax || Number.MAX_VALUE;
- this.speedDelta = new THREE.Vector3( 1, 1, 1 );
- this.damping = new THREE.Vector3( 1, 1, 1 );
- this.dampingPre = new THREE.Vector3( 1, 1, 1 );
- this.dampingDecay = parameters.dampingDecay || _RigidBody.dampingDecay;
- this.offsets = [];
- this.offsetsRotated = [];
- this.collisionAngleThreshold = Math.min( parameters.collisionAngleThreshold || _RigidBody.collisionAngleThresholdMax, _RigidBody.collisionAngleThresholdMax );
- this.relativeTo = parameters.relativeTo;
- this.relativeToQ = new THREE.Quaternion();
- this.rotatedRelativeTo = [];
- this.up = shared.cardinalAxes.up.clone();
- this.moving = this.intersection = this.collision = this.sliding = false;
- this.timeWithoutIntersection = 0;
-
- if ( parameters.damping instanceof THREE.Vector3 ) {
-
- this.damping.copy( parameters.damping );
-
- }
- else {
-
- this.damping.multiplyScalar( main.is_number( parameters.damping ) ? parameters.damping : _RigidBody.damping );
-
- }
-
- offsets = parameters.offsets;
-
- if ( offsets && offsets.length > 0 ) {
-
- for ( i = 0, l = offsets.length; i < l; i++ ) {
-
- offset = offsets[ i ];
-
- if ( offset instanceof THREE.Vector3 ) {
-
- this.offsets.push( offset.clone() );
-
- }
-
- }
-
- }
- else {
-
- this.offsets.push( new THREE.Vector3() );<