static void collision_detection_coins() { /* We simply check if the player intersects with the coins */ character* main_char = entity_get("main_char"); vec2 top_left = vec2_add(main_char->position, vec2_new(-TILE_SIZE, -TILE_SIZE)); vec2 bottom_right = vec2_add(main_char->position, vec2_new(TILE_SIZE, TILE_SIZE)); /* Again we collect pointers to all the coin type entities */ int num_coins = 0; coin* coins[COIN_COUNT]; entities_get(coins, &num_coins, coin); for(int i = 0; i < num_coins; i++) { /* Check if they are within the main char bounding box */ if ((coins[i]->position.x > top_left.x) && (coins[i]->position.x < bottom_right.x) && (coins[i]->position.y > top_left.y) && (coins[i]->position.y < bottom_right.y)) { /* Remove them from the entity manager and delete */ char* coin_name = entity_name(coins[i]); entity_delete(coin_name); /* Play a nice twinkle sound */ audio_sound_play(asset_get_as(P("./sounds/coin.wav"), sound), 0); /* Add some score! */ level_score += 10; /* Update the ui text */ ui_button* score = ui_elem_get("score"); sprintf(score->label->string, "Score %06i", level_score); ui_text_draw(score->label); } } ui_button* victory = ui_elem_get("victory"); /* if all the coins are gone and the victory rectangle isn't disaplayed then show it */ if ((entity_type_count(coin) == 0) && (!victory->active)) { ui_button* victory = ui_elem_get("victory"); ui_button* new_game = ui_elem_get("new_game"); victory->active = true; new_game->active = true; } }
void vegetation_finish() { for(int x = 0; x < X_NUM; x++) for(int y = 0; y < Y_NUM; y++) { char blockname[512]; sprintf(blockname, "vegblock_%i_%i", x, y); static_object* block = entity_get(blockname); //renderable_delete(block->renderable); entity_delete(blockname); } free(blocks); }
void sv_net_remove_client(client_t *cl) { char buf[TEXTMESSAGE_STRLEN]; net_close_connection(cl->nc); if( cl->status >= JOINING ) server.clients--; snprintf(buf, TEXTMESSAGE_STRLEN, "%s disconnected (%d clients remain)", cl->name, server.clients); sv_net_send_text_to_all(buf); if( server.clients <= 0 && server.exit_when_empty ) { printf("Closing Empty Server.\n"); server.quit = 1; } if( cl->ent ) { entity_delete( cl->ent ); } /* Make sure that root & Tail will still point at the right spot after cl is deleted */ if( cl_root == cl ) cl_root = cl->next; if( cl_tail == cl ) cl_tail = cl->prev; if( cl->prev ) cl->prev->next = cl->next; if( cl->next ) cl->next->prev = cl->prev; free(cl); }
void entity_update(float secs) { ent_type_t *et; entity *ent, *next; msec_t now, time; int i; now = server.now; for( ent = root ; ent != NULL ; ent = ent->next ) { et = ent->type_info; if( ent->dripping ) { time = (ent->dripping==1)? et->drip_time : INVISIBLE_DRIP_TIME; if( now - ent->last_drip >= time ) { entity_drip(ent, ent->drip1, ent->drip2); ent->last_drip = now; } } if( ent->lookatdir > 0 ) { ent->speed = 0; /* make the entity slowly turn towards the lookatpoint */ if( ent->dir > ent->lookatdir ) ent->dir -= MAX( 1, (ent->dir - ent->lookatdir)/10); else if( ent->dir < ent->lookatdir ) ent->dir += MAX( 1, (ent->lookatdir - ent->dir)/10); else ent->lookatdir = -1; } else if( ent->mode == ALIVE ) ent->speed = et->speed; else if( ent->mode == LIMBO ) { /* Respawn items */ if( ent->respawn_time && (now >= ent->respawn_time) ) { ent->mode = ALIVE; ent->respawn_time = 0; entity_spawn_effect(ent); } } if( ent->powerup ) { /* Entity is wounded */ if( ent->powerup & (1<<PU_WOUND) ) if( now - ent->last_wound >= M_SEC ) { entity_drip(ent, COL_RED, COL_RED); /* Drip blood */ ent->health -= 2; ent->last_wound = now; } if( ent->powerup & (1<<PU_INVISIBILITY) ) { ent->visible = 0; if( ent->x_v || ent->y_v ) { /* Drip if moving */ ent->dripping = 2; ent->drip1 = ent->color1; ent->drip2 = ent->color2; } else { ent->dripping = et->dripping; ent->drip1 = et->drip1; ent->drip2 = et->drip2; } } for( i=0 ; i<NUM_POWERUPS ; i++ ) { if( ent->powerup & (1<<i) && now > ent->powerup_expire[i] ) { ent->powerup &= ~(1<<i); ent->powerup_expire[i] = 0; switch( i ) { case PU_INVISIBILITY: ent->dripping = et->dripping; ent->drip1 = et->drip1; ent->drip2 = et->drip2; ent->visible = 1; break; case PU_FROZEN: if( ent->mode == FROZEN ) ent->mode = ALIVE; break; case PU_E: /* Worn off, entity is now on a come down... */ if( ent->mode == ENLIGHTENED ) { ent->mode = COMEDOWN; ent->speed = et->speed * 0.50; ent->powerup |= (1<<PU_E); /* Restore bit */ ent->powerup_expire[PU_E] = now + M_SEC * 10; } else if( ent->mode == COMEDOWN ) { ent->mode = ALIVE; } break; } } } } } entity_update_movement(secs); entity_check_collisions(); entity_animate(); for( ent = root ; ent != NULL ; ent = next ) { next = ent->next; if( ent->mode >= FROZEN && ent->health <= 0 ) entity_die(ent); /* Set to either dead or dying */ if( ent->mode == DEAD ) { if( ent->controller == CTRL_CLIENT ) spawn(ent, 1); /* Respawn */ else entity_delete(ent); } } }