void radar_setup(void) { /*----------------------------------------------------------------------------- * The radar will translate based on mapsize *-----------------------------------------------------------------------------*/ radar_background = sfRectangleShape_create(); sfVector2f radar_size; radar_size.x = 250; radar_size.y = 250; sfRectangleShape_setOutlineThickness(radar_background,2); sfRectangleShape_setOutlineColor(radar_background,sfColor_fromRGB(50,50,50)); sfRectangleShape_setFillColor(radar_background,sfColor_fromRGB(1,1,1)); sfRectangleShape_setSize(radar_background,radar_size); radar_blip_texture= sfTexture_createFromFile("res/radar_blip.png",NULL); radar_blip_texture_player= sfTexture_createFromFile("res/radar_blip_player.png",NULL); game_bounds = atoi(jnx_hash_get(config,"GAMEBOUNDS")); assert(game_bounds); }
void rh_init(struct resources *r) { /* TODO: add check for malloc and createFromFile */ r->textures = malloc(sizeof(sfTexture*) * TEXTURE_COUNT); for (size_t i = 0; i < TEXTURE_COUNT; ++i) { r->textures[i] = sfTexture_createFromFile(textures[i], NULL); } r->fonts = malloc(sizeof(sfFont*) * FONT_COUNT); for (size_t i = 0; i < FONT_COUNT; ++i) { r->fonts[i] = sfFont_createFromFile(fonts[i]); } }
int main(int argc, char **argv) { int window_width = 640; int window_height = 480; //Create the render window sfRenderWindow *window = NULL; if(!(window = sfRenderWindow_create((sfVideoMode) {window_width, window_height, 32}, "Mettle", sfClose|sfResize, NULL))) { printf("Unable to create RenderWindow\n"); exit(EXIT_FAILURE); } //Create a queue of inputs actionQueue *actions = actionQueue_create(); playerAction action = actionQueue_next(actions); //Load the hero sprite sfTexture *hero_texture = NULL; static const char *hero_texture_location = "data/img/leatherarmor.png"; if(!(hero_texture = sfTexture_createFromFile(hero_texture_location, NULL))) { printf("Unable to load %s\n", hero_texture_location); exit(EXIT_FAILURE); } entity *hero = entity_createPlayer((sfVector2i) {0, 0}, &action, hero_texture); //Create the "map" sfTexture *map_texture = NULL; static const char *map_texture_location = "data/img/tilesheet.png"; if(!(map_texture = sfTexture_createFromFile(map_texture_location, NULL))) { printf("Unable to load %s\n", map_texture_location); exit(EXIT_FAILURE); } int map_width = (int) ceilf((float) (window_width / TILE_SIZE)); int map_height = (int) ceilf((float) (window_height / TILE_SIZE)); //Allocate space sfSprite *tile = NULL; if(!(tile = sfSprite_create())) { printf("Unable to create sprite\n"); exit(EXIT_FAILURE); } //Initialize the tile sfSprite_setTexture(tile, map_texture, sfFalse); sfSprite_setTextureRect(tile, XY_TO_RECT(4, 2, TILE_SIZE, TILE_SIZE)); //Event holder sfEvent event; //Window active variable sfBool window_active = sfFalse; //Main loop while(sfRenderWindow_isOpen(window)) { //Process events while(sfRenderWindow_pollEvent(window, &event)) { switch(event.type) { //Handle keyboard input case(sfEvtKeyPressed): case(sfEvtKeyReleased): { playerAction action = handleKey(&event.key); if(action) { actionQueue_add(actions, action); } break; } case(sfEvtClosed): sfRenderWindow_close(window); break; case(sfEvtGainedFocus): window_active = sfTrue; break; case(sfEvtLostFocus): window_active = sfFalse; default: break; } } //While there are still actions to do while(action = actionQueue_next(actions)) { hero->ai->think(hero->ai); } //Clear the screen and render sfRenderWindow_clear(window, sfMagenta); //Draw the map int x,y; for(x = 0; x < map_width; x++) { for(y = 0; y < map_height; y++) { sfSprite_setPosition(tile, (sfVector2f) {x * TILE_SIZE, y * TILE_SIZE}); sfRenderWindow_drawSprite(window, tile, NULL); } } //Draw the hero displayComp_draw(hero->display, window); sfRenderWindow_display(window); #ifdef DEBUG sfVector2f pos = sfSprite_getPosition(hero->display->sprite); printf("\rPlayer at %d,%d (%f.0px, %f.0px)", hero->x, hero->y, pos.x, pos.y); fflush(stdout); #endif } //Cleanup sfRenderWindow_destroy(window); return EXIT_SUCCESS; }