Jump to content
  • Advertisement
Sign in to follow this  
Gamesmaster3

How do I change colors of gridlines

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I'm working on a exercise to change the color of the gridlines in this program.I compiled the program without the new code and it works fine so I kind of know where the trouble is but I just don't know what to do about it because it looks like I have the code pretty much right.Maybe it's in the wrong place or something,Anyway the code is below
 
//Include Files
#include "skeleton.h"
//

//Game Engine Functions
//...................................................................
BOOL GameInitialize(HINSTANCE hInstance)
{
	//Create the Game Engine
	_pGame = new GameEngine(hInstance,TEXT("Tripy"),
		TEXT("Tripy"),IDI_SKELETON,IDI_SKELETON_SM);
	if(_pGame == NULL)
		return FALSE;

	//Set the frame rate
	_pGame->SetFrameRate(15);

	return TRUE;
}

void GameStart(HWND hWindow)
{
	//Seed the random number generator
	srand(GetTickCount());
//Set the position and size of the initial rectangle
	_rcRectangle.left = _pGame->GetWidth() * 2/5;
	_rcRectangle.top = _pGame->GetHeight() * 2/5;
	_rcRectangle.right = _rcRectangle.left + _pGame->GetWidth() /5;
	_rcRectangle.bottom =_rcRectangle.top + _pGame->GetHeight()/5;

}

void GameEnd()
{
	//cleanup the game engine
	delete _pGame;
}

 void GameActivate(HWND hWindow)
{
	HDC hDC;
	RECT rect;

	//Draw activation text on the game screen
	GetClientRect(hWindow, &rect);
	hDC = GetDC(hWindow);
	DrawText(hDC,TEXT("Pokemon Hardcore Activated!"), -1,&rect,
		DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	ReleaseDC(hWindow,hDC);
}

void GameDeactivate(HWND hWindow)
{
	HDC hDC;
	RECT rect;

	//Draw Deacivation text on the game acreen
	GetClientRect(hWindow, &rect);
	hDC = GetDC(hWindow);
	DrawText(hDC,TEXT("Pokemon Hardcore Deactivated!"), -1,&rect,
		DT_SINGLELINE |DT_CENTER | DT_VCENTER);
	ReleaseDC(hWindow, hDC);
}

void GamePaint(HDC hDC)
{
	
	//Draw grid linesas a background for the rectangles
	const int iGridlines = 50;
	for(int i = 1;i<= iGridlines;i++)
	{
//Create A Purple Pen
HPEN hPurplePen = CreatePen(PS_SOLID,1,RGB(255,0,255));
	//Selecting The Pen
//........Here is where the problem is and here is the error....................
//C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\MyProjects\basicwindows\skeleton.cpp

//(79) : error C2440: 'initializing' : cannot convert from 'void *' to 'struct 
//HPEN__ *'

	HPEN hPen = SelectObject(hDC,hPurplePen);
//..............................................................................		
		//Draw a horizontal Grid Line
		MoveToEx(hDC,_pGame->GetWidth() * i/iGridlines,0,NULL);
		LineTo(hDC,_pGame->GetWidth() * i/iGridlines,_pGame->GetHeight());

		//Draw vertical grid lines
		MoveToEx(hDC,0,_pGame->GetHeight() * i/iGridlines,NULL);
		LineTo(hDC,_pGame->GetWidth(),_pGame->GetHeight() * i/iGridlines);
	//Return to Original Pen
SelectObject(hDC,hPen);
         //Get rid of the newly created Pen
DeleteObject(hPurplePen);
	
	}

 
}


void GameCycle()
{
	HDC hDC;
	HWND hWindow = _pGame ->GetWindow();
	HBRUSH hBrush;

	//Randomly alter the position and size of the rectangle
	int iInflation = (rand() % 21)-10;
	InflateRect(&_rcRectangle,iInflation,iInflation);
	OffsetRect(&_rcRectangle,(rand() % 19) - 0,(rand() % 19) - 9);

	//Draw the new Rectangle in a random color
	hBrush = CreateSolidBrush(RGB(rand() % 256,rand() % 256,rand() % 256));
	hDC = GetDC(hWindow);
	FillRect(hDC,&_rcRectangle,hBrush);
	ReleaseDC(hWindow,hDC);
	DeleteObject(hBrush);
}


Share this post


Link to post
Share on other sites
Advertisement
Thanks DarkMerchant(cool name by the way)
I tried that out and it worked but I'm scratching my head as to why.
Wasn't it already an HPEN??

Share this post


Link to post
Share on other sites
If you are using the SAMS teach yourself, i would recomend finding some more documentation on WIN32 as the book usually only shows you the code, and gives only a breif summary, I tried that book and it just didn't teach as much as tell how to do stuff.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!