<commit_before>package de.fe1k.game9.components;

import de.fe1k.game9.entities.Entity;
import de.fe1k.game9.events.Event;
import de.fe1k.game9.events.EventCollision;
import de.fe1k.game9.events.EventEntityDestroyed;
import de.fe1k.game9.events.EventUpdate;
import de.fe1k.game9.utils.Direction;
import de.nerogar.noise.input.InputHandler;
import de.nerogar.noise.util.Logger;

import java.util.List;

@Depends(components={ComponentMoving.class})
public class ComponentControllable extends Component {
	private InputHandler inputs;
	private float jumpPower = 0;
	private boolean wasKeyDown = false;

	public ComponentControllable(InputHandler inputHandler) {
		this.inputs = inputHandler;
		Event.register(EventUpdate.class, this::update);
		Event.register(EventCollision.class, this::collision);
	}

	private void update(EventUpdate event) {
		ComponentMoving moving = getOwner().getComponent(ComponentMoving.class);
		boolean isKeyDown = inputs.isKeyDown(' ');
		boolean onGround = moving.touching[Direction.DOWN.val];
		if (onGround) {
			jumpPower = 1;
		}
		if (isKeyDown && !(onGround && wasKeyDown)) {
			moving.velocity.add(moving.gravity.multiplied(-0.09f * jumpPower));
			jumpPower *= 1 - (10 * event.deltaTime);
		}
		moving.velocity.setX(10f);
		wasKeyDown = isKeyDown;
	}

	private void collision(EventCollision event) {
		if (event.collisionDirection.isHorizontal()) {
			// death
			Event.trigger(new EventEntityDestroyed(getOwner()));<commit_msg>fix feedback loop for collisions when particles have bounding<commit_after>package de.fe1k.game9.components;

import de.fe1k.game9.entities.Entity;
import de.fe1k.game9.events.Event;
import de.fe1k.game9.events.EventCollision;
import de.fe1k.game9.events.EventEntityDestroyed;
import de.fe1k.game9.events.EventUpdate;
import de.fe1k.game9.utils.Direction;
import de.nerogar.noise.input.InputHandler;
import de.nerogar.noise.util.Logger;

import java.util.List;

@Depends(components={ComponentMoving.class})
public class ComponentControllable extends Component {
	private InputHandler inputs;
	private float jumpPower = 0;
	private boolean wasKeyDown = false;

	public ComponentControllable(InputHandler inputHandler) {
		this.inputs = inputHandler;
		Event.register(EventUpdate.class, this::update);
		Event.register(EventCollision.class, this::collision);
	}

	private void update(EventUpdate event) {
		ComponentMoving moving = getOwner().getComponent(ComponentMoving.class);
		boolean isKeyDown = inputs.isKeyDown(' ');
		boolean onGround = moving.touching[Direction.DOWN.val];
		if (onGround) {
			jumpPower = 1;
		}
		if (isKeyDown && !(onGround && wasKeyDown)) {
			moving.velocity.add(moving.gravity.multiplied(-0.09f * jumpPower));
			jumpPower *= 1 - (10 * event.deltaTime);
		}
		moving.velocity.setX(10f);
		wasKeyDown = isKeyDown;
	}

	private void collision(EventCollision event) {
		if (!event.movingComponent.getOwner().equals(getOwner())) {
			return;
		}
		if (event.collisionDirection.isHorizontal()) {
			// death
			Event.trigger(new EventEntityDestroyed(getOwner()));
{'fraction_non_alphanumeric': 0.1202884300229433, 'fraction_numerical': 0.015732546705998034, 'mean_word_length': 5.305785123966942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2138512', 'n_tokens_mistral': 1073, 'n_tokens_neox': 983, 'n_words': 180}