2013-06-04 17:38:43 +08:00
|
|
|
#include "PlayerController.h"
|
|
|
|
#include "ComponentsTestScene.h"
|
|
|
|
#include "SceneController.h"
|
|
|
|
#include "ProjectileController.h"
|
|
|
|
|
|
|
|
using namespace cocos2d;
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocostudio;
|
2013-06-04 17:38:43 +08:00
|
|
|
|
|
|
|
PlayerController::PlayerController(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_name = "PlayerController";
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PlayerController::~PlayerController(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlayerController::init()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerController::onEnter()
|
|
|
|
{
|
2014-03-26 16:39:32 +08:00
|
|
|
ComController::onEnter();
|
2013-06-04 17:38:43 +08:00
|
|
|
setTouchEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerController::onExit()
|
|
|
|
{
|
|
|
|
setTouchEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerController::update(float delta)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void PlayerController::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
|
|
|
// Choose one of the touches to work with
|
2013-09-03 18:22:03 +08:00
|
|
|
Touch* touch = touches[0];
|
2014-04-15 18:23:40 +08:00
|
|
|
Vector2 location = touch->getLocation();
|
2013-06-04 17:38:43 +08:00
|
|
|
|
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
Sprite *projectile = Sprite::create("components/Projectile.png", Rect(0, 0, 20, 20));
|
2013-06-15 14:03:30 +08:00
|
|
|
_owner->getParent()->addChild(projectile, 1, 4);
|
2013-06-04 17:38:43 +08:00
|
|
|
|
|
|
|
ProjectileController *com = ProjectileController::create();
|
|
|
|
projectile->addComponent(com);
|
|
|
|
com->move(location.x, location.y);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
((ComAudio*)(_owner->getComponent("Audio")))->playEffect("pew-pew-lei.wav");
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PlayerController* PlayerController::create(void)
|
|
|
|
{
|
|
|
|
PlayerController * pRet = new PlayerController();
|
|
|
|
if (pRet && pRet->init())
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|