Items shadows

mail@pastecode.io avatar
unknown
c_cpp
16 days ago
2.4 kB
20
Indexable
Never
// This should be placed inside the render loop for entities.

if (en->is_item) {
	Matrix4 shadow_xform = xform;
	float t = os_get_elapsed_seconds();
	float sin_value   = (0.3 * sin(t*5.0)) + 0.7;
	float sin_value_2 = (0.1 * sin(t*5.0)) + 0.9;

	xform = m4_translate(xform, v3(0, 4.0 * sin_value, 0));
	Vector2 shadow_size = v2_mulf(v2(sprite_width, sprite_width/3), sin_value_2);
	
	shadow_xform = m4_translate(shadow_xform, v3(sprite_width/2 - shadow_size.x / 2, -3, 0));
	draw_circle_xform(shadow_xform, shadow_size, v4(0, 0, 0, 1 - (sin_value / 3)));
}



// HERE IS THE WHOLE CODE SNIPPET WHICH I USE
// I USE THE ENTITY MOVEMENT ("MAGNET") WHICH I ADDED IN ANOTHER POST OF MINE
// WHICH IS WHY I HAVE "is_being_picked_up" (ITS NOT NEEDED)

// :render
		for (int i = 0; i < MAX_ENTITY_COUNT; i++) {
			Entity* en = &world->entities[i];
			if (en->is_valid) {

				switch (en->arch) {

					default:
					{
						Sprite* sprite = get_sprite(en->sprite_id);
						float sprite_width = sprite->image->width;
						Matrix4 xform = m4_scalar(1.0);
			
						xform         = m4_translate(xform, v3(0, tile_width * 0.5, 0));
						xform         = m4_translate(xform, v3(en->pos.x, en->pos.y, 0));
						xform         = m4_translate(xform, v3(sprite_width * -0.5, 0.0, 0));

						
						
						// LOOK HERE
						if (en->is_item && !(en->is_being_picked_up)) {
							Matrix4 shadow_xform = xform;
							float t = os_get_elapsed_seconds();
							float sin_value   = (0.3 * sin(t*5.0)) + 0.7;
							float sin_value_2 = (0.1 * sin(t*5.0)) + 0.9;

							xform = m4_translate(xform, v3(0, 4.0 * sin_value, 0));
							Vector2 shadow_size = v2_mulf(v2(sprite_width, sprite_width/3), sin_value_2);
							
							shadow_xform = m4_translate(shadow_xform, v3(sprite_width/2 - shadow_size.x / 2, -3, 0));
							draw_circle_xform(shadow_xform, shadow_size, v4(0, 0, 0, 1 - (sin_value / 3)));
						}
						// END

						Vector4 col = COLOR_WHITE;
						if (world_frame.selected_entity == en) {
							col = v4(1.0, 0, 0, 0.5);
						}
						
						draw_image_xform(sprite->image, xform, get_sprite_size(sprite), col);
						// draw_text(font, sprint(get_temporary_allocator(), STR("%f %f"), en->pos.x, en->pos.y), font_height, en->pos, v2(0.1, 0.1), COLOR_RED);

						break;
					}
				}
			}
		}
Leave a Comment