void gameboyStep(Gameboy *gameboy) { inputStep(gameboy->joypad, gameboy->mmu); cpuStep(gameboy->cpu, gameboy->mmu); timerStep(gameboy->timer, gameboy->mmu, gameboy->cpu->cycles); displayStep(gameboy->display, gameboy->mmu, gameboy->cpu->cycles); }
void init(void) { // Starting services sf2d_init(); sf2d_set_vblank_wait(0); sftd_init(); srvInit(); aptInit(); hidInit(); audio_init(); //romfsInit(); // Configuring the right font to use (8bitoperator), and its proprieties font = sftd_load_font_file("font/eightbit.ttf"); // Configuring graphics in general (images, textures, etc) sf2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF)); /* Load Frisk textures Loop over every element in tex_arr_friskWalk and load the PNG buffer. */ for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { tex_arr_friskWalk[i][j] = loadTexture(friskFilenames[i][j]); } } room_init(); // Reusing 'i' from above. // Load room textures. for (int i = 0; i < 3; ++i) fillTexture(&rooms[i].bg); // TODO: Add actual save loading logic. For now, just assume this room. player_pos = rooms[room].exits[0].entrance; // Play music home = sound_create(BGM); if (home != NULL) audio_load_ogg("sound/music/house1.ogg", home); else home->status = -1; timerStep(); }
controllerWidget::controllerWidget(QWidget* parent, drawerWidget* dr, graphWidget* gr, graphInspector* ins,mover* m,drawerSettings* set,QList<graphObject*>* list) : QWidget(parent) { /*Настроим интерфейс*/ setupUi(this); /*Присвоим значения*/ drawer = dr; graph = gr; graphinspector = ins; settings = set; graphs = list; mov = m; steps = 360; count = 1; /*Создаем генераторы движения*/ circleMotion = new circleMotionGenerator(this); /*Настроим лэйауты*/ hboxLayout->addWidget(circleMotion); /*Создаем таймер*/ timer = new QTimer(this); QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timerStep())); QObject::connect(buildButton, SIGNAL(clicked()), this, SLOT(start())); QObject::connect(stepEdit, SIGNAL(valueChanged(int)),this, SLOT(changeStep(int))); QObject::connect(countEdit, SIGNAL(valueChanged(int)),this, SLOT(changeCount(int))); }
// Main part of the coding, where everything works (or not) int main(void) { init(); // Main loop while (aptMainLoop()) { // Verify button presses hidScanInput(); // Unsigned variables for different types of button presses u32 kDown = hidKeysDown(); u32 kHeld = hidKeysHeld(); // u32 kUp = hidKeysUp(); // Exit homebrew if (kDown & KEY_START) { break; } // Activate first easter egg else if (kDown & KEY_SELECT) { easterEgg = !easterEgg; } // Change pages for the easterEgg/debug menu. else if (kDown & KEY_R) { if (++easterPage > MAX_PAGE) easterPage = 0; } else if (kDown & KEY_L) { if (--easterPage < 0) easterPage = MAX_PAGE; } timerStep(); // If no movement, set the sprite timer to 0 if (kDown & KEY_UP || kDown & KEY_DOWN || kDown & KEY_LEFT || kDown & KEY_RIGHT) { sprTimer = 0; } // Reset horizontal and vertical speeds vsp = 0; hsp = 0; // Player movement (pretty easy to understand) // TODO: Would it be possible to make this less... iffy? if (kHeld & KEY_UP) { if (!(kHeld & KEY_DOWN)) { vsp = -.5; // Vertical speed to negative .5 playerDir = BACK; // Player direction = back } } if (kHeld & KEY_DOWN) { vsp = .5; // Vertical speed to .5 playerDir = FORWARD; // Player direction = up } if (kHeld & KEY_LEFT) { if (!(kHeld & KEY_RIGHT)) { hsp = -.5; // Vertical speed to negative .5 playerDir = LEFT; // Player direction = left } } if (kHeld & KEY_RIGHT) { hsp = .5; // Vertical speed to .5 playerDir = RIGHT; // Player direction = right } // Diagonal movement speed fix if (vsp != 0) { if (hsp != 0) { vsp *= .8; hsp *= .8; } } // Movement calculation... AND proper room colision. // TODO: Consider a function for translating and/or clamping coordinates directly? player_pos.x = fclamp(player_pos.x + hsp * dt, rooms[room].collision[0].x, rooms[room].collision[1].x); player_pos.y = fclamp(player_pos.y + vsp * dt, rooms[room].collision[0].y, rooms[room].collision[1].y); // Scrolling calculation. // TODO: Make these constants better/customizable. if (player_pos.x - camera_pos.x >= 300) { camera_pos.x = player_pos.x - 300; } else if (player_pos.x - camera_pos.x <= 100) { camera_pos.x = player_pos.x - 100; } camera_pos.x = fclamp(camera_pos.x, 0, rooms[room].scroll_max.x); if (player_pos.y - camera_pos.y >= 200) { camera_pos.y = player_pos.y - 200; } else if (player_pos.y - camera_pos.y <= 50) { camera_pos.y = player_pos.y - 50; } camera_pos.y = fclamp(camera_pos.y, 0, rooms[room].scroll_max.y); // Player sprites if (hsp == 0 && vsp == 0) curr_tex = tex_arr_friskWalk[playerDir][0]; else curr_tex = tex_arr_friskWalk[playerDir][(int)floor(sprTimer)]; // Sprite animation timer // TODO: Why .15 * .03 * actual time? sprTimer += (.03 * dt); while (sprTimer >= 4) { sprTimer -= 4; } if (!next_exit){ if (roomTimer < 255) { roomTimer = fmin(roomTimer + (4 * dt), 255); } next_exit = exit_room(room, &player_pos); } else { roomTimer -= 4 * dt; if (roomTimer <= 0) { room = next_exit->room_id; player_pos = next_exit->entrance; next_exit = NULL; roomTimer = 0; } } render(); // Swap sf2d framebuffers and wait for VBlank sf2d_swapbuffers(); } // Free images/textures/fonts from memory for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { sf2d_free_texture(tex_arr_friskWalk[i][j]); } } for (int i = 0; i < 3; ++i) { sf2d_free_texture(rooms[i].bg.tex); } sftd_free_font(font); // Exit services sf2d_fini(); sftd_fini(); sound_stop(home); audio_stop(); hidExit(); aptExit(); srvExit(); return 0; }