<commit_before>package oose2015.entities.agents;

import oose2015.ParticleFactory;
import oose2015.entities.Entity;
import oose2015.entities.drops.Gold;
import oose2015.entities.projectiles.Projectile;
import oose2015.Assets;
import oose2015.EntityHandler;
import oose2015.Settings;
import oose2015.gui.PlayerUI;
import oose2015.utilities.VectorUtility;
import oose2015.World;
import oose2015.items.Armor;
import oose2015.items.Weapon;

import org.newdawn.slick.Color;
import org.newdawn.slick.ControllerListener;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.Sound;
import org.newdawn.slick.geom.Vector2f;

/**
 * Created by @Kasper on 26/03/2015
 * <p/>
 * Description:
 * Child class to agent. Creates controllable player object.
 * <p/>
 */

public class Player extends Agent implements ControllerListener{	
    public int gold;

    public int exp;
    private int lastLevelExp;
    private int nextLevelExp;


    public Weapon weapon;
    public Armor armor;
    
    private float nextAttackTime;
    private boolean drawAttack;

	//bow
    boolean startedBowDraw = false;
	float startTime;
	float releaseTime;
	
	public float 	drawTime,
				 	minDrawTime = Settings.MIN_DRAW_SPEED,
				 	maxDrawTime = Settings.MAX_DRAW_SPEED,
				 	maxDrawGraphicSize = Settings.MAX_DRAW_GRAPHIC_SIZE,
				 	drawGraphic = 0,
				 	sweetSpot = Settings.SWEETSPOT,
				 	sweetSpotRange = Settings.SWEETSPOT_RANGE;
    
	//melee
	public float startArc = Settings.PLAYER_ARC_START,
				 endArc = Settings.PLAYER_ARC_END;
	
    //controls
    public int		controllerIndex,
                    attackButton = Settings.ATTACK_BUTTON,
                    rangedButton = Settings.RANGED_BUTTON,
                    leftStickX = Settings.LEFT_STICK_X,
                    leftStickY = Settings.LEFT_STICK_Y,
    				rightStickX = Settings.RIGHT_STICK_X,
    				rightStickY = Settings.RIGHT_STICK_Y;

    //deadzones
    public float 	leftDeadX = Settings.LEFT_DEAD_X,
    				leftDeadY = Settings.LEFT_DEAD_Y,
    				rightDeadX = Settings.RIGHT_DEAD_X,
    				rightDeadY = Settings.RIGHT_DEAD_Y;
    
    //sound variables
    public Sound bowDrawSound;
    public Sound arrowShootSound;
    

    private boolean attackKeyDown = false,
                    rangedKeyDown = false;

	private Input input;
	
    public Color color;

    public PlayerUI playerUI;

    /**
     * Constructor for player [use Input.KEY_X as key arguments]
     * @param position Position
     * @param controllerIndex index for the controller
     * @param input reference to input
     */
    public Player(Vector2f position,Color color, int controllerIndex, Input input){
        playerUI = World.playerUIs[World.PLAYERS.size()];
        World.PLAYERS.add(this);

        this.input = input;
        this.color = color;
        input.addControllerListener(this);
        name = "Player";

        curHealth = Settings.PLAYER_HEALTH;
        maxHealth = curHealth;

        size = new Vector2f(50.0f, 50.0f);

        this.position = position;

        maxVelocity 	= 	Settings.PLAYER_MAX_VELOCITY;
        speedForce 		= 	Settings.PLAYER_SPEED_FORCE;
        mass 			= 	Settings.PLAYER_MASS;
        curHealth 		= 	Settings.PLAYER_HEALTH;
        
        bowDrawSound 	= 	Assets.SOUND_BOW_DRAW;
        arrowShootSound = 	Assets.SOUND_ARROW_SHOOT;
        
        gold = 0;
        exp	 = 0;

        level = 1;
        lastLevelExp = 0;
        nextLevelExp = (level*level)*100;

        this.controllerIndex = controllerIndex;

        weapon = new Weapon(1,0);
        armor = new Armor(1);

        drawAttack = false;
        nextAttackTime = 0f;

        playerUI.setPlayer(this,color);
    }
    
