1

(3 replies, posted in General)

in the code you wrote there is a compatibility problem with c++ standard.

writeFloatValues(file, "color", *text->getColor(), 4);

This is an example of an instruction that doesn't compile with microsoft visual c++ 2010. I had to rewrite it in

writeFloatValues(file, "color", (float*)text->getColor(), 4);

I don't know if it's good because I didn't test yet. However if my solution isn't good, how may I fix it?

I included MLevelLoad and MLevelSave so I can reuse your code for saving the game.

thanks! This is going to be very useful!

3

(3 replies, posted in General)

I have to save the Engine status for have a complete photo of game status? This means I have to save each pointed address from each pointer in engine and so on for each pointer pointed by engine right?


ar &g-> getSoundContext();
    ar &g-> getRenderingContext();
      ar &g-> getPhysicsContext();
      ar &g-> getScriptContext();
      ar &g-> getInputContext();
      ar &g-> getSystemContext();

    // data loaders
     ar &g-> getFontLoader();
     ar &g-> getImageLoader();
     ar &g-> getSoundLoader();
     ar &g-> getMeshLoader();
     ar &g-> getArmatureAnimLoader();
     ar &g-> getTexturesAnimLoader();
     ar &g-> getMaterialsAnimLoader();
     ar &g-> getLevelLoader();
         // behavior manager
    ar &g-> getBehaviorManager();

    // renderer manager
      ar &g-> getRendererManager();

    // package manager
    
      ar &g-> getPackageManager()
      ar &g-> getLevel()
      ar &g-> getGame()
      ar &g-> getRenderer();

And then continue for each pointer...
Or there is another way I cannot figure out?

4

(2 replies, posted in Plugins)

fragment of code in Message.cpp to check a collision
http://pastebin.com/3WiYDuSQ

The project is a behavior to start a new behavior when a collision between parent object and objects specified in obj happens. More objects are separated by semicolon (;).
This will lead to the possibility to attach a behavior to an object when particular condition are verified.

6

(47 replies, posted in Tutorials/Examples)

I'm trying to work with one of your tutorial:

http://nistur.com/projects/maratis-3d/t … atis-tut6/

I can't get your source compiled. I need messages for communicate to MyGame.cpp that an Entities with a particular behavior exists without looking each entity. May I have any tip?

7

(2 replies, posted in Plugins)

Do you have ever heard about RPG Maker?
http://en.wikipedia.org/wiki/RPG_Maker
In my childhood I enjoyed very much this tool that made me fly with my imagination to create beautiful fantasy worlds. It's point and click and don't require any programming knowledge.
Maratis can be extended to support all the functionality RPG Maker had. This is a starting list of them.

Battle System
Message system:
Message.cpp
Message.h
Menu
Inventory
Party Management
Entity Movement: (Complete)
Movement.h
Movement.cpp
EXP System
Savegame

8

(1 replies, posted in Plugins)

done...

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// MovementGamePlugin
// Movement.h
// 
// Code : Anael Seghezzi edited by Giuseppe Alfieri
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef _MY_BEHAVIOR_H
#define _MY_BEHAVIOR_H

#include <MEngine.h>


class Movement : public MBehavior
{
public:

    // constructors / destructors
    Movement(MObject3d * parentObject);
    Movement(Movement & behavior, MObject3d * parentObject);
    ~Movement(void);

private:
    
    // custom variables
    bool animated;
    float m_rotationSpeed;
    bool autoRotate;
    float m_speed;
    float m_flySpeed;
    char  *m_pattern;
    bool cycle;
    
public:

    // destroy
    void destroy(void);

    // get new
    static MBehavior * getNew(MObject3d * parentObject);

    // get copy
    MBehavior * getCopy(MObject3d * parentObject);

    // name
    static const char * getStaticName(void){ return "Movement"; }
    const char * getName(void){ return getStaticName(); }

    // variables
    unsigned int getVariablesNumber(void);
    MVariable getVariable(unsigned int id);

    // events (virtuals from MBehavior class)
    void update(void);
    void runEvent(int param){}
};

#endif

Movement.cpp

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SimpleGamePlugin
// Movement.cpp
// 
// Code : Anael Seghezzi edited by Giuseppe Alfieri
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "Movement.h"


