zoukankan      html  css  js  c++  java
  • 超级马丽与怪物水平碰撞和跳起上下碰撞检测

    超级马丽与怪物的碰撞检测,利用intersectsRect函数检测碰撞。水平碰撞时,怪物杀了超级马丽;跳起来踩怪物时,怪物被杀死。

    EnemyVSHero CCEnemy::checkCollisionWithHero()
    {
        EnemyVSHero ret = eVS_nonKilled;
    
        CCPoint heroPos = CCHero::getHeroInstance()->getPosition();
        CCSize heroSize = CCHero::getHeroInstance()->getContentSize();
        CCRect heroRect = CCRectMake(heroPos.x - heroSize.width/2 + 2, heroPos.y + 3, 
            heroSize.width - 4, heroSize.height - 4);
    
        CCRect heroRectVS = CCRectMake(heroPos.x - heroSize.width/2 - 3, heroPos.y, 
            heroSize.width - 6, 2);
    
        CCPoint enemyPos = this->getPosition();
        CCRect enemyRect = CCRectMake(enemyPos.x - bodySize.width/2 + 1, enemyPos.y, 
            bodySize.width - 2, bodySize.height - 4);
    
        CCRect enemyRectVS = CCRectMake(enemyPos.x - bodySize.width/2 - 2, enemyPos.y + bodySize.height - 4, 
            bodySize.width - 4, 4);
    
        if (heroRectVS.intersectsRect(enemyRectVS))
        {
            ret = eVS_enemyKilled;
            return ret;
        }
    
        if (heroRect.intersectsRect(enemyRect))
        {
            ret = eVS_heroKilled;
            return ret;
        }
    
        return ret;
    }

    画一张图,看起来容易理解。

  • 相关阅读:
    Python logging根据时间创建日志文件
    ORACLE Merge into 使用
    go安装goctl
    Oracle 行转列
    ORACLE with as查询优化
    Linux环境使用Docker安装MongoDb
    Linux环境使用Docker安装MySql
    Docker基础操作
    Linux基础命令
    Ansible自动化运维介绍
  • 原文地址:https://www.cnblogs.com/ycclmy/p/4172626.html
Copyright © 2011-2022 走看看