static void aff_obj(char c, SDL_Rect position, SDL_Surface *ecran) { static SDL_Surface *ladder = NULL; static SDL_Surface *wall = NULL; static SDL_Surface *monster = NULL; static SDL_Surface *pj = NULL; static SDL_Surface *door = NULL; static SDL_Surface *key = NULL; if (!ladder) { init_sprites(&ladder, &wall, &monster, &pj); door = xIMG_Load("../image/exit.png"); key = xIMG_Load("../image/key.png"); } if (c == Wall) xSDL_BlitSurface(wall, NULL, ecran, &position); else if (c == Ladder) xSDL_BlitSurface(ladder, NULL, ecran, &position); else if (c == Monster) xSDL_BlitSurface(monster, NULL, ecran, &position); else if (c == Entry) xSDL_BlitSurface(pj, NULL, ecran, &position); else if (c == Exit) xSDL_BlitSurface(door, NULL, ecran, &position); else if (c == Key) xSDL_BlitSurface(key, NULL, ecran, &position); }
void init_struct(t_mega *all) { all->e.refresh = 1; init_hook(&all->hook); init_cam(&all->cam, (int)START_X, (int)START_Y); init_player(&all->player); init_textures(all); all->sprites = init_sprites(all); init_minimap(&all->e, &all->hook.minimap); stock_minimap(all); all->door.x = 0; }
int handle_init () { idle_timeout = config_get_intval("idle_timeout", 300); memset(&fds, 0, sizeof(fds)); /*proxy_fd = connect_to_svr( config_get_strval ("dbproxy_ip"),*/ /*config_get_intval("dbproxy_port", 0), 65535, 1 );*/ statistic_file = config_get_strval("statistic_logfile"); if ( load_dlls(config_get_strval("games_conf")) == -1 ) return -1; setup_timer(); init_sprites(); if (config_get_strval("addr_mcast_ip")) { if (create_addr_mcast_socket() == 0) { send_addr_mcast_pkg(addr_mcast_1st_pkg); DEBUG_LOG("send mcast"); } else { return -1; } } return 0; }
int main(void) { unsigned char idle = 0; // the crt has disabled interrupts before main is called // z88dk tracks the border colour so that beeper audio does not change the border colour while playing. // (this project contains a 3rd party ntropic player that does not obey z88dk convention so we set the border to same colour) zx_border(INK_BLACK); // set up the block memory allocator with one queue // max size requested by sp1 will be 24 bytes or block size of 25 (+1 for overhead) balloc_reset(0); // make queue 0 empty balloc_addmem(0, sizeof(block_of_ram)/25, 24, block_of_ram); // add free memory from bss section balloc_addmem(0, 8, 24, (void *)0xd101); // another eight from an unused area // interrupt mode 2 setup_int(); // sp1.lib sp1_Initialize(SP1_IFLAG_MAKE_ROTTBL | SP1_IFLAG_OVERWRITE_TILES | SP1_IFLAG_OVERWRITE_DFILE, INK_BLACK | PAPER_BLACK, ' '); // sp1_Validate(&cr); // not necessary since sp1_Initialize will not mark screen for update ps0.bounds = &cr; ps0.flags = SP1_PSSFLAG_INVALIDATE; ps0.visit = 0; intrinsic_ei(); // setup our font pt = font; for (i = 0; i < 96; ++i, pt += 8) sp1_TileEntry(32 + i, pt); // setup the bg tiles pt = tiles; for (i = 0; i < TILES_LEN; ++i, pt += 8) sp1_TileEntry(TILES_BASE + i, pt); init_sprites(); draw_menu(); srand(tick); // 256 different games are possible while(1) { key = in_inkey(); if (key) { if (key == '4') { playfx(FX_SELECT); in_wait_nokey(); run_redefine_keys(); idle = 0; draw_menu(); } if (key == '1' || key == '2' || key == '3') { playfx(FX_SELECT); joy_k.left = in_key_scancode(keys[0]); joy_k.right = in_key_scancode(keys[1]); // we don't use up/down in this game joy_k.down = in_key_scancode(keys[0]); joy_k.up = in_key_scancode(keys[1]); joy_k.fire = in_key_scancode(keys[2]); if (key == '1') joyfunc = (JOYFUNC)in_stick_keyboard; if (key == '2') joyfunc = (JOYFUNC)in_stick_kempston; if (key == '3') joyfunc = (JOYFUNC)in_stick_sinclair1; // run game run_intro(); run_play(); idle = 0; draw_menu(); } } if (idle++ == 255) { // go back to the welcome screen after a while // if the player doesn't do anything idle = 0; draw_menu(); } wait(); sp1_UpdateNow(); } }
int main (int argc, char *argv[]) { int ec; MaxApplZone (); game.clock_enabled = FALSE; game.state = STATE_INIT; init_machine (argc, argv); game.color_fg = 15; game.color_bg = 0; if ((game.sbuf = calloc (_WIDTH, _HEIGHT)) == NULL) { ec = err_NotEnoughMemory; goto bail_out; } #ifdef USE_HIRES if ((game.hires = calloc (_WIDTH * 2, _HEIGHT)) == NULL) { ec = err_NotEnoughMemory; goto bail_out_2; }; opt.hires = 1; #endif if (init_sprites () != err_OK) { ec = err_NotEnoughMemory; goto bail_out_3; } if (init_video () != err_OK) { ec = err_Unk; goto bail_out_4; } console_init (); report ("--- Starting console ---\n\n"); _D ("Init sound"); init_sound (); game.ver = -1; /* Disable conf file warning */ report (" \nSarien " VERSION " is ready.\n"); if (game.state < STATE_LOADED) { console_prompt (); do { main_cycle (); } while (game.state < STATE_RUNNING); if (game.ver < 0) game.ver = 0; /* Enable conf file warning */ } ec = run_game (); deinit_sound (); deinit_video (); bail_out_4: deinit_sprites (); bail_out_3: #ifdef USE_HIRES free (game.hires); #endif bail_out_2: free (game.sbuf); bail_out: if (ec == err_OK || ec == err_DoNothing) { deinit_machine (); exit (ec); } deinit_machine (); return ec; }
int main(int argc, char* args[]) { // This will be the window we'll be rendering to SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; TTF_Font *font; SDL_Texture *sheet = NULL; Text text; init_sprites(); event_init(); if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("SDL could not initialize! SDL_ERROR: %s\n", SDL_GetError()); } else { //if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 1)) { // printf("Warning: Linear texture filtering not enabled"); //} window = SDL_CreateWindow("Piggle", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (window == NULL) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); } else { renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); if (renderer == NULL) { printf("Renderer couldn't be created. Shit's f****d, becuase %s" ", dude.\n", SDL_GetError()); } else { SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); int imgFlags = IMG_INIT_PNG; if (!(IMG_Init(imgFlags) & imgFlags)) { printf("SDL_image couldn't be initialized. Shit's f****d, " "because %s, dude.\n", IMG_GetError()); } if (TTF_Init() == -1) { printf("SDL_ttf couldn't initialize. Shit's f****d, becuase" " %s, dude.\n", TTF_GetError()); } } font = TTF_OpenFont("DroidSansMono.ttf", 16); if (font == NULL) { printf("Failed to load lazy font. Shit's f****d, because %s, " "dude.", TTF_GetError()); } sheet = loadTexture("img/sprites.png", renderer); // When quit is set to true, we'll stop running bool quit = false; piggle_scene_over = false; // Event handler SDL_Event sdl_event; // Set the current scene to the start scene piggle_scene_update = start_scene_update; while (!quit) { timer_start(); EventList events = EventList_new(); while (SDL_PollEvent(&sdl_event) != 0) { Event event; // If the user presses that little "x" if (sdl_event.type == SDL_QUIT) { quit = true; event.type = QUIT; } else if (sdl_event.type == SDL_KEYDOWN) { event.type = KEYDOWN; int key = sdl_event.key.keysym.sym; event.value = event_value_from_key(key); } else if (sdl_event.type == SDL_KEYUP) { event.type = KEYUP; int key = sdl_event.key.keysym.sym; event.value = event_value_from_key(key); } else { continue; } events.add_event(&events, event); } SDL_RenderClear(renderer); DrawActionList actions = DrawActionList_new(); piggle_scene_update(&events, &actions); events.destroy(&events); int i; for (i = 0; i < actions.length; i++) { DrawAction action = actions.actions[i]; if (action.type == SPRITE) { SDL_Rect *sprite = &sprites[action.sprite]; SDL_Rect dest; dest.x = action.x; dest.y = action.y; dest.w = sprite->w; dest.h = sprite->h; SDL_RenderCopy(renderer, sheet, sprite, &dest); } else if (action.type == TEXT) { SDL_Color color = {action.text.red, action.text.green, action.text.blue}; textureFromText(action.text.text, color, &text, font, renderer); SDL_Rect textRect; textRect.x = action.x; textRect.y = action.y; textRect.w = text.width; textRect.h = text.height; SDL_RenderCopy(renderer, text.texture, NULL, &textRect); SDL_DestroyTexture(text.texture); } else if (action.type == RECTANGLE) { SDL_Rect rect = {.x = action.x, .y = action.y, .w = action.rect.width, .h = action.rect.height}; SDL_SetRenderDrawColor(renderer, action.rect.red, action.rect.green, action.rect.blue, 255); SDL_RenderFillRect(renderer, &rect); } } SDL_RenderPresent(renderer); actions.destroy(&actions); if (piggle_scene_over) { piggle_scene_update = piggle_scene_next; piggle_scene_over = false; } if (timer_get_ticks() < 1000 / 60) { SDL_Delay((1000 / 60) - timer_get_ticks()); } } } } SDL_DestroyTexture(sheet); SDL_DestroyTexture(text.texture); text.texture = NULL; sheet = NULL; TTF_CloseFont(font); font = NULL; SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); window = NULL; renderer = NULL; // Quit SDL subsystems TTF_Quit(); IMG_Quit(); SDL_Quit(); event_uninit(); return 0; }
int init_service(int isparent) { if (!isparent) { DEBUG_LOG("INIT_SERVICE"); const char *ip= get_ip_ex(0x01); if ( strncmp( ip,"10.",3 )==0 ) { g_is_test_env=true; DEBUG_LOG("=============TEST ENV TRUE ============="); }else{ g_is_test_env=false; DEBUG_LOG("=============TEST ENV FALSE ============="); } g_log_send_buf_hex_flag=g_is_test_env?1:0; if (sizeof(sprite_t) >= SPRITE_STRUCT_LEN - 800 || sizeof(grp_loop_t) != VIP_BUFF_LEN) { ERROR_RETURN(("sprite struct not big enough\t[%lu %u]", sizeof(sprite_t), SPRITE_STRUCT_LEN), -1); } srand(time(0) * get_server_id()); setup_timer(); INIT_LIST_HEAD(&(g_events.timer_list)); INIT_LIST_HEAD(&active_box_list); if ( config_get_strval("_use_lua_config") ==NULL ){ config_init("./conf/common.conf"); } statistic_logfile = config_get_strval("statistic_file"); if (!statistic_logfile) return -1; if ((init_cli_proto_handles(0) == -1) || (init_db_proto_handles(0) == -1) || (init_home_handle_funs() == -1) || (init_switch_handle_funs() == -1) || (init_all_timer_type() == -1) || (init_magic_code_proto_handles(0) == -1) || (init_spacetime_code_proto_handles(0) == -1) || (init_mall_proto_handles(0) == -1) ) { return -1; } init_sprites(); init_exp_lv(); init_home_maps(); init_all_items(); init_beast_grp(); init_rand_infos(); init_npcs(); init_all_skills(); init_all_clothes(); init_sys_info(); init_all_tasks(); init_mail(); init_shops(); init_vip_items(); init_products(); idc_type = config_get_intval("idc_type" ,1); KDEBUG_LOG(0, "ONLINE START\t[%lu %d]", sizeof(sprite_t), idc_type); if ( //11 (load_xmlconf("./conf/items.xml", load_items) == -1) || (load_xmlconf("./conf/clothes.xml", load_clothes) == -1) || (load_xmlconf("./conf/beasts.xml", load_beasts) == -1) // || (load_xmlconf("./conf/pet_exchange.xml", load_pet_exchange) == -1)//3M || (load_xmlconf("./conf/pet_exchange_egg.xml", load_pet_exchange_egg) == -1) //62 || (load_xmlconf("./conf/gplan.xml", load_rare_beasts) == -1) || (load_xmlconf("./conf/titles.xml", load_honor_titles) == -1) || (load_xmlconf("./conf/picsrv.xml", load_picsrv_config) == -1) ) { return -1; } if ( load_xmlconf("./conf/beastgrp.xml", load_beast_grp) == -1 || (load_xmlconf("./conf/handbook.xml", load_handbook) == -1) || (load_xmlconf("./conf/suits.xml", load_suit) == -1) || ( load_xmlconf("./conf/maps.xml", load_maps) == -1) || (load_xmlconf("./conf/rand_item.xml", load_rand_item) == -1) || (load_xmlconf("./conf/vip_item.xml", load_vip_item) == -1) || (load_xmlconf("./conf/commodity.xml", load_products) == -1) || (load_xmlconf("./conf/skills_price.xml", load_all_skills) == -1) || (load_xmlconf("./conf/tasks_new.xml", load_tasks) == -1)//task:12M || (load_xmlconf("./conf/tasks_new.xml", load_task_loops) == -1) || (load_xmlconf("./conf/holiday.xml", load_holiday_factor) == -1) || (load_xmlconf("./conf/box.xml", load_box) == -1) || (load_xmlconf("./conf/exchanges.xml", load_exchange_info) == -1) || (load_xmlconf("./conf/npc.xml", load_npc) == -1) || (load_xmlconf("./conf/npcSkills.xml", load_shop_skill) == -1) || (load_xmlconf("./conf/npcShop.xml", load_shop_item) == -1) || (load_xmlconf("./conf/mail.xml", load_sys_mail) == -1) || (load_xmlconf("./conf/sysinfo.xml", load_sys_info) == -1) || (load_xmlconf("./conf/fishGame.xml", load_fish_info) == -1) || (load_xmlconf("./conf/professtion.xml", load_init_prof_info) == -1) || (load_xmlconf("./conf/maze.xml", load_maze_xml) == -1) || (load_xmlconf("./conf/mapcopy.xml", load_map_copy) == -1) ) return -1; // sleep(1000); activate_boxes(); start_maze_timer(); /* if(tm_load_dirty("./data/tm_dirty.dat") < 0){ KERROR_LOG(0, "Failed to load drity word file!"); return -1; } */ init_batter_teams(); init_batter_infos(); connect_to_switch_timely(0, 0); regist_timers(); udp_report_fd = create_udp_socket(&udp_report_addr, config_get_strval("report_svr_ip"), config_get_intval("report_svr_port", 0)); udp_post_fd = create_udp_socket(&udp_post_addr, config_get_strval("post_svr_ip"), config_get_intval("post_svr_port", 0)); switch (idc_type) { case idc_type_dx: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("dx_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; case idc_type_wt: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("wt_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; case idc_type_internal: case idc_type_internal + 1: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("in_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; default: return -1; } } return 0; }