"use strict";

var GO_KickWave = function(strength, direction, constraints){
	this.sprite = new Sprite(GO_KickWave.spriteSheet,"KickWave");
	this.sprite.collision_flags = 
		DEFINE_SPRITE_COLLISION_FLAGS.GROUND | 
		DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_ACTIVE;
	this.sprite.setBoundingBox(3,0,12,15);
	this.sprite.constraints=constraints;
	this.sprite.game_object = this; // no longer a generic GO

	this.timer=-1;

	this.strength=strength;
	this.direction=direction;
};
GO_KickWave.spriteImg = SDS_Load_Image("art/sheets/sprite/kickWave.png");
GO_KickWave.spriteSheet = new TileSheet(4, 4, 1, 2, GO_KickWave.spriteImg);
GO_KickWave.STRENGTH = {
	"WEAK" : 0,
	"STRONG" : 1,
	"SUPER" : 2
};

GO_KickWave.prototype = new GameObject(
	new Sprite(
		GO_KickWave.spriteSheet,
		"KickWave"
	),
	"KickWave"
	);

	GO_KickWave.prototype.interactions = 0;

	GO_KickWave.prototype.wave_frames = [0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3];
	GO_KickWave.prototype.wave_speeds = [
		[2,2,2,2,1,1,1,1,1,0,1,0,1,0,1,0], //weak 16px
		[5,5,5,5,4,4,4,3,3,3,2,2,2,1,1,1], // strong 50px
		[5,5,5,5,5,5,5,4,4,4,3,3,3,2,2,2] // super 62px
	];
	GO_KickWave.prototype._collidingS = (
		DEFINE_SPRITE_MOVE_RESULT_FLAGS.EJECTED_SH | 
		DEFINE_SPRITE_MOVE_RESULT_FLAGS.EJECTED_SV |
		DEFINE_SPRITE_MOVE_RESULT_FLAGS.COLLIDING_S);

	GO_KickWave.prototype.Update = function(){
		this.timer++;

		this._heap.dead=false;
		if (this.timer>=this.wave_frames.length){
			this._heap.dead=true;
		}
		else{
			this._heap.dx = this.wave_speeds[this.strength][this.timer];
			if (this.direction<0){
				this._heap.dx = -this._heap.dx;
			}
			this.sprite.move(this._heap.dx,0,  this._heap.spriteMoveRes);
			if (this._heap.spriteMoveRes.flags & DEFINE_SPRITE_MOVE_RESULT_EJECTED_H){
				this._heap.dead=true;
			}
			if (this._heap.spriteMoveRes.flags & this._collidingS){
				for (this._heap.i=0; this._heap.i<this._heap.spriteMoveRes.collisions.length; this._heap.i++){
					if (this._heap.spriteMoveRes.collisions[this._heap.i].game_object.interactions & DEFINE_GAMEOBJECT_INTERACTIONS.DAMAGE){
						this._heap.spriteMoveRes.collisions[this._heap.i].game_object.damage(this,0); // no HP damage, just "stun"
						this._heap.dead=true;
					}
				}
				// TODO: figure out what we hit and stun/break/move it
			}
		}

		if (this._heap.dead){
			this.manager.remove(this);
			this.sprite.map_room.removeSprite(this.sprite);
		}
		else{
			this.sprite.frame = this.wave_frames[this.timer];
			if (this.direction<0){
				this.sprite.frame+=4;
			}
		}

	}
