B_Block *spawn_bb_rect(float x, float y, float z,float w, float h, float d){ B_Block *rect = NULL; rect = newBBlock(); if(rect == NULL){ return NULL; } rect->position.x = x; rect->position.y = y; rect->position.z = z; rect->self = rect; rect->texture = sprite_load(const_cast<char *>("textures/block_tex.jpg"), 640, 640, 1); rect->normal_map = sprite_load(const_cast<char *>("textures/block_tex_normal.jpg"), 640, 640, 1); rect->shaderProgram = get_shader_program(NORMALMAP_SHADER); rect->update = b_update; rect->updateRate = 0; rect->mass = 10.0f; rect->halfExtents.x= w; rect->halfExtents.y= h; rect->halfExtents.z= d; rect->model = readOBJ(const_cast<char *>("textures/testblock.obj")); rect->body = add_new_box_to_world(rect->halfExtents.x,rect->halfExtents.y,rect->halfExtents.z,rect->mass,0.0f,0.0f,0.0f,1); //set_angular_props(rect->body,0,0,0,0,0,0); set_body_position(rect->body, x, y, z); set_body_friction(rect->body, 1000000.0f); set_body_restitution(rect->body, 0.0f); set_damping(rect->body,0.0f,0.0f); set_sleeping_thresholds(rect->body,0.5f,0.5f); plEnableCallbacks(rect->body->body); return rect; }
//end void player_init(){ int i = 0; Tile start = tile_start(); Vec2d pos = {start.mBox.x,start.mBox.y}; SDL_Rect bound = {PLAYER_FRAMEW*.2f,PLAYER_FRAMEW*.2f,PLAYER_FRAMEW*.6f, PLAYER_FRAMEH*.6f}; Sprite *player_sprite = sprite_load(player_char_file,PLAYERW, PLAYERH, PLAYER_FRAMEW, PLAYER_FRAMEH); player_sprite->fpl = 9; animCurrent = WALK; player = entity_load(player_sprite,pos, 100, 100, 0 ); slog("Player: X: %i Y: %i", player->position.x, player->position.y); playerBody.image = player->sprite; playerBody.image_slash = sprite_load("images/player/slash/body slash.png",PLAYERW, PLAYERH, PLAYER_FRAMEW, PLAYER_FRAMEH); playerBody.image_slash->fpl = 5; player->boundBox = bound; player->frame_horizontal = 1; player->frame_vertical = 2; player->think = player_think; player->update = player_update; player->player = true; player->team = TEAM_PLAYER; player->p_em = particle_em_new(); weapon_load_all(); armor_load_all(); PlayerEquip.weapon = getWeapon("longsword"); player->weapon = PlayerEquip.weapon; PlayerEquip.head = getArmor("head chain hood"); PlayerEquip.chest = getArmor("chest chain"); }
/*function definitions*/ void button_configure() { Line buf; Line buttonfile,buttonhitfile,buttonhighfile,buttonsleepfile; __component_button_offset_x = 0; __component_button_offset_y = 0; __component_button_press_active = 0; __component_button_hold_active = 0; __component_button_release_active = 1; __component_button_font_size = 3; vec3d_set(__component_button_color[0],0.8,0.8,0.8); vec3d_set(__component_button_color[1],1,1,0); vec3d_set(__component_button_color[2],0.6,0.6,0.6); vec3d_set(__component_button_color[3],0.3,0.2,0.3); strcpy(buttonfile,"images/btn.png"); strcpy(buttonhitfile,"images/btn_hit.png"); strcpy(buttonhighfile,"images/btn_high.png"); strcpy(buttonsleepfile,"images/btn_sleep.png"); __component_stock_button[0] = sprite_load(buttonfile,-1,-1); __component_stock_button[1] = sprite_load(buttonhighfile,-1,-1); __component_stock_button[2] = sprite_load(buttonhitfile,-1,-1); __component_stock_button[3] = sprite_load(buttonsleepfile,-1,-1); }
entity * grue_spawn(){ Sprite * sprite_grue; entity * ent_grue = NULL; Vec2d pos = {400,400}; Vec2d vel = {-5,0}; SDL_Rect boundBox = {grue_frameW*.1f,grue_frameH *.1f, grue_frameW, grue_frameH}; if( (G_MONSTER_SPAWN_TIMER % (GRUE_TIMER)) != 0){ return NULL; } slog("Timer: %i", G_MONSTER_SPAWN_TIMER); slog("Monster Spawn Timer mod MonsterSpawn Timer is %i " , (G_MONSTER_SPAWN_TIMER % (GRUE_TIMER))); sprite_grue = sprite_load(sprite_grue_filepath, grue_imageW, grue_imageH, grue_frameW, grue_frameH); sprite_grue->fpl = 1;//2 frames per line ent_grue = entity_load(sprite_grue, pos, 150, 25, STATE_PATROL); if(!ent_grue){ slog("Could not spawn GRUE"); return NULL; } //each frame is a single direction ent_grue->frame_horizontal = 0; ent_grue->frame_vertical = 0; ent_grue->velocity = vel; ent_grue->think = grue_think; ent_grue->nextThink = 1; ent_grue->thinkRate = GRUE_THINK_RATE;//think every 30 frames //ent_grue->touch = grue_touch; ent_grue->update = grue_update; ent_grue->state = STATE_PATROL; ent_grue->boundBox = boundBox; return ent_grue; }
void mouse_init() { strncpy(__mouse_file,"images/mouse_icon.png",128); memset(&__mouse,0,sizeof(Mouse)); __mouse.sprite = sprite_load(__mouse_file, __mouse_frame_width, __mouse_frame_height); SDL_ShowCursor(SDL_DISABLE); atexit(mouse_close); }
void mouse_initialize() { mouse = (Mouse *)malloc(sizeof(Mouse)); memset(mouse, 0, sizeof (Mouse)); mouse->alive = 1; mouse->bounds = rect(0, 0, 1, 1); mouse->frameNumber = 0; mouse->sprite = sprite_load("images/test_mouse.png", vect2d_new(16, 16), 16, 48); SDL_ShowCursor(SDL_DISABLE); }
void animal_initialize_normalcat(int x, int y, State direction) { animal_now = SDL_GetTicks(); Sprite *animal_sprite = sprite_load("images/reg_cat_sprite.png", ANIMAL_FRAME_W, ANIMAL_FRAME_H); animal = entity_new(); animal->sprite = animal_sprite; animal->frame = 0; animal->frameSize.x = ANIMAL_FRAME_W; animal->frameSize.y = ANIMAL_FRAME_H; animal->position.x = x; animal->position.y = y; animal->velocity = 0; animal->state = direction; animal->animal_type = CAT; animal->free = animal_free; animal->think = animal_think; animal->draw = animal_draw; animal->update = animal_update; }
Proj *projectile_new(Entity *proj, PROJECTILETYPE type) { Proj *projdata; cJSON *json, *root, *obj; FILE *file; long len; char *data; int i; file = fopen("def/projectilesconfig.txt","r"); if(!file) { slog("No file found. Projectile.c"); return; } fseek(file, 0, SEEK_END); len = ftell(file); fseek(file, 0, SEEK_SET); data = (char *) malloc(len + 1); fread(data, 1, len, file); fclose(file); json = cJSON_Parse(data); root = cJSON_GetObjectItem(json,"projectilesconfig"); if(!root) return; if(type = SHELL) obj = cJSON_GetObjectItem(root,"shell"); else if(type = FLAME) obj = cJSON_GetObjectItem(root,"flame"); else if(type = LASER) obj = cJSON_GetObjectItem(root,"laser"); proj->sprite = sprite_load(cJSON_GetObjectItem(obj,"file")->valuestring, v2d(cJSON_GetObjectItem(obj,"x")->valuedouble, cJSON_GetObjectItem(obj,"y")->valuedouble)); projdata->type = type; proj->data = projdata; for(i = 0; i < MaxProj; i++) { //if(proj } if(type = SHELL) { proj->update = &proj_update_shell; proj->think = NULL; } if(type = FLAME) { proj->update = &proj_update_flame; proj->think = NULL; } if(type = LASER) { proj->update = &proj_update_laser; proj->think = NULL; } return projdata; }
Sprite * tile_load(char *filename) { Sprite * sprite = sprite_load(filename, TILE_WIDTH, TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); return sprite; }
Sprite *actor_load_sprite(Uint8 type) { //config file stuff cJSON *json, *root, *obj, *buf; FILE *actor_config_file; long length; char *data; char *string; //actor sprite info Sprite *sprite = NULL; char *filepath; Vect2d frameSize; int frame; int fpl; int frames; actor_config_file = fopen(ACTOR_CONFIG,"r"); //get the length of the file fseek(actor_config_file, 0, SEEK_END); length = ftell(actor_config_file); //reset position to start of the file and allocate data to be the length of the file + 1 fseek(actor_config_file, 0, SEEK_SET); data = (char*) malloc(length + 1); //store the contents of the file in data, and close the file fread(data, 1, length, actor_config_file); fclose(actor_config_file); json = cJSON_Parse(data); root = cJSON_GetObjectItem(json,"actor_config"); if(!root) { slog("error parseing the file, file not a actor_config"); return NULL; } switch(type) { case ENEMY_CLARENCE: obj = cJSON_GetObjectItem(root, "clarence"); break; case ENEMY_MELT: obj = cJSON_GetObjectItem(root, "melt"); break; case ENEMY_MILK: obj = cJSON_GetObjectItem(root, "milk_tank"); break; case ENEMY_CELERY: obj = cJSON_GetObjectItem(root, "celery_stalker"); break; case ENEMY_PROFESSOR: obj = cJSON_GetObjectItem(root, "professor_slice"); break; case POWER_UP_GOO: obj = cJSON_GetObjectItem(root, "power_up_goo_shot"); break; case POWER_UP_SHIELD: obj = cJSON_GetObjectItem(root, "power_up_shield"); break; case POWER_UP_SPREAD: obj = cJSON_GetObjectItem(root, "power_up_spread_shot"); break; case POWER_UP_DOUBLE: obj = cJSON_GetObjectItem(root, "power_up_double_tap"); break; case POWER_UP_LIFE: obj = cJSON_GetObjectItem(root, "power_up_extra_life"); break; case POWER_UP_BOMB: obj = cJSON_GetObjectItem(root, "power_up_extra_bomb"); break; } buf = cJSON_GetObjectItem(obj, "sprite"); filepath = cJSON_GetObjectItem(buf, "file")->valuestring; sscanf(cJSON_GetObjectItem(buf, "bounds")->valuestring, "%f %f", &frameSize.x, &frameSize.y); fpl = cJSON_GetObjectItem(buf, "fpl")->valueint; frames = cJSON_GetObjectItem(buf, "frames")->valueint; sprite = sprite_load(filepath, frameSize, fpl, frames); return sprite; }
void component_make_button( Component *component, char *buttonText, Uint32 justify, Uint32 buttonType, int buttonHotkey, Uint32 buttonHotkeymod, Line buttonUpFile, Line buttonHighFile, Line buttonDownFile, Vec3D backgroundColor, float backgroundAlpha, Vec3D highlightColor, Vec3D pressColor, Uint32 fontSize ) { ComponentButton * button = NULL; if (!component)return; component_button_new(component); button = component_get_button_data(component); if (button == NULL) { return; } button->alpha = 1; button->fontSize = fontSize; button->input = buttonHotkey; button->hotkeymod = buttonHotkeymod; strncpy(button->buttonText,buttonText,LINELEN); button->buttonType = buttonType; component->data_update = component_button_update; component->data_free = component_button_free; component->data_draw = component_button_draw; button->justify = justify; switch(buttonType) { case ButtonCustom: button->button[ButtonIdle] = sprite_load(buttonUpFile,-1,-1); button->button[ButtonHighlight] = sprite_load(buttonHighFile,-1,-1); button->button[ButtonPressed] = sprite_load(buttonDownFile,-1,-1); if (button->justify == JustifyNone) { button->justify = JustifyCenter; } break; case ButtonText: button->button[ButtonIdle] = NULL; button->button[ButtonHighlight] = NULL; button->button[ButtonPressed] = NULL; if (button->justify == JustifyNone) { button->justify = JustifyLeft; } break; case ButtonStock: button->button[ButtonIdle] = __component_stock_button[ButtonIdle]; button->button[ButtonHighlight] = __component_stock_button[ButtonHighlight]; button->button[ButtonPressed] = __component_stock_button[ButtonPressed]; if (button->justify == JustifyNone) { button->justify = JustifyCenter; } break; case ButtonRect: component->data_draw = component_button_draw_rect; vec3d_cpy(button->backgroundColor,backgroundColor); button->backgroundAlpha = backgroundAlpha; if (button->justify == JustifyNone) { button->justify = JustifyLeft; } vec3d_cpy(button->highlightColor,highlightColor); vec3d_cpy(button->pressColor,pressColor); break; } }