diff options
author | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-27 23:15:42 +0000 |
---|---|---|
committer | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-27 23:15:42 +0000 |
commit | 05b47f7a8c5451f858dc220df0e3a97542edace6 (patch) | |
tree | a2273d619f0625c9d44d40842845ccce2eac1045 /o3d/samples/io/actors | |
parent | 5cdc8bdb4c847cefe7f4542bd10c9880c2c557a0 (diff) | |
download | chromium_src-05b47f7a8c5451f858dc220df0e3a97542edace6.zip chromium_src-05b47f7a8c5451f858dc220df0e3a97542edace6.tar.gz chromium_src-05b47f7a8c5451f858dc220df0e3a97542edace6.tar.bz2 |
This is the O3D source tree's initial commit to the Chromium tree. It
is not built or referenced at all by the chrome build yet, and doesn't
yet build in it's new home. We'll change that shortly.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/io/actors')
-rw-r--r-- | o3d/samples/io/actors/actor.js | 144 | ||||
-rw-r--r-- | o3d/samples/io/actors/arrow.js | 94 | ||||
-rw-r--r-- | o3d/samples/io/actors/avatar.js | 67 | ||||
-rw-r--r-- | o3d/samples/io/actors/coin.js | 68 | ||||
-rw-r--r-- | o3d/samples/io/actors/horizontalpad.js | 85 | ||||
-rw-r--r-- | o3d/samples/io/actors/mover.js | 48 | ||||
-rw-r--r-- | o3d/samples/io/actors/spikem.js | 126 | ||||
-rw-r--r-- | o3d/samples/io/actors/verticalpad.js | 84 |
8 files changed, 716 insertions, 0 deletions
diff --git a/o3d/samples/io/actors/actor.js b/o3d/samples/io/actors/actor.js new file mode 100644 index 0000000..a0e1e50 --- /dev/null +++ b/o3d/samples/io/actors/actor.js @@ -0,0 +1,144 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @fileoverview This file defines the Actor class. + */ + +/** + * Pulls in all names attributes of a source object and applies them to a + * target object. Handy for pulling in a bunch of name:value pairs that were + * passed all at once. + */ +function Actor() { + // Create some defaults for our "required" attributes. + this.x = 0; + this.y = 0; + this.z = 0; + this.width = 20; + this.height = 20; + this.mapX = 0; + this.platformID = 0; + this.rotZ = 0; + this.frameName = ''; +} + +Actor.prototype.absorbNamedValues = function(initObj) { + for (var key in initObj) { + this[key] = initObj[key]; + } +}; + +/** + * Note that for collision detection, all actors are envisioned as 2d rectangles + * inside a single plane. These rectangles have a width and a height, and their + * "origin" is on the bottom center of the rectangle. So if you create a new + * actor, be sure to give it a reasonable width and height. + */ +Actor.prototype.collidesWith = function(otherActor) { + thisLeft = this.mapX - this.width/2; + thisRight = this.mapX + this.width/2; + thisTop = this.z + this.height; + thisBottom = this.z; + + otherLeft = otherActor.mapX - otherActor.width/2; + otherRight = otherActor.mapX + otherActor.width/2; + otherTop = otherActor.z + otherActor.height; + otherBottom = otherActor.z; + + // First see if we're not overlapping in any dimension. + if (thisRight < otherLeft || + thisLeft > otherRight || + thisBottom > otherTop || + thisTop < otherBottom) { + return false; + } + + // Next check for overlap along X. + if (thisRight >= otherLeft && + thisLeft <= otherRight) { + // then we're still in the running... + } else { + return false; + } + + // Next check for overlap along Y. + if (thisBottom <= otherTop && + thisTop >= otherBottom) { + return true; + } + + // We're not overlapping in Y, so bomb. + return false; +}; + +Actor.prototype.isHitBySword = function() { + var isHit = false; + if (avatar.animation == "Hero_Sword" && avatar.frame > 3) { + avatar.width += 80; + avatar.height += avatar.frame * 5; + if (this.collidesWith(avatar)) { + var isHit = true; + } + avatar.width -= 80; + avatar.height -= avatar.frame * 5; + } + return isHit; +} + +Actor.prototype.isHitByArrow = function() { + var isHit = false; + // TODO: Make this allow multiple arrows, perform better, etc. + if (top.arrowActor != undefined) { + // If we don't have the same "parentPlatform, meaning we're in different + // world path space, then we don't collide. + if (world.platforms[top.arrowActor.platformID].parentID != + world.platforms[this.platformID].parentID) { + return false; + } + if (this.collidesWith(top.arrowActor)) { + var isHit = true; + } + } + return isHit; +} + +Actor.prototype.moveMapX = function(change) { + var platformAngle = world.platforms[this.platformID].rotZ; + this.mapX += change; + this.x += change * Math.cos(platformAngle); + this.y += change * Math.sin(platformAngle); +}; + + + + diff --git a/o3d/samples/io/actors/arrow.js b/o3d/samples/io/actors/arrow.js new file mode 100644 index 0000000..0103b5c --- /dev/null +++ b/o3d/samples/io/actors/arrow.js @@ -0,0 +1,94 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @fileoverview This file defines the Arrow class. + */ + +/** + * An arrow that Io can shoot. + */ +function Arrow(initObj) { + this.absorbNamedValues(initObj); + + // Hide myself by moving way off the screen. + this.z = -10000; + this.mapX = -10000; + this.width = 40; + this.height = 1; + this.velX = 0; + + // Figure out which arrow number I am. + this.arrowNumber = parseInt(initObj.name.substr(initObj.name.length-1,1)); + +} +Arrow.prototype = new Actor; + +Arrow.prototype.onTick = function(timeElapsed) { + if (this.mapX < avatar.mapX-500 || this.mapX > avatar.mapX+500 && + this.z > -10000) { + // then hide ourselves way off screen. + this.mapX = -10000; + this.z = -10000; + updateActor(this); + } else { + // Here's how I move. moveMapX is a handy function that updates both + // my "virtual 2d world" mapX, as well as my literal x + y values + this.moveMapX(this.velX * timeElapsed) + updateActor(this); + } +} + +Arrow.prototype.shoot = function() { + this.x = avatar.x; + this.y = avatar.y; + this.z = avatar.z + 33; // Approximate height of IO's crossbow. + this.platformID = avatar.platformID; + this.parentPlatformID = avatar.parentPlatformID; + this.rotZ = world.platforms[this.platformID].rotZ; + this.mapX = avatar.mapX; + + if (Math.abs(avatar.rotZ - this.rotZ) < Math.PI/2) { + this.velX = 50 * 20; + } else { + this.velX = -50 * 20; + this.rotZ -= Math.PI; + } + soundPlayer.play('sound/arrow.mp3', 100); + updateActor(this); +} + +// TODO: This should be a generic concept, not an arrow-specifc +// thing. +Arrow.prototype.hide = function() { + this.mapX = -10000; +} diff --git a/o3d/samples/io/actors/avatar.js b/o3d/samples/io/actors/avatar.js new file mode 100644 index 0000000..aac4f45e --- /dev/null +++ b/o3d/samples/io/actors/avatar.js @@ -0,0 +1,67 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Our avatar object. Hooray! + */ +function Avatar(initObj) { + this.absorbNamedValues(initObj); + + this.animation = "Hero_Stand" + this.velX = 0; + this.velY = 0; + this.velZ = 0; + this.targetRotZ = 0; // Where we'd like to be facing. + this.targetVelX = 0; // Speed we'd like to be going. + this.swordRate = .5; + + this.width = 30; + this.height = 50; + + this.frame = 1; + this.framesSinceShot = 0; // If > 0, tack a "#1" onto our instance name. + this.isJumping = false; + + // We always start on platform 0 to fix a placement bug. + this.platformID = 0; + this.x = 0; + this.y = 0; + this.mapX = 0; + this.z = 200; + this.parentPlatformID = 0; + +} + +Avatar.prototype = new Actor; + +Avatar.prototype.onTick = function(timeElapsed) { + updateActor(this); +} diff --git a/o3d/samples/io/actors/coin.js b/o3d/samples/io/actors/coin.js new file mode 100644 index 0000000..1124d5e --- /dev/null +++ b/o3d/samples/io/actors/coin.js @@ -0,0 +1,68 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @fileoverview This file defines the Coin class. + */ + +/** + * A Coin to be picked up + */ +function Coin(initObj) { + this.absorbNamedValues(initObj); + this.hasBeenPickedUp = false; + this.width = 14; + this.height = 14; + this.isHidden = false; +} +Coin.prototype = new Actor; + +Coin.prototype.onTick = function(timeElapsed) { + if (this.isHidden == true) { + return; + } else if (this.hasBeenPickedUp == true) { + this.z = (this.z*6 + eyeZ+40)/7; + this.x = (this.x*3 + eyeX)/4; + this.y = (this.y*3 + eyeY)/4; + if (Math.abs(this.z - eyeZ+40) < 1) { + this.isHidden = true; + this.z = -10000; + } + } else { + if (this.collidesWith(avatar)) { + soundPlayer.play('sound/coin_3.mp3', 100, 0, true); + this.hasBeenPickedUp = true; + } + } + this.rotZ += .4 * 20 * timeElapsed; + updateActor(this); +} diff --git a/o3d/samples/io/actors/horizontalpad.js b/o3d/samples/io/actors/horizontalpad.js new file mode 100644 index 0000000..b2e3f85 --- /dev/null +++ b/o3d/samples/io/actors/horizontalpad.js @@ -0,0 +1,85 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @fileoverview This file defines the HorizontalPad class. + */ + +/** + * A Horizontal Floater. + */ +function HorizontalPad(initObj) { + this.absorbNamedValues(initObj); + this.maxSpeed = 4 * 20; + this.moveAmount = 4 * 20; + this.width = 42; + this.height = 1; +} +HorizontalPad.prototype = new Actor; + +HorizontalPad.prototype.onTick = function(timeElapsed) { + // When you attach me to a platform, I make it so nobody + // can stand on it... only me. + world.platforms[this.platformID].isNotSolid = true; + + // I move based off of the platform that I'm on. So get that now. + var myPlatform = world.platforms[this.platformID]; + + // I bounce back and forth between the left and right points on my platform. + if (this.mapX < myPlatform.left.mapX) { + this.moveAmount += 1; + } else if (this.mapX > myPlatform.right.mapX) { + this.moveAmount -= 1; + } else if (this.moveAmount >= 0) { + this.moveAmount = this.maxSpeed; + } else { + this.moveAmount = -this.maxSpeed; + } + + // I match my rotation to that of my platform. + this.rotZ = myPlatform.rotZ; + + // Here's how I move. moveMapX is a handy function that updates both + // my "virtual 2d world" mapX, as well as my literal x + y values + this.moveMapX(this.moveAmount * timeElapsed) + + // If I collide with the avatar, then move the avatar along with me, + // and set his "override" groundZ to be my own Z. + if (this.collidesWith(avatar)) { + if (avatar.velZ <= 0 && avatar.z >= this.z - 25) { + avatar.moveMapX(this.moveAmount * timeElapsed); + avatar.groundZ = this.z; + } + } + + updateActor(this); +} diff --git a/o3d/samples/io/actors/mover.js b/o3d/samples/io/actors/mover.js new file mode 100644 index 0000000..8a36eed --- /dev/null +++ b/o3d/samples/io/actors/mover.js @@ -0,0 +1,48 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @fileoverview This file defines the Mover class. + */ + +/** + * A Horizontal Floater. + */ +function Mover(initObj) { + this.absorbNamedValues(initObj); +} +Mover.prototype = new Actor; + +Mover.prototype.onTick = function(timeElapsed) { + this.z += 1 * 20 * timeElapsed; + updateActor(this); +} diff --git a/o3d/samples/io/actors/spikem.js b/o3d/samples/io/actors/spikem.js new file mode 100644 index 0000000..e056c98 --- /dev/null +++ b/o3d/samples/io/actors/spikem.js @@ -0,0 +1,126 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @fileoverview This file defines the Spikem class. + */ + +/** + * A Horizontal Floater. + */ +function Spikem(initObj) { + this.absorbNamedValues(initObj); + this.width = 24; + this.height = 55; + this.velX = -200; + this.velZ = 0; + this.isDead = false; + this.isHit = false; + this.pauseFrames = 0; + this.frameName = "spinning" +} +Spikem.prototype = new Actor; + +Spikem.prototype.onTick = function(timeElapsed) { + if (this.isDead == true) { + return; + } + + if (this.isHit == true) { + if (this.z < -1000) { + isDead = true; + } else { + this.velX = this.velX*.9; + // Here's how I move. moveMapX is a handy function that updates both + // my "virtual 2d world" mapX, as well as my literal x + y values + this.z -= 20; + this.moveMapX(this.velX * timeElapsed) + } + } else { + // I move based off of the platform that I'm on. So get that now. + var myPlatform = world.platforms[this.platformID]; + + // I stay on my platform + if (this.mapX - this.width/2 < myPlatform.left.mapX + && this.velX < 0) { + this.velX *= -1; + } else if (this.mapX + this.width/2 > myPlatform.right.mapX + && this.velX > 0) { + this.velX *= -1; + } + + this.rotZ += this.velX / 60 * timeElapsed; + + if (Math.abs(this.velX) < .1) { + if (Math.random() > .5) { + this.velX = -400; + } else { + this.velX = 400; + } + this.pauseFrames = Math.random() * 0.5 + 1; + } + + if (this.pauseFrames > 0) { + this.frameName = "spinning" + this.pauseFrames -= timeElapsed; + } else { + this.frameName = "charging" + this.velX = this.velX*.9; + // Here's how I move. moveMapX is a handy function that updates both + // my "virtual 2d world" mapX, as well as my literal x + y values + this.moveMapX(this.velX * timeElapsed) + } + + if (this.isHitBySword()) { + this.isHit = true; + soundPlayer.play('sound/_SMASH.mp3', 100); + this.velX = 0; + } else if (this.isHitByArrow()) { + top.arrowActor.hide(); + this.isHit = true; + soundPlayer.play('sound/_SMASH.mp3', 100); + this.velX = top.arrowActor.velX; + } else if (this.collidesWith(avatar)) { + // Play an event sound @100% volume, 0 repeats + soundPlayer.play('sound/ah.mp3', 100); + + this.velZ = 0; + if (avatar.velX < 1) { + avatar.velX = this.velX * 7; + } else { + avatar.velX = avatar.velX * -7; + } + } + } + + updateActor(this); +} diff --git a/o3d/samples/io/actors/verticalpad.js b/o3d/samples/io/actors/verticalpad.js new file mode 100644 index 0000000..fd90425 --- /dev/null +++ b/o3d/samples/io/actors/verticalpad.js @@ -0,0 +1,84 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @fileoverview This file defines the VerticalPad class. + */ + +/** + * A Vertical Pad you can run on. These things oscillate between their starting + * position and a z of 350" + */ +function VerticalPad(initObj) { + this.absorbNamedValues(initObj); + this.maxSpeed = 4 * 20; + this.moveAmount = 4 * 20; + this.bottomZ = this.z; + this.topZ = 350; + this.width = 42; + this.height = 10; +} +VerticalPad.prototype = new Actor; + +VerticalPad.prototype.onTick = function(timeElapsed) { + // I bounce back and forth between the left and right points on my platform. + if (this.z < this.bottomZ) { + this.moveAmount += 1; + } else if (this.z > this.topZ) { + this.moveAmount -= 1; + } else if (this.moveAmount >= 0) { + this.moveAmount = this.maxSpeed; + } else { + this.moveAmount = -this.maxSpeed; + } + + // I match my rotation to that of my platform. + var myPlatform = world.platforms[this.platformID]; + this.rotZ = myPlatform.rotZ; + + + this.z += this.moveAmount * timeElapsed; + + // If I collide with the avatar, then move the avatar along with me, + // and set his "override" groundZ to be my own Z. + if (this.collidesWith(avatar)) { + if (avatar.velZ <= 0 && avatar.z >= this.z - 45) { + avatar.z = this.z + if (this.moveAmount < 0) { + avatar.z += this.moveAmount * timeElapsed; + } + avatar.groundZ = avatar.z; + } + } + + updateActor(this); +} |