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

📄 item.h

📁 游戏开发数据结构Data Structures for Game Programmers
💻 H
字号:
// ============================================================================
// Item.h
// Contains the item class
// ============================================================================
#ifndef ITEM_H
#define ITEM_H

#include "Object.h"


// ============================================================================
//  Item Class
// ============================================================================
class Item : public Object
{
protected:
// =======================================================
//  Data
// =======================================================

// -------------------------------------------------------
// Name:        m_type
// Description: The type of the item.
// -------------------------------------------------------
    int m_type;

// -------------------------------------------------------
// Name:        m_graphic
// Description: The graphic of the item
// -------------------------------------------------------
    SDL_Surface* m_graphic;

// -------------------------------------------------------
// Name:        m_speed
// Description: The number of milliseconds between
//              attacks that this item has.
// -------------------------------------------------------
    int m_speed;

// -------------------------------------------------------
// Name:        m_strength
// Description: The strength of the item.
// -------------------------------------------------------
    int m_strength;

// -------------------------------------------------------
// Name:        m_canBlock
// Description: determines if an item can block the path
// -------------------------------------------------------
    bool m_canBlock;

// -------------------------------------------------------
// Name:        m_isArmor
// Description: determines if an item is armor
// -------------------------------------------------------
    bool m_isArmor;

// -------------------------------------------------------
// Name:        m_canGet
// Description: determines if a person can get this item
// -------------------------------------------------------
    bool m_canGet;

// -------------------------------------------------------
// Name:        m_isExit
// Description: determines if this item is an exit
// -------------------------------------------------------
    bool m_isExit;

// -------------------------------------------------------
// Name:        m_whichExit
// Description: which exit number is valid for this item
//              if it is an exit
// -------------------------------------------------------
    int m_whichExit;

public:
// =======================================================
//  Functions
// =======================================================

// -------------------------------------------------------
// Name:        Item
// Description: constructs an empty item
// -------------------------------------------------------
    Item()
    {
        m_type = -1;
        m_graphic = 0;
        m_canBlock = false;
        m_isArmor = false;
        m_canGet = true;
        m_isExit = false;
        m_whichExit = -1;
    }

    
    int  GetType()              { return m_type;   }
    void SetType( int p_type )  { m_type = p_type; }

    int  GetSpeed()              { return m_speed; }
    void SetSpeed( int p_speed ) { m_speed = p_speed; }

    int  GetStrength()                 { return m_strength; }
    void SetStrength( int p_strength ) { m_strength = p_strength; }

    void SetGraphic( SDL_Surface* p_graphic )
    {
        m_graphic = p_graphic;
    }

    SDL_Surface* GetGraphic()
    {
        return m_graphic;
    }

    void SetBlock( bool p_block )   { m_canBlock = p_block; }
    bool CanBlock()
    {
        return m_canBlock;
    }

    void SetArmor( bool p_armor )   { m_isArmor = p_armor; }
    bool IsArmor()
    {
        return m_isArmor;
    }

    void SetGet( bool p_get )   { m_canGet = p_get; }
    bool CanGet()
    {
        return m_canGet;
    }

    void SetExit( bool p_exit )   { m_isExit = p_exit; }
    bool IsExit()
    {
        return m_isExit;
    }

    void SetExitNumber( int p_exit )   { m_whichExit = p_exit; }
    int GetExitNumber()
    {
        return m_whichExit;
    }

};

Item g_itemtemplates[32];

Item* MakeItem( int p_type, int p_x, int p_y, int p_cell  )
{
    Item* i = new Item;

    *i = g_itemtemplates[p_type];
    i->SetX( p_x );
    i->SetY( p_y );
    i->SetCell( p_cell );
    return i;
}


#endif

⌨️ 快捷键说明

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