2015-6-20求整数的绝对值,碰撞检测,游戏结束时,回掉“back to menu",操作方法

C语言

函数名: abs
功 能: 求整数的绝对值
头文件:stdlib.h
函数原型:int abs(int i);
2// 碰撞检测
bool GameMain::isCollion(CCPoint p1, CCPoint p2, int w1, int h1, int w2, int h2)
{
//判断两个矩形是否碰撞
if (abs(p1.x - p2.x) < w1 + w2 && abs(p1.y - p2.y) < h1 + h2)
{
return true;
}
return false;
}
void GameMain::update(float time)
{

CCPoint hpos = hero->getPosition();
// 碰撞检测
for (int i = 0; i < 3; i++)
{
GameObjEnemy *enemy = (GameObjEnemy*)enemys->objectAtIndex(i); // sjt
CCPoint epos = enemy->getPosition();
if(enemy->islife) // 敌人是否活着
{
for(int i = 0; i < bullets->capacity(); i++) // bullets(主角子弹)
{
if(((GameHeroBullet*)bullets->objectAtIndex(i))->getIsvisble())
{
if(isCollion(((GameHeroBullet*)bullets->objectAtIndex(i))->getPosition(), epos, 5, 13, 21, 28)) //  敌人和主角子弹碰撞检测
{
enemy->setdie();
gamemark->addnumber(200); // ahui
break;
}
}
}
}// endif(enemy->islife) // 敌人是否活着
if (!isreduce && enemy->islife && isCollion(hpos, epos, 21, 22.5, 21, 28)){
// 敌人和主角碰撞检测
enemy->setdie();
setherohurt();
}
}
//主角和敌人子弹碰撞
if (!isreduce){
for (int i = 0; i < enemybullets->capacity(); i++){
if (isCollion(hpos, ((GameEnemyBullet*)enemybullets->objectAtIndex(i))->getPosition(), 21, 22.5, 5, 13)){
setherohurt();
}
}
}
}
3// 游戏结束时,回掉“back to menu",操作方法
bool GameMain::init(){
//初始化游戏结束弹板及按钮
gameover = CCSprite::create("gameover.png");
gameover->setAnchorPoint(ccp(0.5, 0.5));
gameover->setPosition(ccp(0, 0));
gameover->setPosition(ccp(size.width / 2, size.height / 2 + 70));
gameover->setVisible(false);
gameover->setScale(0.5);
addChild(gameover, 5);
CCMenuItemImage *pCloseItem = CCMenuItemImage::create("back.png", "back.png", 
this, menu_selector(GameMain::menuBackCallback));
//正常状态的图片  //按下去时的图片  
pCloseItem->setPosition(ccp(size.width / 2, size.height / 2 - 50));
pCloseItem->setScale(0.5);
CCMenu *pMenu = CCMenu::create(pCloseItem, NULL);
this->addChild(pMenu, 5, 25); // void addChild(CCNode * child, int zOrder, int tag)
pMenu->setVisible(true); 
pMenu->setEnabled(false);
}
void GameMain::setover(){
//设置游戏结束
CCMenu *pMenu = (CCMenu*)this->getChildByTag(25);
pMenu->setVisible(true);
pMenu->setEnabled(true);
gameover->setVisible(true);
gameover->setScale(0);
pMenu->setScale(0);
pMenu->runAction(CCScaleTo::create(0.5, 1));
gameover->runAction(CCScaleTo::create(0.5, 0.5));
}
4//

CCScaleTo与CCScaleBy比较

CCScaleTocreate函数:

?
1
2
3
4
5
6
7
8
9
static CCScaleTo* CCScaleTo::create( float duration , float sx , float sy);
 
     /*
      * duration是动作执行持续时间,单位为秒;
       
      * sx是X方向的拉伸值(注意,是拉伸值!);
 
      * sy是Y方向的拉伸值;
      */

CCScaleBycreate函数:

?
1
2
3
4
5
6
7
8
9
<span></span> Static CCScaleBy* CCScaleBy::create( float duration , float sx , float sy);
 
     /*
      * duration是动作执行持续时间
 
      * sx是X方向的拉伸倍数(注意,现在是倍数!);
 
      * sy是Y方向的拉伸倍数;
      */

5//

error LNK2001: 无法解析的外部符号 "class cocos2d::Vec2 const cocos2d::CCPointZero" (?CCPointZero@cocos2d@@3VV

//pMenu->setPosition(CCPointZero); //sjt
pMenu->setPosition(ccp(0, 0));
6//
CCPointZero = CCPointMake(0,0);
7//
  1.  CCBlink  
  2. //    作用 :创建一额闪烁的动作  
  3. //    参数1:闪烁完成的时间  
  4. //    参数2:闪烁的次数  
  5. //    CCActionInterval * blink = CCBlink ::create(3, 10);  
  6. //    sp->runAction(blink);  

7// AppDelegate::applicationDidFinishLaunching()
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
   
if(!glview) {
       // glview = GLViewImpl::create("My Game");
glview = GLViewImpl::createWithRect("MyMiaoxinWar", Rect(0, 0, 320, 480));// 初始化界面
        director->setOpenGLView(glview);
    }


    // turn on display FPS
   // director->setDisplayStats(true);


    // set FPS. the default value is 1.0/60 if you don't call this
   // director->setAnimationInterval(1.0 / 60);


    // create a scene. it's an autorelease object
   // auto scene = HelloWorld::createScene();
auto scene = GameMenu::scene();// GameMenuScene Classs



    // run
    director->runWithScene(scene);


    return true;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值