Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // RpgMakerPlugin
- // Movement.cpp
- //
- // Code : Giuseppe Alfieri (thanks Anael Seghezzi)
- //
- //
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- #include "Movement.h"
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Init, this part is always similar, constructor, copy constructor etc
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // constructor
- Movement::Movement(MObject3d * parentObject):
- MBehavior(parentObject),
- animated(1),
- m_rotationSpeed(1),
- autoRotate(0),
- m_speed(0),
- m_flySpeed(0),
- m_pattern(),
- cycle(0)
- {}
- // copy constructor
- Movement::Movement(Movement & behavior, MObject3d * parentObject):
- MBehavior(parentObject),
- animated(behavior.animated),
- m_rotationSpeed(behavior.m_rotationSpeed),
- autoRotate(0),
- m_speed(behavior.m_speed),
- m_flySpeed(behavior.m_flySpeed),
- m_pattern(behavior.m_pattern),
- cycle(behavior.cycle)
- {}
- // destructor
- Movement::~Movement(void)
- {}
- // destroy function : always similar
- void Movement::destroy(void)
- {
- delete this;
- }
- // getNew function : always similar
- MBehavior * Movement::getNew(MObject3d * parentObject)
- {
- return new Movement(parentObject);
- }
- // getCopy function : always similar
- MBehavior * Movement::getCopy(MObject3d * parentObject)
- {
- return new Movement(*this, parentObject);
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Variables, allow to access custom variable from script and from Maratis Editor
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- int i=0;
- unsigned int Movement::getVariablesNumber(void){
- return 7;
- }
- MVariable Movement::getVariable(unsigned int id)
- {
- switch(id)
- {
- default:
- return MVariable("NULL", NULL, M_VARIABLE_NULL);
- case 0:
- return MVariable("animated", &animated, M_VARIABLE_BOOL);
- case 1:
- return MVariable("rotationSpeed", &m_rotationSpeed, M_VARIABLE_FLOAT);
- case 2:
- return MVariable("autoRotate", &autoRotate, M_VARIABLE_BOOL);
- case 3:
- return MVariable("movementSpeed", &m_speed, M_VARIABLE_FLOAT);
- case 4:
- return MVariable("flySpeed", &m_flySpeed, M_VARIABLE_FLOAT);
- case 5:
- return MVariable("movementPattern", &m_pattern, M_VARIABLE_STRING);
- case 6:
- return MVariable("CycleMovement", &cycle, M_VARIABLE_BOOL);
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Events
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- // update function (called by MGame class by default)
- void Movement::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;
- // get the associated parent object (who is using this behavior)
- MObject3d * parent = getParentObject();
- // lets rotate the parent object around the z axis, using our custom "rotationSpeed" variable
- if(animated){
- if(autoRotate)
- parent->addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed);
- if(i<strlen(m_pattern)){
- // a pattern string of wasd moves the object using rotationSpeed and moveSpeed
- if(m_pattern[i]=='w'){
- MVector3 axis = parent->getRotatedVector(MVector3(0,m_speed,0));
- parent->setPosition(parent->getPosition() + axis);
- }
- if(m_pattern[i]=='a'){
- parent->addAxisAngleRotation(parent->getInverseRotatedVector(MVector3(0, 0, 0.5)), m_rotationSpeed);
- }
- if(m_pattern[i]=='d'){
- parent->addAxisAngleRotation(parent->getInverseRotatedVector(MVector3(0, 0, 0.5)), -m_rotationSpeed);
- }
- if(m_pattern[i]=='s'){
- MVector3 axis = parent->getRotatedVector(MVector3(0,-m_speed,0));
- parent->setPosition(parent->getPosition() + axis);
- }
- i++;
- }
- else if(cycle)
- i=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement