<commit_before>package game;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import org.dyn4j.dynamics.BodyFixture;
import org.dyn4j.dynamics.World;
import org.dyn4j.dynamics.joint.MotorJoint;
import org.dyn4j.geometry.Convex;
import org.dyn4j.geometry.Geometry;
import org.dyn4j.geometry.MassType;
import org.dyn4j.geometry.Rectangle;
import org.dyn4j.geometry.Transform;
import org.dyn4j.geometry.Vector2;

public class Game extends SimulationFrame {
	/** The serial version id */
	private static final long serialVersionUID = -805418642620588619L;
	
	public static TextureLoader tl;
	
	/** The controller body */
	private SimulationBody controller;
	Listeners l = new Listeners();
	Listeners.Keys k = l.new Keys();
	Entity body2;
	
	/**
	 * Default constructor.
	 */
	public Game()
	{
		super("Game", 45.0);

		this.canvas.addKeyListener(k);
	}
	
	/**
	 * Creates game objects and adds them to the world.
	 */
	protected void initializeWorld()
	{
	    this.world.setGravity(World.EARTH_GRAVITY);
	    
	    body2 = new Entity();
	    BodyFixture f = new BodyFixture(Geometry.createRectangle(2,2));
	    f.setFriction(0);
	    f.setRestitution(0);
	    body2.setTextureName("player");
	    body2.addFixture(f);
	    body2.setLinearVelocity(new Vector2(0.0, 0.0));
	    body2.setAngularVelocity(0.0);
	    body2.setMass(MassType.NORMAL);
	    body2.setAutoSleepingEnabled(false);
	    world.addBody(body2);
	    
		SimulationBody wallb = new SimulationBody();
		wallb.addFixture(Geometry.createRectangle(20, 0.2));
		wallb.translate(0, -6.5);
		wallb.setMass(MassType.INFINITE);
		world.addBody(wallb);
		
		SimulationBody wallr = new SimulationBody();
		wallr.addFixture(Geometry.createRectangle(0.2, 10));
		wallr.translate(5, 0);
		wallr.setMass(MassType.INFINITE);
		world.addBody(wallr);
		
		SimulationBody plat = new SimulationBody();
		plat.addFixture(Geometry.createRectangle(5, 0.2));
		plat.translate(-3, -3);
		plat.setMass(MassType.INFINITE);
		world.addBody(plat);
		
		SimulationBody plat2 = new SimulationBody();
		plat2.addFixture(Geometry.createRectangle(2, 0.2));
		plat2.translate(4, 2);
		plat2.setMass(MassType.INFINITE);
		world.addBody(plat2);
	}
	
	@Override
	protected void update(Graphics2D g, double elapsedTime) {
		body2.setAngularVelocity(0);
		body2.getTransform().setRotation(0);
		System.out.println(body2.getLinearVelocity().x + ", " + body2.getChangeInPosition().x);
		if((k.getW() && (body2.getChangeInPosition().y <= 0.01 && body2.getChangeInPosition().y >= -0.0001)) || (k.getSpace() && (body2.getChangeInPosition().y <= 0.0001 && body2.getChangeInPosition().y >= -0.01)))
		{
			body2.setLinearVelocity(body2.getLinearVelocity().x, 10);
		}
		if(k.getA() && body2.getChangeInPosition().x > -0.2)
		{
			body2.applyForce(new Vector2(-20, 0));
		}
		if(k.getD() && body2.getChangeInPosition().x < 0.2)
		{
			body2.applyForce(new Vector2(20, 0));
		}
		if(!k.getD() && !k.getA())
		{
			if(Math.abs(body2.getLinearVelocity().x) > 0.005)
			{
				body2.setLinearVelocity(body2.getLinearVelocity().x/1.1,body2.getLinearVelocity().y);
			}
			else
			{
				body2.setLinearVelocity(0,body2.getLinearVelocity().y);
			}
		}
		super.update(g, elapsedTime);
	}
	
