Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // RpgMakerPlugin
- // Message.cpp
- //
- // Code : Giuseppe Alfieri
- //
- // need to review something about collisions, it doesn't work like I expected and cannot figure out how to fix this.
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- #include "Message.h"
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Init, this part is always similar, constructor, copy constructor etc
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- Message::Message(MObject3d * parentObject):
- MBehavior(parentObject),
- text()
- {}
- // copy constructor
- Message::Message(Message & behavior, MObject3d * parentObject):
- MBehavior(parentObject),
- text(behavior.text)
- {}
- // destructor
- Message::~Message(void)
- {}
- // destroy function : always similar
- void Message::destroy(void)
- {
- delete this;
- }
- // getNew function : always similar
- MBehavior * Message::getNew(MObject3d * parentObject)
- {
- return new Message(parentObject);
- }
- // getCopy function : always similar
- MBehavior * Message::getCopy(MObject3d * parentObject)
- {
- return new Message(*this, parentObject);
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Variables, allow to access custom variable from script and from Maratis Editor
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- unsigned int Message::getVariablesNumber(void){
- return 1;
- }
- MVariable Message::getVariable(unsigned int id)
- {
- switch(id)
- {
- default:
- return MVariable("NULL", NULL, M_VARIABLE_NULL);
- case 0:
- return MVariable("MessageText", &text, M_VARIABLE_STRING);
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Events
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // update function (called by MGame class by default)
- void Message::update(void)
- {
- MEngine * engine = MEngine::getInstance();
- MGame * game = engine->getGame();
- // check if the game is running, removing thif test will enable In-Editor update (like for the lookAt behavior)
- if(! game->isRunning())
- return;
- unsigned int objid=0,playerid=0;
- // get the associated parent object (who is using this behavior)
- MObject3d * parent = getParentObject();
- // get the actual scene
- MScene* nScene=engine->getLevel()->getCurrentScene();
- // get from the actual scene the object Index to be used for function isObjectsCollision in MPhysicsContext
- nScene->getObjectIndex("select", &playerid);
- nScene->getObjectIndex(parent->getName(), &objid);
- // istanciate MPhysicsContext state
- MPhysicsContext * state = engine->getPhysicsContext();
- int coll=state->isObjectsCollision(playerid,objid);
- //if collision happened between selector and parent object and action key is pressed does something
- if(coll){
- if(MInputContext* input = engine->getInputContext()){
- if(input->isKeyPressed("E")){
- printf("%s",&text);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement