Browse Source

changed the behavior tutorial to include its own copy of aquarium.cs (less coupling)
changed AquariumToy to get back its copy of aquarium.cs, which was moved to TropicalAssets experimentally.

Charlie Patterson 12 years ago
parent
commit
f540661

+ 3 - 7
modules/AquariumToy/1/main.cs

@@ -22,6 +22,7 @@
 
 function AquariumToy::create( %this )
 {
+    exec("./scripts/aquarium.cs");
     exec("./scripts/fish.cs");
 
     // Configure settings.
@@ -29,14 +30,9 @@ function AquariumToy::create( %this )
     AquariumToy.currentFish = 0;
     AquariumToy.selectedAnimation = "TropicalAssets:angelfish1Anim";
     
-    // Set all the fish scene-layers to sort in "batch" mode
+    // Set the fish scene-layer to sort in "batch" mode
     // so that all the fish will be sorted into a batchable order to reduce draw calls.
-    SandboxScene.setLayerSortMode( 0, batch );
-    SandboxScene.setLayerSortMode( 1, batch );
-    SandboxScene.setLayerSortMode( 2, batch );
-    SandboxScene.setLayerSortMode( 3, batch );
-    SandboxScene.setLayerSortMode( 4, batch );
-    SandboxScene.setLayerSortMode( 5, batch );
+    SandboxScene.setLayerSortMode( 15, batch );
     
     addNumericOption("Max Fish", 1, 50, 1, "setMaxFish", %this.maxFish, true, "Sets the maximum number of fish to be created.");
     addSelectionOption(getFishAnimationList(), "Fish Animation", 5, "setSelectedAnimation", false, "Selects the fish animation that can be spawned manually.");

+ 27 - 88
modules/TropicalAssets/1/scripts/aquarium.cs → modules/AquariumToy/1/scripts/aquarium.cs

@@ -66,8 +66,8 @@ function getFishSize(%anim)
 function buildAquarium(%scene)
 {
     // A pre-built aquarium of size 100x75, with blue water, some haze, and some nice rocks.
-    // Triggers will be provide around the edges, kind of like an electric fence,
-    // with a call to addAquariumBoundaries.
+    // Triggers will be provide around the edges to let the developer know when objects in the
+    // aquarium have reached the edges.
 
     // Background
     %background = new Sprite();
@@ -107,105 +107,44 @@ function buildAquarium(%scene)
     addAquariumBoundaries( %scene, 100, 75 );
 }
 
+//-----------------------------------------------------------------------------
+
 function addAquariumBoundaries(%scene, %width, %height)
 {
     // add boundaries on all sides of the aquarium a bit outside of the border of the tank.
-    // The triggers allow for onCollision to be sent to any fish or other object that touch the edges.
+    // The triggers allow for onCollision to be sent to any fish or other object that touches the edges.
     // The triggers are far enough outside the tank so that objects will most likely be just out of view
-    // before they are sent the onCollision callback.  This will they can adjust "off stage".
+    // before they are sent the onCollision callback.  This way will they can adjust "off stage".
 
     // Calculate a width and height to use for the bounds.
     // They should be bigger than the aquarium itself.
     %wrapWidth = %width * 1.5;
     %wrapHeight = %height * 1.5;
 
-    // Left trigger
-    %leftTrigger = new SceneObject() { class = "AquariumBoundary"; };
-    
-    %leftTrigger.side = "left";
-    // make the bound as tall as the tank
-    %leftTrigger.setSize( 5, %wrapHeight );
-    // put the bounds 50% further out than the edge of the tank
-    %leftTrigger.setPosition( -%wrapWidth/2, 0 );
-    %leftTrigger.setSceneLayer( 1 );
-    %leftTrigger.createPolygonBoxCollisionShape( 5, %wrapHeight );
-    %leftTrigger.setDefaultDensity( 1 );
-    %leftTrigger.setDefaultFriction( 1.0 );        
-    %leftTrigger.setAwake( true );
-    %leftTrigger.setActive( true );
-    // the objects that collide with us should handle any callbacks.
-    // remember to set those scene objects to collide with scene group 15 (which is our group)!
-    %leftTrigger.setSceneGroup( 15 );
-    %leftTrigger.setCollisionCallback(false);
-    %leftTrigger.setBodyType( "static" );
-    %leftTrigger.setCollisionShapeIsSensor(0, true);
-    %scene.add( %leftTrigger );
-    
-    // Right trigger
-    %rightTrigger = new SceneObject() { class = "AquariumBoundary"; };
-    
-    // make the bound as tall as the tank
-    %rightTrigger.setSize( 5, %wrapHeight );
-    %rightTrigger.side = "right";
-    // put the bounds 50% further out than the edge of the tank
-    %rightTrigger.setPosition( %wrapWidth/2, 0 );
-    %rightTrigger.setSceneLayer( 1 );
-    %rightTrigger.createPolygonBoxCollisionShape( 5, %wrapHeight );
-    %rightTrigger.setDefaultDensity( 1 );
-    %rightTrigger.setDefaultFriction( 1.0 );    
-    %rightTrigger.setAwake( true );
-    %rightTrigger.setActive( true );
-    // the objects that collide with us should handle any callbacks.
-    // remember to set those scene objects to collide with scene group 15 (which is our group)!
-    %rightTrigger.setSceneGroup( 15 );
-    %rightTrigger.setCollisionCallback(false);
-    %rightTrigger.setBodyType( "static" );
-    %rightTrigger.setCollisionShapeIsSensor(0, true);
-    %scene.add( %rightTrigger );    
-
-    // Left trigger
-    %topTrigger = new SceneObject() { class = "AquariumBoundary"; };
-    
-    %topTrigger.side = "top";
-    // make the bound as wide as the tank
-    %topTrigger.setSize( %wrapWidth, 5 );
-    // put the bounds 50% further out than the edge of the tank
-    %topTrigger.setPosition( 0, -%wrapHeight/2 );
-    %topTrigger.setSceneLayer( 1 );
-    %topTrigger.createPolygonBoxCollisionShape( %wrapWidth, 5 );
-    %topTrigger.setDefaultDensity( 1 );
-    %topTrigger.setDefaultFriction( 1.0 );        
-    %topTrigger.setAwake( true );
-    %topTrigger.setActive( true );
-    // the objects that collide with us should handle any callbacks.
-    // remember to set those scene objects to collide with scene group 15 (which is our group)!
-    %topTrigger.setSceneGroup( 15 );
-    %topTrigger.setCollisionCallback(false);
-    %topTrigger.setBodyType( "static" );
-    %topTrigger.setCollisionShapeIsSensor(0, true);
-    %scene.add( %topTrigger );
-    
-    // Right trigger
-    %bottomTrigger = new SceneObject() { class = "AquariumBoundary"; };
+    %scene.add( createOneAquariumBoundary( "left",   -%wrapWidth/2 SPC 0,  5 SPC %wrapHeight) );
+    %scene.add( createOneAquariumBoundary( "right",  %wrapWidth/2 SPC 0,   5 SPC %wrapHeight) );
+    %scene.add( createOneAquariumBoundary( "top",    0 SPC -%wrapHeight/2, %wrapWidth SPC 5 ) );
+    %scene.add( createOneAquariumBoundary( "bottom", 0 SPC %wrapHeight/2,  %wrapWidth SPC 5 ) );
+}
+
+//-----------------------------------------------------------------------------
+
+function createOneAquariumBoundary(%side, %position, %size)
+{
+    %boundary = new SceneObject() { class = "AquariumBoundary"; };
     
-    // make the bound as wide as the tank
-    %bottomTrigger.setSize( %wrapWidth, 5 );
-    %bottomTrigger.side = "bottom";
-    // put the bounds 50% further out than the edge of the tank
-    %bottomTrigger.setPosition( 0, %wrapHeight/2 );
-    %bottomTrigger.setSceneLayer( 1 );
-    %bottomTrigger.createPolygonBoxCollisionShape( %wrapWidth, 5 );
-    %bottomTrigger.setDefaultDensity( 1 );
-    %bottomTrigger.setDefaultFriction( 1.0 );    
-    %bottomTrigger.setAwake( true );
-    %bottomTrigger.setActive( true );
+    %boundary.setSize( %size );
+    %boundary.side = %side;
+    %boundary.setPosition( %position );
+    %boundary.setSceneLayer( 1 );
+    %boundary.createPolygonBoxCollisionShape( %size );
     // the objects that collide with us should handle any callbacks.
     // remember to set those scene objects to collide with scene group 15 (which is our group)!
-    %bottomTrigger.setSceneGroup( 15 );
-    %bottomTrigger.setCollisionCallback(false);
-    %bottomTrigger.setBodyType( "static" );
-    %bottomTrigger.setCollisionShapeIsSensor(0, true);
-    %scene.add( %bottomTrigger );
+    %boundary.setSceneGroup( 15 );
+    %boundary.setCollisionCallback(false);
+    %boundary.setBodyType( "static" );
+    %boundary.setCollisionShapeIsSensor(0, true);
+    return %boundary;
 }
 
 //-----------------------------------------------------------------------------

+ 0 - 32
modules/TropicalAssets/1/main.cs

@@ -1,32 +0,0 @@
-//-----------------------------------------------------------------------------
-// Copyright (c) 2013 GarageGames, LLC
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to
-// deal in the Software without restriction, including without limitation the
-// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-// sell copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//-----------------------------------------------------------------------------
-
-function TropicalAssets::create( %this )
-{
-    exec("./scripts/aquarium.cs");
-}
-
-//-----------------------------------------------------------------------------
-
-function TropicalAssets::destroy( %this )
-{
-}

+ 2 - 4
modules/TropicalAssets/1/module.taml

@@ -1,10 +1,8 @@
 <ModuleDefinition
 	ModuleId="TropicalAssets"
 	VersionId="1"
-	Description="Tropical Fish Assets.  Particularly useful for the AquariumToy"
-	ScriptFile="main.cs"
-	CreateFunction="create"
-	DestroyFunction="destroy">
+	Description="Tropical Fish Assets.  Particularly useful for the AquariumToy"
+>
 		<DeclaredAssets
 			Path="assets"
 			Extension="asset.taml"

+ 6 - 3
tutorials/fishTutorialBase/modules/DeadlyReef/main.cs

@@ -43,10 +43,12 @@ function DeadlyReef::create( %this )
 
     // load some scripts and variables
     // exec("./scripts/someScript.cs");
+    exec("./scripts/aquarium.cs");
 
     buildAquarium(mainScene);
     createAquariumEffects(mainScene);
-    DeadlyReef.spawnPlayerFish();
+
+    DeadlyReef.spawnPlayerFish();
 }
 
 //-----------------------------------------------------------------------------
