Hangbot - Asimov Testgame

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 5th, 2013, 5:48 pm

Hi all,

Well got a bit more done. So far the attached exe will do this.

1) Shows a catergory view before game starts. so far only one option.
2) Loads in a text resource file. Picks a random line, and puts the line to the screen.
3) Lets you make guesses with the letters.

What it doesn't do yet.

1) It doesn't penalise you for a wrong answer.
2) It doesn't end the round when you get the whole word.

Ok I have another thing to work out. I need to add a fixed width font, but here is the problem. So far all my data is inside the exe. eg, pictures and text. Now I can load in a font using this line
AddFontResourceEx(L"data/mt.ttf",FR_PRIVATE,0);

The font doesn't have to be installed either, and it will work, but I am wondering if I can put this font in my resource file and somehow load it from there.

The reason for this is that I can't just guess that the user will have the font I want to use.

So I am not sure if this is possible.

The reason I want to use fixed width is because the dash spacing on some letters is narrower than other letters, so when you guess a letter right the spacing changes, if you know what I mean.
I might come up with another solution soon.

BTW for those who wants to know. Below is my final solution to loading a textfile to my vector strings from a resource file.

Code: Select all

void Dict::loadText(int textFile)
{
	dictionary.clear();
	HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(textFile), L"TXT"); // <- make sure it's the type you specify it to be...
	if (hRes == 0)
       { 
			MessageBox(NULL, LPWSTR(L"Text Not Loaded"), TEXT("TEXT"), NULL);
        }

   HGLOBAL hMem = LoadResource(NULL, hRes);
   DWORD size = SizeofResource(NULL, hRes);
   char* resText = (char*)LockResource(hMem);
   char* text = (char*)malloc(size + 1);
   memcpy(text, resText, size);
   text[size] = 0;
	
   void* lockedRes = LockResource(hMem);

char buffer[100];
int buffercount=0;
for (int g=0; g<size; g++)

	{
		buffer[buffercount]=((char*)lockedRes)[g];
		buffercount++;
		if(((char*)lockedRes)[g]=='\n')
		{		
			dictionary.push_back(string(buffer,buffercount-2));
			buffercount=0;
		}
	}

FreeResource(hMem);
}

Attachments
Hangbot.zip
(325.86 KiB) Downloaded 176 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 5th, 2013, 10:11 pm

Hi all,

Well more success. It took me ages to find all this information, and some lucky person is going to come across this thread and get all the information in one go. This didn't take me as long as loading text to work out, but it did take a couple of hours to get working.

Ok to load a font from resource first load in to the resource file as "Import User Resource".
Bear in mind this might only work with ttf fonts as I haven't tried any other type using this method.

Anyway the code to load in from resource follows.

Code: Select all

void fontloader::setFont2(int fontsize,IDirect3DDevice9* m_pd3dDevice)
{
	
	DWORD   Count ;
    HRSRC Resource = FindResource(NULL, MAKEINTRESOURCE(IDR_MONOFONTY),L"TTF");
    DWORD   Length   = SizeofResource(NULL,Resource) ;
    HGLOBAL Address  = LoadResource(NULL,Resource) ;
    HANDLE Handle = AddFontMemResourceEx(Address,Length,0,&Count) ;
    if(Handle==0)
    {
      MessageBox(NULL, TEXT("Font Failed"), TEXT("FATAL ERROR"), NULL);
    }
	size=fontsize;
	D3DXCreateFont( m_pd3dDevice, size, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("MonospaceTypewriter"), &g_Font );

}

I hope that is helpful to someone.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Hangbot - Asimov Testgame

Post by LuisR14 » July 6th, 2013, 7:28 am

i guess you skipped my post? o.o ( meh :P )
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 6th, 2013, 8:39 am

Hi Luis,
haha, you misspelled to the correct function you should use :P
sscanf is the function similar to fscanf that scans a string array instead :)
but i think you should use swscanf instead o.o
Not intentionally I assure you. I did read the above one, but after messing I did it a completely different way heh heh.

I have a terrible memory for commands. I very often know what I need to do, but forget the command I need to use. Which is why I take lots of notes heh heh
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 6th, 2013, 4:44 pm

Hi all,

I have a new problem now. I know how to show a sprite, but now want to use a png because it has alpha transparency, unfortunately when displayed there is no alpha at all.

Here is my code

Code: Select all

void Sprite::RenderAlpha(float x,float y,IDirect3DDevice9* m_pd3dDevice)
{
Pos.x = x;
Pos.y = y;
Pos.z = 0.0f;

// Draw The Sprite
sprite->Begin(D3DXSPRITE_ALPHABLEND);
sprite->Draw(m_texture, NULL, NULL, &Pos, 0xFFFFFFFF);
sprite->End();
};
Notice I have turned on AlphaBlend. I thought this would do the alpha, but no it doesn't.

