Example #1
0
void renderTilesheetAnimate(TILESHEET *ts) {
	int i, j, change;
	TS_FRAME *frame;

	if (ts == NULL)
		return;


	for (i = 0; i < ts->animation.tiles; i++) {
		change = 0;
		ts->animation.tile[i].time_rest += darnitTimeLastFrameTook();
		j = ts->animation.tile[i].frame[ts->animation.tile[i].frame_at].time;
		while (ts->animation.tile[i].time_rest >= j) {
			ts->animation.tile[i].time_rest -= j;
			ts->animation.tile[i].frame_at++;
			if (ts->animation.tile[i].frame_at >= ts->animation.tile[i].frames)
				ts->animation.tile[i].frame_at = 0;
			j = ts->animation.tile[i].frame[ts->animation.tile[i].frame_at].time;
			frame = &ts->animation.tile[i].frame[ts->animation.tile[i].frame_at];
			change = 1;
		}

		if (change) {
			i = frame->tile_dst % (ts->w / ts->wsq);
			j = frame->tile_dst / (ts->w / ts->wsq);
			renderUpdateTilesheet(ts, i * ts->wsq, j * ts->hsq, &ts->animation.data[ts->animation.tile_skip * frame->tile_src], ts->wsq, ts->hsq);
		}
	}

	return;
}
Example #2
0
void textboxAnimate(void *handle) {
	MAIN *m = handle;

	if (m->box.pos == m->box.strlen)
		return;
	
	m->box.time_elapsed_rest += darnitTimeLastFrameTook(m->darnit);
	while (m->box.time_elapsed_rest >= m->box.speed) {
		if (m->box.str[m->box.pos] == ' ') {	/* TODO: Add word-wrapping */
			m->box.pos += darnitTextSurfaceCharAppend(m->box.text, " ");
			m->box.text_w_pos = darnitFontGetGlyphW(m->system.std_font, &m->box.str[m->box.pos]);
		} else if (m->box.str[m->box.pos] == '\n') {
			m->box.pos += darnitTextSurfaceCharAppend(m->box.text, "\n");
			m->box.text_w_pos = 0;
		} else {
			m->box.text_w_pos = darnitFontGetGlyphW(m->system.std_font, &m->box.str[m->box.pos]);
			m->box.pos += darnitTextSurfaceCharAppend(m->box.text, &m->box.str[m->box.pos]);
		}
		m->box.time_elapsed_rest -= m->box.speed;
	}

	return;
}