int main(int argc, char **argv) { DARNIT_SPRITE *sprite; if (argc <3) { fprintf(stdout, "Usage: %s <sprite> <direction>\n", argv[0]); return -1; } if (d_init("libDarnit spriteview", "spriteview", NULL) == NULL) { fprintf(stderr, "libDarnit failed to init\n"); return -1; } if ((sprite = d_sprite_load(argv[1], atoi(argv[2]), DARNIT_PFORMAT_RGB5A1)) == NULL) { fprintf(stderr, "Unable to open sprite %s\n", argv[1]); d_quit(); return -1; } d_sprite_move(sprite, 0, 0); d_sprite_animate_start(sprite); d_render_blend_enable(); for (;;) { d_render_begin(); d_sprite_draw(sprite); d_render_end(); d_loop(); } return 0; }
int object_init() { int i, objects, j, x, y, l, dir; const char *sprite; for (i = objects = 0; i < rpg.map.map->objects; i++) if (!strcmp(d_map_prop(rpg.map.map->object[i].ref, "TYPE"), "npc")) objects++; if (!(rpg.object.entry = malloc(sizeof(OBJECT_ENTRY) * objects)) && objects) return -1; rpg.object.bbox = d_bbox_new(objects); for (i = j = 0; i < rpg.map.map->objects; i++) { if (!strcmp(d_map_prop(rpg.map.map->object[i].ref, "TYPE"), "teleporter")) { /* TODO: Implement teleporters */ continue; } if (!strcmp(d_map_prop(rpg.map.map->object[i].ref, "TYPE"), "npc")) { x = rpg.map.map->object[i].x; y = rpg.map.map->object[i].y; l = rpg.map.map->object[i].l; MAP_COORD_DECODE(x, y, l, &x, &y); rpg.object.entry[j].x = x; rpg.object.entry[j].y = y; rpg.object.entry[j].layer = l; rpg.object.entry[j].data.pointer = NULL; rpg.object.entry[j].data.num = 0; sprite = MAP_OBJ_PROP("sprite", i); dir = atoi(MAP_OBJ_PROP("sprite_dir", i)); if (!strcmp(sprite, "NO SUCH KEY")) rpg.object.entry[j].sprite = d_sprite_load(sprite, dir, DARNIT_PFORMAT_RGB5A1); else rpg.object.entry[j].sprite = NULL; rpg.object.entry[j].handler = object_resolve(i); if (rpg.object.entry[j].handler) rpg.object.entry[j].handler(OBJECT_MSG_INIT, &rpg.object.entry[j]); j++; } } rpg.object.entries = objects; return 1; }
int main(int argc, char **argv) { int i, j, js0_x, js0_y, js1_x, js1_y; void *font, *surface, *text, *mapsheet, *sprite, *textinput, *mtsprite, *fps_text, *tilebuf, *fancy_text; void *music; char test[256], fps[16]; char *test_text; DARNIT_MOUSE mouse; DARNIT_KEYS keys; DARNIT_MAP *map; DARNIT_SPRITE *mapsprite; if (!d_init("TESTAPP - libDarnit", "testapp", NULL)) return -1; compression_test(); /* Sound/music */ music = d_sound_tracked_load("latyl-greasy_duck_v1.mod", DARNIT_AUDIO_STREAM, DARNIT_AUDIO_STEREO); d_sound_play(music, 0, 127, 127, 0); /* Text rendering */ test_text = malloc(64); font = d_font_load("dejavu_sans.ttf", 28, 512, 512); text = d_text_surface_new(font, 80, 800, 0, 460); fancy_text = d_text_surface_color_new(font, 16, 800, 0, 420); colorTest(fancy_text); fps_text = d_text_surface_new(font, 16, 200, 0, 40); /* Menutk test */ surface = d_menu_vertical_new("Hello\nGoodbye\nOther\nNothing\nLess than nothing", 50, 100, font, 200, 10, 3); sprintf(test_text, "Héllo, world. Modify m€! Test of offsets"); textinput = d_menu_textinput_new(0, 0, font, test_text, 64, 200); /* Sprites */ sprite = d_sprite_load("test.spr", 0, DARNIT_PFORMAT_RGB5A1); mapsprite = d_sprite_load("baurn.spr", 0, DARNIT_PFORMAT_RGB5A1); d_sprite_move(sprite, 50, 50); d_sprite_move(mapsprite, 0, 0); d_sprite_animate_start(sprite); d_sprite_animate_start(mapsprite); mtsprite = d_mtsprite_load("testspr.mts"); d_mtsprite_animate_start(mtsprite); /* Maps */ mapsheet = d_render_tilesheet_load("mapsheet.png", 32, 32, DARNIT_PFORMAT_RGBA8); if ((map = d_map_load("testmap_iso.ldmz")) == NULL) fprintf(stderr, "Map load failed\n"); d_tilemap_sprite_add(map->layer[0].tilemap, mapsprite); /* Tile caches */ tilebuf = d_render_tile_new(1, mapsheet); d_render_tile_move(tilebuf, 0, 64, 64); d_render_tile_tilesheet_coord_set(tilebuf, 0, 16, 16, 32, 32); /* Misc */ fprintf(stderr, "String lenght: %i\n", d_font_string_w(font, "ASDFÅÄÖ,,")); for (i = j = 0;;) { d_sprite_move(mapsprite, 64, j * 4); keys = d_keys_get(); d_text_surface_reset(text); d_text_surface_reset(fps_text); mouse = d_mouse_get(); d_joystick_get(&js0_x, &js0_y, &js1_x, &js1_y); sprintf(test, "X: %i, Y: %i, W: %i;; TX: %i, TY: %i;; nub0 (%i,%i) ;; nub1(%i,%i)", mouse.x, mouse.y, mouse.wheel, i*4, j*4, js0_x, js0_y, js1_x, js1_y); sprintf(fps, "%i", d_last_frame_time()); d_text_surface_string_append(text, test); d_text_surface_string_append(fps_text, "ASDFÅÄÖ,,"); if (keys.lmb) d_render_fade_in(1000, 1.0f, 0.0f, 0.0f); if (keys.rmb) d_render_fade_out(1000); d_render_begin(); if (keys.left == 1) i--; if (keys.right == 1) i++; if (keys.up == 1) j--; if (keys.down == 1) j++; if (keys.select) fprintf(stderr, "Blololol\n"); if (keys.r == 1) d_tilemap_camera_move(map->layer->tilemap, i*4, j*4); d_render_blend_enable(); d_tilemap_draw(map->layer->tilemap); if (keys.l == 1) if (d_menu_loop(surface) != -1) return 0; d_menu_loop(textinput); d_sprite_draw(sprite); d_text_surface_draw(text); d_text_surface_draw(fancy_text); d_text_surface_draw(fps_text); d_render_offset(-200, -200); d_mtsprite_draw(mtsprite); d_render_offset(0, 0); d_render_blend_disable(); d_render_tile_draw(tilebuf, 1); d_render_end(); d_loop(); } return 0; }
void character_room_init() { character_room.pane.pane = ui_pane_create(10, 10, DISPLAY_WIDTH - 20, DISPLAY_HEIGHT - 20, character_room.vbox = ui_widget_create_vbox()); character_room.pane.next = NULL; character_room.pane.pane->background_color.r = PANE_R; character_room.pane.pane->background_color.g = PANE_G; character_room.pane.pane->background_color.b = PANE_B; ui_vbox_add_child(character_room.vbox, character_room.label = ui_widget_create_label(gfx.font.large, "The Dictators"), 0); UI_WIDGET *tmp; character_room.hbox1 = ui_widget_create_hbox(); tmp = ui_widget_create_vbox(); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.large, "Rump"), 0); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.small, "Favourite vegetable: Carrot"), 0); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.small, "\"Make America hate again!\""), 0); ui_hbox_add_child(character_room.hbox1, tmp, 1); tmp = ui_widget_create_vbox(); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.large, "Dim Young 'Un"), 0); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.small, "Favourite vegetable: Potato"), 0); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.small, "\"Everyone be like: Dear Leader, your onion breath is so fresh!\""), 0); ui_hbox_add_child(character_room.hbox1, tmp, 1); character_room.hbox2 = ui_widget_create_hbox(); tmp = ui_widget_create_vbox(); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.large, "Shitler"), 0); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.small, "Favourite vegetable: Onion"), 0); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.small, "\"NEIN NEIN NEIN NEIN\""), 0); ui_hbox_add_child(character_room.hbox2, tmp, 1); tmp = ui_widget_create_vbox(); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.large, "Ståhlin"), 0); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.small, "Favourite vegetable: Rutabaga"), 0); ui_vbox_add_child(tmp, ui_widget_create_label(gfx.font.small, "\"My gulag brings all the boys to the yard\""), 0); ui_hbox_add_child(character_room.hbox2, tmp, 1); character_room.hbox_buttons = ui_widget_create_hbox(); ui_vbox_add_child(character_room.hbox_buttons, character_room.button.back = ui_widget_create_button_text(gfx.font.small, "Back"), 0); ui_vbox_add_child(character_room.vbox, character_room.hbox1, 1); ui_vbox_add_child(character_room.vbox, character_room.hbox2, 1); ui_vbox_add_child(character_room.vbox, character_room.hbox_buttons, 0); character_room.button.back->event_handler->add(character_room.button.back, button_callback, UI_EVENT_TYPE_UI_WIDGET_ACTIVATE); character_room.sprite[0] = d_sprite_load("res/player.spr", 2, DARNIT_PFORMAT_RGBA8); character_room.sprite[1] = d_sprite_load("res/player2.spr", 3, DARNIT_PFORMAT_RGBA8); character_room.sprite[2] = d_sprite_load("res/player3.spr", 2, DARNIT_PFORMAT_RGBA8); character_room.sprite[3] = d_sprite_load("res/player4.spr", 3, DARNIT_PFORMAT_RGBA8); d_sprite_move(character_room.sprite[0], 160, 180); d_sprite_move(character_room.sprite[1], DISPLAY_WIDTH - 180, 180); d_sprite_move(character_room.sprite[2], 160, 360); d_sprite_move(character_room.sprite[3], DISPLAY_WIDTH - 180, 360); d_sprite_activate(character_room.sprite[0], 2); d_sprite_activate(character_room.sprite[1], 3); d_sprite_activate(character_room.sprite[2], 2); d_sprite_activate(character_room.sprite[3], 3); int i; for(i = 0; i < 4; i++) { d_sprite_animate_start(character_room.sprite[i]); } }