⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staticmapobj.cpp.svn-base

📁 坦克大战游戏完整全套源代码
💻 SVN-BASE
字号:
#include <hge.h>
#include "staticMapObj.h"
#include "game/mainGameState.h"

Entity::iEntity *StaticMapObj::getEntityInterface(EntityInterfaceId id)
{
    switch(id)
    {
    case EII_CollisionEntity:
        return &collisionEntity;
    case EII_GraphicEntity:
        return &graphicEntity;
    }

    return Entity::getEntityInterface(id);
}

void StaticMapObj::CollisionEntity::onCollision(iCollisionEntity &o, const iContactInfo &ci)
{
    HGE *hge = hgeCreate(HGE_VERSION);
    float deltaTime = hge->Timer_GetDelta();
    hge->Release();
    
    TankContactInfo &tci = (TankContactInfo &)ci;
    Point2f contactPos = tci.getData()->GetContact(0);
    Point2f dir = o.getBody().GetPointVelocity(contactPos, deltaTime);
    Point2f impulse = dir * 0.001f;// * o.getBody().getMass();
    Point2f force = impulse / deltaTime;
    getBody().AddForce(force, contactPos);
}

void StaticMapObj::GraphicEntity::render(float gameTime, float deltaTime)
{
    deltaTime;
    int frameTime = int(gameTime * 60);
    assert(animShape);
    RenderQueue::getSingleton().render(getEntity().pos, -getEntity().orientation, frameTime, animShape, getEntity().getRenderLayerId());

#ifdef _DEBUG
#if 0
    const Rectf &r = getEntity().collisionEntity.getBoundingBox();
    RenderQueue::getSingleton().render(Point2f(r.left, r.top), Point2f(r.right, r.top), ARGB(128, 255, 255, 255));
    RenderQueue::getSingleton().render(Point2f(r.right, r.top), Point2f(r.right, r.bottom), ARGB(128, 0, 0, 255));
    RenderQueue::getSingleton().render(Point2f(r.right, r.bottom), Point2f(r.left, r.bottom), ARGB(128, 0, 0, 255));
    RenderQueue::getSingleton().render(Point2f(r.left, r.bottom), Point2f(r.left, r.top), ARGB(128, 0, 0, 255));
#endif
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -