示例#1
0
Cart::Cart(LPCSTR BitmapDir, int StartWeight, int Startx, int Starty, int Startz)
{
	DeleteThis = false;
	//Direct Draw Initialization
	DDSURFACEDESC2 ddsd;
	INITIALIZE_DDRAW(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
	ddsd.dwWidth = 3520;
	ddsd.dwHeight = 64;
	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;

	if(FAILED(lpdd->CreateSurface(&ddsd, &TheBitmap, NULL)))
	{
		// Failed making surface
	}

	mysz = BitmapDir;
	DDReLoadBitmap(TheBitmap, BitmapDir);

	//Setup the source Rectangle for animations
	SourceRect.top = 0;
	SourceRect.left = 0;
	SourceRect.right = 64;
	SourceRect.bottom = 64;

	// Default settings for Cart
	RenderThis = true;
	Weight = StartWeight;
	Current = Finished;
	CurrentStatus = None;
	NumberOfPowerups = 0;
	x = Startx;
	y = Starty;
	x = Startz;
	Animating = false;

	CollBox.left = x + 32;
	CollBox.top = y + 32;
	CollBox.right = x + 32;
	CollBox.bottom = y + 32;
	Speed = 20;
	Skipframe = 0;

	//Start positions of all the animations
	LeftU2Start = 64;
	RightU2Start = 64;
	LeftUStart = 704;
	RightUStart = 704;
	UpStart = 704;
	LeftD2Start = 768;
	RightD2Start = 768;
	LeftDStart = 1408;
	RightDStart = 1408;

	JumpStart = 1408;
	JumpFallStart = 3520;

}
示例#2
0
Dynamite::Dynamite(LPCSTR BitmapDir, const char *text, int Startx, int Starty, int Startz, int Time)
{
	DeleteThis = false;
	ObjString = text;
	//Direct Draw Initialization
	DDSURFACEDESC2 ddsd;
	INITIALIZE_DDRAW(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
	ddsd.dwWidth = 64;
	ddsd.dwHeight = 64;
	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;

	if(FAILED(lpdd->CreateSurface(&ddsd, &TheBitmap, NULL)))
	{
		// Failed making surface
	}

	INITIALIZE_DDRAW(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
	ddsd.dwWidth = 640;
	ddsd.dwHeight = 64;
	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;

	if(FAILED(lpdd->CreateSurface(&ddsd, &ExplosionBitmap, NULL)))
	{
		// Failed making surface
	}

	mysz = BitmapDir;
	DDReLoadBitmap(TheBitmap, BitmapDir);
	DDReLoadBitmap(ExplosionBitmap, "gfx/Explosions.bmp");

	SourceRect.left = 0;
	SourceRect.top = 0;
	SourceRect.bottom = 63;
	SourceRect.right = 63;

	RenderThis = true;
	DoCount = false;
	x = Startx;
	y = Starty;
	z = Startz;

	FramesCounter = 0;
	Timer = Time;
	StartTime = Time;
	char temp[2];
	_itoa(Timer, temp, 10);
	thestring = temp; 

	TimeDisplay = new Text(18,"Dynamite Text", thestring, x + 25, y + 25, z, 200, 80,false);
}
示例#3
0
////added for search by text functions. Leigh
Track::Track(LPCSTR BitmapDir, const char *text, int Startx, int Starty, int Startz, TrackType TheType, int SpeedAmount)
{
	DeleteThis = false;
	ObjString = text;
	//Direct Draw Initialization
	DDSURFACEDESC2 ddsd;
	INITIALIZE_DDRAW(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
	ddsd.dwWidth = 64;
	ddsd.dwHeight = 64;
	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;

	if(FAILED(lpdd->CreateSurface(&ddsd, &TheBitmap, NULL)))
	{
		// Failed making surface
	}

	x = Startx;
	y = Starty;
	z = Startz;

	mysz = BitmapDir;
	DDReLoadBitmap(TheBitmap, BitmapDir);

	//Setup the source Rectangle for drawing
	SourceRect.top = 0;
	SourceRect.left = 0;
	SourceRect.right = 64;
	SourceRect.bottom = 64;

	//Other variables used for Track objects
	SpeedOffset = SpeedAmount;
	CollBox.top = Starty;
	CollBox.bottom = (Starty + 63);
	CollBox.left = Startx;
	CollBox.right = (Startx + 63);

	Type = TheType;
	RenderThis = true;
	Reverse = false;
	
	if (Type == Normal || Type == Start || Type == Finish || Type == SpeedUp || Type == SpeedDown)
		Vector = Right;
	else
		Vector = Down;

	string temp;
	temp = BitmapDir;

	if (temp == "gfx/TD.bmp")
	{
		Vector = Down;
	}
}
cls_sprite_surface::cls_sprite_surface()
{
	DDRAW_INIT_STRUCT(ddbltfx);//初始化fx结构
	ddbltfx.dwFillColor = _RGB16BIT565(0,0,0);
	this->hwnd=globalhwnd;
	//MessageBox(hwnd,"constructor has been called!","info",MB_OK);
	sfmgrtemp=(SF_MGR *)malloc(sizeof(SF_MGR));

	for (int i=0;i<1000;i++){
	sprite_surface[i].lpddsrc=NULL;//要么指向什么,要么为NULL,《高质量c++编程》
	sprite_surface[i].srcname=NULL;
	sprite_surface[i].spritename=NULL;
	sprite_surface[i].sprite_numframe=NULL;
	sprite_surface[i].used=0;
	sprite_surface[i].sprite.theframe_height=0;
	sprite_surface[i].sprite.theframe_width=0;
	sprite_surface[i].sprite.counter=0;
	sprite_surface[i].sprite.current_frame=0;
	sprite_surface[i].sprite.x=0;
	sprite_surface[i].sprite.y=0;
	}
	//memset(&sprite_surface,0,sizeof(sprite_surface));少用!
	//http://topic.csdn.net/u/20080219/11/e4eafd76-ac72-44f0-bb48-8c4b439b07f8.html

}
int Game_Main(void *parms = NULL, int num_parms = 0)
{
// this is the main loop of the game, do all your processing
// here

// make sure this isn't executed again
if (window_closed)
   return(0);

// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
   {
   PostMessage(main_window_handle,WM_CLOSE,0,0);
   window_closed = 1;
   } // end if

// copy the bitmap image to the primary buffer line by line
// notice the 24 to 16 bit conversion pixel by pixel

// lock the primary surface
lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);

// get video pointer to primary surfce
USHORT *primary_buffer = (USHORT *)ddsd.lpSurface;       

// process each line and copy it into the primary buffer
for (int index_y = 0; index_y < SCREEN_HEIGHT; index_y++)
    {
    for (int index_x = 0; index_x < SCREEN_WIDTH; index_x++)
        {
        // get BGR values, note the scaling down of the channels, so that they
        // fit into the 5.6.5 format
        UCHAR blue  = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 0]) >> 3,
              green = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 1]) >> 3,
              red   = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 2]) >> 3;

        // this builds a 16 bit color value in 5.6.5 format (green dominant mode)
        USHORT pixel = _RGB16BIT565(red,green,blue);

        // write the pixel
        primary_buffer[index_x + (index_y*ddsd.lPitch >> 1)] = pixel;

        } // end for index_x

    } // end for index_y