@@ -76,7 +78,8 @@ function DeadlyReef::spawnPlayerFish(%this)
     };
 
     %fish.createPolygonBoxCollisionShape(%size);
+    %fish.setCollisionShapeIsSensor(0, true);
     %fish.setCollisionGroups( "15" );
-    %fish.FixedAngle = true;
-    mainScene.add( %fish ); 
+
+    mainScene.add( %fish ); 
 }

+ 174 - 0
tutorials/fishTutorialBase/modules/DeadlyReef/scripts/aquarium.cs

@@ -0,0 +1,174 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+function getFishAnimationList()
+{
+   %list = "TropicalAssets:angelfish1Anim" @ "," @ "TropicalAssets:angelfish2Anim" @ "," @ "TropicalAssets:butterflyfishAnim";
+   %list = %list @ "," @ "TropicalAssets:pufferfishAnim" @ "," @ "TropicalAssets:rockfishAnim" @ "," @ "TropicalAssets:seahorseAnim";
+   %list = %list @ "," @ "TropicalAssets:triggerfish1Anim" @ "," @ "TropicalAssets:eelAnim";
+}
+
+//-----------------------------------------------------------------------------
+
+function getFishSize(%anim)
+{
+    switch$(%anim)
+    {
+        case "TropicalAssets:angelfish1Anim":
+        %fishInfo = "15 15";
+
+        case "TropicalAssets:angelfish2Anim":
+        %fishInfo = "15 15";
+        
+        case "TropicalAssets:butterflyfishAnim":
+        %fishInfo = "15 15";
+        
+        case "TropicalAssets:pufferfishAnim":
+        %fishInfo = "15 15";
+        
+        case "TropicalAssets:rockfishAnim":
+        %fishInfo = "15 7.5";
+        
+        case "TropicalAssets:seahorseAnim":
+        %fishInfo = "7.5 15";
+        
+        case "TropicalAssets:triggerfish1Anim":
+        %fishInfo = "15 15";
+
+        case "TropicalAssets:eelAnim":
+        %fishInfo = "7.5 3.75";
+    }
+
+    return %fishInfo;
+}
+
+//-----------------------------------------------------------------------------
+
+function buildAquarium(%scene)
+{
+    // A pre-built aquarium of size 100x75, with blue water, some haze, and some nice rocks.
+    // Triggers will be provide around the edges to let the developer know when objects in the
+    // aquarium have reached the edges.
+
+    // Background
+    %background = new Sprite();
+    %background.setBodyType( "static" );
+    %background.setImage( "TropicalAssets:background" );
+    %background.setSize( 100, 75 );
+    %background.setCollisionSuppress();
+    %background.setAwake( false );
+    %background.setActive( false );
+    %background.setSceneLayer(30);
+    %scene.add( %background );
+    
+    // Far rocks
+    %farRocks = new Sprite();
+    %farRocks.setBodyType( "static" );
+    %farRocks.setPosition( 0, -7.5 );
+    %farRocks.setImage( "TropicalAssets:rocksfar" );
+    %farRocks.setSize( 100, 75 );
+    %farRocks.setCollisionSuppress();
+    %farRocks.setAwake( false );
+    %farRocks.setActive( false );
+    %farRocks.setSceneLayer(20);
+    %scene.add( %farRocks );
+    
+    // Near rocks
+    %nearRocks = new Sprite();
+    %nearRocks.setBodyType( "static" );
+    %nearRocks.setPosition( 0, -8.5 );
+    %nearRocks.setImage( "TropicalAssets:rocksnear" );
+    %nearRocks.setSize( 100, 75 );
+    %nearRocks.setCollisionSuppress();
+    %nearRocks.setAwake( false );
+    %nearRocks.setActive( false );
+    %nearRocks.setSceneLayer(10);
+    %scene.add( %nearRocks );
+    
+    addAquariumBoundaries( %scene, 100, 75 );
+}
+
+//-----------------------------------------------------------------------------
+
+function addAquariumBoundaries(%scene, %width, %height)
+{
+    // add boundaries on all sides of the aquarium a bit outside of the border of the tank.
+    // The triggers allow for onCollision to be sent to any fish or other object that touches the edges.
+    // The triggers are far enough outside the tank so that objects will most likely be just out of view
+    // before they are sent the onCollision callback.  This way will they can adjust "off stage".
+
+    // Calculate a width and height to use for the bounds.
+    // They should be bigger than the aquarium itself.
+    %wrapWidth = %width * 1.5;
+    %wrapHeight = %height * 1.5;
+
+    %scene.add( createOneAquariumBoundary( "left",   -%wrapWidth/2 SPC 0,  5 SPC %wrapHeight) );
+    %scene.add( createOneAquariumBoundary( "right",  %wrapWidth/2 SPC 0,   5 SPC %wrapHeight) );
+    %scene.add( createOneAquariumBoundary( "top",    0 SPC -%wrapHeight/2, %wrapWidth SPC 5 ) );
+    %scene.add( createOneAquariumBoundary( "bottom", 0 SPC %wrapHeight/2,  %wrapWidth SPC 5 ) );
+}
+
+//-----------------------------------------------------------------------------
+
+function createOneAquariumBoundary(%side, %position, %size)
+{
+    %boundary = new SceneObject() { class = "AquariumBoundary"; };
+    
+    %boundary.setSize( %size );
+    %boundary.side = %side;
+    %boundary.setPosition( %position );
+    %boundary.setSceneLayer( 1 );
+    %boundary.createPolygonBoxCollisionShape( %size );
+    // the objects that collide with us should handle any callbacks.
+    // remember to set those scene objects to collide with scene group 15 (which is our group)!
+    %boundary.setSceneGroup( 15 );
+    %boundary.setCollisionCallback(false);
+    %boundary.setBodyType( "static" );
+    %boundary.setCollisionShapeIsSensor(0, true);
+    return %boundary;
+}
+
+//-----------------------------------------------------------------------------
+
+function createAquariumEffects(%scene)
+{
+    %obj = new Scroller();
+    %obj.setBodyType( "static" );
+    %obj.setImage( "TropicalAssets:wave" );
+    %obj.setPosition( 0, 0 );
+    %obj.setScrollX(2);
+    %obj.setSize( 100, 75 );
+    %obj.setRepeatX( 0.2 );   
+    %obj.setSceneLayer( 0 );
+    %obj.setSceneGroup( 0 );
+    %obj.setCollisionSuppress();
+    %obj.setAwake( false );
+    %obj.setActive( false );
+    %scene.add( %obj );
+    
+    // Add the caustics particle.
+    %caustics = new ParticlePlayer();
+    %caustics.Particle = "TropicalAssets:Caustics";
+    %scene.add( %caustics ); 
+}
+
+//-----------------------------------------------------------------------------