Claypool

Courses

Publications

Students

Projects

Service

Downloads

Misc


Dragonfly: ViewObject.h Source File
Dragonfly 2.2
A text-based game engine

ViewObject.h

00001 ///
00002 /// The view object.
00003 ///
00004 
00005 #ifndef __VIEW_OBJECT_H__
00006 #define __VIEW_OBJECT_H__
00007 
00008 #include <string>
00009 
00010 using namespace std;
00011 
00012 #include "GameObject.h"
00013 #include "Event.h"              
00014 
00015 /// General location of ViewObject on screen.
00016 enum ViewObjectLocation {
00017   TOP_LEFT,
00018   TOP_CENTER,
00019   TOP_RIGHT,
00020   BOTTOM_LEFT,
00021   BOTTOM_CENTER,
00022   BOTTOM_RIGHT,
00023 };
00024 
00025 class ViewObject : public Object {
00026 
00027  protected:
00028   string view_string;           ///< Label for value (e.g. "Points")
00029   int value;                    ///< Value displayed (e.g. points)
00030   bool border;                  ///< True if border around display
00031   int color;                    ///< Color for text
00032 
00033  public:
00034   /// Construct ViewObject. 
00035   /// Defaults: border, top_center, default color, current level.
00036   ViewObject(int on_level = -1);
00037   virtual ~ViewObject();
00038 
00039   /// Draw view string and value.
00040   virtual void draw();
00041 
00042   /// Handle "view" event if tag matches view_string (others ignored).
00043   /// Return 0 if ignored, else 1
00044   virtual int eventHandler(Event *p_event);
00045 
00046   /// General location of the ViewObject on the screen.
00047   void setLocation(ViewObjectLocation new_location);
00048 
00049   // Set persistence of object. Persistent objects are active across all
00050   // levels.  Return 0 if ok, else -1.
00051   int setPersistence(bool persistent);
00052 
00053   // Set visibility of object.  Objects not visible are not drawn.
00054   // Return 0 if ok, else -1.
00055   int setVisibility(bool visible);
00056 
00057   void setValue(int new_value);
00058   int getValue();
00059   void setBorder(bool new_border);
00060   bool getBorder();
00061   void setColor(int new_color);
00062   int getColor();
00063   void setViewString(string new_view_string);
00064   string getViewString();
00065 };
00066 #endif // __VIEW_OBJECT_H__
00067 
 All Classes Functions Variables Friends