From e0e962b074bae407cb0f1ed9376d57080d436ab9 Mon Sep 17 00:00:00 2001 From: headrokoko Date: Mon, 29 Dec 2014 20:52:54 +0900 Subject: [PATCH] =?UTF-8?q?20141229=20Enemy=E3=81=AE=E7=99=BA=E7=94=9F?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E3=82=92=E3=83=A9=E3=83=B3=E3=83=80=E3=83=A0?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/HelloWorldScene.cpp | 66 +++++++++++++++++++++++++++--------- Classes/HelloWorldScene.h | 12 +++++-- Resources/Bomb.psd | Bin 23356 -> 23711 bytes Resources/Sample.tmx | 2 +- 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/Classes/HelloWorldScene.cpp b/Classes/HelloWorldScene.cpp index b269902..7967144 100644 --- a/Classes/HelloWorldScene.cpp +++ b/Classes/HelloWorldScene.cpp @@ -51,20 +51,19 @@ bool HelloWorld::init() return false; } - CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint"); + CCDictionary* spawnPoint = objectGroup->objectNamed("SpawnPoint"); int x = ((CCString)*spawnPoint->valueForKey("x")).intValue(); int y = ((CCString)*spawnPoint->valueForKey("y")).intValue(); - + spawnpoint = ccp(x,y); //CreatePlayer(ccp(x,y)); - //CreateBomb(ccp(x,y)); + //CreateBomb(spawnpoint); this->setTouchEnabled(true); - //CreateObj().Create(this, _world, enemy, ccp(x,y) ); //オブジェクト生成クラスへenemy生成命令 - scheduleUpdate(); //updateメソッドを実行 + //this->schedule(schedule_selector(HelloWorld::EnemySpwan),1); return true; } @@ -73,16 +72,11 @@ void HelloWorld::update(float dt) { _world->Step(dt,10,10); - //for(b2Body* subbody = _world->GetBodyList(); subbody; subbody = subbody->GetNext()) - { - //if(subbody->GetUserData() != NULL) - { - //CCSprite* SP = (CCSprite*)subbody->GetUserData(); //P_bodyに格納されたuserdate(Sprite)の取り出し - - //SP->setPosition(CCPointMake(P_body->GetPosition().x * PTM_RATIO, P_body->GetPosition().y * PTM_RATIO)); //P_bodyに割り当てられた画像の位置をP_bodyの位置に設定 +} - } - } +void HelloWorld::EnemySpwan() +{ + CCLog("test"); } //背景設定メソッド @@ -100,7 +94,7 @@ void HelloWorld::CreateBackground() } -//Enemy作成 +//Bomb作成 void HelloWorld::CreateBomb(CCPoint point) { PhysiSprite* BombSprite = new PhysiSprite(); @@ -132,6 +126,43 @@ void HelloWorld::CreateBomb(CCPoint point) } +//Enemy作成 +void HelloWorld::CreateEnemy(CCPoint point) +{ + PhysiSprite* Enemyprite = new PhysiSprite(); + Enemyprite->autorelease(); + Enemyprite->initWithFile("Player.png"); + + + float posX = (float)(rand()%(95-10+1)+10) / 100 ; + + Enemyprite->setPosition(point); + this->addChild(Enemyprite); + + b2BodyDef EnemyBodyDef; + EnemyBodyDef.type = b2_dynamicBody; + EnemyBodyDef.linearVelocity = b2Vec2(0.0f, 15.0f); + EnemyBodyDef.position.Set(ScreenSize.width * posX / PTM_RATIO, ScreenSize.height * 0.1f / PTM_RATIO); + + EnemyBodyDef.userData = Enemyprite; + + b2Body* Enemy_body = _world->CreateBody(&EnemyBodyDef); + + b2CircleShape EnemyShape; + EnemyShape.m_radius = Enemyprite->getContentSize().width * 0.5 / PTM_RATIO; + + b2FixtureDef BombFixDef; + BombFixDef.shape = &EnemyShape; + BombFixDef.density = 1.0f; + BombFixDef.friction = 0.9; + + Enemy_body->CreateFixture(&BombFixDef); + Enemyprite->setPhysiBody(Enemy_body); + + //this->setViewPointCenter(BombSprite->getPosition()); + +} + //プレイヤー作成 void HelloWorld::CreatePlayer(CCPoint point) { @@ -171,7 +202,7 @@ void HelloWorld::initPhysics() _world = new b2World(gravity); //_worldにgravityを入力 //ゲーム画面端の設定 - CCSize ScreenSize = CCDirector::sharedDirector()->getWinSize(); + ScreenSize = CCDirector::sharedDirector()->getWinSize(); b2BodyDef worldBodyDef; worldBodyDef.position.Set(0,0); @@ -235,6 +266,7 @@ void HelloWorld::registerWithTouchDispatcher() CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true); } +//クリック押下イベント bool HelloWorld::ccTouchBegan(CCTouch *touch, CCEvent *event) { CCDirector* pDirector = CCDirector::sharedDirector(); @@ -243,6 +275,8 @@ bool HelloWorld::ccTouchBegan(CCTouch *touch, CCEvent *event) //CreatePlayer(touchPoint); CreateBomb(touchPoint); + CreateEnemy(touchPoint); + return true; } diff --git a/Classes/HelloWorldScene.h b/Classes/HelloWorldScene.h index 8f4592a..96c78e6 100644 --- a/Classes/HelloWorldScene.h +++ b/Classes/HelloWorldScene.h @@ -12,6 +12,11 @@ USING_NS_CC; class HelloWorld : public cocos2d::CCLayer { + +protected: + + void EnemySpwan(); + public: ~HelloWorld(); @@ -21,10 +26,11 @@ class HelloWorld : public cocos2d::CCLayer virtual void CreateBackground(); //背景作成メソッド virtual void CreatePlayer(CCPoint point); //プレイヤー作成メソッド - //virtual void CreateEnemy(CCPoint point); //Enemy作成メソッド + virtual void CreateEnemy(CCPoint point); //Enemy作成メソッド virtual void CreateBomb(CCPoint point); //爆弾作成メソッド virtual void draw(); //debugDraw作成メソッド  + void initPhysics(); //物理演算初期化 void update(float dt); //updateメソッド @@ -47,6 +53,7 @@ class HelloWorld : public cocos2d::CCLayer void ccTouchEnded(CCTouch *touch, CCEvent *event); b2World* _world; //b2World用のフィールド宣言 + CCSize ScreenSize; CCSpriteBatchNode* ESpriteBatchNode; @@ -61,7 +68,7 @@ class HelloWorld : public cocos2d::CCLayer private: - + CCPoint spawnpoint; CCSpriteBatchNode* batchNode; b2Body* P_body; //プレイヤーの物理ボディ @@ -80,6 +87,7 @@ class HelloWorld : public cocos2d::CCLayer HudLayer *_hud; //HUDレイヤー int _numCollected; + int count; }; diff --git a/Resources/Bomb.psd b/Resources/Bomb.psd index 9f5874fd8f9caf9aac83fed97aa4f7c79f41c7c0..345d57eb06537466a5a7c5fff689a092ac39e88d 100644 GIT binary patch delta 484 zcmZurOG^S#82#>yGrmflK-v_TONsC`IyccWQ z-o5vnvEiIQv`kMREZ3RXKd4NxJhF+YXc9+6F&tOsOd9ftDSrw_(^5)G`Xwn5$7vkI zI1yM02E>aqS+^N1FarX(zyZ^AcG5{u zT-%H6Q3EFJ4?r%f22Eg)gV8_(k_Wse`}HU5F3AT2N9*Mb=0vdPhGjg SenW*{Kt5{^5NB5>r2YeM@t({8 delta 175 zcmbQglX1^BMkNcUfM5nj1_)pVQVL+q!2n_dL7>1!rCCf|79oblR>tO5rbd&GG1(w- zH}f#FF)}$hPd>n`w%Lm1KBI!Og`<<3xv`_Ov6+#%tC^FtiK(f%tEG#nnWLkTfs^rO zOSYxPn=Py+igH;fz)anI+5aFT69d!aX@PodoFI$uOnwk#u=!VD3)|*>5faP*Dsw4| diff --git a/Resources/Sample.tmx b/Resources/Sample.tmx index 2144b0d..a8b005e 100644 --- a/Resources/Sample.tmx +++ b/Resources/Sample.tmx @@ -9,6 +9,6 @@ - +