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

📄 worldobject.h

📁 c++游戏源码 素材文件 需要openAl32.dll可以在网上下载
💻 H
字号:
#ifndef WORLDOBJECT_H
#define WORLDOBJECT_H

class invasion;

// The purpose of this class is to store an object's
// position in world coordinates and its collision
// box dimensions. The object's position is the
// upper left corner, in world coordinates, and the
// width and height are the dimensions of the box.
class world_object : public screen_object
{
public:
    world_object();

    // Transform to world coordinates and render.
    virtual bool Render( invasion *theGame);

    // Get a chance to update internal state every
    //  frame.
    virtual bool Update( invasion *theGame);

    // Does this object intersect or collide with
    //  another object?
    virtual bool Intersects( world_object &other);

    // When this object is moving and we hit
    //  a stationary object, what do we do?
    virtual void Hit( world_object &stationary);

    void Collidable(bool new_visible);
    bool Collidable();

    void Visible(bool new_visible);
    bool Visible();

    void WorldX( float x);
    float WorldX();

    void WorldY( float y);
    float WorldY();

    void CollisionWidth( float w);
    float CollisionWidth();

    void CollisionHeight( float h);
    float CollisionHeight();

    // Derived classes must supply this function in
    //  order to be able to downcast. A safer and
    //  more automatic approach is to use the C++
    //  dynamic_cast operator. Then Type() would not
    //  be necessary.
    virtual std::string Type() = 0;

    // We need to implement Render() because it's
    //  required by screen_object. But we have our
    //  own Render up above. So this one does nothing.
    bool Render();

protected:
    // Let derived classes use this directly.
    // This is the upper left corner, in world
    //  coordinates.
    vectorf worldPos;

private:
    float collisionWidth;
    float collisionHeight;
    bool collidable;
    bool visible;

public:
    // Forms a singly linked list. Advanced readers
    //  should consider the Standard Template Library.
    world_object *next;
};


inline void
world_object::Collidable(bool new_collidable)
{
    collidable = new_collidable;
}


inline bool
world_object::Collidable()
{
    return (collidable);
}


inline void
world_object::Visible(bool new_visible)
{
    visible = new_visible;
}


inline bool
world_object::Visible()
{
    return (visible);
}


inline void
world_object::WorldX( float x)
{
    worldPos.X( x);
}


inline float
world_object::WorldX()
{
    return (worldPos.X());
}


inline void
world_object::WorldY( float y)
{
    worldPos.Y( y);
}


inline float
world_object::WorldY()
{
    return (worldPos.Y());
}


inline void
world_object::CollisionWidth( float w)
{
    collisionWidth = w;
}


inline float
world_object::CollisionWidth()
{
    return (collisionWidth);
}


inline void
world_object::CollisionHeight( float h)
{
    collisionHeight = h;
}


inline float
world_object::CollisionHeight()
{
    return (collisionHeight);
}


inline bool
world_object::Render()
{
    return (true);
}

#endif

⌨️ 快捷键说明

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