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

📄 bb_l.cpp

📁 BugBots是一个游戏
💻 CPP
字号:
#include <ClanLib/core.h>#include <ClanLib/display.h>#include <ClanLib/application.h>#include "clump.h"#include "food.h"#include "BugBot.h"#include "mainbrain.h"#include "utility.h"#include <list>#include <vector>#include <algorithm>//#include <fstream>#include <time.h>//#include <conio.h>#include <iostream>#include "sutil.h"#include "MapHandler.h"using namespace std;bool double_pixel_mode = true;//ofstream errorlog;const extern int SCREENWIDTH ;const extern int SCREENHEIGHT;MapHandler MH;const int size=2;extern std::vector<std::list<BugBot>::iterator> BotIts;//according to Dan Smith, this was the offending line//Spot GlobalMap[320][200];struct color{    float r;    float g;    float b;};color color_map[15] = {    {0.0,0.0,0.0}, //0 Black    {0.5,0.0,0.0}, //1 Red    {0.0,0.5,0.0}, //2 Green    {0.5,0.5,0.0}, //3 Yellow    {0.0,0.0,0.5}, //4 Blue    {0.5,0.0,0.5}, //5 Magenta    {0.0,0.5,0.5}, //6 Cyan    {0.5,0.5,0.5}, //7 White (Gray)    {1.0,0.0,0.0}, //8 Bright Red    {0.0,1.0,0.0}, //9 Bright Green    {1.0,1.0,0.0}, //10 Bright Yellow    {0.0,0.0,1.0}, //11 Bright Blue    {1.0,0.0,1.0}, //12 Bright Magenta    {0.0,1.0,1.0}, //13 Bright Cyan    {1.0,1.0,1.0}};//14 Bright Whitebool CheckPosition(const Position &pos){    if(pos.x <0 || pos.x >= SCREENWIDTH)	std::cout << "Bad x " << pos.x << endl;    if(pos.y <0 || pos.y >= SCREENHEIGHT)	std::cout << "Bad y " << pos.y << endl;											      return true;}class BBApp: CL_ClanApplication{public:	char *get_title(){ return "BugBots";}		void lock()	{		m_target->lock();	}	void unlock()	{		m_target->unlock();	}	void draw_pixel(int x, int y, float r, float g, float b)	{		unsigned  char *data = (unsigned char *)m_target->get_data();		static const int bpp = m_target->get_bytes_per_pixel();		static const int pitch = m_target->get_pitch();		//static const int r_mask = m_target->get_red_mask();		//static const int g_mask = m_target->get_green_mask();		//static const int b_mask = m_target->get_blue_mask();		int color = CL_Color::get_color(m_target,r,g,b);		int trans_x = m_target->get_translate_offset_x();		int trans_y = m_target->get_translate_offset_y();		x += trans_x;		y += trans_y;		CL_ClipRect clip = m_target->get_clip_rect();		if ((x < clip.m_x1) ||		    (x >= clip.m_x2) ||		    (y < clip.m_y1) ||		    (y >= clip.m_y2)) return;										switch (bpp)		{		case	1 :			{			 unsigned char *d = data + y * pitch + x;			*d = (unsigned char) color;			break;		}		case	2 :		{			 unsigned short *d = (unsigned short*) (data + y * pitch + x*2);			*d = (unsigned short) color;			break;		}		case	3 :		{			// that should do the trick - untested !!!			unsigned char *d = data + y *pitch + x*3;			*(d++) = (unsigned char) color;			color >>= 8;			*(d++) = (unsigned char) color;			color >>= 8;			*d = (unsigned char) color;			break;		}		case	4 :		{				unsigned int *d = (unsigned int*) (data + y * pitch + x*4);			*d = (unsigned int) color;			break;		}		default:		{			cl_assert(false);			break;		}		}			}		int main(int argc, char **argv)	{	    CL_SetupCore::init();	    CL_SetupDisplay::init();				    if(argc > 1 )	    {		if(!strcmp(argv[1],"--fullscreen"))		{			    double_pixel_mode = false;		}	    }					     #ifdef _DEBUG	    CL_ConsoleWindow console("Console",80,1000);	    console.redirect_stdio();#endif							     	    if( double_pixel_mode )		CL_Display::set_videomode(SCREENWIDTH * size,SCREENHEIGHT *size,32,false);	    else		CL_Display::set_videomode(SCREENWIDTH,SCREENHEIGHT,32,true);  	    m_target = CL_Display::get_target();	    srand(time(NULL)); 	    Position pmb1;	    pmb1.Random();    	    MH.NewMainBrain(pmb1,1,8,8,8,3);   	    Position pmb2;	    pmb2.Random();	    MH.NewMainBrain(pmb2,4,11,11,11,10);	    Position pc1;	    pc1.Random();	    MH.NewClump(pc1,10);	    Position c2pos;	    c2pos.Random();	    MH.NewClump(c2pos,20);    	    Position c3pos;	    c3pos.Random();	    MH.NewClump(c3pos,30);    	    bool done = false;	    while(!CL_Keyboard::get_keycode(CL_KEY_ESCAPE) && !done)	    {		std::vector<Position> corpse_pos;		m_target = CL_Display::get_target();		lock();		for(std::list<MainBrain>::iterator i=MH.GetMainBrainBegin();		    i!=MH.GetMainBrainEnd();i++)		{		    (*i).Update();/*  m_target->draw_pixel((*i).GetPos().x,(*i).GetPos().y,  color_map[14].r, color_map[14].g,  color_map[14].b); */		    if(double_pixel_mode)		    {			if(!MH.WithinSpace(Position(i->GetPos())))			{			    std::cout << "MB found outside space" << endl;			}						for(int r=0; r < size; r++)			    for(int c=0; c < size; c++)			    {				draw_pixel((*i).GetPos().x*size + r,						     (*i).GetPos().y*size +c,						     color_map[14].r, color_map[14].g,						     color_map[14].b);			       			    }					    }else{						CheckPosition(i->GetPos());		        draw_pixel((*i).GetPos().x,(*i).GetPos().y,					     color_map[14].r, color_map[14].g,						   color_map[14].b);					    }		}		for(std::list<BugBot>::iterator b=MH.GetBugBotBegin();		    b!=MH.GetBugBotEnd();b++)		{				    (*b).Update();		    Position pos= (*b).GetPos();											     		    if(!MH.WithinSpace(pos))		    {			std::cout << "BB found outside space" << endl;		    }		    if(!(*b).IsCorpse())		    {			int team = (*b).GetTeam();			int color = (*MH.GetMainBrainIter(team)).			    GetColor((*b).GetFlags());	      							     			//      m_target->			//	draw_pixel(pos.x,pos.y,color_map[color].r, color_map[color].g,			//		   color_map[color].b);			if (double_pixel_mode)			{						    for(int r=0; r < size; r++)				for(int c=0; c < size; c++)				{				    draw_pixel((pos.x *size) + r,							 (pos.y *size) +c,							 color_map[color].r, color_map[color].g,							 color_map[color].b);				}						}else			{ 			    CheckPosition(pos);						    draw_pixel(pos.x,pos.y,color_map[color].r, color_map[color].g,						 color_map[color].b);						}		    }		    else		    {			corpse_pos.push_back(pos);		    }		}		for(std::vector<Position>::iterator pp=corpse_pos.begin();		    pp!=corpse_pos.end();pp++)		{		    // m_target->draw_pixel((*pp).x,(*pp).y,color_map[7].r,		    //		 color_map[7].g,		    //		 color_map[7].b);		    if( double_pixel_mode)		    {						for(int r=0; r < size; r++)			    for(int c=0; c < size; c++)			    {				draw_pixel((*pp).x *size + r,						     (*pp).y *size +c,						     color_map[7].r, color_map[7].g,						     color_map[7].b);			    }					    }		    else{			CheckPosition(*pp);						draw_pixel((*pp).x,(*pp).y,color_map[7].r,					     color_map[7].g,				   color_map[7].b);					    }		} 		for(std::list<Clump>::iterator c=MH.GetClumpBegin();		    c!=MH.GetClumpEnd();c++)		{			    (*c).Update();			}      			for(std::list<Food>::iterator f=MH.GetFoodBegin();f!=MH.GetFoodEnd();f++)		{											     		    if(!MH.WithinSpace(f->GetPos()))		    {			std::cout << "Food found outside space" << endl;		    }	   //	  m_target->draw_pixel((*f).GetPos().x,(*f).GetPos().y,		    //		       color_map[2].r, color_map[2].g, color_map[2].b);		    if( double_pixel_mode)		    {						for(int r=0; r < size; r++)			    for(int c=0; c < size; c++)			    {				draw_pixel((*f).GetPos().x *size + r,						     (*f).GetPos().y *size +c,						     color_map[2].r, color_map[2].g,						     color_map[2].b);			    }					 		    }else		    {			CheckPosition(f->GetPos());						draw_pixel((*f).GetPos().x,(*f).GetPos().y,					     color_map[2].r, color_map[2].g, color_map[2].b);					    }		}      		// MH.CorrectMap();		corpse_pos.clear();		//   CL_Display::sync_buffers();		unlock();		CL_Display::flip_display();		CL_Display::clear_display(0,0,0);		CL_System::keep_alive();	    }	    return 0;	}private:    CL_Target *m_target;  };BBApp app;

⌨️ 快捷键说明

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