I want it to look like it is in the attached picture.
I have also attached the image with alpha, which is a png.

I don't just want one colour transparent, as I want to use the alpha from the image.
Attachments
guessbox.png
(864 Bytes) Downloaded 46 times
alphatest.jpg
(46.08 KiB) Downloaded 46 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 6th, 2013, 5:01 pm

Hi all,

Don't worry I have the solution, and it wasn't where I thought it was.

Code: Select all

void Sprite::LoadTexture(wstring loadfile,IDirect3DDevice9* m_pd3dDevice){
	HRESULT result;
	result = D3DXCreateTextureFromFileEx(m_pd3dDevice, loadfile.c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2,
	D3DX_DEFAULT, 0, D3DFMT_R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &m_texture);

	assert(!FAILED(result));

	result = D3DXCreateSprite(m_pd3dDevice, &sprite);

	assert(!FAILED(result));

}
To make the above code render transparent alpha, just change one little bit
Change D3DFMT_R8G8B8 to this D3DFMT_A8R8G8B8

Directx is a breeze to use after using GDi for loading the graphics.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 7th, 2013, 12:16 am

Hi all,

Made some progress. Got a little problem with a random bug. It is annoying. If it did it everytime I could track it down. Well see the line theword = dictionary.at(r); it crashes every now and again, and strangely enough I think it crashes because the vector array has not loaded. Or maybe the value of r is maybe one too great. Trouble is don't want to change anything until I pinpoint the bug.
Maybe dictionary.size()-1 might cure it. I am gonna have to find a way to cause the bug so I can sort it.

Anyway attached the latest version of Hangbot. The graphic of the corridor is not finished yet, as I haven't added the texturing yet. Would you believe it just has Vray light, a normalmap and an opacity map, but no texturing as of yet. You might notice that the Robot is not there yet either. That is because I haven't finished building him yet.

I am now at the iccy stage where I am refining stuff. Also I need to add sound, and I need more categories and some source of words from somewhere LOL.

Code: Select all

void Dict::randomWord()
{
	loadText(IDR_MOVIES);

	srand(time(NULL));
	r= 1 + (rand() % dictionary.size());


theword = dictionary.at(r);
transform(theword.begin(), theword.end(), theword.begin(), toupper);

}

Attachments
Hangbot.zip
(684.27 KiB) Downloaded 168 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Hangbot - Asimov Testgame

Post by LuisR14 » July 7th, 2013, 3:07 am

why not load the format from the file by using D3DFMT_UNKNOWN? :P
well anyways, i think it's because of the "1 +" that it's crashing, since "rand() % dictionary.size" mods it to 0 thru size-1 :) (and well the index of .at() requires 0-based index i believe, edit: yep just checked and it is 0-based)
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 7th, 2013, 11:22 am

Hi Luis,

I will look into that. I put one because it was a random number between 1 and the maximum number.
I didn't start at 0 because I pushed a test item in at 0 to try and stop it crashing LOL.

I really need to finish building the robot now. The robot itself is built, but I am working on the arm, and it is quite complicated. Then the proper texturing, as the rust texture I threw on for the title screen is not the proper texture LOL

Pics attached.
Attachments
hewey10.jpg
hewey10.jpg (80.81 KiB) Viewed 4149 times
arm7.jpg
arm7.jpg (73.3 KiB) Viewed 4149 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 7th, 2013, 3:06 pm

Hi all,

I solved the bug I mentioned in the previous post. Turned that the maximum value of dictionary.size() was 63. So I manually set r which is my random number to 63 and it crashed. So the answer was to change dictionary.size() to dictionary.size()-1 and now everything is fine. It now no longer crashes on startup.

I do now however have a random crash when entering letters in game. It doesn't do it every time which is annoying so I am having trouble tracking it down. It also crashes and takes me to stddthrow.cpp so that isn't much help. I wish it would show the variable it is crashing.

My guess is that one of my loops in letterDraw.cpp is going over a variables limit. I am not sure why this is happening, but I am having trouble tracking down which loop is doing this.

I will post a pic of the error in case someone knows a way for me to track this down. Logic tells me which class is giving me the error, but which variable loop I don't know yet.

PS
I kept getting this error on lines
warning C4018: '<' : signed/unsigned mismatch
for (int ff=0; ff < originalWord.length(); ff++)

Apparently there is a missmatch with origialWod.length, even though the program runs fine.
Apparently the correct syntax is the following
for (size_t ff=0; ff < originalWord.length(); ff++)

and that gets rid of the error and works the same, wierd or what?

PS deleted picture, cos it was toooo big LOL.
Last edited by Asimov on July 12th, 2013, 5:24 pm, edited 1 time in total.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

Post Reply