Exemple #1
0
void update(void) {
	if (input_timeout > 0) input_timeout -= 1;
	brightness = 1.f - fabsf((float)rotate_timeout - (ROTATE_INTERVAL / 2)) / ((float)ROTATE_INTERVAL / 2);
	rotate_timeout -= 1;
	if (rotate_timeout == 0) {
		rotate_index = (rotate_index + 1) % 3;
		rotate_timeout = ROTATE_INTERVAL;
	}

	++dude.animate_timeout;
	sprite_t *sprite = sprite_thing_get(dude.type);
	if (sprite->rate && dude.animate_timeout > sprite->rate * ANIMATE_RATE) {
		dude.current_frame = (dude.current_frame + 1) % sprite->frame_count;
		dude.animate_timeout = 0;
	}
	if (action_interval == 0) {
		action_interval = rand() % ACTION_INTERVAL;
		walking = !walking;
		dude.type = walking ? dude_walk : dude_stand;
		dude.current_frame = 0;
	}
	if (walking) {
		position += DUDE_WALK_SPEED;
		LOG_DEBUG("pos %f", position);
	}
	--action_interval;
	
}
Exemple #2
0
void render(void) {
	SDL_SetRenderDrawColor(display.renderer, 0x20, 0x20, 0x20, 0xFF);
	SDL_RenderClear(display.renderer);
	draw_text_splat(&title_1, -1, 25);
	draw_text_splat(&title_2, -1, 35);
	
	SDL_SetTextureAlphaMod(rotator[rotate_index].texture, 0xFF * brightness);
	draw_text_splat(&rotator[rotate_index], -1, REFERENCE_HEIGHT - 24);
	
	SDL_SetRenderDrawBlendMode(display.renderer, SDL_BLENDMODE_BLEND);
	for (int x = 0; x < REFERENCE_WIDTH; x += 32) {
		SDL_Rect dest_rect = { x, 128, 32, 32 };
		SDL_RenderCopy(display.renderer, backlight->texture, &backlight->src_rect[0], &dest_rect);
	}
	sprite_t *dude_sprite = sprite_thing_get(dude.type);
	SDL_Rect dest_rect = {
		position,
		144,
		dude_sprite->src_rect[dude.current_frame].w,
		dude_sprite->src_rect[dude.current_frame].h
	};
	SDL_RenderCopy(display.renderer, dude_sprite->texture, &dude_sprite->src_rect[dude.current_frame], &dest_rect);
	for (int x = 0; x < REFERENCE_WIDTH; x += 32) {
		SDL_Rect fore_rect = { x, 128, 32, 32 };
		SDL_Rect bott_rect = { x, 160, 32, 32 };
		SDL_RenderCopy(display.renderer, foreground->texture, &foreground->src_rect[0], &fore_rect);
		SDL_RenderCopy(display.renderer, bottom->texture, &bottom->src_rect[0], &bott_rect);
	}
}
Exemple #3
0
void activate(void) {
	create_text_splat(kl("title_1"), 18, 0, &title_1);
	create_text_splat(kl("title_2"), 24, 0, &title_2);
	create_text_splat(kl("byline"), 8, 0, &rotator[0]);
	create_text_splat(kl("ludum"), 8, 0, &rotator[1]);
	create_text_splat(kl("any_key"), 8, 0, &rotator[2]);
	rotate_index = 0;
	rotate_timeout = ROTATE_INTERVAL;
	event_add_handler(&any_key_handler, on_any_key, SDL_KEYUP);
	input_timeout = INPUT_SUPPRESS;
	
	backlight = sprite_thing_get(building_window_backlight);
	foreground = sprite_thing_get(building_window_fg);
	bottom = sprite_thing_get(building_fullwidth);
	dude.type = dude_stand;
	walking = false;
	action_interval = 0;
	position = -24;
}
Exemple #4
0
void process_animate(void) {
    for (size_t i = 0; i < MAX_THINGS; ++i) {
        thing_t *tp = &game.things[i];
        if (! tp->type) continue;

        sprite_t *sprite = sprite_thing_get(tp->type);
        if (tp->action_timeout && --tp->action_timeout == 0) {
            animate_next_state(tp);
        }

        if (sprite->frame_count == 0) continue;

        if (tp->animate_timeout > 0) {
            --tp->animate_timeout;
            continue;
        }

        tp->current_frame = (tp->current_frame + 1) % sprite->frame_count;

        tp->animate_timeout = FRAME_INTERVAL * sprite->rate;

    }
}
Exemple #5
0
static void render(void) {
	SDL_Rect target = target_rect(&sky, -64, (REFERENCE_HEIGHT - BUILDING_HEIGHT / 4) - 128, 0.25f);
	target.y += sunset;
	SDL_RenderCopy(display.renderer, sky.texture, sky.src_rect, &target);
	for (size_t i = 0; i < MAX_THINGS; ++i) {
		thing_t *thing = &game.things[i];
		if (! thing->type) continue;
		sprite_t *sprite = sprite_thing_get(thing->type);
		target = target_rect(sprite, thing->position.x, thing->position.y, 1.f);
		
		if (thing->current_frame > sprite->frame_count) {
			LOG_WARN("%llu frame out of range!", (long long unsigned)i);
			thing->current_frame = 0;
		}
		
		SDL_RenderCopyEx(display.renderer, sprite->texture,
						 &sprite->src_rect[thing->current_frame], &target, thing->angle, NULL, 0);
	}
	
	if (camera.target.y > 0) {
		timer_blit(game.active_ticks, REFERENCE_WIDTH - 10, 10);
	}
	
}