Exemplo n.º 1
0
void ITEMS::on_render()
{
	int num = snap_num_items(SNAP_CURRENT);
	for(int i = 0; i < num; i++)
	{
		SNAP_ITEM item;
		const void *data = snap_get_item(SNAP_CURRENT, i, &item);

		if(item.type == NETOBJTYPE_PROJECTILE)
		{
			render_projectile((const NETOBJ_PROJECTILE *)data, item.id);
		}
		else if(item.type == NETOBJTYPE_PICKUP)
		{
			const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
			if(prev)
				render_pickup((const NETOBJ_PICKUP *)prev, (const NETOBJ_PICKUP *)data);
		}
		else if(item.type == NETOBJTYPE_LASER)
		{
			render_laser((const NETOBJ_LASER *)data);
		}
		else if(item.type == NETOBJTYPE_FLAG)
		{
			const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
			if (prev)
				render_flag((const NETOBJ_FLAG *)prev, (const NETOBJ_FLAG *)data);
		}
	}

	// render extra projectiles
	/*
	for(int i = 0; i < extraproj_num; i++)
	{
		if(extraproj_projectiles[i].start_tick < client_tick())
		{
			extraproj_projectiles[i] = extraproj_projectiles[extraproj_num-1];
			extraproj_num--;
		}
		else
			render_projectile(&extraproj_projectiles[i], 0);
	}*/
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
    int i, fileMenuId;
    cpArray *constraints;

    domino_t *dom;
    projectile_t *pj;

    if (!Sys_CreateWindow("Atlas2D", 800, 600, false)) {
        Sys_KillWindow();
        return 0;
    }

    atlInitAtlas();

#ifdef __APPLE__
/*
    fileMenuId = Sys_CreateMenu("File");
    Sys_AppendMenuItem(fileMenuId, "Open...", openCB);
    Sys_AppendMenuSeparator(fileMenuId);
    Sys_AppendMenuItem(fileMenuId, "Save", saveCB);
    Sys_AppendMenuItem(fileMenuId, "Save As...", saveAsCB);
*/
#endif

    g_FontBase = Sys_LoadBmpFont("Helvetica");

    cpInitChipmunk();
    initSpace();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    while (!atlEscapePressed) {
        update();

        glClear(GL_COLOR_BUFFER_BIT);

        if (editorBody) {
            drawEditorPalette();
        }

        render_cannon(g_Cannon);
        atlDrawPhysicsObject(platforms[0]->shape, g_Space);

/*
        cpSpaceHashEach(g_Space->staticShapes,
                        (cpSpaceHashIterator)atlDrawPhysicsObject, g_Space);
        cpSpaceHashEach(g_Space->activeShapes,
                        (cpSpaceHashIterator)atlDrawPhysicsObject, g_Space);
*/

        for (i = 0; i < MAX_DOMINOES; ++i) {
            dom = g_Dominoes[i];
            if (!dom) continue;
            render_domino(dom);
        }

        for (i = 0; i < g_Cannon->ai; ++i) {
            pj = g_Cannon->ammo[i];
            if (!pj) continue;
            render_projectile(pj);
        }

        constraints = g_Space->constraints;
        for (i = 0; i < constraints->num; ++i) {
            atlDrawConstraint((cpConstraint *)constraints->arr[i]);
        }

        Sys_SwapBuffers();
        Sys_EventLoop();
    }

    /* has to be called before the cpSpaceFree* functions because it removes
     * bodies and shapes itself */
    FreeDominoes();

    cpSpaceFreeChildren(g_Space);
    cpSpaceFree(g_Space);

    for (i = 0; i < MAX_PLATFORMS; ++i) {
        if (platforms[i])
            free(platforms[i]);
    }

    if (g_Cannon)
        free(g_Cannon);

    atlFreeImages();
    atlFreeBmpFont(g_FontBase);

    Sys_KillWindow();

    return 0;
}