void Button::update_state(touchPosition stylus) { bool stylus_on_button = stylus_on(stylus); bool stylus_down = keysDown() & KEY_TOUCH; bool stylus_up = keysUp() & KEY_TOUCH; bool stylus_held = keysHeld() & KEY_TOUCH; switch (state) { case BUTTON_NORMAL: if (stylus_down && stylus_on_button) { state = BUTTON_PRESSED; } break; case BUTTON_PRESSED: if (stylus_up && stylus_on(last_stylus)) { state = BUTTON_CLICKED; } else if (stylus_held && !stylus_on_button) { state = BUTTON_NORMAL; } break; case BUTTON_CLICKED: state = BUTTON_NORMAL; break; default: break; } last_stylus = stylus; }
u16 nds_keysUp() { while (nds_power_state() == POWER_STATE_ASLEEP) { swiWaitForVBlank(); } return _nds_handedness_swap(keysUp()); }
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) { //dc=keysd; //if (dc) //{ //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); //swiWaitForVBlank(); //scanKeys(); //keysd = keysDown(); //keysu = keysUp(); //ldc=keysd; //} /*if (prevkey && prevbutton) { scanKeys(); } */ //scanKeys(); keysd = keysDown(); keysu = keysUp(); short ax=0,v=0,h=0; if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");} if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");} if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");} if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");} if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=0;}//fprintf(stderr,"KEY_UP\n");} if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=0;}//fprintf(stderr,"KEY_DOWN\n");} if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=0;}//fprintf(stderr,"KEY_LEFT\n");} if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=0;}//fprintf(stderr,"KEY_RIGHT\n");} if((keysd&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;} if((keysd&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;} if((keysd&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;} if((keysd&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;} if((keysd&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;} if((keysd&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;} if((keysd&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;} if((keysd&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;} if((keysu&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=0;} if((keysu&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=0;} if((keysu&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=0;} if((keysu&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=0;} if((keysu&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=0;} if((keysu&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=0;} if((keysu&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=0;} if((keysu&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=0;} }
void Menu::NX(int sock) { int volume = 77; while(1) { consoleClear(); iprintf("\n netxmms-nds\n ___________\n\n" " A - PLAY\n" " B - PAUSE\n" " Y - STOP\n" " R - NEXT\n" " L - PREVIOUS\n" " < - VOLUME-\n" " > - VOLUME+\n\n" " VOLUME: %d%%", volume); while(1) { swiWaitForVBlank(); scanKeys(); int pressed = keysDown(); int held = keysHeld(); if(pressed & KEY_A) NX::Play(sock); if(pressed & KEY_B) NX::Pause(sock); if(pressed & KEY_Y) NX::Stop(sock); if(pressed & KEY_R) NX::Next(sock); if(pressed & KEY_L) NX::Previous(sock); if(pressed & KEY_LID) { int s = REG_POWERCNT; REG_POWERCNT = 0; while(1) { scanKeys(); if(keysUp() & KEY_LID) { REG_POWERCNT = s; break; } } } if(held & KEY_LEFT && volume > 0) { volume--; NX::Volume(sock, volume); break; } else if(held & KEY_RIGHT && volume < 100) { volume++; NX::Volume(sock, volume); break; } } } }
void gameControls() { u32 kDown, kUp; struct eventTranslate *translateTable = gameKeyTable; int numTranslations = numGameKeys; kDown = keysDown(); kUp = keysUp(); if (menuactive) { translateTable = menuKeyTable; numTranslations = numMenuKeys; } else if (automapmode & am_active) { translateTable = mapKeyTable; numTranslations = numMapKeys; } else { event_t event; if (last_weapon_key != 0 && players[displayplayer].pendingweapon != wp_nochange) { event.type = ev_keyup; event.data1 = last_weapon_key; D_PostEvent(&event); last_weapon_key = 0; } if(kDown & KEY_Y) { weapontype_t weapon_index = players[displayplayer].readyweapon; weapon_index++; while(players[displayplayer].weaponowned[weapon_index] == false) { weapon_index++; if (weapon_index >= NUMWEAPONS) weapon_index = 0; } last_weapon_key = weapons[weapon_index]; event.type = ev_keydown; event.data1 = last_weapon_key; D_PostEvent(&event); } } translateKeys(ev_keydown, kDown, translateTable, numTranslations); translateKeys(ev_keyup, kUp, translateTable, numTranslations); }
void I_GetEvent(void) { // Mappings of DS keys to SRB2 keys UINT32 dskeys[] = { KEY_A, KEY_B, KEY_X, KEY_Y, KEY_L, KEY_R, KEY_START, KEY_SELECT }; event_t event; UINT32 held, up, down; UINT32 i; // Check how the state has changed since last time scanKeys(); // For the d-pad, we only care about the current state held = keysHeld(); event.type = ev_joystick; event.data1 = 0; // First (and only) axis set if (held & KEY_LEFT) event.data2 = -1; else if (held & KEY_RIGHT) event.data2 = 1; else event.data2 = 0; if (held & KEY_UP) event.data3 = -1; else if (held & KEY_DOWN) event.data3 = 1; else event.data3 = 0; D_PostEvent(&event); // For the buttons, we need to report changes in state up = keysUp(); down = keysDown(); for (i = 0; i < sizeof(dskeys)/sizeof(dskeys[0]); i++) { // Has this button's state changed? if ((up | down) & dskeys[i]) { event.type = (up & dskeys[i]) ? ev_keyup : ev_keydown; event.data1 = KEY_JOY1 + i; D_PostEvent(&event); } } }
void NDS_PumpEvents(_THIS) { scanKeys(); /* TODO: defer click-age */ if (keysDown() & KEY_TOUCH) { SDL_SendMouseButton(0, SDL_PRESSED, 0); } else if (keysUp() & KEY_TOUCH) { SDL_SendMouseButton(0, SDL_RELEASED, 0); } if (keysHeld() & KEY_TOUCH) { touchPosition t = touchReadXY(); SDL_SendMouseMotion(0, 0, t.px, t.py, 1); /* last arg is pressure, hardcoded 1 for now */ } }
void EventDispatcher::dispatchEvents(void) { Event* currentEvent; uint32 downKeys = keysDown(); uint32 heldKeys = keysHeld(); uint32 upKeys = keysUp(); /* This might be an infinite loop if there exists two events that fire each other */ for (; startPointer != endPointer; startPointer = getNext(startPointer)) { currentEvent = events[startPointer]; if (currentEvent->enabled) { void* args = NULL; bool callFunc = false; /* Build the args here */ switch (currentEvent->type) { case BUTTON_PRESS: if (downKeys != 0) { callFunc = true; } break; case BUTTON_HOLD: if (heldKeys != 0) { callFunc = true; } break; case BUTTON_RELEASE: if (upKeys != 0) { callFunc = true; } break; case FRAME_CHANGE: callFunc = true; break; } if (callFunc == true) { /* Call that shit */ currentEvent->eventCallback(args); } } } }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- SoundEngine* soundengine = new SoundEngine( SAMPLERATE ); SoundSetup( soundengine, SAMPLERATE, BUFSIZE ); int* tempBuf = (int*)malloc(sizeof(int)*soundengine->granulizerBufferSize); int displayBuf[CIRCLEDIVS]; int time = 0; u8 squares = 10; while(1) { // -------------------- // // -- INPUT HANDLING -- // // -------------------- // touchPosition touch; touchRead( &touch ); scanKeys(); u32 down=0, up=0, held=0; down=keysDown(); held=keysHeld(); up=keysUp(); if(down&KEY_UP) squares++; if(down&KEY_DOWN) squares--; if(down&KEY_TOUCH) soundengine->granulizer->SetPlaybackRate(0,1); if(held&KEY_TOUCH) { soundengine->granulizer->SetPlaybackPos(touch.px,SCREEN_WIDTH); soundengine->granulizer->SetGrainSize(touch.py); } if(up&KEY_TOUCH) { soundengine->granulizer->SetPlaybackRate(1,1); soundengine->stop(0); } // -------------- // // -- GRAPHICS -- // // -------------- // for(int i=0; i<soundengine->granulizerBufferSize; i++) { tempBuf[i]=abs(soundengine->granulizerBuffer[i]); } downSampleArray(tempBuf,soundengine->granulizerBufferSize,displayBuf,CIRCLEDIVS); for(int i=0; i<CIRCLEDIVS; i++) { int maxRadius=700; int radius=maxRadius*displayBuf[i]/MAXAMP; int nextRadius=maxRadius*displayBuf[(i+1)%CIRCLEDIVS]/MAXAMP; int angle=DEGREES_IN_CIRCLE*i/CIRCLEDIVS; int nextAngle=DEGREES_IN_CIRCLE*((i+1)%CIRCLEDIVS)/CIRCLEDIVS; int x=sinLerp(angle)*radius/DEGREES_IN_CIRCLE+(SCREEN_WIDTH/2); int y=cosLerp(angle)*radius/DEGREES_IN_CIRCLE+(SCREEN_HEIGHT/2); int nextX=sinLerp(nextAngle)*nextRadius/DEGREES_IN_CIRCLE+(SCREEN_WIDTH/2); int nextY=cosLerp(nextAngle)*nextRadius/DEGREES_IN_CIRCLE+(SCREEN_HEIGHT/2); GraphicsEng::Instance()->DrawLine(x,y,nextX,nextY,RGB15(31,31,31),ALPHA_ON,SUB_LAYER); } for(int i=0; i<GLOBALBUFFERSIZE; i++) { int val = soundengine->globalBuffer[(soundengine->globalBufferCursor+i)%GLOBALBUFFERSIZE]; val = val*(SCREEN_HEIGHT/2)/MAXAMP; GraphicsEng::Instance()->DrawPoint( SCREEN_WIDTH*i/GLOBALBUFFERSIZE, (SCREEN_HEIGHT/2)+val, RGB15(31,31,31), ALPHA_ON, MAIN_LAYER); } GraphicsEng::Instance()->Update(); time++; } }
bool InputHelper::KeyUp(int key) { return keysUp() & key; }
int main() { //enable vram and map it to the right places vramSetMainBanks( VRAM_A_MAIN_SPRITE, //A and B maped consecutivly as sprite memory VRAM_B_MAIN_SPRITE, //this gives us 256KB which is the max VRAM_C_MAIN_BG_0x06000000, //map C to background memory VRAM_D_LCD //not using D ); //set the video mode videoSetMode( MODE_0_2D | DISPLAY_SPR_ACTIVE | //turn on sprites DISPLAY_BG0_ACTIVE | //turn on background 0 DISPLAY_SPR_1D | //this is used when in tile mode DISPLAY_SPR_1D_BMP //and this in bitmap mode ); consoleInit(0, 0,BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true); //turn off the sprites initSprites(); // direct bitmap sprite // print at using ansi escape sequence \x1b[line;columnH iprintf("\x1b[1;1HDirect Bitmap:"); sprites[0].attribute[0] = ATTR0_BMP | ATTR0_ROTSCALE_DOUBLE | 10; sprites[0].attribute[1] = ATTR1_SIZE_32 | 20; sprites[0].attribute[2] = ATTR2_ALPHA(1)| 0; // red 32*32 square for 1d bitmap mode for(int i=0;i<32*32;i++) SPRITE_GFX[i]=RGB15(31,0,0)|(1<<15); //dont forget alpha bit // 256 color sprite // print at using ansi escape sequence \x1b[line;columnH iprintf("\x1b[9;1H256 color:"); sprites[1].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 75; sprites[1].attribute[1] = ATTR1_SIZE_32 | 20; // size 64x64, x 10 sprites[1].attribute[2] = 64; // Blue for 256 color sprite SPRITE_PALETTE[1]=RGB15(0,0,31); // blue 64*64 square for 256 color mode (must write two pixles at time) for(int i=0;i<32*16;i++) SPRITE_GFX[i+64*16]=(1<<8)|1; // 16 color sprite // print at using ansi escape sequence \x1b[line;columnH iprintf("\x1b[16;1H16 color:"); sprites[2].attribute[0] = ATTR0_COLOR_16 | ATTR0_ROTSCALE_DOUBLE | 135; sprites[2].attribute[1] = ATTR1_SIZE_32 | 20; sprites[2].attribute[2] = ATTR2_PALETTE(1) | 96; //yellow for 16 color sprite (it is using palette 1 so colors 16-31) SPRITE_PALETTE[17]=RGB15(31,31,0); // yellow 32*32 square for 16 color mode (must write 4 pixels at a time) for(int i=0;i<32*8;i++) SPRITE_GFX[i+96*16]=(1<<12)|(1<<8)|(1<<4)|1; int angle=0; //we tied all our sprites to the same rotation attributes (0) spriteRotations[0].hdx=256; spriteRotations[0].hdy=0; spriteRotations[0].vdx=0; spriteRotations[0].vdy=256; while(1) { angle+=64; spriteRotations[0].hdx = cosLerp(angle) >> 4; spriteRotations[0].hdy = sinLerp(angle) >> 4; spriteRotations[0].vdx = -spriteRotations[0].hdy; spriteRotations[0].vdy = spriteRotations[0].hdx; swiWaitForVBlank(); u32 display_temp = 0; scanKeys(); if(keysDown()&KEY_A) { screenshotbmp("shot.bmp"); display_temp=REG_DISPCNT; REG_DISPCNT=MODE_FB1; } if(keysUp()&KEY_A) { videoSetMode( MODE_0_2D | DISPLAY_SPR_ACTIVE | //turn on sprites DISPLAY_BG0_ACTIVE | //turn on background 0 DISPLAY_SPR_1D | //this is used when in tile mode DISPLAY_SPR_1D_BMP | //and this in bitmap mode DCAP_OFFSET(1)); } updateOAM(); } }
//--------------------------------------------------------------------------------- // Program entry point //--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- // the vblank interrupt must be enabled for VBlankIntrWait() to work // since the default dispatcher handles the bios flags no vblank handler // is required int gamecount = 1; irqInit(); irqEnable(IRQ_VBLANK); //consoleDemoInit(); consoleInit( 0, /* charbase */ 4, /* mapbase */ 0, /* background number */ NULL, /* font */ 0, /* font size */ 15 /* 16 color palette */); BG_COLORS[0]=RGB8(0,0,0); BG_COLORS[241]=RGB5(31,31,31); SetMode(MODE_0 | BG0_ON); // ansi escape sequence to clear screen and home cursor // /x1b[line;columnH iprintf("\x1b[2J"); // ansi escape sequence to set print co-ordinates // /x1b[line;columnH // ansi escape sequence to move cursor up // /x1b[linesA // ansi escape sequence to move cursor left // /x1b[columnsD // ansi escape sequence to move cursor down // /x1b[linesB // ansi escape sequence to move cursor right // /x1b[columnsC iprintf("\x1b[0;0HGames: %d",gamecount); while (1) { VBlankIntrWait(); scanKeys(); int keys_pressed = keysDown(); int keys_released = keysUp(); if (keys_pressed & KEY_UP) { gamecount = gamecount + 1; iprintf("\x1b[0;0H "); iprintf("\x1b[0;0HGames: %d",gamecount); } if (keys_pressed & KEY_DOWN) { if (gamecount > 1) { gamecount = gamecount - 1; iprintf("\x1b[0;0H "); iprintf("\x1b[0;0HGames: %d",gamecount); } } if (keys_pressed & KEY_A) { wincount = 0; rollstats[0] = 0; rollstats[1] = 0; rollstats[2] = 0; rollstats[3] = 0; rollstats[4] = 0; rollstats[5] = 0; simulateCraps(gamecount); iprintf("\x1b[1;0HWe simulated %d games",gamecount); iprintf("\x1b[2;0HYou won %d games",wincount); printStats(); } } }
void VblankHandler(void) { scanKeys(); u16 keysdown = keysDown(); u16 keysup = keysUp(); u16 keysheld = keysHeld(); touchPosition touch; touchRead(&touch); if(!touch_was_down && keysdown & KEY_TOUCH) { touch_was_down = 1; pm_x0 = touch.px; pm_y0 = touch.py; // Is the pen on the keyboard? if( (touch.px > 8*keyb_xpos) && (touch.py > 8*keyb_ypos) && (touch.px < 8*(keyb_xpos+keyb_width)) && (touch.py < 8*(keyb_ypos+keyb_height)) ) { // Look up the note in the hit-array u8 kbx, kby; kbx = touch.px/8 - keyb_xpos; kby = touch.py/8 - keyb_ypos; u8 note = keyb_hit[kby][kbx]; currnote = note + 12*baseOctave; lastnote = note; setKeyPal(note); // Play the note play(note); } } else if(keysup & KEY_TOUCH) { touch_was_down = 0; resetPals(); stop(lastnote); pitchChange(0); } else if(touch_was_down && keysheld & KEY_TOUCH) { s16 dx, dy; dx = touch.px - pm_x0; if(dx<0) dx = 0; dy = touch.py - pm_y0; pitchChange(-dy); pressureChange(dx); } if(keysdown & KEY_X) { pitchChange(0); } if(keysdown & KEY_Y) { pressureChange(0); } if(keysdown & KEY_RIGHT) { if(baseOctave < 9) baseOctave++; displayOctave(baseOctave); iprintf("base octave %u\n", baseOctave); } if(keysdown & KEY_LEFT) { if(baseOctave > 0) baseOctave--; displayOctave(baseOctave); iprintf("base octave %u\n", baseOctave); } if(keysdown & KEY_UP) { if(channel < 15) channel++; displayChannel(channel); iprintf("using midi channel %u\n", channel); } if(keysdown & KEY_DOWN) { if(channel > 0) channel--; displayChannel(channel); iprintf("using midi channel %u\n", channel); } if(keysdown & KEY_B) { //TIMER1_DATA = TIMER_FREQ_64(1000); //TIMER1_CR = TIMER_ENABLE | TIMER_DIV_64 | TIMER_IRQ_REQ; timerStart(1, ClockDivider_64, TIMER_FREQ_64(1000), Smoke); row=0; tick=0; } }
void roomEditorCursor(selection_struct* sel) { if(!sel)sel=&editorSelection; if((keysDown() & KEY_TOUCH) && !(sel->entity && !sel->entity->placed)) { u8 type; void* ptr=getBlockEntityTouch(&type); if(sel->entity && sel->selectingTarget) { if(type) { sel->selectingTarget=false; sel->entity->target=(entity_struct*)ptr; cleanUpContextButtons(); } }else{ if(type) { //entity entity_struct* e=(entity_struct*)ptr; undoSelection(sel); sel->active=true; sel->selecting=false; sel->selectingTarget=false; sel->entity=e; }else{ //blockface blockFace_struct* bf=(blockFace_struct*)ptr; if(bf) { if(sel->active && isFaceInSelection(bf, sel)) { sel->currentFace=bf; sel->currentPosition=vect(bf->x,bf->y,bf->z); sel->selecting=false; sel->selectingTarget=false; }else{ undoSelection(sel); sel->firstFace=sel->secondFace=bf; sel->active=true; sel->selecting=true; sel->selectingTarget=false; } sel->entity=NULL; }else{ undoSelection(sel); } } } }else if(keysHeld() & KEY_TOUCH) { if(sel->active && !(sel->entity && sel->selectingTarget)) { if(sel->entity) { blockFace_struct* bf=getBlockFaceTouch(NULL); if(bf) { sel->error=!moveEntityToBlockFace(sel->entity, bf); } }else{ if(sel->selecting) { blockFace_struct* bf=getBlockFaceTouch(NULL); if(bf)sel->secondFace=bf; }else{ blockFace_struct* bf=sel->currentFace; bool fill=true; vect3D p=getDragPosition(bf, lineOfTouchOrigin, lineOfTouchVector, lineOfTouchVector); p=vect((p.x+(ROOMARRAYSIZEX*BLOCKSIZEX+BLOCKSIZEX)/2)/BLOCKSIZEX,(p.y+(ROOMARRAYSIZEY*BLOCKSIZEY+BLOCKSIZEY)/2)/BLOCKSIZEY,(p.z+(ROOMARRAYSIZEZ*BLOCKSIZEZ+BLOCKSIZEZ)/2)/BLOCKSIZEZ); switch(bf->direction) { case 0: p.y=bf->y; p.z=bf->z; fill=p.x>sel->currentPosition.x; break; case 1: p.y=bf->y; p.z=bf->z; fill=p.x<sel->currentPosition.x; break; case 2: p.x=bf->x; p.z=bf->z; fill=p.y>sel->currentPosition.y; break; case 3: p.x=bf->x; p.z=bf->z; fill=p.y<sel->currentPosition.y; break; case 4: p.x=bf->x; p.y=bf->y; fill=p.z>sel->currentPosition.z; break; default: p.x=bf->x; p.y=bf->y; fill=p.z<sel->currentPosition.z; break; } if(p.x!=sel->currentPosition.x || p.y!=sel->currentPosition.y || p.z!=sel->currentPosition.z) { blockFace_struct oldFirstFace=*sel->firstFace; blockFace_struct oldSecondFace=*sel->secondFace; blockFace_struct oldCurrentFace=*sel->currentFace; vect3D v=vectDifference(p, sel->currentPosition); vect3D o=(bf->direction%2)?(sel->origin):(adjustVectForNormal(bf->direction, sel->origin)); vect3D s=v; fixOriginSize(&o, &s); s=adjustVectForNormal((bf->direction%2)?(bf->direction):(oppositeDirection[bf->direction]), addVect(s,sel->size)); vect3D oe=adjustVectForNormal(bf->direction, sel->origin); vect3D se=sel->size; moveEntitiesRange(oe, se, v); if(fill)fillBlockArrayRange(editorRoom.blockArray, &editorRoom.blockFaceList, o, s); else emptyBlockArrayRange(editorRoom.blockArray, &editorRoom.blockFaceList, o, s); getEntityBlockFacesRange(editorRoom.blockFaceList, addVect(oe,v), se, true); adjustSelection(&editorRoom, sel, oldFirstFace, oldSecondFace, oldCurrentFace, v); sel->currentPosition=p; } } } }else{ if(abs(oldTouch.px-currentTouch.px)>2)rotateMatrixY(editorCamera.transformationMatrix, -TOUCHSPEEDX*(oldTouch.px-currentTouch.px), true); if(abs(oldTouch.py-currentTouch.py)>2)rotateMatrixX(editorCamera.transformationMatrix, -TOUCHSPEEDY*(oldTouch.py-currentTouch.py), false); } }else if(keysUp() & KEY_TOUCH) { if(sel->active) { if(sel->entity && sel->entity->type) { if(!sel->selectingTarget)setupContextButtons(sel->entity->type->contextButtonsArray, sel->entity->type->numButtons); else setupContextButtons(targetSelectionButtonArray, 2); }else if(sel->planar && sel->firstFace && (sel->firstFace->direction==2 || sel->firstFace->direction==3))setupContextButtons(groundSelectionButtonArray, 4); else if(sel->planar)setupContextButtons(planarSelectionButtonArray, 2); else setupContextButtons(nonplanarSelectionButtonArray, 4); } } }
int main(void) { mmInitDefaultMem((mm_addr)soundbank_bin); //set video mode and map vram to the background videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_SPRITE); //set video mode and map vram to the background videoSetModeSub(MODE_1_2D | DISPLAY_BG1_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); vramSetBankD(VRAM_D_MAIN_BG_0x06000000); vramSetBankE(VRAM_E_MAIN_SPRITE); lcdMainOnBottom(); #ifdef BBDEBUG consoleDemoInit(); #endif sound s; s.load_bank(0); sprites spr; machine m(&s); machine_view mv(&spr); #ifndef BBDEBUG thread_view tv; #endif cursor c(&m,&spr); pointer p(&spr); iprintf("%d\n",list::unit_test()); int frame=0; int x=0; int y=0; int tx=0; int ty=0; int dx=0; int dy=0; int touchedlast=0; int tempo=2; int bank=0; u8 flip=0; u8 flip_count=1; irqEnable( IRQ_VCOUNT ); while(1) { // wait until line 0 swiIntrWait( 0, IRQ_VCOUNT); u32 t=tempo; //t=t/(flip+1); //iprintf("%d\n",t); if (tempo==0 || frame%t==0) { m.run(); /* flip_count--; if (flip_count==0) { flip_count=4; if (flip) flip=0; else flip=1; }*/ } scanKeys(); frame++; touchPosition touch; touchRead(&touch); if (keysDown() & KEY_UP) m.slow_down_closest(c.get_cursor_addr()); if (keysDown() & KEY_DOWN) m.speed_up_closest(c.get_cursor_addr()); if (tempo<0) tempo=0; if (keysDown() & KEY_L) sound_check(m); if (keysDown() & KEY_LEFT) { bank--; s.load_bank(bank); } if (keysDown() & KEY_RIGHT) { bank++; s.load_bank(bank); } if(keysDown() & KEY_TOUCH) { tx=touch.px; ty=touch.py; if (!c.touch(tx,ty,&p)) { touchedlast=1; } } else if(keysHeld() & KEY_TOUCH) { if (!c.menu_shown() && !c.drag(touch.px+x,touch.py+y,(touch.px+x)/16,(touch.py+y)/16)) { if (touchedlast>0) touchedlast++; x+=tx-touch.px; y+=ty-touch.py; tx=touch.px; ty=touch.py; } } if (keysUp() & KEY_TOUCH) { if (touchedlast>0 && touchedlast<5) { int lx=(tx+x)/16; int ly=(ty+y)/16; c.set_pos(lx,ly,lx*16,ly*16); } touchedlast=0; } if (keysUp() & KEY_A) { for (u32 i=0; i<HEAP_SIZE; i++) { m.poke(i,rand()); } } c.update(x,y); if (c.menu_shown()) { dx=c.get_x()-128; dy=c.get_y()-82; if (dx!=x) x+=(dx-x)*0.1; if (dy!=y) y+=(dy-y)*0.1; } p.update(x,y,&m); REG_BG0HOFS = x; REG_BG0VOFS = y; spr.update(); mv.update(x,y,&m); s.update(); #ifndef BBDEBUG tv.update(&m); #endif BG_PALETTE_SUB[0]=13<<10; swiWaitForVBlank(); BG_PALETTE_SUB[0]=31; } return 0; }
void DS_Controls(void) { touchPosition touch; scanKeys(); // Do DS input housekeeping u16 keys = keysDown(); u16 held = keysHeld(); if (held & KEY_TOUCH) { touchRead(&touch); } if (held & KEY_B) { if (held & KEY_L) { AM_ZoomIn(); } if (held & KEY_R) { AM_ZoomOut(); } } if (keys & KEY_UP || ((held & KEY_TOUCH) && touch.py < 80)) { event_t event; event.type = ev_keydown; event.data1 = KEYD_UPARROW; D_PostEvent(&event); } if (keys & KEY_LEFT) { event_t event; event.type = ev_keydown; event.data1 = KEYD_LEFTARROW; D_PostEvent(&event); } if (keys & KEY_DOWN || ((held & KEY_TOUCH) && touch.py > 120)) { event_t event; event.type = ev_keydown; event.data1 = KEYD_DOWNARROW; D_PostEvent(&event); } if (keys & KEY_RIGHT) { event_t event; event.type = ev_keydown; event.data1 = KEYD_RIGHTARROW; D_PostEvent(&event); } if (keys & KEY_START) { event_t event; event.type = ev_keydown; event.data1 = KEYD_ESCAPE; D_PostEvent(&event); } if (keys & KEY_SELECT) { event_t event; event.type = ev_keydown; event.data1 = KEYD_ENTER; D_PostEvent(&event); } if (keys & KEY_A) { event_t event; event.type = ev_keydown; if (menuactive) event.data1= KEYD_ENTER; else event.data1 = KEYD_RCTRL; D_PostEvent(&event); } if (keys & KEY_B) { event_t event; event.type = ev_keydown; if(menuactive) event.data1 = KEYD_ESCAPE; else event.data1 = ' '; D_PostEvent(&event); } if (keys & KEY_X) { event_t event; event.type = ev_keydown; event.data1 = KEYD_RSHIFT; D_PostEvent(&event); } if (keys & KEY_Y) { bool good = false; while (!good) { // Jefklak 23/11/06 - regular shotgun in DOOMII please if(gamemission == doom2 && weapon_index == 2) { if(!weapon_shotgun_cycled) weapon_shotgun_cycled = true; else { weapon_index++; weapon_shotgun_cycled = true; } } else { weapon_index++; weapon_shotgun_cycled = false; } if (weapon_index >= NUMWEAPONS) weapon_index = 0; if (players[displayplayer].weaponowned[weapon_index]) good = true; } event_t event; event.type = ev_keydown; event.data1 = weapons[weapon_index]; D_PostEvent(&event); event.data1 = 'y'; D_PostEvent(&event); } if (keys & KEY_R) { if (!(held & KEY_B)) { event_t event; event.type = ev_keydown; event.data1 = '.'; D_PostEvent(&event); } } if (keys & KEY_L) { if (!(held & KEY_B)) { event_t event; event.type = ev_keydown; event.data1 = ','; D_PostEvent(&event); } } keys = keysUp(); if (keys & KEY_UP || (keys & KEY_TOUCH) || ((held & KEY_TOUCH) && touch.py >= 80)) { event_t event; event.type = ev_keyup; event.data1 = KEYD_UPARROW; D_PostEvent(&event); } if (keys & KEY_LEFT) { event_t event; event.type = ev_keyup; event.data1 = KEYD_LEFTARROW; D_PostEvent(&event); } if (keys & KEY_DOWN || (keys & KEY_TOUCH) || ((held & KEY_TOUCH) && touch.py <= 120)) { event_t event; event.type = ev_keyup; event.data1 = KEYD_DOWNARROW; D_PostEvent(&event); } if (keys & KEY_RIGHT) { event_t event; event.type = ev_keyup; event.data1 = KEYD_RIGHTARROW; D_PostEvent(&event); } if (keys & KEY_START) { event_t event; event.type = ev_keyup; event.data1 = KEYD_ESCAPE; D_PostEvent(&event); } if (keys & KEY_SELECT) { event_t event; event.type = ev_keyup; event.data1 = KEYD_ENTER; D_PostEvent(&event); } if (keys & KEY_A) { event_t event; event.type = ev_keyup; event.data1 = KEYD_RCTRL; D_PostEvent(&event); } if (keys & KEY_B) { event_t event; event.type = ev_keyup; event.data1 = ' '; D_PostEvent(&event); } if (keys & KEY_X) { event_t event; event.type = ev_keyup; event.data1 = KEYD_RSHIFT; D_PostEvent(&event); } if (keys & KEY_Y) { event_t event; event.type = ev_keyup; event.data1 = weapons[weapon_index]; D_PostEvent(&event); event.data1 = 'y'; D_PostEvent(&event); } if (keys & KEY_R) { event_t event; event.type = ev_keyup; event.data1 = '.'; D_PostEvent(&event); } if (keys & KEY_L) { event_t event; event.type = ev_keyup; event.data1 = ','; D_PostEvent(&event); } if (keysHeld() & KEY_TOUCH) // this is only for x axis { event_t event; event.type = ev_mouse; //event.data1 = I_SDLtoDoomMouseState(Event->motion.state); event.data1 = 0; event.data2 = ((touch.px - 128) / 3) << 5; //event.data3 = (-(touch.py - 96) / 8) << 5; event.data3 = (0) << 5; D_PostEvent(&event); } }
int main() { irqInit(); SetMode((LCDC_BITS)(MODE_1 | BG0_ON | BG2_ON | OBJ_ENABLE)); irqSet(IRQ_VBLANK, vblank); irqEnable(IRQ_VBLANK); float xpos = 0; float ypos = 0; float xdir = 0; float ydir = 0; int dir = 0; BG_COLORS[0] = RGB5(31, 0, 31); CpuFastSet(tileset_img, OBJ_BASE_ADR, COPY32 | (256 * 16) / 4); CpuFastSet(tileset_pal, OBJ_COLORS, COPY32 | (256 / 4)); CpuFastSet(tileset_img, PATRAM4(0, 0), COPY32 | (256 * 16) / 4); CpuFastSet(tileset_pal, BG_COLORS, COPY32 | (256 / 4)); // mock up a map /* ((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[0] = 0; ((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[1] = 1; ((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[32] = 32; ((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[33] = 33; ((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[64] = 64; ((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[65] = 65; */ for (int y = 0; y < 32; ++y) { for (int x = 0; x < 32; ++x) { ((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[x + y * 32] = 5; } } for (int x = 0; x < 32; ++x) ((vu8*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[x] = 16; for (int x = 0; x < 32; ++x) ((vu8*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[31 * 32 + x] = 16; for (int y = 0; y < 32; ++y) ((vu8*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[y * 32] = 16; for (int y = 0; y < 32; ++y) ((vu8*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[y * 32 + 31] = 16; BGCTRL[0] = SCREEN_BASE(MAP_BASE_BLOCK + 0) | CHAR_BASE(0) | BG_SIZE_0 | BG_16_COLOR | BG_PRIORITY(1); // | CHAR_PALETTE(1); BGCTRL[2] = SCREEN_BASE(MAP_BASE_BLOCK + 1) | CHAR_BASE(0) | BG_SIZE_1 | BG_16_COLOR | BG_PRIORITY(0); // | CHAR_PALETTE(1); float rot = 0.0f; float last_rot = rot; float bg_scroll = 0; int frame = 0; while (1) { int sprite_frame = (int(floor(bg_scroll)) >> 3) & 1; if (fabs(xdir) < 1e-1) sprite_frame = 0; // if (ypos > 0) sprite_frame = 2; int tile_start = sprite_frame * 2; int pal = 0; for (int i = 0; i < 128; ++i) { sprites[i].attr0 = ATTR0_DISABLED; } int sprite = 0; // sprites[sprite].attr0 = OBJ_Y(int(ypos) + 80 - 8) | ATTR0_COLOR_16 | ATTR0_WIDE; // sprites[sprite].attr1 = OBJ_X(int(xpos) + 120) | OBJ_SIZE(Sprite_16x8) | (dir ? ATTR1_FLIP_X : 0); sprites[sprite].attr0 = OBJ_Y(int(0) + 80 - 16) | ATTR0_COLOR_16 | ATTR0_WIDE; sprites[sprite].attr1 = OBJ_X(int(0) + 120 - 8) | OBJ_SIZE(Sprite_16x8) | (dir ? ATTR1_FLIP_X : 0); sprites[sprite].attr2 = OBJ_CHAR(tile_start) | ATTR2_PALETTE(pal); // | OBJ_TRANSLUCENT; sprite++; // sprites[sprite].attr0 = OBJ_Y(int(ypos) + 80) | ATTR0_COLOR_16 | ATTR0_SQUARE; // sprites[sprite].attr1 = OBJ_X(int(xpos) + 120) | OBJ_SIZE(Sprite_16x16) | (dir ? ATTR1_FLIP_X : 0); sprites[sprite].attr0 = OBJ_Y(int(0) + 80 - 8) | ATTR0_COLOR_16 | ATTR0_SQUARE; sprites[sprite].attr1 = OBJ_X(int(0) + 120 - 8) | OBJ_SIZE(Sprite_16x16) | (dir ? ATTR1_FLIP_X : 0); sprites[sprite].attr2 = OBJ_CHAR(tile_start + 32) | ATTR2_PALETTE(pal); // | OBJ_TRANSLUCENT; sprite++; float st = sin(last_rot); float ct = cos(last_rot); last_rot = last_rot + (rot - last_rot) * 0.1; int pa = int(0x100 * ct); int pb =-int(0x100 * st); int pc = int(0x100 * st); int pd = int(0x100 * ct); // don't setup any hw-regs until vblank VBlankIntrWait(); // setup bg0 scroll REG_BG0HOFS = int(bg_scroll) & 0xFFFF; // setup bg2 transform REG_BG2PA = pa; REG_BG2PB = pb; REG_BG2PC = pc; REG_BG2PD = pd; REG_BG2X = (int(xpos) << 8) - (pa * 120 + pb * 80); REG_BG2Y = (int(ypos) << 8) - (pc * 120 + pd * 80); ++frame; CpuSet(sprites, OAM, (128 * sizeof(OAM[0])) / 2); scanKeys(); u32 held = keysHeld(); u32 down = keysDown(); u32 up = keysUp(); float upx = sin(rot); float upy = -cos(rot); float leftx = upy; float lefty = -upx; if (KEY_UP & down) { xdir = upx * 5; ydir = upy * 5; } if (KEY_L & down) { rot += M_PI / 2; } if (KEY_R & down) { rot -= M_PI / 2; } /* if (KEY_L & up) { rot += M_PI / 4; } if (KEY_R & up) { rot -= M_PI / 4; } */ // external forces #if 0 xdir *= 0.95; // friction ydir *= 0.95; // friction #else float a = leftx * xdir + lefty * ydir; // dot(dir, left) float b = upx * xdir + upy * ydir; // dot(dir, up) float new_xdir = upx * b + 0.85 * leftx * a; float new_ydir = upy * b + 0.85 * lefty * a; xdir = new_xdir; ydir = new_ydir; #endif if (fabs(xdir) < 1e-1) xdir = 0; if (fabs(ydir) < 1e-1) ydir = 0; if (KEY_RIGHT & held) { xdir -= leftx * 0.5f; ydir -= lefty * 0.5f; dir = 0; } if (KEY_LEFT & held) { xdir += leftx * 0.5f; ydir += lefty * 0.5f; dir = 1; } xdir -= upx * 0.25; // gravity ydir -= upy * 0.25; // gravity float last_xpos = xpos; float last_ypos = ypos; // apply forces xpos += xdir; ypos += ydir; // resolve constraints if (xpos < 0) xpos = 0; if (xpos > 255) xpos = 255; if (ypos < 0) ypos = 0; if (ypos > 255) ypos = 255; float delta_xpos = last_xpos - xpos; float delta_ypos = last_ypos - ypos; bg_scroll += (delta_xpos * leftx + delta_ypos * lefty) * 0.5f; } return 0; }
void Menu::Configuration() { CONFIG config; if(!Config::Load(&config)) { config.port = 0; memset(config.ip, 0, 4); } while(1) { consoleClear(); iprintf("\n CONFIGURATION\n _____________\n\n" " PORT: %d\n" " IP ADDRESS: %03d.%03d.%03d.%03d\n" " HOLD A B X Y\n\n" " < - PORT-\n" " > - PORT+\n" " L - IP-\n" " R - IP+\n" " UP/DOWN - +10/+100 (HOLD)\n" " _____________\n\n" " START - SAVE & RETURN\n" " SELECT - DON'T SAVE & RETURN", config.port, (u8) config.ip[0], (u8) config.ip[1], (u8) config.ip[2], (u8) config.ip[3]); while(1) { swiWaitForVBlank(); scanKeys(); int pressed = keysDown(); int held = keysHeld(); if(held & KEY_LEFT || pressed & KEY_LEFT) { if(held & KEY_UP) config.port -= 10; else if(held & KEY_DOWN) config.port -= 100; else config.port--; break; } if(held & KEY_RIGHT || pressed & KEY_RIGHT) { if(held & KEY_UP) config.port += 10; else if(held & KEY_DOWN) config.port += 100; else config.port++; break; } if(held & KEY_L || pressed & KEY_L) { u8 inc; if(held & KEY_UP) inc = 10; else if(held & KEY_DOWN) inc = 100; else inc = 1; if(held & KEY_A) config.ip[0] -= inc; if(held & KEY_B) config.ip[1] -= inc; if(held & KEY_X) config.ip[2] -= inc; if(held & KEY_Y) config.ip[3] -= inc; break; } if(held & KEY_R || pressed & KEY_R) { int inc; if(held & KEY_UP) inc = 10; else if(held & KEY_DOWN) inc = 100; else inc = 1; if(held & KEY_A) config.ip[0] += inc; if(held & KEY_B) config.ip[1] += inc; if(held & KEY_X) config.ip[2] += inc; if(held & KEY_Y) config.ip[3] += inc; break; } if(pressed & KEY_START) { Config::Write(&config); return; } if(pressed & KEY_SELECT) { return; } if(pressed & KEY_LID) { int s = REG_POWERCNT; REG_POWERCNT = 0; while(1) { scanKeys(); if(keysUp() & KEY_LID) { REG_POWERCNT = s; break; } } } } } }
int main() { /* ドロイド君の x, y 座標 */ s16 dx = 120, dy = 120; /* りんごの x, y 座標 */ const s16 ax = 160, ay = 120; /* 窓の x, y 座標 */ const s16 wx = 40, wy = 40; /* タイルのベースアドレス */ u16* tile = (u16*)TILE_BASE_ADR(0); /* * ドロイド君の状態。 * 0 => 待機 * 1 => ジャンプ準備中 * 2 => ジャンプ中 */ int state = 0; /* 歩き状態 (0, 1, 2) */ int wstate = 0; /* ドロイド君の y 方向の速度 */ float vy = 0; /* フレーム数用の変数 */ u16 f = 0; /* 表示するキャラクタ */ u16 ch = 0; /* キー状態取得用変数 */ u16 kd = 0; u16 kdr = 0; u16 ku = 0; u16 kh = 0; /* 汎用変数 */ u16 i, xx, yy; /* フレーム数初期化 */ frame = 0; /* 割り込みの初期化 */ irqInit(); /* * VBLANK 割り込みを有効化 * これによって VBlankIntrWait() が使えるようになる */ irqEnable(IRQ_VBLANK); /* * モードの設定。 * MODE 0、スプライト有効化、BG0 有効化 */ SetMode(MODE_0 | OBJ_ENABLE | BG0_ON); /* スプライトのメモリ領域(OAM)にスプライトデータをコピー */ GbaGraphics::setSpriteData(spritesTiles, spritesTilesLen / 2); /* スプライトと BG のパレットのメモリ領域にパレットデータをコピー */ GbaGraphics::setSpritePalette(spritesPal, 16); GbaGraphics::setBGPalette(spritesPal, 16); GbaGraphics::setBGColor(RGB5(15,15,31)); /* スプライトの初期化 */ GbaGraphics::initSprites(); /* ドロイド君の準備 */ GbaGraphics::Sprite droid(0, 0, Sprite_16x16); droid.setPosition(dx, dy); droid.draw(); /* りんごの準備 */ GbaGraphics::Sprite apple(1, (2 * 32), Sprite_16x16); apple.setPosition(ax, ay); apple.draw(); /* 窓の準備 */ GbaGraphics::Sprite window(2, 2 + (2 * 32), Sprite_16x16); window.setPosition(wx, wy); window.draw(); /* BG 0 の設定 */ BGCTRL[0] = BG_MAP_BASE(31) | BG_16_COLOR | BG_SIZE_0 | TILE_BASE(0) | BG_PRIORITY(0); /* BG0 を初期化 */ for ( xx = 0; xx < 32; xx++ ) { for ( yy = 0; yy < 32; yy++ ) { MAP[31][yy][xx] = 6 * 32; } } /* 画像をタイルにコピー */ for ( i = 0; i < spritesTilesLen / 2; i++ ) { tile[i] = spritesTiles[i]; } /* BG0 をセット */ MAP[31][17][0] = 5 * 32; MAP[31][17][29] = 2 + 5 * 32; for ( i = 1; i < 29; i++ ) { MAP[31][17][i] = 1 + 5 * 32; } for ( xx = 0; xx < 30; xx++ ) { for ( yy = 18; yy < 32; yy++ ) { MAP[31][yy][xx] = 3 + 5 * 32; } } // コンソール出力のテスト cprintf("droid(%d, %d), apple(%d, %d), window(%d, %d), %s", dx, dy, ax, ay, wx, wy, "console test."); /* メインループ */ while (1) { /* VBLANK 割り込み待ち */ VBlankIntrWait(); /* フレーム数カウント */ frame += 1; /* キー状態取得 */ scanKeys(); kd = keysDown(); kdr = keysDownRepeat(); ku = keysUp(); kh = keysHeld(); switch(state) { case 0: /* 待機中 */ if( (kd & KEY_UP) ) { state = 1; f = 0; ch = 0; break; } if( (kh & KEY_LEFT) ) { dx--; droid.setHFlip(true); } if( (kh & KEY_RIGHT) ) { dx++; droid.setHFlip(false); } if( dx < -16 ) { dx = SCREEN_WIDTH; } if( kd & ( KEY_LEFT | KEY_RIGHT ) ) { wstate = 0; f = 0; } if( ku & ( KEY_LEFT | KEY_RIGHT ) ) { ch = 0; } if ( SCREEN_WIDTH < dx ) { dx = -16; } if ( kh & ( KEY_LEFT | KEY_RIGHT ) ) { /* 歩きモーション */ if ( 5 < f++ ) { switch ( wstate ) { case 0: wstate = 1; ch = 2; break; case 1: wstate = 2; ch = 0; break; case 2: wstate = 3; ch = 4; break; default: wstate = 0; ch = 0; break; } f = 0; } } if ( dy == (ay - 13) ) { if ( !(((ax - 11) < dx) && (dx < (ax + 11))) ) { /* りんごから落ちる */ vy = -0.; state = 2; wstate = 0; break; } } droid.setCharacter(ch); droid.setPosition(dx, dy); break; case 1: case 3: /* ジャンプ準備 */ droid.setCharacter(6); if( 3 < f++ ) { vy = 4.; if ( 1 == state ) state = 2; else state = 4; } break; case 2: case 4: /* ジャンプ中 */ if( (kd & KEY_UP) ) { /* 二段ジャンプ */ if ( state == 2 ) { state = 3; f = 0; break; } } if( kh & KEY_LEFT ) { dx--; droid.setHFlip(true); } if( kh & KEY_RIGHT ) { dx++; droid.setHFlip(false); } if( dx < -16 ) { dx = SCREEN_WIDTH; } if ( SCREEN_WIDTH < dx ) { dx = -16; } if( (0.5 < vy) && ( kh & KEY_UP ) ) { vy += 0.2; } dy -= (s16)vy; if(vy < 0) { droid.setCharacter(10); } else { droid.setCharacter(8); } if ( dy < 0 ) { dy = 0; vy = -0.; } if ( (vy < 0) && ((ax - 11) < dx) && (dx < (ax + 11)) ) { if ( ay - 13 < dy ) { /* りんごに乗る */ dy = ay - 13; state = 0; } } if ( 120 < dy ) { /* 着地 */ dy = 120; state = 0; } droid.setPosition(dx, dy); vy = vy - 0.3; break; } droid.draw(); } }
int main(void) { touchPosition touch; defaultExceptionHandler(); lcdMainOnBottom(); irqEnable(IRQ_VBLANK); videoSetMode(MODE_FB0); vramSetBankA(VRAM_A_LCD); consoleDemoInit(); ClearScreen(); touchPosition firstTouch = { 0, 0 }; touchPosition lastTouch = { 0, 0 }; int colours[3] = { 31, 31, 31 }; int colourIndex = 0; printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]); std::stack<node*>* path = NULL; bool searched = false; node start(10,10,NULL); node target(244,180,NULL); Robot robot; robot.setPosition(start.x,start.y); int nextTouch = 0; //we like infinite loops in console dev! while(1) { swiWaitForVBlank(); scanKeys(); touchRead(&touch); int kd = keysDown(); if (kd & KEY_A) { ClearScreen(); } if (kd & KEY_UP) { ++colours[colourIndex]; if (colours[colourIndex] > 31) colours[colourIndex] = 0; printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]); } if (kd & KEY_DOWN) { --colours[colourIndex]; if (colours[colourIndex] < 0) colours[colourIndex] = 31; printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]); } if (kd & KEY_LEFT) { --colourIndex; if (colourIndex < 0) colourIndex = 2; } if (kd & KEY_RIGHT) { ++colourIndex; if (colourIndex > 2) colourIndex = 0; } if (kd & KEY_Y) { robot.setPosition(start.x,start.y); path = NULL; node::cleanup(); } if(kd & KEY_B) { printf("Working...\n"); searched = true; node current(robot.getPosition().px, robot.getPosition().py,NULL); path = astar::generate_path( astar::search(¤t,&target) ); printf("Path found!\n"); } if (kd & KEY_R) { nextTouch = 2; } if (kd & KEY_L) { nextTouch = 1; } if(kd & KEY_TOUCH) { switch (nextTouch) { case 0: firstTouch = touch; draw::plot(touch.px,touch.py,RGB15(colours[0],colours[1],colours[2])); break; case 1: // Set start start.x = touch.px; start.y = touch.py; robot.setPosition(touch); break; case 2: // Set target target.x = touch.px; target.y = touch.py; break; default: break; } } if(keysHeld() & KEY_TOUCH) { if (nextTouch == 0) { lastTouch = touch; draw::line(firstTouch.px, firstTouch.py, lastTouch.px, lastTouch.py, RGB15(colours[0],colours[1],colours[2])); firstTouch = touch; //q.push(touch); } } if (keysUp() & KEY_TOUCH) { nextTouch = 0; } if (path) { if (searched && !path->empty()) { assert(path != NULL); assert(path->top() != NULL); robot.move(path->top()->x, path->top()->y); if (robot.getPosition().px == path->top()->x && robot.getPosition().py == path->top()->y) path->pop(); } else if (path->empty()) { node::cleanup(); delete path; path = NULL; searched = false; } } robot.draw(); draw::plot(target.x, target.y, RGB15(31,0,0)); draw::plot(target.x+1, target.y, RGB15(31,0,0)); draw::plot(target.x+2, target.y, RGB15(31,0,0)); draw::plot(target.x-1, target.y, RGB15(31,0,0)); draw::plot(target.x-2, target.y, RGB15(31,0,0)); draw::plot(target.x, target.y+1, RGB15(31,0,0)); draw::plot(target.x, target.y+2, RGB15(31,0,0)); draw::plot(target.x, target.y-1, RGB15(31,0,0)); draw::plot(target.x, target.y-2, RGB15(31,0,0)); draw::plot(target.x+1, target.y+1, RGB15(31,0,0)); draw::plot(target.x+1, target.y-1, RGB15(31,0,0)); draw::plot(target.x-1, target.y+1, RGB15(31,0,0)); draw::plot(target.x-1, target.y-1, RGB15(31,0,0)); } return 0; }
int main() { float scrollPos = 0.0f; float scrollDir = 0.0f const float scrollFriction = 0.9f; const float clampFriction = 0.9f; int dragAnchor = 0; bool draging = false; int prevDragAnchor = 0; float maxScrollPos = 100; while (1) { scanKeys(); // process input int down = keysDown(); int up = keysUp(); touchPosition touchPos; touchRead(&touchPos); if (down & KEY_TOUCH) { // always stop when tapping the screen scrollDir = 0.0f; if (touchPos.px < SCREEN_WIDTH / 2) { prevDragAnchor = dragAnchour = touchPos.py; draging = true; } else { int canvasPos = touchPos.py - scrollPos; int entry = canvasPos / ENTRY_HEIGHT; selectEntry(entry); } } else if (up & KEY_TOUCH) { draging = false; } // animate if (!draging) { scrollPos += scrollDir; scrollDir *= scrollFriction; if (fabs(scrollDir) < 0.01f) scrollDir = 0.0f; if (scrollPos < 0.0f) { // clamp to start scrollDir = 0.0f; scrollPos *= clampFriction; } else if (scrollPos > maxScrollPos) { // clamp to end scrollDir = 0.0f; scrollPos = scrollPos + (maxScrollPos - scrollPos) * clampFriction; } setScroll(int(scrollPos)); } else { setScroll(touchPos.py - dragAnchor); // track scrollDir scrollDir += touchPos.py - prevDragAnchor; scrollDir *= scrollFriction; prevDragAnchor = dragAnchor; } swiWaitForVBlank(); } }