| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588 |
- function CPin(iXPos, iYPos, oSprite, oPhysics, oParentContainer) {
- var _pStartPos;
- var _oPin;
- var _oParentContainer;
- var _oPhysics;
- var _oReflection;
- var _oContainer;
- var _fStartShadowPos = null;
- var _fScale = 190;
- var _oPosRefCast;
- var _oTween = null;
- var _oAngles;
- var _iStartRefRegY;
- var _bDown = false;
- var _bPlayedSound = false;
- this._init = function (iXPos, iYPos, oSprite) {
- _oContainer = new createjs.Container();
- _oParentContainer.addChild(_oContainer);
- _oPin = this.createPin(iXPos, iYPos, oSprite);
- _oReflection = this.createPin(iXPos, iYPos, oSprite);
- _oReflection.scaleY = -1;
- _iStartRefRegY = _oReflection.regY += PIN_REF_REGY_FACTOR + 0.5;
- this.scale(_fScale);
- _oAngles = new CANNON.Vec3();
- _oContainer.addChild(_oReflection, _oPin);
- };
- this.createPin = function () {
- var oPin;
- var oData = {
- images: [oSprite],
- // width, height & registration point of each sprite
- frames: {width: oSprite.width / 10, height: oSprite.height / 8, regX: (oSprite.width / 10) / 2, regY: (oSprite.height / 8) / 2}
- };
- var oSpriteSheet = new createjs.SpriteSheet(oData);
- oPin = createSprite(oSpriteSheet, 0, (oSprite.width / 10) / 2, (oSprite.height / 8) / 2, oSprite.width / 10, oSprite.height / 8);
- oPin.stop();
- oPin.x = iXPos;
- oPin.y = iYPos;
- return oPin;
- };
- this.setStartPos = function (iX, iY) {
- _pStartPos = {x: iX, y: iY};
- };
- this.getStartPos = function () {
- return _pStartPos;
- };
- this.resetState = function () {
- _oPin.gotoAndStop(0);
- this.setPosition(_pStartPos.x, _pStartPos.y);
- _oContainer.alpha = 1;
- };
- this.isDownYet = function () {
- return _bDown;
- };
- this.setDown = function (bVal) {
- _bDown = bVal;
- if (bVal) {
- createjs.Tween.get(this).wait(750).call(function () {
- s_oScenario.setElementVelocity(_oPhysics, {x: 0, y: 0, z: 0});
- });
- }
- };
- this.animReposition = function (iY, fAlpha) {
- createjs.Tween.get(_oPin).to({y: iY}, 500);
- createjs.Tween.get(_oReflection).wait(250).to({alpha: fAlpha}, 200);
- };
- this.animTake = function (iY) {
- createjs.Tween.get(_oPin).to({y: iY}, 500).call(function () {
- _oContainer.visible = false;
- });
- createjs.Tween.get(_oReflection).to({alpha: 0}, 200);
- };
- this.unload = function () {
- _oParentContainer.removeChild(_oContainer);
- };
- this.startPosShadowY = function (fYPos) {
- _fStartShadowPos = fYPos;
- };
- this.getStartShadowYPos = function () {
- return _fStartShadowPos;
- };
- this.tweenFade = function (fVal, iTime, iWait) {
- _oTween = createjs.Tween.get(_oContainer).wait(iWait).to({alpha: fVal}, iTime).call(function () {
- _oTween = null;
- });
- };
- this.playAudio = function () {
- if (_bPlayedSound) {
- return;
- }
- playSound("pin_hitted", 1, false);
- _bPlayedSound = true;
- };
- this.setPlayedSound = function (bVal) {
- _bPlayedSound = bVal;
- };
- this.pinRotation = function () {
- _oPhysics.quaternion.y = 0;
- _oPhysics.quaternion.toEuler(_oAngles);
- _oPhysics.shapes[0].getAveragePointLocal(_oAngles);
- _oAngles.x = Math.round(Math.degrees(_oAngles.x * 2));
- _oAngles.y = Math.round(Math.degrees(_oAngles.y * 2));
- _oAngles.z = Math.round(Math.degrees(_oAngles.z * 2));
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(0);
- _oReflection.gotoAndStop(0);
- } else if (_oAngles.y <= 9 && _oAngles.y > 7 || _oAngles.y > -9 && _oAngles.y < -7) {
- if (_oAngles.x >= -2 && _oAngles.x <= 3) {
- _oPin.gotoAndStop(29);
- } else if (_oAngles.x >= 4 && _oAngles.x <= 7) {
- _oPin.gotoAndStop(19);
- } else if (_oAngles.x >= 8 && _oAngles.x <= 12) {
- _oPin.gotoAndStop(9);
- } else if (_oAngles.x >= 13 && _oAngles.x <= 15) {
- _oPin.gotoAndStop(79);
- } else if (_oAngles.x >= 16 && _oAngles.x <= 18 || _oAngles.x <= -16 && _oAngles.x >= -18) {
- _oPin.gotoAndStop(69);
- } else if (_oAngles.x >= -15 && _oAngles.x <= -12) {
- _oPin.gotoAndStop(59);
- } else if (_oAngles.x >= -11 && _oAngles.x <= -6) {
- _oPin.gotoAndStop(49);
- } else if (_oAngles.x >= -5 && _oAngles.x <= -2) {
- _oPin.gotoAndStop(39);
- }
- } else if (_oAngles.z >= -3 && _oAngles.z <= 3) {
- if (_oAngles.y >= -8 && _oAngles.y <= 8) {
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(0);
- } else if (_oAngles.x === 1) {
- _oPin.gotoAndStop(1);
- } else if (_oAngles.x === 2) {
- _oPin.gotoAndStop(2);
- } else if (_oAngles.x === 3) {
- _oPin.gotoAndStop(3);
- } else if (_oAngles.x === 4) {
- _oPin.gotoAndStop(4);
- } else if (_oAngles.x === 5) {
- _oPin.gotoAndStop(5);
- } else if (_oAngles.x === 6) {
- _oPin.gotoAndStop(6);
- } else if (_oAngles.x === 7) {
- _oPin.gotoAndStop(7);
- } else if (_oAngles.x === 8) {
- _oPin.gotoAndStop(8);
- } else if (_oAngles.x === 9) {
- _oPin.gotoAndStop(9);
- } else if (_oAngles.x === -1) {
- _oPin.gotoAndStop(41);
- } else if (_oAngles.x === -2) {
- _oPin.gotoAndStop(42);
- } else if (_oAngles.x === -3) {
- _oPin.gotoAndStop(43);
- } else if (_oAngles.x === -4) {
- _oPin.gotoAndStop(44);
- } else if (_oAngles.x === -5) {
- _oPin.gotoAndStop(45);
- } else if (_oAngles.x === -6) {
- _oPin.gotoAndStop(46);
- } else if (_oAngles.x === -7) {
- _oPin.gotoAndStop(47);
- } else if (_oAngles.x === -8) {
- _oPin.gotoAndStop(48);
- } else if (_oAngles.x === -9) {
- _oPin.gotoAndStop(49);
- }
- } else if (_oAngles.y <= -8 && _oAngles.y >= -18 || _oAngles.y <= 18 && _oAngles.y >= 11) {
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(0);
- } else if (_oAngles.x === 1) {
- _oPin.gotoAndStop(41);
- } else if (_oAngles.x === 2) {
- _oPin.gotoAndStop(42);
- } else if (_oAngles.x === 3) {
- _oPin.gotoAndStop(43);
- } else if (_oAngles.x === 4) {
- _oPin.gotoAndStop(44);
- } else if (_oAngles.x === 5) {
- _oPin.gotoAndStop(45);
- } else if (_oAngles.x === 6) {
- _oPin.gotoAndStop(46);
- } else if (_oAngles.x === 7) {
- _oPin.gotoAndStop(47);
- } else if (_oAngles.x === 8) {
- _oPin.gotoAndStop(48);
- } else if (_oAngles.x === 9) {
- _oPin.gotoAndStop(49);
- } else if (_oAngles.x === -1) {
- _oPin.gotoAndStop(1);
- } else if (_oAngles.x === -2) {
- _oPin.gotoAndStop(2);
- } else if (_oAngles.x === -3) {
- _oPin.gotoAndStop(3);
- } else if (_oAngles.x === -4) {
- _oPin.gotoAndStop(4);
- } else if (_oAngles.x === -5) {
- _oPin.gotoAndStop(5);
- } else if (_oAngles.x === -6) {
- _oPin.gotoAndStop(6);
- } else if (_oAngles.x === -7) {
- _oPin.gotoAndStop(7);
- } else if (_oAngles.x === -8) {
- _oPin.gotoAndStop(8);
- } else if (_oAngles.x === -9) {
- _oPin.gotoAndStop(9);
- }
- }
- } else if (_oAngles.z >= 4 && _oAngles.z <= 7) {
-
- if (_oAngles.y >= -8 && _oAngles.y <= 8) {
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(10);
- } else if (_oAngles.x === 1) {
- _oPin.gotoAndStop(11);
- } else if (_oAngles.x === 2) {
- _oPin.gotoAndStop(12);
- } else if (_oAngles.x === 3) {
- _oPin.gotoAndStop(13);
- } else if (_oAngles.x === 4) {
- _oPin.gotoAndStop(14);
- } else if (_oAngles.x === 5) {
- _oPin.gotoAndStop(15);
- } else if (_oAngles.x === 6) {
- _oPin.gotoAndStop(16);
- } else if (_oAngles.x === 7) {
- _oPin.gotoAndStop(17);
- } else if (_oAngles.x === 8) {
- _oPin.gotoAndStop(18);
- } else if (_oAngles.x === 9) {
- _oPin.gotoAndStop(19);
- } else if (_oAngles.x === -1) {
- _oPin.gotoAndStop(51);
- } else if (_oAngles.x === -2) {
- _oPin.gotoAndStop(52);
- } else if (_oAngles.x === -3) {
- _oPin.gotoAndStop(53);
- } else if (_oAngles.x === -4) {
- _oPin.gotoAndStop(54);
- } else if (_oAngles.x === -5) {
- _oPin.gotoAndStop(55);
- } else if (_oAngles.x === -6) {
- _oPin.gotoAndStop(56);
- } else if (_oAngles.x === -7) {
- _oPin.gotoAndStop(57);
- } else if (_oAngles.x === -8) {
- _oPin.gotoAndStop(58);
- } else if (_oAngles.x === -9) {
- _oPin.gotoAndStop(59);
- }
- } else if (_oAngles.y <= -8 && _oAngles.y >= -18 || _oAngles.y <= 18 && _oAngles.y >= 10) {
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(0);
- } else if (_oAngles.x === 1) {
- _oPin.gotoAndStop(31);
- } else if (_oAngles.x === 2) {
- _oPin.gotoAndStop(32);
- } else if (_oAngles.x === 3) {
- _oPin.gotoAndStop(33);
- } else if (_oAngles.x === 4) {
- _oPin.gotoAndStop(34);
- } else if (_oAngles.x === 5) {
- _oPin.gotoAndStop(35);
- } else if (_oAngles.x === 6) {
- _oPin.gotoAndStop(36);
- } else if (_oAngles.x === 7) {
- _oPin.gotoAndStop(37);
- } else if (_oAngles.x === 8) {
- _oPin.gotoAndStop(38);
- } else if (_oAngles.x === 9) {
- _oPin.gotoAndStop(39);
- } else if (_oAngles.x === -1) {
- _oPin.gotoAndStop(71);
- } else if (_oAngles.x === -2) {
- _oPin.gotoAndStop(72);
- } else if (_oAngles.x === -3) {
- _oPin.gotoAndStop(73);
- } else if (_oAngles.x === -4) {
- _oPin.gotoAndStop(74);
- } else if (_oAngles.x === -5) {
- _oPin.gotoAndStop(75);
- } else if (_oAngles.x === -6) {
- _oPin.gotoAndStop(76);
- } else if (_oAngles.x === -7) {
- _oPin.gotoAndStop(77);
- } else if (_oAngles.x === -8) {
- _oPin.gotoAndStop(78);
- } else if (_oAngles.x === -9) {
- _oPin.gotoAndStop(79);
- }
- }
- } else if (_oAngles.z >= 8 && _oAngles.z <= 10) {
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(20);
- } else if (_oAngles.x === 1) {
- _oPin.gotoAndStop(21);
- } else if (_oAngles.x === 2) {
- _oPin.gotoAndStop(22);
- } else if (_oAngles.x === 3) {
- _oPin.gotoAndStop(23);
- } else if (_oAngles.x === 4) {
- _oPin.gotoAndStop(24);
- } else if (_oAngles.x === 5) {
- _oPin.gotoAndStop(25);
- } else if (_oAngles.x === 6) {
- _oPin.gotoAndStop(26);
- } else if (_oAngles.x === 7) {
- _oPin.gotoAndStop(27);
- } else if (_oAngles.x === 8) {
- _oPin.gotoAndStop(28);
- } else if (_oAngles.x === 9) {
- _oPin.gotoAndStop(29);
- } else if (_oAngles.x === -1) {
- _oPin.gotoAndStop(61);
- } else if (_oAngles.x === -2) {
- _oPin.gotoAndStop(62);
- } else if (_oAngles.x === -3) {
- _oPin.gotoAndStop(63);
- } else if (_oAngles.x === -4) {
- _oPin.gotoAndStop(64);
- } else if (_oAngles.x === -5) {
- _oPin.gotoAndStop(65);
- } else if (_oAngles.x === -6) {
- _oPin.gotoAndStop(66);
- } else if (_oAngles.x === -7) {
- _oPin.gotoAndStop(67);
- } else if (_oAngles.x === -8) {
- _oPin.gotoAndStop(68);
- } else if (_oAngles.x === -9) {
- _oPin.gotoAndStop(69);
- }
- } else if (_oAngles.z <= -4 && _oAngles.z >= -7) {
- if (_oAngles.y >= -10 && _oAngles.y <= 10) {
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(70);
- } else if (_oAngles.x === 1) {
- _oPin.gotoAndStop(71);
- } else if (_oAngles.x === 2) {
- _oPin.gotoAndStop(72);
- } else if (_oAngles.x === 3) {
- _oPin.gotoAndStop(73);
- } else if (_oAngles.x === 4) {
- _oPin.gotoAndStop(74);
- } else if (_oAngles.x === 5) {
- _oPin.gotoAndStop(75);
- } else if (_oAngles.x === 6) {
- _oPin.gotoAndStop(76);
- } else if (_oAngles.x === 7) {
- _oPin.gotoAndStop(77);
- } else if (_oAngles.x === 8) {
- _oPin.gotoAndStop(78);
- } else if (_oAngles.x === 9) {
- _oPin.gotoAndStop(79);
- } else if (_oAngles.x === -1) {
- _oPin.gotoAndStop(31);
- } else if (_oAngles.x === -2) {
- _oPin.gotoAndStop(32);
- } else if (_oAngles.x === -3) {
- _oPin.gotoAndStop(33);
- } else if (_oAngles.x === -4) {
- _oPin.gotoAndStop(34);
- } else if (_oAngles.x === -5) {
- _oPin.gotoAndStop(35);
- } else if (_oAngles.x === -6) {
- _oPin.gotoAndStop(36);
- } else if (_oAngles.x === -7) {
- _oPin.gotoAndStop(37);
- } else if (_oAngles.x === -8) {
- _oPin.gotoAndStop(38);
- } else if (_oAngles.x === -9) {
- _oPin.gotoAndStop(39);
- }
- } else if (_oAngles.y <= -11 && _oAngles.y >= -18 || _oAngles.y <= 18 && _oAngles.y >= 11) {
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(50);
- } else if (_oAngles.x === 1) {
- _oPin.gotoAndStop(51);
- } else if (_oAngles.x === 2) {
- _oPin.gotoAndStop(52);
- } else if (_oAngles.x === 3) {
- _oPin.gotoAndStop(53);
- } else if (_oAngles.x === 4) {
- _oPin.gotoAndStop(54);
- } else if (_oAngles.x === 5) {
- _oPin.gotoAndStop(55);
- } else if (_oAngles.x === 6) {
- _oPin.gotoAndStop(56);
- } else if (_oAngles.x === 7) {
- _oPin.gotoAndStop(57);
- } else if (_oAngles.x === 8) {
- _oPin.gotoAndStop(58);
- } else if (_oAngles.x === 9) {
- _oPin.gotoAndStop(59);
- } else if (_oAngles.x === -1) {
- _oPin.gotoAndStop(11);
- } else if (_oAngles.x === -2) {
- _oPin.gotoAndStop(12);
- } else if (_oAngles.x === -3) {
- _oPin.gotoAndStop(13);
- } else if (_oAngles.x === -4) {
- _oPin.gotoAndStop(14);
- } else if (_oAngles.x === -5) {
- _oPin.gotoAndStop(15);
- } else if (_oAngles.x === -6) {
- _oPin.gotoAndStop(16);
- } else if (_oAngles.x === -7) {
- _oPin.gotoAndStop(17);
- } else if (_oAngles.x === -8) {
- _oPin.gotoAndStop(18);
- } else if (_oAngles.x === -9) {
- _oPin.gotoAndStop(19);
- }
- }
- } else if (_oAngles.z === -8) {
-
- if (_oAngles.x === 0) {
- _oPin.gotoAndStop(60);
- } else if (_oAngles.x === 1) {
- _oPin.gotoAndStop(61);
- } else if (_oAngles.x === 2) {
- _oPin.gotoAndStop(62);
- } else if (_oAngles.x === 3) {
- _oPin.gotoAndStop(63);
- } else if (_oAngles.x === 4) {
- _oPin.gotoAndStop(64);
- } else if (_oAngles.x === 5) {
- _oPin.gotoAndStop(65);
- } else if (_oAngles.x === 6) {
- _oPin.gotoAndStop(66);
- } else if (_oAngles.x === 7) {
- _oPin.gotoAndStop(67);
- } else if (_oAngles.x === 8) {
- _oPin.gotoAndStop(68);
- } else if (_oAngles.x === 9) {
- _oPin.gotoAndStop(69);
- } else if (_oAngles.x === -1) {
- _oPin.gotoAndStop(21);
- } else if (_oAngles.x === -2) {
- _oPin.gotoAndStop(22);
- } else if (_oAngles.x === -3) {
- _oPin.gotoAndStop(23);
- } else if (_oAngles.x === -4) {
- _oPin.gotoAndStop(24);
- } else if (_oAngles.x === -5) {
- _oPin.gotoAndStop(25);
- } else if (_oAngles.x === -6) {
- _oPin.gotoAndStop(26);
- } else if (_oAngles.x === -7) {
- _oPin.gotoAndStop(27);
- } else if (_oAngles.x === -8) {
- _oPin.gotoAndStop(28);
- } else if (_oAngles.x === -9) {
- _oPin.gotoAndStop(29);
- }
- }
- _oReflection.gotoAndStop(_oPin.currentFrame);
- };
- this.getPosRef = function () {
- return _oPosRefCast;
- };
- this.setPosRef = function (iZPos) {
- _oPosRefCast = iZPos;
- };
- this.setRegYRef = function (iY) {
- _oReflection.regY = iY;
- };
- this.getRegYRef = function () {
- return _iStartRefRegY;
- };
- this.setPositionReflection = function (iX, iY) {
- _oReflection.x = iX;
- _oReflection.y = iY;
- };
- this.setPosition = function (iXPos, iYPos) {
- _oPin.x = iXPos;
- _oPin.y = iYPos;
- };
- this.getPhysics = function () {
- return _oPhysics;
- };
- this.setAlpha = function (fVal) {
- _oContainer.alpha = fVal;
- };
- this.setAngle = function (iAngle) {
- _oPin.rotation = iAngle;
- };
- this.setVisible = function (bVal) {
- _oContainer.visible = bVal;
- };
- this.setVisibleRef = function (bVal) {
- _oReflection.visible = bVal;
- };
- this.getVisible = function () {
- return _oContainer.visible;
- };
- this.isVisibleRef = function () {
- return _oReflection.visible;
- };
- this.getX = function () {
- return _oPin.x;
- };
- this.getY = function () {
- return _oPin.y;
- };
- this.getStartScale = function () {
- return _fScale;
- };
- this.scale = function (fValue) {
- _oPin.scaleX = fValue;
- _oPin.scaleY = fValue;
- _oReflection.scaleX = fValue;
- _oReflection.scaleY = -fValue;
- };
- this.setAlphaByHeight = function (fHeight) {
- _oReflection.alpha = fHeight;
- };
- this.getAlphaRef = function () {
- return _oReflection.alpha;
- };
- this.getScale = function () {
- return _oPin.scaleX;
- };
- this.getObject = function () {
- return _oContainer;
- };
- this.getDepthPos = function () {
- return _oPhysics.position.y;
- };
- _oPhysics = oPhysics;
- _oParentContainer = oParentContainer;
- this._init(iXPos, iYPos, oSprite);
- return this;
- }
|