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

📄 chloridelevel.cpp

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

using namespace llamaworks2d;

#include "Invasion.h"
#include "Door.h"
#include "Key.h"
#include "Slug.h"
#include "SceneSprite.h"

const int BACKGROUND = 0;
const int DOOR = 1;
const int KEY = 2;
const int WALLFRONT = 3;
const int SLUG = 4;
const int SLUG2 = 5;

chloride_level::chloride_level() :
    chlorideStartX(0),
    chlorideStartY(0),
    maxWorldX(0),
    maxWorldY(0)
{
}


bool chloride_level::Update( 
    invasion *theGame)
{
    bool updateOK = true;
    return (updateOK);
}


bool chloride_level::RenderBackground(
    invasion *theGame)
{
    bool renderOK = true;

    scene_sprite *theBackground =
        (scene_sprite*)allObjects[BACKGROUND];
    renderOK = theBackground->Render( theGame);

    return (renderOK);
}


bool chloride_level::RenderForeground(
    invasion *theGame)
{
    bool renderOK = true;

    scene_sprite *theWallFront =
        (scene_sprite*)allObjects[WALLFRONT];
    renderOK = theWallFront->Render( theGame);

    return (renderOK);
}


bool chloride_level::ObjectFactory(
    FILE *levelFile,
    std::string tagToParse)
{
    bool parseOK = true;
    std::string temp;
    invasion *theGame = (invasion*)theApp.Game();
    chloride *theCaptain = theGame->TheCaptain();
    
    if (IsTag(tagToParse,"CaptainChloride"))
    {
        EliminateWhiteSpace(levelFile);
        temp = ReadTagOrValue(levelFile);
        int startX, startY;
        parseOK = ParseXY(levelFile,
            startX, startY);
        if (parseOK)
        {
            // store these in case Chloride dies.
            chlorideStartX = (float)startX;
            chlorideStartY = (float)startY;

            // initialize Chloride directly.
            theCaptain->WorldX( chlorideStartX);
            theCaptain->WorldY( chlorideStartY);
            theGame->AddWorldObject(theCaptain);

            EliminateWhiteSpace(levelFile);
            temp = ReadTagOrValue(levelFile);

            if (!IsTag(temp,"/CaptainChloride"))
            {
                parseOK = false;
            }
        }
    }
    else if (IsTag(tagToParse,"Background"))
    {
        scene_sprite *theBackground = new scene_sprite;
        if (theBackground != NULL)
        {
            EliminateWhiteSpace(levelFile);
            temp = ReadTagOrValue(levelFile);
            if (IsTag(temp,"Sprite"))
            {
                parseOK = ParseSprite(levelFile,theBackground);
                if (parseOK)
                {
                    allObjects.push_back(theBackground);
                    // the upper left corner, in world coordinates
                    theBackground->WorldX(
                        (float)theBackground->X());
                    theBackground->WorldY(
                        (float)theBackground->Y());
                }
            }

            EliminateWhiteSpace(levelFile);
            temp = ReadTagOrValue(levelFile);

            if (!IsTag(temp,"/Background"))
            {
                parseOK = false;
            }
            if (parseOK)
            {
                maxWorldX = (float)theBackground->BitmapWidth();
                maxWorldY = (float)theBackground->BitmapHeight();
            }
        }
        else
        {
            parseOK = false;
            theApp.AppError(LWES_OUT_OF_MEMORY);
        }
    }
    else if (IsTag(tagToParse,"WallFront"))
    {
        scene_sprite *theWallFront = new scene_sprite;
        if (theWallFront != NULL)
        {
            EliminateWhiteSpace(levelFile);
            temp = ReadTagOrValue(levelFile);
            if (IsTag(temp,"Sprite"))
            {
                parseOK = ParseSprite(levelFile,theWallFront);
                if (parseOK)
                {
                    allObjects.push_back(theWallFront);
                    // the upper left corner, in world coordinates
                    theWallFront->WorldX(
                        (float)theWallFront->X());
                    theWallFront->WorldY(
                        (float)theWallFront->Y());
                }
            }

            EliminateWhiteSpace(levelFile);
            temp = ReadTagOrValue(levelFile);

            if (!IsTag(temp,"/WallFront"))
            {
                parseOK = false;
            }
        }
        else
        {
            parseOK = false;
            theApp.AppError(LWES_OUT_OF_MEMORY);
        }
    }
    else if (IsTag(tagToParse,"Door"))
    {
        door *theDoor = new door;
        if (theDoor != NULL)
        {
            EliminateWhiteSpace(levelFile);
            temp = ReadTagOrValue(levelFile);
            if (IsTag(temp,"Sprite"))
            {
                parseOK = ParseSprite(
                    levelFile,&theDoor->mySprite);

                if (parseOK)
                {
                    allObjects.push_back(theDoor);
        
                    // the upper left corner, in world coordinates
                    theDoor->WorldX(
                        (float)theDoor->mySprite.X());
                    theDoor->WorldY(
                        (float)theDoor->mySprite.Y());
                }
            }

            // the width and height, in world coordinates
            if (parseOK)
            {
                EliminateWhiteSpace(levelFile);
                temp = ReadTagOrValue(levelFile);
                if (IsTag(temp,"XY"))
                {
                    int collisionWidth, collisionHeight;
                    parseOK = ParseXY(levelFile,
                        collisionWidth, collisionHeight);
                    if (parseOK)
                    {
                        theDoor->CollisionWidth(
                            (float)collisionWidth);
                        theDoor->CollisionHeight(
                            (float)collisionHeight);
                    }
                }
            }

            // end tag
            if (parseOK)
            {
                EliminateWhiteSpace(levelFile);
                temp = ReadTagOrValue(levelFile);

                if (!IsTag(temp,"/Door"))
                {
                    parseOK = false;
                }
            }

            if (parseOK)
            {
                theGame->AddWorldObject(theDoor);
                parseOK = theDoor->LoadResources();
            }
        }
        else
        {
            parseOK = false;
            theApp.AppError(LWES_OUT_OF_MEMORY);
        }
    }
    else if (IsTag(tagToParse,"Key"))
    {
        key *theKey = new key;
        if (theKey != NULL)
        {
            EliminateWhiteSpace(levelFile);
            temp = ReadTagOrValue(levelFile);
            if (IsTag(temp,"Sprite"))
            {
                parseOK = ParseSprite(
                    levelFile,&theKey->mySprite);

                if (parseOK)
                {
                    allObjects.push_back(theKey);
        
                    // the upper left corner, in world coordinates
                    theKey->WorldX(
                        (float)theKey->mySprite.X());
                    theKey->WorldY(
                        (float)theKey->mySprite.Y());
                }
            }

            // the width and height, in world coordinates
            int collisionWidth, collisionHeight;
            if (parseOK)
            {
                parseOK = ParseXY(levelFile,
                    collisionWidth, collisionHeight);
            }
            if (parseOK)
            {
                theKey->CollisionWidth(
                    (float)collisionWidth);
                theKey->CollisionHeight(
                    (float)collisionHeight);
            }

            // end tag
            if (parseOK)
            {
                EliminateWhiteSpace(levelFile);
                temp = ReadTagOrValue(levelFile);

                if (!IsTag(temp,"/Key"))
                {
                    parseOK = false;
                }
            }

            if (parseOK)
            {
                theGame->AddWorldObject(theKey);
            }
        }
        else
        {
            parseOK = false;
            theApp.AppError(LWES_OUT_OF_MEMORY);
        }
    }
    else if (IsTag(tagToParse,"Slug"))
    {
        slug *theSlug = new slug;
        if (theSlug != NULL)
        {
            EliminateWhiteSpace(levelFile);
            temp = ReadTagOrValue(levelFile);
            if (IsTag(temp,"AnimatedSprite"))
            {
                parseOK = ParseAnimatedSprite(
                    levelFile, &theSlug->myAnims);

                if (parseOK)
                {
                    allObjects.push_back(theSlug);

                    // the upper left corner, in world coordinates
                    theSlug->WorldX(
                        (float)theSlug->myAnims.X());
                    theSlug->WorldY(
                        (float)theSlug->myAnims.Y());
                }
            }

            // the width and height, in world coordinates
            if (parseOK)
            {
                EliminateWhiteSpace(levelFile);
                temp = ReadTagOrValue(levelFile);
                if (IsTag(temp,"XY"))
                {
                    int collisionWidth, collisionHeight;
                    parseOK = ParseXY(levelFile,
                        collisionWidth, collisionHeight);
                    if (parseOK)
                    {
                        theSlug->CollisionWidth(
                            (float)collisionWidth);
                        theSlug->CollisionHeight(
                            (float)collisionHeight);
                    }
                }
            }

            // end tag
            if (parseOK)
            {
                EliminateWhiteSpace(levelFile);
                temp = ReadTagOrValue(levelFile);

                if (!IsTag(temp,"/Slug"))
                {
                    parseOK = false;
                }
            }

            if (parseOK)
            {
                theGame->AddWorldObject(theSlug);
            }
        }
        else
        {
            parseOK = false;
            theApp.AppError(LWES_OUT_OF_MEMORY);
        }
    }

    return (parseOK);
}

⌨️ 快捷键说明

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