Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Alien Tesh

There must be an easier way....

This topic is 6052 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

Let me just off start by saying that the code works, but I know that there’s a cleaner way of going about it. I’m currently making a game that prints a sort of play by play to the screen. I’ve got about 2000 or so different strings that can get called. What I’m doing now is storing all the strings into a huge switch statement. And when needed in the game, I reference the switch statement to print the appropriate string to the screen. Here’s an example… void PlayByPlay() { HDC hdc; char buffer[80]; hdc = GetDC(G.hWnd); SetBkColor(hdc, RGB(0,0,0)); SetTextColor(hdc, RGB(255,255,255)) switch (G.playByPlayID) { case (1): { sprintf(buffer, “Example string 1a”); TextOut(hdc, 65,50, buffer, strlen(buffer)); sprintf(buffer, “Example string 1b”); TextOut(hdc, 40,80, buffer, strlen(buffer)); break; } } ETC….. ReleaseDC(G.hWnd, hdc); } Then in my code I make calls like this when needed… G.playByPlayID = 1; PlayByPlay(); Even though the code works, I can’t help but feel like I’m doing this the hard way, because let me just say… the switch statement is HUGE. Thanks in advance… A.T.

Share this post


Link to post
Share on other sites
Advertisement
Try this:

  
void PlayByPlay(char *msg)
{
HDC hdc;
char buffer[80];

hdc = GetDC(G.hWnd);

SetBkColor(hdc, RGB(0,0,0));
SetTextColor(hdc, RGB(255,255,255))

sprintf(buffer, "%s", msg);
TextOut(hdc, 65,50, buffer, strlen(buffer));

ReleaseDC(G.hWnd, hdc);
}


...and call it like:

  
PlayByPlay("Character turned to the right");


or you can do the array thing.

-Steven

Edited by - Spinal Confusion on November 21, 2001 4:32:59 PM

Share this post


Link to post
Share on other sites
The only issue I see with using a string array is that when i have multiple lines of text at once. The TextOut function would need different x and y location numbers. Different strings need to be in different locations.

sprintf(buffer, “Example string 1a”);
TextOut(hdc, 65,50, buffer, strlen(buffer)); <----

sprintf(buffer, “Example string 1b”);
TextOut(hdc, 40,80, buffer, strlen(buffer)); <----


I guess I could figure out a way around this... but does anyone have any suggestions how I deal with this part.

Thanks...
A.T.

Share this post


Link to post
Share on other sites
Yeh.
struct PlayByPlayMessage
{
char *Message;
int X;
int Y;
//other stuff
};

PlayByPlayMessage Messages[3] = {{"It's good!", 25, 33},
{"It's outta here!", 15, 33},
{"Romerez is on deck.", 10, 33}};

Something like that...

Later,
Zealouselixir

EDITED FOR CODE MISTAKES


Edited by - ZealousElixir on November 21, 2001 4:46:40 PM

Share this post


Link to post
Share on other sites
With Steve''s example...

PlayByPlay("Character turned to the right", 40, 60);

or with null and void''s..

MyStringStruct *Thingy[] = {
{"Alpha", 50, 50},
{"Beta", 40, 50},
{"Gamma", 60, 55},
{"Delta", 40, 40 }};

I''d prefer the struct way.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!