// now unlock the primary surface
if (FAILED(lpddsprimary->Unlock(NULL)))
   return(0);

// do nothing -- look at pretty picture

// return success or failure or your own return code here
return(1);

} // end Game_Main
示例#6
0
//-----------------------------------------------------------------------------
// Name: CreateSurface()
// Desc: creates a offscreen plain surface
//-----------------------------------------------------------------------------
LPDIRECTDRAWSURFACE7 CreateSurface(int width, int height, SCCOLOR TransparentColor)
{// this function creates an offscreen plain surface

	//DDSURFACEDESC2 ddsd;         // working description
	LPDIRECTDRAWSURFACE7 lpdds;  // temporary surface
    
	// set to access caps, width, and height
	memset(&ddsd,0,sizeof(ddsd));
	ddsd.dwSize  = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;

	// set dimensions of the new bitmap surface
	ddsd.dwWidth  =  width;
	ddsd.dwHeight =  height;

	// set surface to offscreen plain
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;//default is video memory VRAM
	
	// create the surface
	ddReturnVal  = lpddObj->CreateSurface(&ddsd,&lpdds,NULL);
	if(ddReturnVal == DDERR_OUTOFVIDEOMEMORY)//out of vram
	{
		// set surface to offscreen plain system memory
		ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
		ddReturnVal  = lpddObj->CreateSurface(&ddsd,&lpdds,NULL);
	}
	if (DDFailedCheck(ddReturnVal, "CreateSurface() failed", cpErrorBuf ))//DDERR_OUTOFVIDEOMEMORY DDSCAPS_SYSTEMMEMORY
	{	MessageBox(main_window_handle, cpErrorBuf, "CreateSurface()", MB_ICONEXCLAMATION);   return(NULL); }
	
	// set color key to TransparentColor
	DDCOLORKEY color_key; // used to set color key
	color_key.dwColorSpaceLowValue  = _RGB16BIT565(TransparentColor.r,TransparentColor.g,TransparentColor.b);
	color_key.dwColorSpaceHighValue = _RGB16BIT565(TransparentColor.r,TransparentColor.g,TransparentColor.b);

	// now set the color key for source blitting
	ddReturnVal  = lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key);
	if (DDFailedCheck(ddReturnVal, "SetColorKey() failed", cpErrorBuf ))
	{	MessageBox(main_window_handle, cpErrorBuf, "CreateSurface()", MB_ICONEXCLAMATION);   return(NULL); }

	// return surface
	return(lpdds);

} // end CreateSurface()
示例#7
0
////////constructor for differing height/width animated tracks
AnimatedTrack::AnimatedTrack(LPCSTR BitmapDir, const char *text, int Startx, int Starty, int Startz,int width, int height, int NumberFrames, RECT Collision)
{
	DeleteThis = false;
	ObjString = text;
	Width = width;
	Height = height;
	//Direct Draw Initialization
	DDSURFACEDESC2 ddsd;
	INITIALIZE_DDRAW(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
	ddsd.dwWidth = (NumberFrames * Width);
	ddsd.dwHeight = Height;
	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(255, 0, 255);

	if(FAILED(lpdd->CreateSurface(&ddsd, &TheBitmap, NULL)))
	{
		// Failed making surface
	}

	x = Startx;
	y = Starty;
	z = Startz;

	mysz = BitmapDir;
	DDReLoadBitmap(TheBitmap, BitmapDir);

	//Setup the source Rectangle for animations
	SourceRect.top = 0;
	SourceRect.left = 0;
	SourceRect.right = Width-1;
	SourceRect.bottom = Height-1;

	// Other variables used with animated track objects
	SpeedOffset = 2;
	CollBox = Collision;
	Frames = NumberFrames;
	RenderThis = true;
	AnimateReverse = false;

}
示例#8
0
////added for search by text functions. Leigh
Track::Track(LPCSTR BitmapDir, const char *text, int Startx, int Starty, int Startz, RECT Collision)
{
	DeleteThis = false;
	ObjString = text;
	//Direct Draw Initialization
	DDSURFACEDESC2 ddsd;
	INITIALIZE_DDRAW(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
	ddsd.dwWidth = 64;
	ddsd.dwHeight = 64;
	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;

	if(FAILED(lpdd->CreateSurface(&ddsd, &TheBitmap, NULL)))
	{
		// Failed making surface
	}

	x = Startx;
	y = Starty;
	z = Startz;

	mysz = BitmapDir;
	DDReLoadBitmap(TheBitmap, BitmapDir);

	//Setup the source Rectangle for drawing
	SourceRect.top = 0;
	SourceRect.left = 0;
	SourceRect.right = 64;
	SourceRect.bottom = 64;

	//Other variables used for Track objects
	SpeedOffset = -1;
	Type = Normal;
	CollBox = Collision;
	RenderThis = true;

}
示例#9
0
Text::Text(int FSIZE, const char *text, string printtext,int Startx, int Starty, int Startz, int W, int H, bool Console)
{

	ObjString = text;
	textout = printtext.c_str();
	Width = W;
	Height = H;
	DeathCounter = 50;//frames before deleting
	ConsoleDisplay = Console;
	fontsize = FSIZE;
	
	CollBox.top = Starty;
	CollBox.bottom = (Starty + H);
	CollBox.left = Startx;
	CollBox.right = (Startx +(W));

	DDSURFACEDESC2 ddsd;
	INITIALIZE_DDRAW(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
	ddsd.dwWidth = W;
	ddsd.dwHeight = H;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(255, 0, 255);

	if(FAILED(lpdd->CreateSurface(&ddsd, &TheBitmap, NULL)))
	{
		// Failed making surface
	}

	x = Startx;
	y = Starty;
	z = Startz;
//text render code

	 if (lpddsback->GetDC(&hdc) == DD_OK)  
	 {  
		 
		  SetBkMode(hdc, TRANSPARENT); 
		  SetTextColor(hdc, RGB(255,255,255));
		  if(textout.length() < (int)(Width/8))
		  {
			  LOGFONT logfont = {fontsize,0,0,0,FW_SEMIBOLD,false,false,false,DEFAULT_CHARSET ,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS, PROOF_QUALITY,FF_MODERN,"Lucida Console"};
			  tempfont = CreateFontIndirect(&logfont);
			SelectObject(hdc,tempfont);
			TextOut(hdc, x, y, textout.c_str(), textout.length()); 
		  }
		  else
		  {
			for(int i = 0;(i*(int)(Width/8))<(int)textout.length();i++)
			{
			  LOGFONT logfont = {fontsize,0,0,0,FW_SEMIBOLD,false,false,false,DEFAULT_CHARSET ,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS, PROOF_QUALITY,FF_MODERN,"Lucida Console"};
			  tempfont = CreateFontIndirect(&logfont);
			SelectObject(hdc,tempfont);
				TextOut(hdc, x, (y+(i*20)), (textout.substr((i*(int)(Width/8)),(int)(Width/8))).c_str(), (textout.substr((i*(int)(Width/8)),(int)(Width/8))).length()); 
			}
		  }

		  lpddsback->ReleaseDC(hdc);  


	 }


	

	SourceRect.top = 0;
	SourceRect.left = 0;
	SourceRect.right = W;
	SourceRect.bottom = H;

	RenderThis = true;
}
示例#10
0
//-----------------------------------------------------------------------------
// Name: Init()
// Desc: Initializes Driect draw and anything that needs to be inited
//-----------------------------------------------------------------------------
int InitDD()
{// this function is where i do all the initialization 
 // for the game

	// create dd object and test for error
	ddReturnVal = DirectDrawCreateEx(NULL, (void **)&lpddObj, IID_IDirectDraw7, NULL);
	if (DDFailedCheck(ddReturnVal, "DirectDrawCreateEx() failed", cpErrorBuf ))
	{	MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION);   return(0); }
	
	// set cooperation level to windowed mode normal
	ddReturnVal = lpddObj->SetCooperativeLevel(main_window_handle, DDSCL_NORMAL);
	if (DDFailedCheck(ddReturnVal, "SetCooperativeLevel() failed", cpErrorBuf ))
	{	MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION);   return(0); }
	
	/*
	// set the display mode
	ddReturnVal = lpddObj->SetDisplayMode(nWindowWidth,nWindowHeight,BPP,0,0);
	if (DDFailedCheck(ddReturnVal, "SetDisplayMode() failed", cpErrorBuf ))
	{	MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION);   return(0); }
	*/

	// Create the primary surface first set the fields
	memset(&ddsd,0,sizeof(ddsd));
	ddsd.dwSize         = sizeof(ddsd);
	ddsd.dwFlags        = DDSD_CAPS; //set the flags to validate both capabilites field adn the backbuffer count field
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; //tell dd that u have a complex flippable surface
	//ddsd.dwBackBufferCount = 1; //set the back buffer count

	//Createt the primary surface
	ddReturnVal = lpddObj->CreateSurface(&ddsd,&lpddsPrimary,NULL);
    if (DDFailedCheck(ddReturnVal, "CreateSurface() failed", cpErrorBuf ))
	{	MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION);   return(0); }
	
	//Create an off-screen surface as a backBuffer
	SCCOLOR col={255,0,255};
	lpddsSecondary = CreateSurface(WINDOW_WIDTH, WINDOW_HEIGHT, col);

	//Attach a clipper
	RECT cliplist[1];
	cliplist[0].top = iWindow_y; cliplist[0].left = iWindow_x;
	cliplist[0].bottom = iWindow_y+nWindowHeight;//GetSystemMetrics(SM_CYSCREEN);
	cliplist[0].right = iWindow_x+nWindowWidth;//GetSystemMetrics(SM_CXSCREEN);
	AttachClipper(lpddsPrimary,main_window_handle);
	
	//attack a color key
	// set color key to TransparentColor
	DDCOLORKEY color_key; // used to set color key
	color_key.dwColorSpaceLowValue  = _RGB16BIT565(TransColor.r,TransColor.g,TransColor.b);
	color_key.dwColorSpaceHighValue = _RGB16BIT565(TransColor.r,TransColor.g,TransColor.b);
	
	// now set the color key for source blitting
	ddReturnVal  = lpddsPrimary->SetColorKey(DDCKEY_SRCBLT, &color_key);
	if (DDFailedCheck(ddReturnVal, "SetColorKey() failed", cpErrorBuf ))
	{	MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION);   return(0); }
	
	//"""""""""""""""""""""Init Sprites"""""""""""""""""""""
	static int array[]={0,1},
		       array2[]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13};
	Sprites[0].InitSprite(64,64,1,1,1,120);
	Sprites[0].SetAnimations(array,0,SPRITE_ANIM_ONCE,0);
	Sprites[0].LoadSpriteImage("myface1.bmp");
	Sprites[0].SetState(SPRITE_STATE_ALIVE);
	Sprites[0].SetXPos(100);
	Sprites[0].SetYPos(100);
	
	Sprites[1].InitSprite(43,37,14,6,3,120);
	Sprites[1].SetAnimations(array2,13,SPRITE_ANIM_CONT,0);
	Sprites[1].LoadSpriteImage("Expl16.bmp");
	Sprites[1].SetState(SPRITE_STATE_ALIVE);
	Sprites[1].SetXPos(200);
	Sprites[1].SetYPos(100);
	//""""""""""""""""""End Init Sprites""""""""""""""""""""
	
	return(1);
}