Beispiel #1
0
target_t *target_create(void){
	target_t *target = malloc(sizeof(target_t));

	target->type = TARGET_NONE;
	target->rect = rect_create();
	target->sprite = NULL;
	target->event = NULL;
	
	return target;
}
Beispiel #2
0
rect_t msg_line_rect(void)
{
    assert(_msg_line_doc); /* call msg_on_startup()! */
    return rect_create(
               _msg_line_rect.x,
               _msg_line_rect.y,
               _msg_line_rect.cx,
               doc_line_count(_msg_line_doc)
           );
}
Beispiel #3
0
void msg_line_init(const rect_t *display_rect)
{
    if (display_rect && rect_is_valid(display_rect))
    {
        if (_msg_line_doc)
        {
            msg_line_clear();
            doc_free(_msg_line_doc);
        }
        _msg_line_rect = *display_rect;
        if (_msg_line_rect.x + _msg_line_rect.cx > Term->wid)
            _msg_line_rect.cx = Term->wid - _msg_line_rect.x;
        _msg_line_doc = doc_alloc(_msg_line_rect.cx);
        _msg_line_sync_pos = doc_cursor(_msg_line_doc);
    }
    else
    {
        rect_t r = rect_create(0, 0, MIN(72, Term->wid - 13), 10);
        msg_line_init(&r);
    }
}
Beispiel #4
0
sprite_t *sprite_create(){
	sprite_t *sprite = malloc(sizeof(sprite_t));
	sprite->rect = rect_create();
	return sprite;
}
Beispiel #5
0
void do_physics_to_it(body_t *body, rect_list_t *terr_rects, rect_list_t *plat_rects){
	rect_t *start = rect_create();
	rect_match_to(start, body->rect);
	
	rect_node_t *iter;
	
	body->flags &= ~BLOCKED_MASK;
	
	body->rect->x += body->vx;
	iter = terr_rects->head;
	while(iter != NULL){
		if(rect_overlap(body->rect, iter->data)){
			if(body->vx > 0 && rect_get_r_edge(body->rect) >= rect_get_l_edge(iter->data)){
				body->vx = 0;
				rect_set_r_edge(body->rect, rect_get_l_edge(iter->data));
				body->flags |= BLOCKED_R;
			}else if(body->vx < 0 && rect_get_l_edge(body->rect) <= rect_get_r_edge(iter->data)){
				body->vx = 0;
				rect_set_l_edge(body->rect, rect_get_r_edge(iter->data));
				body->flags |= BLOCKED_L;
			}
			break;
		}
		iter = iter->next;
	}

	body->rect->y += body->vy;
	iter = terr_rects->head;
	while(iter != NULL){
		if(rect_overlap(body->rect, iter->data)){
			if(body->vy > 0 && rect_get_b_edge(body->rect) >= rect_get_t_edge(iter->data)){
				body->vy = 0;
				rect_set_b_edge(body->rect, rect_get_t_edge(iter->data));
				body->flags |= BLOCKED_D;
			}else if(body->vy < 0 && rect_get_t_edge(body->rect) <= rect_get_b_edge(iter->data)){
				body->vy = 0;
				rect_set_t_edge(body->rect, rect_get_b_edge(iter->data));
				body->flags |= BLOCKED_U;
			}
			break;
		}
		iter = iter->next;
	}
	
	if(body->vy > 0 && !(body->flags & PLAT_DROP)){
		iter = plat_rects->head;
		while(iter != NULL){
			if(rect_overlap(body->rect, iter->data)){
				if(rect_get_b_edge(start) <= rect_get_t_edge(iter->data)){
					body->vy = 0;
					rect_set_b_edge(body->rect, rect_get_t_edge(iter->data));
					body->flags |= BLOCKED_D;
					break;
				}

			}
			iter = iter->next;
		}
	}
	
	rect_delete(start);
}