camera.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 = 30;
  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. // Viewing dead corpse, so we probably want to respawn.
  38. $Game.preparePlayer(%client);
  39. // Set the camera back into observer mode, since in
  40. // debug mode we like to switch to it.
  41. %this.setMode(%obj,"Observer");
  42. }
  43. }
  44. function Observer::setMode(%this,%obj,%mode,%arg1,%arg2,%arg3)
  45. {
  46. switch$ (%mode)
  47. {
  48. case "Observer":
  49. // Let the player fly around
  50. %obj.setFlyMode();
  51. case "Corpse":
  52. // Lock the camera down in orbit around the corpse,
  53. // which should be arg1
  54. %transform = %arg1.getTransform();
  55. %obj.setOrbitMode(%arg1, %transform, 0.5, 4.5, 4.5);
  56. }
  57. %obj.mode = %mode;
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Camera methods
  61. //-----------------------------------------------------------------------------
  62. //-----------------------------------------------------------------------------
  63. function Camera::onAdd(%this,%obj)
  64. {
  65. // Default start mode
  66. %this.setMode(%this.mode);
  67. }
  68. function Camera::setMode(%this,%mode,%arg1,%arg2,%arg3)
  69. {
  70. // Punt this one over to our datablock
  71. %this.getDatablock().setMode(%this,%mode,%arg1,%arg2,%arg3);
  72. }