コード例 #1
0
	entity_handle create_character(cosmos& world, const components::transform spawn_transform, const vec2i screen_size, const std::string name, const assets::animation_response_id torso_set) {
		const auto character = world.create_entity(name);

		name_entity(character, entity_name::PERSON);

		const auto crosshair = create_character_crosshair(world, screen_size);
		crosshair.get<components::crosshair>().character_entity_to_chase = character;
		crosshair.set_logic_transform(spawn_transform.pos);

		ingredients::wsad_character(character, crosshair, torso_set);
		
		auto& element = character += components::gui_element();
		element.rect_world.last_state.screen_size = screen_size;

		ingredients::wsad_character_physics(character);

		character.get<components::physics>().set_transform(spawn_transform);

		ingredients::character_inventory(character);

		const auto corpse_of_sentience = world.create_entity("corpse_of_sentience");
		name_entity(corpse_of_sentience, entity_name::CORPSE);
		ingredients::wsad_character_corpse(corpse_of_sentience);

		character.map_sub_entity(sub_entity_name::CORPSE_OF_SENTIENCE, corpse_of_sentience);

		character.add_standard_components();

		// LOG("Character mass: %x", character.get<components::physics>().get_mass());
		return character;
	}
コード例 #2
0
	entity_handle create_brick_wall(cosmos& world, const components::transform pos, const vec2 size) {
		const auto crate = world.create_entity("brick_wall");

		ingredients::sprite_scalled(crate, pos, size, assets::texture_id::BRICK_WALL, white, render_layer::DYNAMIC_BODY);
		ingredients::standard_static_body(crate);
		crate.get<components::fixtures>().set_restitution(0.0f);
		crate.get<components::fixtures>().set_density(100);
		crate.add_standard_components();

		return crate;
	}
コード例 #3
0
	entity_handle create_sample_backpack(cosmos& world, vec2 pos) {
		auto def = world.create_entity("sample_backpack");

		name_entity(def, entity_name::VIOLET_BACKPACK);
		ingredients::backpack(def);

		ingredients::sprite(def, pos, assets::texture_id::BACKPACK, augs::white, render_layer::SMALL_DYNAMIC_BODY);
		ingredients::see_through_dynamic_body(def);
		
		def.add_standard_components();
		return def;
	}
コード例 #4
0
	entity_handle create_crate(cosmos& world, const components::transform pos, const vec2 size) {
		const auto crate = world.create_entity("crate");

		name_entity(crate, entity_name::CRATE);
		ingredients::sprite_scalled(crate, pos, size, assets::texture_id::CRATE, white, render_layer::DYNAMIC_BODY);
		ingredients::standard_dynamic_body(crate, true);
		crate.get<components::fixtures>().set_restitution(0.8f);
		crate.get<components::fixtures>().set_density(0.03f);
		crate.add_standard_components();

		return crate;
	}
コード例 #5
0
	entity_handle create_character_crosshair(cosmos& world, const vec2i screen_size) {
		auto root = world.create_entity("crosshair");
		auto recoil = world.create_entity("crosshair_recoil_body");
		auto zero_target = world.create_entity("zero_target");

		{
			auto& sprite = root += components::sprite();
			auto& render = root += components::render();
			auto& transform = root += components::transform();
			auto& crosshair = root += components::crosshair();
			auto& processing = root += components::processing();
			
			sprite.set(assets::texture_id::TEST_CROSSHAIR, rgba(255, 255, 255, 255));

			render.layer = render_layer::CROSSHAIR;

			crosshair.base_offset.set(-20, 0);
			crosshair.sensitivity.set(3, 3);
			crosshair.visible_world_area.set(1920, 1080);
			crosshair.update_bounds();

			ingredients::make_always_visible(root);
		}

		{
			auto& force_joint = recoil += components::force_joint();
			zero_target += components::transform();
			components::physics body;
			components::fixtures colliders;

			auto& sprite = recoil += components::sprite();

			sprite.set(assets::texture_id::TEST_CROSSHAIR, rgba(0, 255, 0, 0));

			auto& render = recoil += components::render();
			render.layer = render_layer::OVER_CROSSHAIR;
			ingredients::make_always_visible(recoil);

			auto& info = colliders.new_collider();

			info.shape.from_renderable(recoil);

			info.filter = filters::renderable();
			//info.filter.categoryBits = 0;
			info.density = 0.1f;
			info.sensor = true;

			body.linear_damping = 5;
			body.angular_damping = 5;

			force_joint.chased_entity = zero_target;
			//force_joint.consider_rotation = false;
			//force_joint.distance_when_force_easing_starts = 10.f;
			//force_joint.force_towards_chased_entity = 1000.f;
			//force_joint.power_of_force_easing_multiplier = 1.f;
			force_joint.divide_transform_mode = true;

			recoil += body;
			recoil += colliders;
			recoil.get<components::fixtures>().set_owner_body(recoil);
		}

		root.map_sub_entity(sub_entity_name::CROSSHAIR_RECOIL_BODY, recoil);
		
		root.add_standard_components();
		recoil.add_standard_components();
		zero_target.add_standard_components();

		return root;
	}