    /**
     * Melee attack in given arc.
     */
    @Override
    protected void attack(){
        nextAttackTime = World.TIME + weapon.attackDelay;

        for (int i = World.ENEMIES.size()-1; i >= 0; i--) {
            Enemy enemy = World.ENEMIES.get(i);
    		float dist = VectorUtility.getDistanceToEntity(this, enemy);
    		if(dist < weapon.attackRadius){
    			float enemyAngle = calculateAngleToTarget(enemy);

                float startAngle = startArc + rotation;
                float endAngle = endArc + rotation;

                boolean attacksEnemy;

                if(startAngle > 360 || endAngle < 0){

                    if(endAngle < 0)endAngle += 360;
                    if(startAngle > 360) startAngle -= 360;

                    System.out.println("Enemy Angle: " + enemyAngle + ".. eA: " + endAngle + " sA: " + startAngle);

                    attacksEnemy = (enemyAngle > endAngle && enemyAngle < 361) || (enemyAngle > -1 && enemyAngle < startAngle);
                }else
                    attacksEnemy = (enemyAngle > endAngle && enemyAngle < startAngle);

                if(attacksEnemy && enemy.takeDamage(this,weapon.damage))
                    addExp(enemy.expDrop);


            }
    	}
    }
    
    /**
     * Calculates speed and damage of ranged attack, and creates new projectile.
     */
    protected void rangedAttack(){
        boolean hitSweetSpot = false;

    	if(drawTime < minDrawTime)
    		return;
    	else if(drawTime > sweetSpot-sweetSpotRange && drawTime < sweetSpot)
    		hitSweetSpot = true;
    	else if(drawTime > maxDrawTime)
    		drawTime = maxDrawTime;
    	float projectileSpeed = Settings.PROJECTILE_SPEED_FORCE *(drawTime/maxDrawTime);
    	float damage = weapon.damage*(drawTime/maxDrawTime);
        if(hitSweetSpot)
            damage *= 2f;<commit_msg>removed print out<commit_after>package oose2015.entities.agents;

import oose2015.ParticleFactory;
import oose2015.entities.Entity;
import oose2015.entities.drops.Gold;
import oose2015.entities.projectiles.Projectile;
import oose2015.Assets;
import oose2015.EntityHandler;
import oose2015.Settings;
import oose2015.gui.PlayerUI;
import oose2015.utilities.VectorUtility;
import oose2015.World;
import oose2015.items.Armor;
import oose2015.items.Weapon;

import org.newdawn.slick.Color;
import org.newdawn.slick.ControllerListener;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.Sound;
import org.newdawn.slick.geom.Vector2f;

/**
 * Created by @Kasper on 26/03/2015
 * <p/>
 * Description:
 * Child class to agent. Creates controllable player object.
 * <p/>
 */

public class Player extends Agent implements ControllerListener{	
    public int gold;

    public int exp;
    private int lastLevelExp;
    private int nextLevelExp;


    public Weapon weapon;
    public Armor armor;
    
    private float nextAttackTime;
    private boolean drawAttack;

	//bow
    boolean startedBowDraw = false;
	float startTime;
	float releaseTime;
	
	public float 	drawTime,
				 	minDrawTime = Settings.MIN_DRAW_SPEED,
				 	maxDrawTime = Settings.MAX_DRAW_SPEED,
				 	maxDrawGraphicSize = Settings.MAX_DRAW_GRAPHIC_SIZE,
				 	drawGraphic = 0,
				 	sweetSpot = Settings.SWEETSPOT,
				 	sweetSpotRange = Settings.SWEETSPOT_RANGE;
    
	//melee
	public float startArc = Settings.PLAYER_ARC_START,
				 endArc = Settings.PLAYER_ARC_END;
	
    //controls
    public int		controllerIndex,
                    attackButton = Settings.ATTACK_BUTTON,
                    rangedButton = Settings.RANGED_BUTTON,
                    leftStickX = Settings.LEFT_STICK_X,
                    leftStickY = Settings.LEFT_STICK_Y,
    				rightStickX = Settings.RIGHT_STICK_X,
    				rightStickY = Settings.RIGHT_STICK_Y;

    //deadzones
    public float 	leftDeadX = Settings.LEFT_DEAD_X,
    				leftDeadY = Settings.LEFT_DEAD_Y,
    				rightDeadX = Settings.RIGHT_DEAD_X,
    				rightDeadY = Settings.RIGHT_DEAD_Y;
    
    //sound variables
    public Sound bowDrawSound;
    public Sound arrowShootSound;
    

    private boolean attackKeyDown = false,
                    rangedKeyDown = false;

	private Input input;
	
    public Color color;

    public PlayerUI playerUI;

    /**
     * Constructor for player [use Input.KEY_X as key arguments]
     * @param position Position
     * @param controllerIndex index for the controller
     * @param input reference to input
     */
    public Player(Vector2f position,Color color, int controllerIndex, Input input){
        playerUI = World.playerUIs[World.PLAYERS.size()];
        World.PLAYERS.add(this);

        this.input = input;
        this.color = color;
        input.addControllerListener(this);
        name = "Player";

        curHealth = Settings.PLAYER_HEALTH;
        maxHealth = curHealth;

        size = new Vector2f(50.0f, 50.0f);

        this.position = position;

        maxVelocity 	= 	Settings.PLAYER_MAX_VELOCITY;
        speedForce 		= 	Settings.PLAYER_SPEED_FORCE;
        mass 			= 	Settings.PLAYER_MASS;
        curHealth 		= 	Settings.PLAYER_HEALTH;
        
        bowDrawSound 	= 	Assets.SOUND_BOW_DRAW;
        arrowShootSound = 	Assets.SOUND_ARROW_SHOOT;
        
        gold = 0;
        exp	 = 0;

        level = 1;
        lastLevelExp = 0;
        nextLevelExp = (level*level)*100;

        this.controllerIndex = controllerIndex;

        weapon = new Weapon(1,0);
        armor = new Armor(1);

        drawAttack = false;
        nextAttackTime = 0f;

        playerUI.setPlayer(this,color);
    }
    
    /**
     * Melee attack in given arc.
     */
    @Override
    protected void attack(){
        nextAttackTime = World.TIME + weapon.attackDelay;

        for (int i = World.ENEMIES.size()-1; i >= 0; i--) {
            Enemy enemy = World.ENEMIES.get(i);
    		float dist = VectorUtility.getDistanceToEntity(this, enemy);
    		if(dist < weapon.attackRadius){
    			float enemyAngle = calculateAngleToTarget(enemy);

                float startAngle = startArc + rotation;
                float endAngle = endArc + rotation;

                boolean attacksEnemy;

                if(startAngle > 360 || endAngle < 0){

                    if(endAngle < 0)endAngle += 360;
                    if(startAngle > 360) startAngle -= 360;

                    attacksEnemy = (enemyAngle > endAngle && enemyAngle < 361) || (enemyAngle > -1 && enemyAngle < startAngle);
                }else
                    attacksEnemy = (enemyAngle > endAngle && enemyAngle < startAngle);

                if(attacksEnemy && enemy.takeDamage(this,weapon.damage))
                    addExp(enemy.expDrop);


            }
    	}
    }
    
    /**
     * Calculates speed and damage of ranged attack, and creates new projectile.
     */
    protected void rangedAttack(){
        boolean hitSweetSpot = false;

    	if(drawTime < minDrawTime)
    		return;
    	else if(drawTime > sweetSpot-sweetSpotRange && drawTime < sweetSpot)
    		hitSweetSpot = true;
    	else if(drawTime > maxDrawTime)
    		drawTime = maxDrawTime;
    	float projectileSpeed = Settings.PROJECTILE_SPEED_FORCE *(drawTime/maxDrawTime);
    	float damage = weapon.damage*(drawTime/maxDrawTime);
        if(hitSweetSpot)
            damage *= 2f;
{'fraction_non_alphanumeric': 0.08578186118439006, 'fraction_numerical': 0.01855726371327208, 'mean_word_length': 2.377572964669739, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '2876464', 'n_tokens_mistral': 3746, 'n_tokens_neox': 3381, 'n_words': 732}