示例#1
0
文件: main.c 项目: kubilus1/SGDK
int main()
{
    char str[16];

    VDP_setScreenWidth256();
    VDP_setHInterrupt(0);
    VDP_setHilightShadow(0);

    // speed up controller checking
    JOY_setSupport(PORT_1, JOY_SUPPORT_6BTN);
    JOY_setSupport(PORT_2, JOY_SUPPORT_OFF);

    JOY_setEventHandler(handleJoyEvent);

    BMP_init(TRUE, PAL0, FALSE);

    camdist = FIX16(15);

    M3D_reset();
    M3D_setCamDistance(camdist);
    M3D_setLightEnabled(1);
    M3D_setLightXYZ(FIX16(0.9), FIX16(0.9), FIX16(-0.9));

    // allocate translation and rotation structure
    M3D_setTransform(&transformation, &translation, &rotation);
    M3D_setTranslation(&transformation, FIX16(0), FIX16(0), FIX16(20));
    M3D_setRotation(&transformation, FIX16(0), FIX16(0), FIX16(0));

    flatDrawing = 0;

    while (1)
    {
        doActionJoy(JOY_1, JOY_readJoypad(JOY_1));

        M3D_setCamDistance(camdist);

        // do work here
        rotation.x += rotstep.x;
        rotation.y += rotstep.y;
        rotation.z += rotstep.z;
        transformation.rebuildMat = 1;

        updatePointsPos();

        // ensure previous flip buffer request has been started
        BMP_waitWhileFlipRequestPending();
        BMP_showFPS(1);

        BMP_clear();

        drawPoints(0xFF);

        BMP_drawText("trans z:", 0, 2);
        fix16ToStr(translation.z, str, 2);
        BMP_drawText(str, 10, 2);
        BMP_drawText("cam dist:", 0, 3);
        fix16ToStr(camdist, str, 2);
        BMP_drawText(str, 11, 3);

        BMP_flip(1);
    }
}
示例#2
0
int main()
{
    char col;

    JOY_setEventHandler(joyEvent);

    VDP_setScreenWidth256();
    VDP_setHInterrupt(0);
    VDP_setHilightShadow(0);

    BMP_init(TRUE, PLAN_A, PAL0, FALSE);

    paused = 0;
    col = 0xFF;

    /* Initialise particules */
    baseposx = intToFix16(BMP_WIDTH / 2);
    baseposy = intToFix16(BMP_HEIGHT / 2);
    gravity = FIX16(0.4);

    initPartic(100);

    /* Do main job here */
    while(1)
    {
        char str[8];

        handleInput();

        if (!paused)
        {
            // calculates particules physic
            updatePartic(partics, numpartic);

            // ensure previous flip buffer request has been started
            BMP_waitWhileFlipRequestPending();

            // can now draw text
            BMP_showFPS(0);

            // display particul number
            intToStr(numpartic, str, 1);
            BMP_clearText(1, 3, 4);
            BMP_drawText(str, 1, 3);

            // display gravity
            fix16ToStr(gravity, str, 2);
            BMP_clearText(1, 4, 5);
            BMP_drawText(str, 1, 4);

            // clear bitmap
            BMP_clear();
            // draw particules
            drawPartic(partics, numpartic, col);

            // swap buffer
            BMP_flip(1);
        }
        else
        {
            BMP_drawText("PAUSE", 1, 4);
        }
    }
}
示例#3
0
static void fastStarFieldFX()
{
	u16 vramIndex = TILE_USERINDEX;
	s16 i, ns, s;
	Sprite sprites[256];

	SYS_disableInts();

	VDP_clearPlan(APLAN, 0);
	VDP_clearPlan(BPLAN, 0);
	VDP_setPlanSize(32, 32);

	/* Draw the foreground */
	VDP_drawImageEx(BPLAN, &starfield, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, vramIndex), 0, 0, TRUE, FALSE);
	vramIndex += starfield.tileset->numTile; 	

	/*	Set the proper scrolling mode (line by line) */
	VDP_setScrollingMode(HSCROLL_LINE, VSCROLL_PLANE);

	/*	Create the scrolling offset table */
	s = 1;
	for(i = 0; i < TABLE_LEN; i++)
	{
		scroll_PLAN_B[i] = 0;
		do
		{
			ns = -((random() % 3) + 1);
		}
		while (ns == s);
		scroll_speed[i] = ns;
		s = ns;
	}

	/* Setup the sprites */
	SPR_init(256);
	for(i = 0; i < MAX_DONUT; i++)
	    SPR_initSprite(&sprites[i], &donut, 0, 0, TILE_ATTR_FULL(PAL2, TRUE, FALSE, FALSE, 0));

	SPR_update(sprites, MAX_DONUT);

	VDP_setPalette(PAL2, donut.palette->data);	    	

	SYS_enableInts();

	/*	Start !!!! */
	s = 0;
	while (TRUE)
	{
		VDP_waitVSync();
		BMP_showFPS(1);

		/* 	Scroll the starfield */
		VDP_setHorizontalScrollLine(PLAN_B, 2, scroll_PLAN_B, TABLE_LEN, TRUE);
		for(i = 0; i < TABLE_LEN; i++)
			scroll_PLAN_B[i] = (scroll_PLAN_B[i] + scroll_speed[i]) & 0xFF;

		/*	Animate the donuts */
		for(i = 0; i < MAX_DONUT; i++)
		{
	        // SPR_setPosition(&sprites[i], (cosFix16(s + (i << 5)) << 1) + 160 - 16, sinFix16(s + (i << 5)) + 112 - 16);
	        sprites[i].x = (cosFix16(s + (i << 5)) << 1) + 160 - 16 + 0x80;
	        sprites[i].y = sinFix16(s + (i << 5)) + 112 - 16 + 0x80;
			SPR_setFrame(&sprites[i], ((s >> 4) + i) & 0x7);
		}

		s += 4;	
		SPR_update(sprites, MAX_DONUT);
	}
}