camera.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Global movement speed that affects all cameras. This should be moved
  23. // into the camera datablock.
  24. $Camera::movementSpeed = 40;
  25. function Observer::onTrigger(%this,%obj,%trigger,%state)
  26. {
  27. // state = 0 means that a trigger key was released
  28. if (%state == 0)
  29. return;
  30. // Default player triggers: 0=fire 1=altFire 2=jump
  31. %client = %obj.getControllingClient();
  32. switch$ (%obj.mode)
  33. {
  34. case "Observer":
  35. // Do something interesting.
  36. case "Corpse":
  37. // Fade out the corpse
  38. if (isObject(%obj.orbitObj))
  39. {
  40. cancelAll(%obj.orbitObj);
  41. %obj.orbitObj.schedule(0, "startFade", 1000, 0, true);
  42. %obj.orbitObj.schedule(1000, "delete");
  43. }
  44. // Viewing dead corpse, so we probably want to respawn.
  45. game.preparePlayer(%client);
  46. // Set the camera back into observer mode, since in
  47. // debug mode we like to switch to it.
  48. %this.setMode(%obj,"Observer");
  49. }
  50. }
  51. function Observer::setMode(%this,%obj,%mode,%arg1,%arg2,%arg3)
  52. {
  53. switch$ (%mode)
  54. {
  55. case "Observer":
  56. // Let the player fly around
  57. %obj.setFlyMode();
  58. case "Corpse":
  59. // Lock the camera down in orbit around the corpse,
  60. // which should be arg1
  61. %transform = %arg1.getTransform();
  62. %obj.setOrbitMode(%arg1, %transform, 0.5, 4.5, 4.5);
  63. %obj.orbitObj = %arg1;
  64. }
  65. %obj.mode = %mode;
  66. }