Ejemplo n.º 1
0
Editor *EditorFactoryPrivate<Editor>::createEditor(QtProperty *property, QWidget *parent)
{
    Editor *editor = new Editor(parent);
    initializeEditor(property, editor);
    return editor;
}
Ejemplo n.º 2
0
static void update(void) {
    int steps, i;
    cpFloat dt;
    cpVect look, lastPos, curPos;
    projectile_t *pj; /* temp for looping */

    static cpVect delta = {0, 0};
    static projectile_t *curProj = NULL;
    static bool canToggleEditor = true;

    curPos = atlMousePos();
    lastPos = atlMouseLastPos();

    /* rotate 'gun' based on mouse position */
    look = cpvnormalize(cpvsub(curPos, g_Cannon->body->p));
    cpBodySetAngle(g_Cannon->body, cpvtoangle(look));

    if (isKeyPressed(KEY_e) && canToggleEditor) {
        canToggleEditor = false;
        editorMode = !editorMode;
    } else if (!isKeyPressed(KEY_e)) {
        canToggleEditor = true;
    }

    if (editorMode) {
        if (!editorBody)
            initializeEditor();
        handleEditor();
    } else {
        if (editorBody)
            destroyEditor();

        if (atlLeftMouseDown()) {

            if (!curProj) {
                /* don't let player hold the left mouse button to fire multiple rounds */
                delta = cpvnormalize(cpvsub(atlMouseClickPos(), g_Cannon->body->p));
                if (g_Cannon->ai < MAX_PROJECTILES) {
                    curProj = g_Cannon->ammo[g_Cannon->ai++];

                    if (curProj) {
                        cpSpaceAddBody(g_Space, curProj->body);
                        curProj->body->p = cpvadd(g_Cannon->body->p,
                                                  cpvmult(look, g_Cannon->length));

                        cpSpaceAddShape(g_Space, curProj->shape);
                        cpBodyApplyImpulse(curProj->body,
                                           cpvmult(cpvforangle(g_Cannon->body->a), 600.0f),
                                           cpvzero);
                        cpBodyActivate(curProj->body);
                    }
                }
            }
        } else {
            curProj = NULL;
        }
    }

    /* treat projectiles as limited resources. only allocated at the start of a level */
    for (i = 0; i <= g_Cannon->ai-1; ++i) {
        pj = g_Cannon->ammo[i];
        if (!pj)
            continue;

        if (pj->body->v.x >= -0.01f && pj->body->v.x <= 0.01f &&
            pj->body->v.y >= -0.01f && pj->body->v.y <= 0.01f) {
            /* TODO: mark an object for deletion, but don't delete immediately */
            cpSpaceRemoveBody(g_Space, pj->body);
            cpSpaceRemoveShape(g_Space, pj->shape);
            free(g_Cannon->ammo[i]);
            g_Cannon->ammo[i] = NULL;
        }
    }

    steps = 3;
    dt = 1.0f/60.0f/(cpFloat)steps;

    for (i = 0; i < steps; ++i) {
        cpSpaceStep(g_Space, dt);
    }
}