<commit_before>package lt.miliauskas.battlesats;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;

public class LaserWeapon {
	
	public static final int STATE_IDLE = 0;
	public static final int STATE_FIRING = 1;	

	protected Flier flier;
	protected float range;
	protected float damagePerSecond; 
	protected float beamRadius;
	protected Flier target = null;
	protected int state = STATE_IDLE;
	
	protected Paint laserPaint = new Paint();	
	
	public LaserWeapon(Flier flier, float range, float damagePerSecond, float beamRadius) {
		this.flier = flier;
		this.range = range;
		this.damagePerSecond = damagePerSecond;
		this.beamRadius = beamRadius;
		laserPaint.setAntiAlias(true);
		laserPaint.setARGB(90, 0, 200, 200);
	}
	
	/*
	 * Rotates canvas to prepare for drawing the laser.
	 * 
	 * Call this before calling draw().
	 * 
	 */
	public void rotateCanvas(Canvas canvas) {
		if (target != null) {
			float d_x = target.position.x - flier.position.x;
			float d_y = target.position.y - flier.position.y;
			float angle = (float)Math.atan2(d_x, d_y);
			canvas.rotate(-angle * 180.0f / (float)Math.PI);
		}
	}
	
	public void draw(Canvas canvas) {
		if (state == STATE_FIRING) {
			// Draw laser beam.
			float d_x = target.position.x - flier.position.x;
			float d_y = target.position.y - flier.position.y;
			// TODO: use drawLine with a set stroke width
			canvas.drawRect(
					-beamRadius, 0,
					beamRadius,	PointF.length(d_x, d_y),
					laserPaint);
		}
	}
	
	public void doDamage(long elapsed, int enemyType) {
		state = STATE_IDLE;
		target = flier.thread.findNearestFlier(flier.position, enemyType);
		if (target != null) {
			float dist = PointF.length(target.position.x - flier.position.x, target.position.y - flier.position.y);
			if (dist <= range) {
				state = STATE_FIRING;
				target.hurt(elapsed * damagePerSecond / 1000.0f);
			}
		}
	}

}<commit_msg>Comments.<commit_after>package lt.miliauskas.battlesats;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;

public class LaserWeapon {
	
	public static final int STATE_IDLE = 0;
	public static final int STATE_FIRING = 1;	

	protected Flier flier;
	protected float range;
	protected float damagePerSecond; 
	protected float beamRadius;
	protected Flier target = null;
	protected int state = STATE_IDLE;
	
	protected Paint laserPaint = new Paint();	
	
	public LaserWeapon(Flier flier, float range, float damagePerSecond, float beamRadius) {
		this.flier = flier;
		this.range = range;
		this.damagePerSecond = damagePerSecond;
		this.beamRadius = beamRadius;
		laserPaint.setAntiAlias(true);
		laserPaint.setARGB(90, 0, 200, 200);
	}
	
	/*
	 * Rotates canvas to prepare for drawing the laser.
	 * 
	 * Call this before calling draw().
	 * 
	 */
	public void rotateCanvas(Canvas canvas) {
		// XXX Separating rotateCanvas from draw is bug-prone.
		if (target != null) {
			float d_x = target.position.x - flier.position.x;
			float d_y = target.position.y - flier.position.y;
			float angle = (float)Math.atan2(d_x, d_y);
			canvas.rotate(-angle * 180.0f / (float)Math.PI);
		}
	}
	
	public void draw(Canvas canvas) {
		if (state == STATE_FIRING) {
			// Draw laser beam.
			float d_x = target.position.x - flier.position.x;
			float d_y = target.position.y - flier.position.y;
			// TODO: use drawLine with a set stroke width
			canvas.drawRect(
					-beamRadius, 0,
					beamRadius,	PointF.length(d_x, d_y),
					laserPaint);
		}
	}
	
	public void doDamage(long elapsed, int enemyType) {
		state = STATE_IDLE;
		// TODO: try to hold onto current target before looking for a new one
		target = flier.thread.findNearestFlier(flier.position, enemyType);
		if (target != null) {
			float dist = PointF.length(target.position.x - flier.position.x, target.position.y - flier.position.y);
			if (dist <= range) {
				state = STATE_FIRING;
				target.hurt(elapsed * damagePerSecond / 1000.0f);
			}
		}
	}

}
{'fraction_non_alphanumeric': 0.1094577553593947, 'fraction_numerical': 0.011097099621689786, 'mean_word_length': 3.4561797752808987, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6336488', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1333, 'n_words': 352}