mirror of https://github.com/axmolengine/axmol.git
Removing unused codes.
This commit is contained in:
parent
302106a8a9
commit
942c797749
|
@ -1,107 +0,0 @@
|
|||
#include "ComponentsTestScene.h"
|
||||
#include "GameOverScene.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "PlayerController.h"
|
||||
#include "SceneController.h"
|
||||
#include "../ExtensionsTest.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::extension;
|
||||
|
||||
ComponentsTestLayer::~ComponentsTestLayer()
|
||||
{
|
||||
}
|
||||
|
||||
ComponentsTestLayer::ComponentsTestLayer()
|
||||
{
|
||||
}
|
||||
|
||||
CCScene* ComponentsTestLayer::scene()
|
||||
{
|
||||
CCScene * scene = NULL;
|
||||
do
|
||||
{
|
||||
// 'scene' is an autorelease object
|
||||
scene = CCScene::create();
|
||||
CC_BREAK_IF(! scene);
|
||||
|
||||
// 'layer' is an autorelease object
|
||||
ComponentsTestLayer *layer = ComponentsTestLayer::create();
|
||||
CC_BREAK_IF(! layer);
|
||||
|
||||
// add layer as a child to scene
|
||||
scene->addChild(layer);
|
||||
} while (0);
|
||||
|
||||
// return the scene
|
||||
return scene;
|
||||
}
|
||||
|
||||
// on "init" you need to initialize your instance
|
||||
bool ComponentsTestLayer::init()
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(! CCLayerColor::initWithColor( ccc4(255,255,255,255) ) );
|
||||
|
||||
CCNode *root = createGameScene();
|
||||
CC_BREAK_IF(!root);
|
||||
this->addChild(root, 0, 1);
|
||||
|
||||
root->getChildByTag(1)->addComponent(CCComAudio::create());
|
||||
root->getChildByTag(1)->addComponent(PlayerController::create());
|
||||
|
||||
root->addComponent(CCComAudio::create());
|
||||
root->addComponent(CCComAttribute::create());
|
||||
root->addComponent(SceneController::create());
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
cocos2d::CCNode* ComponentsTestLayer::createGameScene()
|
||||
{
|
||||
CCNode *root = NULL;
|
||||
do
|
||||
{
|
||||
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
|
||||
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
|
||||
|
||||
|
||||
CCSprite *player = CCSprite::create("components/Player.png", CCRectMake(0, 0, 27, 40) );
|
||||
|
||||
player->setPosition( ccp(origin.x + player->getContentSize().width/2,
|
||||
origin.y + visibleSize.height/2) );
|
||||
|
||||
root = cocos2d::CCNode::create();
|
||||
root->addChild(player, 1, 1);
|
||||
|
||||
|
||||
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(ComponentsTestLayer::toExtensionsMainLayer));
|
||||
itemBack->setColor(ccc3(0, 0, 0));
|
||||
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
||||
CCMenu *menuBack = CCMenu::create(itemBack, NULL);
|
||||
menuBack->setPosition(CCPointZero);
|
||||
addChild(menuBack);
|
||||
|
||||
}while (0);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
void ComponentsTestLayer::toExtensionsMainLayer(cocos2d::CCObject *sender)
|
||||
{
|
||||
ExtensionsTestScene *pScene = new ExtensionsTestScene();
|
||||
pScene->runThisTest();
|
||||
pScene->release();
|
||||
}
|
||||
|
||||
|
||||
void runComponentsTestLayerTest()
|
||||
{
|
||||
CCScene *pScene = ComponentsTestLayer::scene();
|
||||
CCDirector::sharedDirector()->replaceScene(pScene);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef __COMPONENTSTESTSCENE_H__
|
||||
#define __COMPONENTSTESTSCENE_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
|
||||
void runComponentsTestLayerTest();
|
||||
|
||||
class ComponentsTestLayer : public cocos2d::CCLayerColor
|
||||
{
|
||||
public:
|
||||
ComponentsTestLayer();
|
||||
~ComponentsTestLayer();
|
||||
|
||||
// Here's a difference. Method 'init' in cocos2d-x returns bool,
|
||||
// instead of returning 'id' in cocos2d-iphone
|
||||
virtual bool init();
|
||||
|
||||
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
|
||||
static cocos2d::CCScene* scene();
|
||||
|
||||
// implement the "static node()" method manually
|
||||
CREATE_FUNC(ComponentsTestLayer);
|
||||
|
||||
// init scene
|
||||
cocos2d::CCNode* createGameScene();
|
||||
|
||||
//back to Extensions Main Layer
|
||||
void toExtensionsMainLayer(cocos2d::CCObject *sender);
|
||||
};
|
||||
|
||||
#endif // __HELLOWORLD_SCENE_H__
|
|
@ -1,107 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "EnemyController.h"
|
||||
#include "SceneController.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
EnemyController::EnemyController(void)
|
||||
{
|
||||
m_strName = "EnemyController";
|
||||
}
|
||||
|
||||
EnemyController::~EnemyController(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool EnemyController::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void EnemyController::onEnter()
|
||||
{
|
||||
// Determine where to spawn the target along the Y axis
|
||||
CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
|
||||
float minY = getOwner()->getContentSize().height/2;
|
||||
float maxY = winSize.height - getOwner()->getContentSize().height/2;
|
||||
int rangeY = (int)(maxY - minY);
|
||||
// srand( TimGetTicks() );
|
||||
int actualY = ( rand() % rangeY ) + (int)minY;
|
||||
|
||||
// Create the target slightly off-screen along the right edge,
|
||||
// and along a random position along the Y axis as calculated
|
||||
m_pOwner->setPosition(
|
||||
ccp(winSize.width + (getOwner()->getContentSize().width/2),
|
||||
CCDirector::sharedDirector()->getVisibleOrigin().y + actualY) );
|
||||
|
||||
|
||||
// Determine speed of the target
|
||||
int minDuration = (int)2.0;
|
||||
int maxDuration = (int)4.0;
|
||||
int rangeDuration = maxDuration - minDuration;
|
||||
// srand( TimGetTicks() );
|
||||
int actualDuration = ( rand() % rangeDuration ) + minDuration;
|
||||
|
||||
// Create the actions
|
||||
CCFiniteTimeAction* actionMove = CCMoveTo::create( (float)actualDuration,
|
||||
ccp(0 - getOwner()->getContentSize().width/2, actualY) );
|
||||
CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create(getOwner()->getParent()->getComponent("SceneController"),
|
||||
callfuncN_selector(SceneController::spriteMoveFinished));
|
||||
m_pOwner->runAction( CCSequence::create(actionMove, actionMoveDone, NULL) );
|
||||
}
|
||||
|
||||
void EnemyController::onExit()
|
||||
{
|
||||
}
|
||||
|
||||
void EnemyController::update(float delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EnemyController* EnemyController::create(void)
|
||||
{
|
||||
EnemyController * pRet = new EnemyController();
|
||||
if (pRet && pRet->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void EnemyController::die()
|
||||
{
|
||||
CCComponent *com = m_pOwner->getParent()->getComponent("SceneController");
|
||||
cocos2d::CCArray *_targets = ((SceneController*)com)->getTargets();
|
||||
_targets->removeObject(m_pOwner);
|
||||
m_pOwner->removeFromParentAndCleanup(true);
|
||||
((SceneController*)com)->increaseKillCount();
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_ENEMYCONTROLLER_H__
|
||||
#define __CC_ENEMYCONTROLLER_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
|
||||
|
||||
class EnemyController : public cocos2d::extension::CCComController
|
||||
{
|
||||
protected:
|
||||
EnemyController(void);
|
||||
virtual ~EnemyController(void);
|
||||
|
||||
public:
|
||||
virtual bool init();
|
||||
virtual void onEnter();
|
||||
virtual void onExit();
|
||||
virtual void update(float delta);
|
||||
|
||||
static EnemyController* create(void);
|
||||
public:
|
||||
void die();
|
||||
};
|
||||
|
||||
|
||||
#endif // __FUNDATION__CCCOMPONENT_H__
|
|
@ -1,103 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2010 Ray Wenderlich
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "GameOverScene.h"
|
||||
#include "ComponentsTestScene.h"
|
||||
#include "../ExtensionsTest.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
bool GameOverScene::init()
|
||||
{
|
||||
if( CCScene::init() )
|
||||
{
|
||||
this->_layer = GameOverLayer::create();
|
||||
this->_layer->retain();
|
||||
this->addChild(_layer);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
GameOverScene::~GameOverScene()
|
||||
{
|
||||
if (_layer)
|
||||
{
|
||||
_layer->release();
|
||||
_layer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool GameOverLayer::init()
|
||||
{
|
||||
if ( CCLayerColor::initWithColor( ccc4(255,255,255,255) ) )
|
||||
{
|
||||
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
|
||||
this->_label = CCLabelTTF::create("","Artial", 32);
|
||||
_label->retain();
|
||||
_label->setColor( ccc3(0, 0, 0) );
|
||||
_label->setPosition( ccp(winSize.width/2, winSize.height/2) );
|
||||
this->addChild(_label);
|
||||
|
||||
this->runAction( CCSequence::create(
|
||||
CCDelayTime::create(3),
|
||||
CCCallFunc::create(this,
|
||||
callfunc_selector(GameOverLayer::gameOverDone)),
|
||||
NULL));
|
||||
|
||||
|
||||
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(ComponentsTestLayer::toExtensionsMainLayer));
|
||||
itemBack->setColor(ccc3(0, 0, 0));
|
||||
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
||||
CCMenu *menuBack = CCMenu::create(itemBack, NULL);
|
||||
menuBack->setPosition(CCPointZero);
|
||||
addChild(menuBack);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void GameOverLayer::gameOverDone()
|
||||
{
|
||||
CCDirector::sharedDirector()->replaceScene( ComponentsTestLayer::scene() );
|
||||
}
|
||||
|
||||
GameOverLayer::~GameOverLayer()
|
||||
{
|
||||
if (_label)
|
||||
{
|
||||
_label->release();
|
||||
_label = NULL;
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2010 Ray Wenderlich
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _GAME_OVER_SCENE_H_
|
||||
#define _GAME_OVER_SCENE_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
class GameOverLayer : public cocos2d::CCLayerColor
|
||||
{
|
||||
public:
|
||||
GameOverLayer():_label(NULL) {};
|
||||
virtual ~GameOverLayer();
|
||||
bool init();
|
||||
CREATE_FUNC(GameOverLayer);
|
||||
|
||||
void gameOverDone();
|
||||
|
||||
CC_SYNTHESIZE_READONLY(cocos2d::CCLabelTTF*, _label, Label);
|
||||
};
|
||||
|
||||
class GameOverScene : public cocos2d::CCScene
|
||||
{
|
||||
public:
|
||||
GameOverScene():_layer(NULL) {};
|
||||
~GameOverScene();
|
||||
bool init();
|
||||
CREATE_FUNC(GameOverScene);
|
||||
|
||||
CC_SYNTHESIZE_READONLY(GameOverLayer*, _layer, Layer);
|
||||
};
|
||||
|
||||
#endif // _GAME_OVER_SCENE_H_
|
|
@ -1,92 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "PlayerController.h"
|
||||
#include "ComponentsTestScene.h"
|
||||
#include "SceneController.h"
|
||||
#include "ProjectileController.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::extension;
|
||||
|
||||
PlayerController::PlayerController(void)
|
||||
{
|
||||
m_strName = "PlayerController";
|
||||
}
|
||||
|
||||
PlayerController::~PlayerController(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool PlayerController::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlayerController::onEnter()
|
||||
{
|
||||
setTouchEnabled(true);
|
||||
}
|
||||
|
||||
void PlayerController::onExit()
|
||||
{
|
||||
setTouchEnabled(false);
|
||||
}
|
||||
|
||||
void PlayerController::update(float delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PlayerController::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
|
||||
{
|
||||
// Choose one of the touches to work with
|
||||
CCTouch* touch = (CCTouch*)( pTouches->anyObject() );
|
||||
CCPoint location = touch->getLocation();
|
||||
|
||||
|
||||
CCSprite *projectile = CCSprite::create("components/Projectile.png", CCRectMake(0, 0, 20, 20));
|
||||
m_pOwner->getParent()->addChild(projectile, 1, 4);
|
||||
|
||||
ProjectileController *com = ProjectileController::create();
|
||||
projectile->addComponent(com);
|
||||
com->move(location.x, location.y);
|
||||
|
||||
((CCComAudio*)(m_pOwner->getComponent("Audio")))->playEffect("pew-pew-lei.wav");
|
||||
}
|
||||
|
||||
PlayerController* PlayerController::create(void)
|
||||
{
|
||||
PlayerController * pRet = new PlayerController();
|
||||
if (pRet && pRet->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PLAYERCONTROLLER_H__
|
||||
#define __CC_PLAYERCONTROLLER_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
|
||||
|
||||
class PlayerController : public cocos2d::extension::CCComController
|
||||
{
|
||||
protected:
|
||||
PlayerController(void);
|
||||
virtual ~PlayerController(void);
|
||||
|
||||
public:
|
||||
virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
|
||||
|
||||
public:
|
||||
virtual bool init();
|
||||
virtual void onEnter();
|
||||
virtual void onExit();
|
||||
virtual void update(float delta);
|
||||
|
||||
static PlayerController* create(void);
|
||||
};
|
||||
|
||||
|
||||
#endif // __FUNDATION__CCCOMPONENT_H__
|
|
@ -1,163 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "ProjectileController.h"
|
||||
#include "SceneController.h"
|
||||
#include "EnemyController.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
ProjectileController::ProjectileController(void)
|
||||
{
|
||||
m_strName = "ProjectileController";
|
||||
}
|
||||
|
||||
ProjectileController::~ProjectileController(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool ProjectileController::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProjectileController::onEnter()
|
||||
{
|
||||
CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
|
||||
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
|
||||
m_pOwner->setPosition( ccp(origin.x+20, origin.y+winSize.height/2) );
|
||||
m_pOwner->setTag(3);
|
||||
CCComponent *com = m_pOwner->getParent()->getComponent("SceneController");
|
||||
((SceneController*)com)->getProjectiles()->addObject(m_pOwner);
|
||||
}
|
||||
|
||||
void ProjectileController::onExit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ProjectileController::update(float delta)
|
||||
{
|
||||
CCComponent *com = m_pOwner->getParent()->getComponent("SceneController");
|
||||
cocos2d::CCArray *_targets = ((SceneController*)com)->getTargets();
|
||||
|
||||
CCSprite *projectile = dynamic_cast<CCSprite*>(m_pOwner);
|
||||
CCRect projectileRect = CCRectMake(
|
||||
projectile->getPosition().x - (projectile->getContentSize().width/2),
|
||||
projectile->getPosition().y - (projectile->getContentSize().height/2),
|
||||
projectile->getContentSize().width,
|
||||
projectile->getContentSize().height);
|
||||
|
||||
CCArray* targetsToDelete =new CCArray;
|
||||
CCObject* jt = NULL;
|
||||
CCARRAY_FOREACH(_targets, jt)
|
||||
{
|
||||
CCSprite *target = dynamic_cast<CCSprite*>(jt);
|
||||
CCRect targetRect = CCRectMake(
|
||||
target->getPosition().x - (target->getContentSize().width/2),
|
||||
target->getPosition().y - (target->getContentSize().height/2),
|
||||
target->getContentSize().width,
|
||||
target->getContentSize().height);
|
||||
|
||||
// if (CCRect::CCRectIntersectsRect(projectileRect, targetRect))
|
||||
if (projectileRect.intersectsRect(targetRect))
|
||||
{
|
||||
targetsToDelete->addObject(target);
|
||||
}
|
||||
}
|
||||
|
||||
CCARRAY_FOREACH(targetsToDelete, jt)
|
||||
{
|
||||
CCSprite *target = dynamic_cast<CCSprite*>(jt);
|
||||
((EnemyController*)(target->getComponent("EnemyController")))->die();
|
||||
}
|
||||
|
||||
bool isDied = targetsToDelete->count();
|
||||
|
||||
targetsToDelete->release();
|
||||
|
||||
if (isDied)
|
||||
{
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
ProjectileController* ProjectileController::create(void)
|
||||
{
|
||||
ProjectileController * pRet = new ProjectileController();
|
||||
if (pRet && pRet->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
|
||||
void ProjectileController::move(float flocationX, float flocationY)
|
||||
{
|
||||
CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
|
||||
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
|
||||
// Determinie offset of location to projectile
|
||||
float offX = flocationX - m_pOwner->getPosition().x;
|
||||
float offY = flocationY - m_pOwner->getPosition().y;
|
||||
|
||||
// Bail out if we are shooting down or backwards
|
||||
if (offX <= 0) return;
|
||||
|
||||
// Ok to add now - we've double checked position
|
||||
|
||||
|
||||
// Determine where we wish to shoot the projectile to
|
||||
float realX = origin.x + winSize.width + (m_pOwner->getContentSize().width/2);
|
||||
float ratio = offY / offX;
|
||||
float realY = (realX * ratio) + m_pOwner->getPosition().y;
|
||||
CCPoint realDest = ccp(realX, realY);
|
||||
|
||||
// Determine the length of how far we're shooting
|
||||
float offRealX = realX - m_pOwner->getPosition().x;
|
||||
float offRealY = realY - m_pOwner->getPosition().y;
|
||||
float length = sqrtf((offRealX * offRealX) + (offRealY*offRealY));
|
||||
float velocity = 480/1; // 480pixels/1sec
|
||||
float realMoveDuration = length/velocity;
|
||||
|
||||
// Move projectile to actual endpoint
|
||||
m_pOwner->runAction( CCSequence::create(
|
||||
CCMoveTo::create(realMoveDuration, realDest),
|
||||
CCCallFuncN::create(getOwner()->getParent()->getComponent("SceneController"),
|
||||
callfuncN_selector(SceneController::spriteMoveFinished)),
|
||||
NULL) );
|
||||
|
||||
}
|
||||
|
||||
void ProjectileController::die()
|
||||
{
|
||||
CCComponent *com = m_pOwner->getParent()->getComponent("SceneController");
|
||||
cocos2d::CCArray *_projectiles = ((SceneController*)com)->getProjectiles();
|
||||
_projectiles->removeObject(m_pOwner);
|
||||
m_pOwner->removeFromParentAndCleanup(true);
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PROJECTILECONTROLLER_H__
|
||||
#define __CC_PROJECTILECONTROLLER_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
|
||||
|
||||
class ProjectileController : public cocos2d::extension::CCComController
|
||||
{
|
||||
protected:
|
||||
ProjectileController(void);
|
||||
virtual ~ProjectileController(void);
|
||||
|
||||
public:
|
||||
virtual bool init();
|
||||
virtual void onEnter();
|
||||
virtual void onExit();
|
||||
virtual void update(float delta);
|
||||
|
||||
static ProjectileController* create(void);
|
||||
public:
|
||||
void move(float flocationX, float flocationY);
|
||||
void die();
|
||||
};
|
||||
|
||||
|
||||
#endif // __FUNDATION__CCCOMPONENT_H__
|
|
@ -1,147 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "SceneController.h"
|
||||
#include "ComponentsTestScene.h"
|
||||
#include "PlayerController.h"
|
||||
#include "GameOverScene.h"
|
||||
#include "EnemyController.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::extension;
|
||||
|
||||
SceneController::SceneController(void)
|
||||
: _fAddTargetTime(0.0f)
|
||||
, _fElapsedTime(0.0f)
|
||||
, _targets(NULL)
|
||||
, _projectiles(NULL)
|
||||
{
|
||||
m_strName = "SceneController";
|
||||
}
|
||||
|
||||
SceneController::~SceneController(void)
|
||||
{
|
||||
if (_targets)
|
||||
{
|
||||
_targets->release();
|
||||
_targets = NULL;
|
||||
}
|
||||
|
||||
if (_projectiles)
|
||||
{
|
||||
_projectiles->release();
|
||||
_projectiles = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool SceneController::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void SceneController::onEnter()
|
||||
{
|
||||
_fAddTargetTime = 1.0f;
|
||||
|
||||
_targets = new CCArray;
|
||||
_projectiles = new CCArray;
|
||||
|
||||
((CCComAudio*)(m_pOwner->getComponent("Audio")))->playBackgroundMusic("background-music-aac.wav", true);
|
||||
((CCComAttribute*)(m_pOwner->getComponent("ComAttribute")))->setInt("KillCount", 0);
|
||||
}
|
||||
|
||||
void SceneController::onExit()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SceneController::update(float delta)
|
||||
{
|
||||
// return;
|
||||
_fElapsedTime += delta;
|
||||
if (_fElapsedTime > _fAddTargetTime)
|
||||
{
|
||||
addTarget();
|
||||
_fElapsedTime = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
SceneController* SceneController::create(void)
|
||||
{
|
||||
SceneController * pRet = new SceneController();
|
||||
if (pRet && pRet->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void SceneController::addTarget()
|
||||
{
|
||||
CCSprite *target = CCSprite::create("components/Target.png", CCRectMake(0,0,27,40));
|
||||
m_pOwner->addChild(target, 1, 2);
|
||||
|
||||
target->addComponent(EnemyController::create());
|
||||
target->setTag(2);
|
||||
_targets->addObject(target);
|
||||
}
|
||||
|
||||
void SceneController::spriteMoveFinished(CCNode* sender)
|
||||
{
|
||||
CCSprite *sprite = (CCSprite *)sender;
|
||||
m_pOwner->removeChild(sprite, true);
|
||||
|
||||
if (sprite->getTag() == 2) // target
|
||||
{
|
||||
_targets->removeObject(sprite);
|
||||
GameOverScene *gameOverScene = GameOverScene::create();
|
||||
gameOverScene->getLayer()->getLabel()->setString("You Lose :[");
|
||||
CCDirector::sharedDirector()->replaceScene(gameOverScene);
|
||||
}
|
||||
else if (sprite->getTag() == 3)
|
||||
{
|
||||
_projectiles->removeObject(sprite);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SceneController::increaseKillCount()
|
||||
{
|
||||
int nProjectilesDestroyed = ((CCComAttribute*)(m_pOwner->getComponent("ComAttribute")))->getInt("KillCount");
|
||||
|
||||
CCComAttribute *p = (CCComAttribute*)(m_pOwner->getComponent("ComAttribute"));
|
||||
p->setInt("KillCount", ++nProjectilesDestroyed);
|
||||
|
||||
if (nProjectilesDestroyed >= 5)
|
||||
{
|
||||
GameOverScene *gameOverScene = GameOverScene::create();
|
||||
gameOverScene->getLayer()->getLabel()->setString("You Win!");
|
||||
CCDirector::sharedDirector()->replaceScene(gameOverScene);
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_SceneController_H__
|
||||
#define __CC_SceneController_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
|
||||
|
||||
class SceneController : public cocos2d::extension::CCComController
|
||||
{
|
||||
protected:
|
||||
SceneController(void);
|
||||
virtual ~SceneController(void);
|
||||
|
||||
public:
|
||||
virtual bool init();
|
||||
virtual void onEnter();
|
||||
virtual void onExit();
|
||||
virtual void update(float delta);
|
||||
|
||||
static SceneController* create(void);
|
||||
|
||||
public:
|
||||
cocos2d::CCArray* getTargets() {return _targets;};
|
||||
cocos2d::CCArray* getProjectiles() {return _projectiles;};
|
||||
void spriteMoveFinished(cocos2d::CCNode* sender);
|
||||
void increaseKillCount();
|
||||
|
||||
void addTarget();
|
||||
float _fAddTargetTime;
|
||||
float _fElapsedTime;
|
||||
|
||||
|
||||
protected:
|
||||
cocos2d::CCArray *_targets;
|
||||
cocos2d::CCArray *_projectiles;
|
||||
};
|
||||
|
||||
|
||||
#endif // __FUNDATION__CCCOMPONENT_H__
|
Loading…
Reference in New Issue