static void handleInput() { u16 value; value = JOY_readJoypad(JOY_1); if (value & BUTTON_A) { if (value & BUTTON_UP) { if (numpartic < MAX_PARTIC) { if (numpartic == 1) numpartic += 9; else numpartic += 10; if (numpartic > MAX_PARTIC) numpartic = MAX_PARTIC; } } if (value & BUTTON_DOWN) { if (numpartic > 1) { if (numpartic == MAX_PARTIC) numpartic -= 9; else numpartic -= 10; if (numpartic < 1) numpartic = 1; } } } else if (value & BUTTON_B) { if (value & BUTTON_UP) { if (gravity > FIX16(0.1)) gravity -= FIX16(0.02); } if (value & BUTTON_DOWN) { if (gravity < FIX16(1.0)) gravity += FIX16(0.02); } } else { if (value & BUTTON_UP) { if (baseposy < intToFix16(BMP_HEIGHT - 10)) baseposy += FIX16(5.0); } if (value & BUTTON_DOWN) { if (baseposy > intToFix16(10)) baseposy -= FIX16(5.0); } if (value & BUTTON_LEFT) { if (baseposx > intToFix16(10)) baseposx -= FIX16(3.5); } if (value & BUTTON_RIGHT) { if (baseposx < intToFix16(BMP_WIDTH - 10)) baseposx += FIX16(3.5); } } }
/** Moves the characters on input in the (x,y) plane (velocity has a constant absolute value) */ void directionalInput ( Vector2D * player, u16 JOY_NUMBER ) { // Player 1 u16 value = JOY_readJoypad(JOY_NUMBER); // Resetting values (in case no button press occurs) player->x = FIX32(0); player->y = FIX32(0); // Diagonal motion if (value & (BUTTON_LEFT | BUTTON_RIGHT) & (BUTTON_UP | BUTTON_DOWN)) { if (value & BUTTON_LEFT) player->x -= DEFAULT_SPEED_DIAG; else if (value & BUTTON_RIGHT) player->x += DEFAULT_SPEED_DIAG; if (value & BUTTON_UP) player->y -= DEFAULT_SPEED_DIAG; else if (value & BUTTON_DOWN) player->y += DEFAULT_SPEED_DIAG; } // Single axis motion else { if (value & BUTTON_LEFT) player->x -= DEFAULT_SPEED; else if (value & BUTTON_RIGHT) player->x += DEFAULT_SPEED; else if (value & BUTTON_UP) player->y -= DEFAULT_SPEED; else if (value & BUTTON_DOWN) player->y += DEFAULT_SPEED; } // // --------------------------------------------------------------------- // // Player 2 // value = JOY_readJoypad(JOY_2); // // Resetting values (in case no button press occurs) // p2->x = FIX32(0); // p2->y = FIX32(0); // // Diagonal motion // if (value & (BUTTON_LEFT | BUTTON_RIGHT) & (BUTTON_UP | BUTTON_DOWN)) // { // if (value & BUTTON_LEFT) p2->x -= DEFAULT_SPEED_DIAG; // else if (value & BUTTON_RIGHT) p2->x += DEFAULT_SPEED_DIAG; // if (value & BUTTON_UP) p2->y -= DEFAULT_SPEED_DIAG; // else if (value & BUTTON_DOWN) p2->y += DEFAULT_SPEED_DIAG; // } // // Single axis motion // else // { // if (value & BUTTON_LEFT) p2->x -= DEFAULT_SPEED; // else if (value & BUTTON_RIGHT) p2->x += DEFAULT_SPEED; // else if (value & BUTTON_UP) p2->y -= DEFAULT_SPEED; // else if (value & BUTTON_DOWN) p2->y += DEFAULT_SPEED; // } }
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); } }
int main() { u16 i, newJoy = 0, oldJoy = 0, autoRepeatDelay = 0, redraw = 1; s16 choice = 0; const char *str; struct FileSystem fs; u16 numFiles; // Init the screen, display message VDP_setScreenWidth320(); VDP_setHInterrupt(0); VDP_setHilightShadow(0); VDP_setTextPalette(PAL0); VDP_drawText("MakeStuff USB MegaDrive Dev Kit v2", 3, 10); VDP_drawText("Reading SD-card...", 11, 12); // Initialise the SD card sdInit(); // Get the geometry of the first SD-card partition fatOpenFileSystem(&fs); // Initialise workspace for the directory list initFiles((u16*)0x440000); // Get the list of game ROMs fatListDirectory(&fs, fs.rootDirCluster, storeFile); // Sort the list alphabetically numFiles = dirPtr - dirList; quickSort((CVPtr *)dirList, 0, numFiles, (CompareFunc)myFileComp); // Display the list for ( ; ; ) { newJoy = JOY_readJoypad(0); if ( newJoy & BUTTON_UP && choice > 0 ) { if ( !(oldJoy & BUTTON_UP) ) { choice--; redraw = 1; autoRepeatDelay = 0; } else { if ( autoRepeatDelay == 10 ) { choice--; redraw = 1; } else { autoRepeatDelay++; } } } if ( newJoy & BUTTON_DOWN && choice < numFiles-1 ) { if ( !(oldJoy & BUTTON_DOWN) ) { choice++; redraw = 1; autoRepeatDelay = 0; } else { if ( autoRepeatDelay == 10 ) { choice++; redraw = 1; } else { autoRepeatDelay++; } } } if ( newJoy & BUTTON_START ) { doSelect(&fs, choice); } oldJoy = newJoy; VDP_waitVSync(); if ( redraw ) { VDP_clearPlan(VDP_PLAN_A, 1); VDP_waitDMACompletion(); for ( i = 2; i < 26; i++ ) { if ( i >= 11-choice && i < numFiles-choice+11 ) { str = dirList[choice+i-11]->fileName; if ( i == 11 ) { VDP_setTextPalette(PAL1); VDP_drawText(str, 2, i); VDP_setTextPalette(PAL0); } else { VDP_drawText(str, 2, i); } } } } redraw = 0; } }