/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Init, this part is always similar, constructor, copy constructor etc
/////////////////////////////////////////////////////////////////////////////////////////////////////////
int i=0;
//char tmp[128];
// 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
/////////////////////////////////////////////////////////////////////////////////////////////////////////

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){
    printf("Strlen m_pattern %d\n", strlen(m_pattern));
    printf("INT i: %d\n", i);
    printf("Pattern: %s\n", m_pattern);
    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 oldPosition=parent->getPosition();
    MVector3* trnPosition=new MVector3(0,m_speed,0);
    MVector3 newPosition=oldPosition + *trnPosition;
    parent->setPosition(newPosition);
    }
    if(m_pattern[i]=='a'){
        parent->addAxisAngleRotation(MVector3(0, 0, m_rotationSpeed), 3);
    }
    if(m_pattern[i]=='d'){
        parent->addAxisAngleRotation(MVector3(0, 0, -m_rotationSpeed), 3);
    }
    if(m_pattern[i]=='s'){
        MVector3 oldPosition=parent->getPosition();
        MVector3* trnPosition=new MVector3(0,-m_speed,0);
        MVector3 newPosition=oldPosition + *trnPosition;
        parent->setPosition(newPosition);
    }
    i++;
    }
    else if(cycle)
        i=0;
    
    }
}

Now I want to set the "a" and "d" patterns to rotate the object so that works like

-- turn around
    if isKeyPressed("A") then
        rotate(Player, {0, 0, 0.5}, 3)
    end
    
    if isKeyPressed("D") then
        rotate(Player, {0, 0, 0.5}, -3)
    end

9

(1 replies, posted in Plugins)

I'm trying to implement a plugin for moving objects. This plugin could make easier to manage object movement by simply writing a string with the specific movement an object could do. This is the idea, now I'm blocked... This is the code.



Movement.cpp

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SimpleGamePlugin
// Movement.cpp
// 
// Code : Anael Seghezzi edited by Giuseppe Alfieri
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "Movement.h"


/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Init, this part is always similar, constructor, copy constructor etc
/////////////////////////////////////////////////////////////////////////////////////////////////////////
int patternLenght, i=0;

// constructor
Movement::Movement(MObject3d * parentObject):
MBehavior(parentObject),
animated(1),
m_rotationSpeed(1),
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),
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
/////////////////////////////////////////////////////////////////////////////////////////////////////////

unsigned int Movement::getVariablesNumber(void){
    return 6;
}

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("movementSpeed", &m_speed, M_VARIABLE_FLOAT);
    case 3:
        return MVariable("flySpeed", &m_flySpeed, M_VARIABLE_FLOAT);
    case 4:
        return MVariable("movementPattern", &m_pattern, M_VARIABLE_STRING);   
    case 5:
        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){
    patternLenght=strlen(m_pattern);
    printf("%d", patternLenght);
    parent->addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed);
    if(i<patternLenght){
    // a pattern string of wasd moves the object using rotationSpeed and moveSpeed
    if(m_pattern[i]=='w'){
    MVector3 oldPosition=parent->getPosition();
    MVector3* trnPosition=new MVector3(0,m_speed,0);
    MVector3 newPosition=oldPosition + *trnPosition;
    parent->setPosition(newPosition);
    }
    if(m_pattern[i]=='a'){
        parent->addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed);
    }
    if(m_pattern[i]=='d'){
        parent->addAxisAngleRotation(MVector3(0, 0, -1), m_rotationSpeed);
    }
    if(m_pattern[i]=='s'){
        MVector3 oldPosition=parent->getPosition();
        MVector3* trnPosition=new MVector3(m_speed/2,0,0);
        MVector3 newPosition=oldPosition + *trnPosition;
        parent->setPosition(newPosition);
    }
    i++;
    }
    else if(cycle)
        i=0;
    
    }
}

Movement.h

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// MovementGamePlugin
// Movement.h
// 
// Code : Anael Seghezzi edited by Giuseppe Alfieri
/////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef _MY_BEHAVIOR_H
#define _MY_BEHAVIOR_H

#include <MEngine.h>


class Movement : public MBehavior
{
public:

    // constructors / destructors
    Movement(MObject3d * parentObject);
    Movement(Movement & behavior, MObject3d * parentObject);
    ~Movement(void);

private:
    
    // custom variables
    bool animated;
    float m_rotationSpeed;
    float m_speed;
    float m_flySpeed;
    char  *m_pattern;
    bool cycle;
    
public:

    // destroy
    void destroy(void);

    // get new
    static MBehavior * getNew(MObject3d * parentObject);

    // get copy
    MBehavior * getCopy(MObject3d * parentObject);

    // name
    static const char * getStaticName(void){ return "Movement"; }
    const char * getName(void){ return getStaticName(); }

    // variables
    unsigned int getVariablesNumber(void);
    MVariable getVariable(unsigned int id);

    // events (virtuals from MBehavior class)
    void update(void);
    void runEvent(int param){}
};

#endif