Page 1 of 1

Pickup class

Posted: Mon Mar 02, 2009 9:27 pm
by Sundar
Hi i was looking for a pickup class & couldn't find one. so i thought i will post one when i am done. Hope somebody finds it useful. Note : uses stl list for pickupmanager

FYI : I realized that this might be get confused 3d pickup. i apologies for any confusion this is rather pickup overlay class with pickup overlay manager rather than actual 3d pickup class

Code: Select all

#define PICKUP_SIZE 64
#define PICKUP_EVENT_ID_START 1000
enum pickupStyle
{
	PICKUP_HORIZONTAL,
	PICKUP_VERTICLE,
};
class pickup
{
	video::IVideoDriver* driver;
	irr::video::ITexture* image;
	irr::video::ITexture* pimage;
	irr::gui::IGUIButton* button;
	irr::core::rect<s32> position;
	int pickupType;
	
public:
	pickup(IrrlichtDevice * device,std::string imgfilename,irr::core::rect<s32> pos)
	{
		std::string imgPressedfilename("test1.bmp");
		driver = device->getVideoDriver();
		position = pos;
		pimage = driver->getTexture(imgPressedfilename.c_str());
		driver->makeColorKeyTexture(pimage,irr::core::position2di(0,0));				
		image = driver->getTexture(imgfilename.c_str());
		driver->makeColorKeyTexture(image,irr::core::position2di(0,0));		
		button = device->getGUIEnvironment()->addButton(irr::core::rect<s32>(0,0,PICKUP_SIZE,PICKUP_SIZE));//position, 0, 0);
		button->setIsPushButton(true);
		button->setPressedImage(pimage);
		button->setUseAlphaChannel(true); 
		button->setImage(image);
		button->setDrawBorder(false);

	}
	void setPosition(int x,int y){button->setRelativePosition(irr::core::rect<s32>(x,y,x+PICKUP_SIZE,y+PICKUP_SIZE));}
	void setEnabled(bool bFlag){button->setEnabled(bFlag);}
	void setPickupId(irr::s32 id){button->setID(id);}
	void setPickupType(int type){pickupType = type;}
	void setToolTipText(std::wstring toolTip){button->setToolTipText(toolTip.c_str());}
	int getPickupType(){return pickupType;}	
	irr::core::stringw getToolTipText(void) {return(button->getToolTipText());}

};
class pickupManager
{
	std::list<pickup *> pickups;
	std::list<pickup *>::iterator pi;
	int size;
	int xStartPos;
	int yStartPos;
	pickupStyle style;
public:
	pickupManager(){size = 0;	style = PICKUP_HORIZONTAL;}
	void insterPickup(pickup *p){
		++size;
		p->setPosition(xStartPos,yStartPos + (size * PICKUP_SIZE));
		p->setPickupId(PICKUP_EVENT_ID_START + size);		
		pickups.push_front(p);
	}
	void setxyStartPos(int xpos,int ypos){xStartPos = xpos;yStartPos = ypos;}
	void setStyle(pickupStyle st){
		int xinc = 0,yinc = 0,i = 0;
		style = st;
		if(style == PICKUP_HORIZONTAL) xinc = PICKUP_SIZE;
		if(style == PICKUP_VERTICLE) yinc = PICKUP_SIZE;
		for(pi = pickups.begin(), i = 0; pi != pickups.end(); pi++,++i)
		{ 
			(*pi)->setPosition(xStartPos + (xinc * i) ,yStartPos + (yinc * i));
		}
	}
	~pickupManager()
	{
	//	for(pi = pickups.begin(); pi != pickups.end(); pi++){ delete *pi;}
	}
};
usage

Code: Select all

pickupManager pm;

pm.setxyStartPos(300,100);
pm.insterPickup(&p);
pm.insterPickup(&p1);
pm.insterPickup(&p2);


Posted: Tue Mar 03, 2009 8:06 am
by FuzzYspo0N
This is cool, thanks for the resource to the community

Posted: Tue Mar 03, 2009 8:13 pm
by Sundar
you are welcome :)