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

📄 slug.cpp

📁 c++游戏源码 素材文件 需要openAl32.dll可以在网上下载
💻 CPP
字号:
#include "LlamaWorks2D.h"

using namespace llamaworks2d;

#include "Invasion.h"
#include "Slug.h"

// How fast does this slug move?
// Must be a positive number.
const float SPEED = 10.0;

const int ANIM_WALK_LEFT = 0;
const int ANIM_WALK_RIGHT = 1;

slug::slug() :
    currState(STATE_ASLEEP)
{
}

bool slug::Update(invasion *theGame)
{
    switch(currState)
    {
    case STATE_ASLEEP:
        // Slugwroths are strange creatures and prefer to
        // sleep facing to the right!
        myAnims.CurrentAnimation(ANIM_WALK_RIGHT);
        break;

    case STATE_CHASING:
        myAnims.CurrentAnimation(ANIM_WALK_LEFT);
        worldPos += velocity;
        theGame->CollisionCheck(*this);
        break;

    default:
        ASSERT(0); //Unhandled state!
        break;
    }

    return (true);
}

bool slug::Render(invasion *theGame)
{
    bool renderOK = true;

    vector screenPos;
    theGame->WorldToScreen(worldPos,screenPos);
    myAnims.X(screenPos.X());
    myAnims.Y(screenPos.Y());
    renderOK = myAnims.Render();
    
    return (renderOK);
}

void slug::WakeUp( world_object *waker)
{
    // We wake up and follow whatever hit us.
    currState = STATE_CHASING;
    if (waker->WorldX() < WorldX())
    {
        // Run to the left.
        velocity.X(-SPEED);
    }
    else
    {
        // Run to the right.
        velocity.X(SPEED);
    }
}

void slug::Kill()
{
    Collidable(false);
    Visible(false);
}

void slug::Hit( world_object &stationary)
{
    // We hit something. Go back to previous position.
    worldPos -= velocity;
}

⌨️ 快捷键说明

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