	/**<commit_msg>Fix jumping in midair<commit_after>package game;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import org.dyn4j.dynamics.BodyFixture;
import org.dyn4j.dynamics.World;
import org.dyn4j.dynamics.joint.MotorJoint;
import org.dyn4j.geometry.Convex;
import org.dyn4j.geometry.Geometry;
import org.dyn4j.geometry.MassType;
import org.dyn4j.geometry.Rectangle;
import org.dyn4j.geometry.Transform;
import org.dyn4j.geometry.Vector2;

public class Game extends SimulationFrame {
	/** The serial version id */
	private static final long serialVersionUID = -805418642620588619L;
	
	public static TextureLoader tl;
	
	/** The controller body */
	private SimulationBody controller;
	Listeners l = new Listeners();
	Listeners.Keys k = l.new Keys();
	Entity body2;
	
	/**
	 * Default constructor.
	 */
	public Game()
	{
		super("Game", 45.0);

		this.canvas.addKeyListener(k);
	}
	
	/**
	 * Creates game objects and adds them to the world.
	 */
	protected void initializeWorld()
	{
	    this.world.setGravity(World.EARTH_GRAVITY);
	    
	    body2 = new Entity();
	    //BodyFixture f = new BodyFixture(Geometry.createRectangle(2,2));
	    BodyFixture f = new BodyFixture(Geometry.createCircle(0.5));
	    f.setFriction(0);
	    f.setRestitution(0);
	    body2.setTextureName("player");
	    body2.addFixture(f);
	    body2.setLinearVelocity(new Vector2(0.0, 0.0));
	    body2.setAngularVelocity(0.0);
	    body2.setMass(MassType.NORMAL);
	    body2.setAutoSleepingEnabled(false);
	    world.addBody(body2);
	    
		SimulationBody wallb = new SimulationBody();
		wallb.addFixture(Geometry.createRectangle(20, 0.2));
		wallb.translate(0, -6.5);
		wallb.setMass(MassType.INFINITE);
		world.addBody(wallb);
		
		SimulationBody wallr = new SimulationBody();
		wallr.addFixture(Geometry.createRectangle(0.2, 10));
		wallr.translate(5, 0);
		wallr.setMass(MassType.INFINITE);
		world.addBody(wallr);
		
		SimulationBody plat = new SimulationBody();
		plat.addFixture(Geometry.createRectangle(5, 0.2));
		plat.translate(-3, -3);
		plat.setMass(MassType.INFINITE);
		world.addBody(plat);
		
		SimulationBody plat2 = new SimulationBody();
		plat2.addFixture(Geometry.createRectangle(2, 0.2));
		plat2.translate(4, 2);
		plat2.setMass(MassType.INFINITE);
		world.addBody(plat2);
	}
	
	@Override
	protected void update(Graphics2D g, double elapsedTime) {
		body2.setAngularVelocity(0);
		body2.getTransform().setRotation(0);
		System.out.println(body2.getLinearVelocity().x + ", " + body2.getChangeInPosition().x);
		if((k.getW() && (body2.getChangeInPosition().y <= 0.0001 && body2.getChangeInPosition().y >= -0.0001)) || (k.getSpace() && (body2.getChangeInPosition().y <= 0.0001 && body2.getChangeInPosition().y >= -0.0001)))
		{
			body2.setLinearVelocity(body2.getLinearVelocity().x, 10);
		}
		if(k.getA() && body2.getChangeInPosition().x > -0.2)
		{
			body2.applyForce(new Vector2(-20, 0));
		}
		if(k.getD() && body2.getChangeInPosition().x < 0.2)
		{
			body2.applyForce(new Vector2(20, 0));
		}
		if(!k.getD() && !k.getA())
		{
			if(Math.abs(body2.getLinearVelocity().x) > 0.005)
			{
				body2.setLinearVelocity(body2.getLinearVelocity().x/1.1,body2.getLinearVelocity().y);
			}
			else
			{
				body2.setLinearVelocity(0,body2.getLinearVelocity().y);
			}
		}
		super.update(g, elapsedTime);
	}
	
	/**
{'fraction_non_alphanumeric': 0.15105386416861827, 'fraction_numerical': 0.04186182669789227, 'mean_word_length': 4.160876132930514, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '3173726', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2495, 'n_words': 389}