SHOW:
|
|
- or go back to the newest paste.
| 1 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // RpgMakerPlugin | |
| 3 | - | // Message.cpp |
| 3 | + | // Movement.cpp |
| 4 | // | |
| 5 | - | // Code : Giuseppe Alfieri |
| 5 | + | // Code : Giuseppe Alfieri (thanks Anael Seghezzi) |
| 6 | // | |
| 7 | - | // need to review something about collisions, it doesn't work like I expected and cannot figure out how to fix this. |
| 7 | + | |
| 8 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 9 | ||
| 10 | - | #include "Message.h" |
| 10 | + | #include "Movement.h" |
| 11 | ||
| 12 | ||
| 13 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 14 | // Init, this part is always similar, constructor, copy constructor etc | |
| 15 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 16 | - | Message::Message(MObject3d * parentObject): |
| 16 | + | |
| 17 | // constructor | |
| 18 | - | text() |
| 18 | + | Movement::Movement(MObject3d * parentObject): |
| 19 | MBehavior(parentObject), | |
| 20 | animated(1), | |
| 21 | m_rotationSpeed(1), | |
| 22 | - | Message::Message(Message & behavior, MObject3d * parentObject): |
| 22 | + | autoRotate(0), |
| 23 | m_speed(0), | |
| 24 | - | text(behavior.text) |
| 24 | + | m_flySpeed(0), |
| 25 | m_pattern(), | |
| 26 | cycle(0) | |
| 27 | {}
| |
| 28 | - | Message::~Message(void) |
| 28 | + | |
| 29 | // copy constructor | |
| 30 | Movement::Movement(Movement & behavior, MObject3d * parentObject): | |
| 31 | MBehavior(parentObject), | |
| 32 | - | void Message::destroy(void) |
| 32 | + | animated(behavior.animated), |
| 33 | m_rotationSpeed(behavior.m_rotationSpeed), | |
| 34 | autoRotate(0), | |
| 35 | m_speed(behavior.m_speed), | |
| 36 | m_flySpeed(behavior.m_flySpeed), | |
| 37 | m_pattern(behavior.m_pattern), | |
| 38 | - | MBehavior * Message::getNew(MObject3d * parentObject) |
| 38 | + | cycle(behavior.cycle) |
| 39 | {}
| |
| 40 | - | return new Message(parentObject); |
| 40 | + | |
| 41 | // destructor | |
| 42 | Movement::~Movement(void) | |
| 43 | {}
| |
| 44 | - | MBehavior * Message::getCopy(MObject3d * parentObject) |
| 44 | + | |
| 45 | // destroy function : always similar | |
| 46 | - | return new Message(*this, parentObject); |
| 46 | + | void Movement::destroy(void) |
| 47 | {
| |
| 48 | delete this; | |
| 49 | } | |
| 50 | ||
| 51 | // getNew function : always similar | |
| 52 | MBehavior * Movement::getNew(MObject3d * parentObject) | |
| 53 | {
| |
| 54 | - | unsigned int Message::getVariablesNumber(void){
|
| 54 | + | return new Movement(parentObject); |
| 55 | - | return 1; |
| 55 | + | |
| 56 | ||
| 57 | // getCopy function : always similar | |
| 58 | - | MVariable Message::getVariable(unsigned int id) |
| 58 | + | MBehavior * Movement::getCopy(MObject3d * parentObject) |
| 59 | {
| |
| 60 | return new Movement(*this, parentObject); | |
| 61 | } | |
| 62 | ||
| 63 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 64 | // Variables, allow to access custom variable from script and from Maratis Editor | |
| 65 | - | return MVariable("MessageText", &text, M_VARIABLE_STRING);
|
| 65 | + | |
| 66 | int i=0; | |
| 67 | unsigned int Movement::getVariablesNumber(void){
| |
| 68 | return 7; | |
| 69 | } | |
| 70 | ||
| 71 | MVariable Movement::getVariable(unsigned int id) | |
| 72 | {
| |
| 73 | switch(id) | |
| 74 | {
| |
| 75 | - | void Message::update(void) |
| 75 | + | |
| 76 | return MVariable("NULL", NULL, M_VARIABLE_NULL);
| |
| 77 | case 0: | |
| 78 | return MVariable("animated", &animated, M_VARIABLE_BOOL);
| |
| 79 | case 1: | |
| 80 | return MVariable("rotationSpeed", &m_rotationSpeed, M_VARIABLE_FLOAT);
| |
| 81 | case 2: | |
| 82 | return MVariable("autoRotate", &autoRotate, M_VARIABLE_BOOL);
| |
| 83 | case 3: | |
| 84 | - | unsigned int objid=0,playerid=0; |
| 84 | + | return MVariable("movementSpeed", &m_speed, M_VARIABLE_FLOAT);
|
| 85 | case 4: | |
| 86 | return MVariable("flySpeed", &m_flySpeed, M_VARIABLE_FLOAT);
| |
| 87 | - | // get the actual scene |
| 87 | + | case 5: |
| 88 | - | MScene* nScene=engine->getLevel()->getCurrentScene(); |
| 88 | + | return MVariable("movementPattern", &m_pattern, M_VARIABLE_STRING);
|
| 89 | - | // get from the actual scene the object Index to be used for function isObjectsCollision in MPhysicsContext |
| 89 | + | case 6: |
| 90 | - | nScene->getObjectIndex("select", &playerid);
|
| 90 | + | return MVariable("CycleMovement", &cycle, M_VARIABLE_BOOL);
|
| 91 | - | nScene->getObjectIndex(parent->getName(), &objid); |
| 91 | + | |
| 92 | - | // istanciate MPhysicsContext state |
| 92 | + | |
| 93 | - | MPhysicsContext * state = engine->getPhysicsContext(); |
| 93 | + | |
| 94 | ||
| 95 | - | int coll=state->isObjectsCollision(playerid,objid); |
| 95 | + | |
| 96 | - | //if collision happened between selector and parent object and action key is pressed does something |
| 96 | + | |
| 97 | - | if(coll){
|
| 97 | + | |
| 98 | - | if(MInputContext* input = engine->getInputContext()){
|
| 98 | + | |
| 99 | - | if(input->isKeyPressed("E")){
|
| 99 | + | |
| 100 | - | printf("%s",&text);
|
| 100 | + | |
| 101 | void Movement::update(void) | |
| 102 | - | } |
| 102 | + | |
| 103 | MEngine * engine = MEngine::getInstance(); | |
| 104 | MGame * game = engine->getGame(); | |
| 105 | ||
| 106 | // check if the game is running, removing thif test will enable In-Editor update (like for the lookAt behavior) | |
| 107 | if(! game->isRunning()) | |
| 108 | return; | |
| 109 | ||
| 110 | // get the associated parent object (who is using this behavior) | |
| 111 | MObject3d * parent = getParentObject(); | |
| 112 | ||
| 113 | // lets rotate the parent object around the z axis, using our custom "rotationSpeed" variable | |
| 114 | if(animated){
| |
| 115 | if(autoRotate) | |
| 116 | parent->addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed); | |
| 117 | if(i<strlen(m_pattern)){
| |
| 118 | // a pattern string of wasd moves the object using rotationSpeed and moveSpeed | |
| 119 | if(m_pattern[i]=='w'){
| |
| 120 | MVector3 axis = parent->getRotatedVector(MVector3(0,m_speed,0)); | |
| 121 | parent->setPosition(parent->getPosition() + axis); | |
| 122 | } | |
| 123 | if(m_pattern[i]=='a'){
| |
| 124 | parent->addAxisAngleRotation(parent->getInverseRotatedVector(MVector3(0, 0, 0.5)), m_rotationSpeed); | |
| 125 | } | |
| 126 | if(m_pattern[i]=='d'){
| |
| 127 | parent->addAxisAngleRotation(parent->getInverseRotatedVector(MVector3(0, 0, 0.5)), -m_rotationSpeed); | |
| 128 | } | |
| 129 | if(m_pattern[i]=='s'){
| |
| 130 | MVector3 axis = parent->getRotatedVector(MVector3(0,-m_speed,0)); | |
| 131 | parent->setPosition(parent->getPosition() + axis); | |
| 132 | } | |
| 133 | i++; | |
| 134 | } | |
| 135 | else if(cycle) | |
| 136 | i=0; | |
| 137 | ||
| 138 | } | |
| 139 | } |