int main(int argc, char *argv[]) { GList* list = NULL; json_t *root; SDL_Surface *optimized_surface = NULL; SDL_Surface *temp = NULL; Sound *bg_music = NULL; Sound *level_music = NULL; int done; const Uint8 *keys; char imagepath[512]; game_initialize_system(); SDL_ShowCursor(SDL_DISABLE); bg_music = sound_load_music("sounds/vanguard_bouncy.mp3"); if(!bg_music) { slog("Could not load music\n"); } level_music = sound_load_music("sounds/chippy_cloud_kid.mp3"); if(!level_music) { slog("Could not load music\n"); } Mix_VolumeMusic(5); if(temp) { optimized_surface = SDL_ConvertSurface( temp, graphics_surface->format, NULL ); SDL_FreeSurface(temp); } SDL_Event e; done = 0; int lock = true; do { if(menu_flag) { menu_draw(); if(lock == false) { Mix_HaltMusic(); lock = true; } if(Mix_PlayingMusic() == 0) { Mix_PlayMusic(bg_music->music, -1); } } else { tilemap_render_tile(); entity_draw_all(); if(lock == true) { Mix_HaltMusic(); lock = false; } if(Mix_PlayingMusic() == 0) { Mix_PlayMusic(level_music->music, -1); } } mouse_draw_self(); graphics_next_frame(); SDL_PumpEvents(); entity_think_all(); while(SDL_PollEvent(&e) != 0) { if(e.type == SDL_QUIT) { done = 1; } bool leftclick = false ; bool rightclick = false; if(e.type == SDL_MOUSEBUTTONDOWN) { if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) { leftclick = true; } else if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)) { rightclick = true; } } if(leftclick == true) { if(menu_flag) menu_click(); else tilemap_click(); } else if(rightclick == true) { if(menu_flag) menu_click(); else tilemap_remove_tile(); } bool pressed = false; if(e.type == SDL_KEYDOWN) { if(!pressed) { if(make_flag) { keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_W]) { State state = UP; tilemap_m_click(state); } else if(keys[SDL_SCANCODE_A]) { State state = LEFT; tilemap_m_click(state); } else if(keys[SDL_SCANCODE_S]) { State state = DOWN; tilemap_m_click(state); } else if(keys[SDL_SCANCODE_D]) { State state = RIGHT; tilemap_m_click(state); } if(keys[SDL_SCANCODE_T]) { State state = UP; tilemap_c_click(state); } else if(keys[SDL_SCANCODE_F]) { State state = LEFT; tilemap_c_click(state); } else if(keys[SDL_SCANCODE_G]) { State state = DOWN; tilemap_c_click(state); } else if(keys[SDL_SCANCODE_H]) { State state = RIGHT; tilemap_c_click(state); } } } pressed = true; } else if(e.type == SDL_KEYUP) { pressed = false; } } keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } SDL_RenderPresent(graphics_renderer); // update the screen with any rendering performed since previous call } while(!done); exit(0); return 0; }
/* * Initialize the application list by reading in the EMUDESK.INF * file, either from memory or from the disk if the shel_get * indicates no message is there. */ void app_start(void) { WORD i, x, y; ANODE *pa; WSAVE *pws; BYTE *pcurr, *ptmp, *pauto = NULL; WORD envr, xcnt, ycnt, xcent, wincnt, dummy; /* remember start drive */ gl_stdrv = dos_gdrv(); G.g_pbuff = gl_buffer; for (i = NUM_ANODES - 2; i >= 0; i--) G.g_alist[i].a_next = &G.g_alist[i + 1]; G.g_ahead = (ANODE *) NULL; G.g_aavail = G.g_alist; G.g_alist[NUM_ANODES - 1].a_next = (ANODE *) NULL; app_rdicon(); G.g_wicon = (12 * gl_wschar) + (2 * G.g_iblist[0].ib_xtext); G.g_hicon = G.g_iblist[0].ib_hicon + gl_hschar + 2; xcnt = G.g_wdesk / (G.g_wicon+MIN_WINT);/* icon count */ G.g_icw = G.g_wdesk / xcnt; /* width */ ycnt = G.g_hdesk / (G.g_hicon+MIN_HINT);/* icon count */ G.g_ich = G.g_hdesk / ycnt; /* height */ shel_get(gl_afile, SIZE_AFILE); if (gl_afile[0] != '#') /* invalid signature */ { /* so read from disk */ LONG ret; WORD fh; char inf_file_name[16]; strcpy(inf_file_name, INF_FILE_NAME); inf_file_name[0] += gl_stdrv; /* Adjust drive letter */ ret = dos_open(inf_file_name, 0x0); if (ret >= 0L) { fh = (WORD) ret; ret = dos_read(fh, SIZE_AFILE, gl_afile); G.g_afsize = (ret < 0L) ? 0L : ret; dos_close(fh); gl_afile[G.g_afsize] = '\0'; } } /* If there's still no desktop.inf data, use built-in now: */ if (gl_afile[0] != '#') { LONG drivemask; char *text; int icon_index = 0; int drive_x = 0, drive_y = 0; int trash_x, trash_y; int icon_type; char drive_letter; /* Environment and Windows */ strcat(gl_afile, desk_inf_data1); /* Scan for valid drives: */ drivemask = dos_sdrv(dos_gdrv()); for (i = 0; i < BLKDEVNUM; i++) { if (drivemask&(1L<<i)) { x = strlen(gl_afile); drive_x = icon_index % xcnt; /* x position */ drive_y = icon_index / xcnt; /* y position */ icon_type = (i > 1) ? 0 /* Hard disk */ : 1 /* Floppy */; drive_letter = 'A' + i; rsrc_gaddr(R_STRING, STDISK, (void **)&text); sprintf(gl_afile + x, "#M %02X %02X %02X FF %c %s %c@ @\r\n", drive_x, drive_y, icon_type, drive_letter, text, drive_letter); icon_index++; } } /* Copy core data part 2 */ strcat(gl_afile, desk_inf_data2); /* add Trash icon to end */ x = strlen(gl_afile); trash_x = 0; /* Left */ trash_y = ycnt-1; /* Bottom */ if (drive_y >= trash_y) /* if the last drive icon overflows over */ trash_x = xcnt-1; /* the trash row, force trash to right */ rsrc_gaddr(R_STRING, STTRASH, (void **)&text); sprintf(gl_afile + x, "#T %02X %02X 03 FF %s@ @\r\n", trash_x, trash_y, text); G.g_afsize = strlen(gl_afile); } wincnt = 0; inf_rev_level = 0; pcurr = gl_afile; while(*pcurr) { if (*pcurr++ != '#') /* look for start of line */ continue; switch(*pcurr) { case 'R': /* revision level */ pcurr++; pcurr = scan_2(pcurr,&inf_rev_level); break; case 'Z': /* autorun: Z nn pathname@ */ pcurr = scan_str(pcurr+5,&pauto); /* save pathname in buffer */ break; /* (a bit wasteful) */ case 'T': /* Trash */ case 'M': /* Media (Hard/Floppy) */ case 'G': /* GEM Application */ case 'Y': /* GEM App. with parms */ case 'F': /* File (DOS w/o parms) */ case 'P': /* Parm (DOS w/ parms) */ case 'D': /* Directory */ case 'I': /* Executable file icon */ case 'N': /* Non-executable file icon */ pa = app_alloc(TRUE); if (!pa) /* paranoia */ return; pcurr = app_parse(pcurr, pa); if ((pa->a_type == AT_ISFILE) && pauto) { /* autorun exists & not yet merged */ if (strcmp(pauto,pa->a_pappl) == 0) { pa->a_flags |= AF_AUTORUN; /* it's this program */ pauto = NULL; /* (and no other) */ } } break; case 'W': /* Window */ pcurr++; if (wincnt < NUM_WNODES) { pws = &G.g_cnxsave.cs_wnode[wincnt]; pcurr = scan_2(pcurr, &dummy); pcurr = scan_2(pcurr, &pws->vsl_save); /* BugFix */ pcurr = scan_2(pcurr, &pws->x_save); pws->x_save *= gl_wchar; pcurr = scan_2(pcurr, &pws->y_save); pws->y_save *= gl_hchar; pcurr = scan_2(pcurr, &pws->w_save); pws->w_save *= gl_wchar; pcurr = scan_2(pcurr, &pws->h_save); pws->h_save *= gl_hchar; /* */ pcurr = scan_2(pcurr, &pws->obid_save); ptmp = pws->pth_save; pcurr++; while(*pcurr != '@') *ptmp++ = *pcurr++; *ptmp = '\0'; wincnt += 1; } break; case 'E': /* Environment */ pcurr++; pcurr = scan_2(pcurr, &envr); G.g_cnxsave.cs_view = ( (envr & INF_E1_VIEWTEXT) != 0); G.g_cnxsave.cs_sort = ( (envr & INF_E1_SORTMASK) >> 5); G.g_cnxsave.cs_confdel = ( (envr & INF_E1_CONFDEL) != 0); G.g_cnxsave.cs_confcpy = ( (envr & INF_E1_CONFCPY) != 0); G.g_cnxsave.cs_dblclick = envr & INF_E1_DCMASK; pcurr = scan_2(pcurr, &envr); G.g_cnxsave.cs_confovwr = ( (envr & INF_E2_ALLOWOVW) == 0); G.g_cnxsave.cs_mnuclick = ( (envr & INF_E2_MNUCLICK) != 0); menu_click(G.g_cnxsave.cs_mnuclick, 1); /* tell system */ if (envr & INF_E2_IDTDATE) G.g_cnxsave.cs_datefmt = DATEFORM_IDT; else G.g_cnxsave.cs_datefmt = (envr & INF_E2_DAYMONTH) ? DATEFORM_DMY : DATEFORM_MDY; if (envr & INF_E2_IDTTIME) G.g_cnxsave.cs_timefmt = TIMEFORM_IDT; else G.g_cnxsave.cs_timefmt = (envr & INF_E2_24HCLOCK) ? TIMEFORM_24H : TIMEFORM_12H; sound(FALSE, !(envr & INF_E2_SOUND), 0); pcurr = scan_2(pcurr, &dummy); /* skip video stuff */ pcurr = scan_2(pcurr, &dummy); pcurr = scan_2(pcurr, &envr); if (envr & INF_E5_NOSORT) G.g_cnxsave.cs_sort = CS_NOSORT; break; } } for (pa = G.g_ahead; pa; pa = pa->a_next) { if (pa->a_flags & AF_ISDESK) { x = pa->a_xspot * G.g_icw; y = pa->a_yspot * G.g_ich + G.g_ydesk; snap_disk(x, y, &pa->a_xspot, &pa->a_yspot, 0, 0); } } /* set up outlines for dragging files displayed as icons */ G.g_nmicon = 9; /* number of points */ memset(G.g_xyicon, 0, sizeof(G.g_xyicon)); xcent = (G.g_wicon - G.g_iblist[0].ib_wicon) / 2; G.g_xyicon[0] = xcent; G.g_xyicon[2] = xcent; G.g_xyicon[3] = G.g_hicon-gl_hschar-2; G.g_xyicon[5] = G.g_hicon-gl_hschar-2; G.g_xyicon[7] = G.g_hicon; G.g_xyicon[8] = G.g_wicon; G.g_xyicon[9] = G.g_hicon; G.g_xyicon[10] = G.g_wicon; G.g_xyicon[11] = G.g_hicon-gl_hschar-2; G.g_xyicon[12] = G.g_wicon-xcent; G.g_xyicon[13] = G.g_hicon-gl_hschar-2; G.g_xyicon[14] = G.g_wicon-xcent; G.g_xyicon[16] = xcent; /* set up outlines for dragging files displayed as text */ G.g_nmtext = 5; /* number of points */ memset(G.g_xytext, 0, sizeof(G.g_xytext)); G.g_xytext[2] = gl_wchar * DRAG_BOX_WIDTH; G.g_xytext[4] = gl_wchar * DRAG_BOX_WIDTH; G.g_xytext[5] = gl_hchar; G.g_xytext[7] = gl_hchar; }