Advertisement
firelite

Message.cpp

May 15th, 2013
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // RpgMakerPlugin
  3. // Message.cpp
  4. //
  5. // Code : Giuseppe Alfieri
  6. //
  7. // need to review something about collisions, it doesn't work like I expected and cannot figure out how to fix this.
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "Message.h"
  11.  
  12.  
  13. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  14. // Init, this part is always similar, constructor, copy constructor etc
  15. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. Message::Message(MObject3d * parentObject):
  17. MBehavior(parentObject),
  18. text()
  19. {}
  20.  
  21. // copy constructor
  22. Message::Message(Message & behavior, MObject3d * parentObject):
  23. MBehavior(parentObject),
  24. text(behavior.text)
  25. {}
  26.  
  27. // destructor
  28. Message::~Message(void)
  29. {}
  30.  
  31. // destroy function : always similar
  32. void Message::destroy(void)
  33. {
  34. delete this;
  35. }
  36.  
  37. // getNew function : always similar
  38. MBehavior * Message::getNew(MObject3d * parentObject)
  39. {
  40. return new Message(parentObject);
  41. }
  42.  
  43. // getCopy function : always similar
  44. MBehavior * Message::getCopy(MObject3d * parentObject)
  45. {
  46. return new Message(*this, parentObject);
  47. }
  48.  
  49. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. // Variables, allow to access custom variable from script and from Maratis Editor
  51. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  52.  
  53.  
  54. unsigned int Message::getVariablesNumber(void){
  55. return 1;
  56. }
  57.  
  58. MVariable Message::getVariable(unsigned int id)
  59. {
  60. switch(id)
  61. {
  62. default:
  63. return MVariable("NULL", NULL, M_VARIABLE_NULL);
  64. case 0:
  65. return MVariable("MessageText", &text, M_VARIABLE_STRING);
  66. }
  67. }
  68.  
  69.  
  70. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  71. // Events
  72. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  73.  
  74. // update function (called by MGame class by default)
  75. void Message::update(void)
  76. {
  77.  
  78. MEngine * engine = MEngine::getInstance();
  79. MGame * game = engine->getGame();
  80.  
  81. // check if the game is running, removing thif test will enable In-Editor update (like for the lookAt behavior)
  82. if(! game->isRunning())
  83. return;
  84. unsigned int objid=0,playerid=0;
  85. // get the associated parent object (who is using this behavior)
  86. MObject3d * parent = getParentObject();
  87. // get the actual scene
  88. MScene* nScene=engine->getLevel()->getCurrentScene();
  89. // get from the actual scene the object Index to be used for function isObjectsCollision in MPhysicsContext
  90. nScene->getObjectIndex("select", &playerid);
  91. nScene->getObjectIndex(parent->getName(), &objid);
  92. // istanciate MPhysicsContext state
  93. MPhysicsContext * state = engine->getPhysicsContext();
  94.  
  95. int coll=state->isObjectsCollision(playerid,objid);
  96. //if collision happened between selector and parent object and action key is pressed does something
  97. if(coll){
  98. if(MInputContext* input = engine->getInputContext()){
  99. if(input->isKeyPressed("E")){
  100. printf("%s",&text);
  101.  
  102. }
  103.  
  104. }
  105.  
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement