#include "MovingPlatform.h"
#include "WorldManager.h"
#include "ResourceManager.h"

MovingPlatform::MovingPlatform(){
	//this->setSprite(new Sprite(1));
	this->xs=0;
	this->ys=0;
	this->moveDelay=0;
}
MovingPlatform::~MovingPlatform(){}
void MovingPlatform::move(int dx,int dy){
	GameObject* col=WorldManager::getInstance().isCollision(this,Position(this->getPos().getX()+dx,this->getPos().getY()+dy));
	if(col==NULL){
		this->setPos(Position(this->getPos().getX()+dx,this->getPos().getY()+dy));
	}
	else if(col->getType()!="hero"){
		this->xs*=-1;
		this->ys*=-1;
	}
}
void MovingPlatform::step(){}
int MovingPlatform::eventHandler(Event *e){
	if (e->getType() == "step") {
		//step();
		if(this->moveDelay>0){
			this->moveDelay--;
		}
		if(this->moveDelay==0){
			this->move(this->xs,this->ys);
			this->moveDelay=this->moveDelaySet;
		}
		draw();
		return 1;
	}
	return 0;
}
