CoolGamer48 65 Posting Pro in Training

I do believe that older versions of the Unreal Engine (which is the engine used to make UT3 that you were referring to) are available at prices affordable by an average individual (vs. an entire gaming company or someone who's extremely rich). I heard somewhere that the very first version of the engine is free, though that might be for non-commercial use.

CoolGamer48 65 Posting Pro in Training

Hey, sorry if this is in the wrong forum.

My computer keeps crashing, causing it to restart, and I don't know why. Here's what I know:

  • It's happened only on Windows XP
  • Its happened on one of my machines multiple times,and just started happening on my second
  • The crashes always occur when I'm using VC++ with DirectX
  • Both machines have sub par video cards

The Microsoft error I used to get on my first machine said that it was an issue with a device driver. This makes me think that both my current drivers, while technically compatible with DirectX, don't work well with it. Is this probably what's causing the error? If so, how exactly should I fix it? If not, what is the problem and what should I do?

One last thing: With the crash that just occurred on my second machine, I was having some weird behavior with a 3D model in my program. I ran the program once, and it worked. I then changed just one thing, a parameter to a SetCamera() function, changing the x value from 5.0 to 20.0, and I could no longer see the model (centered at the origin). I moved it back to 5, could see it. Moved it to 4, could see it. Moved it back to 5, could not see it, and basically played around with the numbers until right after one compile, the computer restarted. I wasn't working in 3D for most of the …

CoolGamer48 65 Posting Pro in Training

Hey,

What will happen if you link to the same lib twice using #pragma? Will this cause an error, or if the lib is already being linked to, will the second #pragma be ignored?

Thanks.

CoolGamer48 65 Posting Pro in Training

I got it, but that wasn't it.

It was an issue with Windows Explorer. For some reason, it's set to not display file extensions on files (except DLLs, and maybe some other exceptions). The .X file was originally shown w/o a .X at the end, so that's the way I wrote it in C++, but in reality, the .X was part of the name. I then tried renaming it in Explorer to <modelname>.x, but that renamed it to <modelname>.x.x

So, now I have it to appear as just the model name w/o the extension in Explorer, but I include the extension in C++. Works.

CoolGamer48 65 Posting Pro in Training

@Q2: Thanks, that did it.

@Q1: Would that fact that I use __declspec(dllexport) in front of my functions do anything?

I checked, and when I removed that, it worked, but when I put them back, it still worked. I think the IDE just needed time or something... It works now.

CoolGamer48 65 Posting Pro in Training

Ok, so some quick questions on using my DLL

First one is VC++ specific: If you've ever used APIs (like DirectX) with VC++ (or even if you haven't), you might know about the feature in VC++ that lists the parameters of a function as you type them in a call to the function. So, I have a file, RezNebMath.h (dont ask about the RezNeb part, just a name), which I've compiled into a DLL/LIB combo (along with other files, like a .cpp and a .def), and I added the directory its in to my compilers default search directories for includes, so I #include it with <>, not "". The compilation and link work fine, and the program executes, its just that as I'm typing, VC++ isnt aware that something like Random() is a function (even if I press "Go to deceleration"), yet if I right click on <RezNebMath.h>, and click "Open File", it comes up, and on the first few lines is the prototype for Random(). So anyone know why it doesn't know the function exists until compilation. I know this works for other files that aren't in the project's directory, and included to with <>.

Question number 2 is also VC++ specific, but perhaps less than number 1: I need to have my DLL in the same directory as my source at compilation time in order for it to run after its done compiling. I looked through the list of default search directories for various file types …

CoolGamer48 65 Posting Pro in Training

Yes, in time you will understand the magic of OOP (object oriented programming).

Also, as to the struct/class thing: While that is the technical difference between them, the reason they both exist is because structs are left-over functionality from C, and classes are the object-oriented, C++ alternative. Initially, structs (if I am correct), didn't allow methods, and perhaps other nice class things, like inheritance and access-level specifiers. When classes came around and got all of that, they added the functionality to structs.

Also, a teacher of mine once said that structs are merely templates (used in the English sense, not the C++ sense) for multi-type arrays.

CoolGamer48 65 Posting Pro in Training

Ok, I'm writing a simple program with VC++ and DirectX. It's basically a working framework for 3D games, but all I need it to do right now is load a mesh and display it, and it is killing me. I've done this successfully before, I don't know why its not working now.

The function I use to load the .X file is Mesh::LoadFromX()

declared here:

int LoadFromX(char* filename);

defined here:

//Model::LoadFromX()
//Loads the model from a .X file
//Takes the filename of the model as a parameter
//Returns 1 on success, 0 on failure
//DOES NOT WORK
int Model::LoadFromX(char* filename)
{
	ID3DXBuffer* matbuffer;
	HRESULT result;

	result = D3DXLoadMeshFromX(filename,D3DXMESH_SYSTEMMEM,d3ddev,NULL,&matbuffer,NULL,(DWORD*)&m_materialCount,&m_mesh);
	if(result != D3D_OK)
	{
		switch(result)
		{
		case D3DERR_INVALIDCALL:
			MessageBox(NULL,"D3DERR_INVALIDCALL from D3DXLoadMeshFromX() in Model::LoadFromX()","Error",MB_OK | MB_ICONERROR);
			break;
		case E_OUTOFMEMORY:
			MessageBox(NULL,"E_OUTOFMEMORY from D3DXLoadMeshFromX() in Model::LoadFromX()","Error",MB_OK | MB_ICONERROR);
			break;
		case D3DXFERR_FILENOTFOUND:
			MessageBox(NULL,"D3DXFERR_FILENOTFOUND from D3DXLoadMeshFromX() in Model::LoadFromX()","Error",MB_OK | MB_ICONERROR);
			break;
		default:
		{
			char error[1000];
			sprintf(error,"Unknown error from D3DXLoadMeshFromX() in Model::LoadFromX(): %d",result);
			MessageBox(NULL,error,"Error",MB_OK | MB_ICONERROR);
		}
		}
		return 0;
	}

	D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)matbuffer->GetBufferPointer();
	m_materials = new D3DMATERIAL9[m_materialCount];
	m_textures = new IDirect3DTexture9*[m_materialCount];

	for(int i = 0;i < m_materialCount;i++)
	{
		m_materials[i] = d3dxMaterials[i].MatD3D;
		m_materials[i].Ambient = m_materials[i].Diffuse;

		m_textures[i] = NULL;
		if(d3dxMaterials[i].pTextureFilename != NULL && d3dxMaterials[i].pTextureFilename != "")
		{
			result = D3DXCreateTextureFromFile(d3ddev,d3dxMaterials[i].pTextureFilename,&m_textures[i]);
			if(result != D3D_OK)
			{
				MessageBox(NULL,"Could not load proper texture file","Error loading model",MB_OK | MB_ICONERROR);
				return 0;
			}
		}
	}

	matbuffer->Release();
	return 1;
}

and called here:

house = new Model;
	house->LoadFromX("fachwerk33T.x");

I keep getting D3DXFERR_FILENOTFOUND from the call to D3DXLoadMeshFromX().

The .X file is at …

CoolGamer48 65 Posting Pro in Training

Yes. Some companies publish DLLs without accompanying *.lib. And *.libs have other uses than DLLs. When you create a static library a DLL is not produced.

So, how would you use/access a DLL that doesn't have a .lib paired with it? And what is a static library?

EDIT: I think I found out what a static library is from Google, is this right:
A static library is linked to after you compile the project but before the executable actually runs. This creates a bigger file, but lets the program run faster than it would with dynamic linking.

Dynamic linking is when the compiler links to a .lib that corresponds to a DLL, and it looks up the function it needs during runtime, as they are called. This results in a smaller, but slower, program.

Is that right?

CoolGamer48 65 Posting Pro in Training

DLLs are pre-compiled code. When you compile a dll (or get one from someone else that has been compiled for you) you will get two files: *.dll and *.lib. The *.dll is saved in a directory that is your PATH environment variable, such as c:\windows, and the code in the dll is run when your program is executed. The *.lib file is used by the compiler at link time to resolve all the symbols and function names that are in the dll. Your compiler used the *.lib every time it links your program -- normally every time you compile your program.

I see. So is there anytime when you would have .dll file, but no accompanying .lib file, or visa versa?

Yes and no. DLLs compiled by C compiler (not c++) can generally be called from other languages. DLLs compiled by c++ can be called by other languages if the c++ functions meet certain criteria, such as no c++ classes or c++ specific code.

Interesting... so C code can be interpreted by many different languages, but C++ code can't. Is that only when the code is compressed into a DLL? Like if I were to do the VB equivalent of #include (if such a thing exists) with a .h file using only C code, would it work?

The *.lib files generally can not be used with other languages -- they often can't even be used by other compilers.

So, what about the .lib files included with DirectX? Did they …

CoolGamer48 65 Posting Pro in Training

Gears of War had 32 people JUST on programming (12 were listed under "Unreal Engine Programmers"). In total, around 150 people from Epic Games alone worked on the game.

Bioshock (surprisingly to me), had less, around 24 programmers listed in the credits. I was too lazy to count all of the people.

In short, it would take a miracle for even you and five friends to make a game like Bioshock or Gears of War on your own. Remember - its 20-30 people just programming. The other 100 or so people design the levels, make the 3D models, write the story, record the sound, etc. W/o all that your game wouldn't be all that fun, regardless of how well its programmed.

Not to crush your spirits though... you could still continue/start to learn DirectX and work on some more basic projects, or, prepare for a career in game programming (which, fyi, i don't have experience in).

CoolGamer48 65 Posting Pro in Training

A .lib is a library of functions that are statically linked to a program -- they are NOT shared by other programs. Each program that links with a *.lib file has all the code in that file. If you have two programs A.exe and B.exe that link with C.lib then each A and B will both contain the code in C.lib.

That sounds very similar to a *.h file in C++. Is the difference between then that .lib files are not recompiled every time you compile the project? Also, when using APIs like DirectX, I find I often have to #include a file like dinput8.h, and then also link to a .lib file like dinput8.lib. Why is that? And are .libs language specific, like given any lib, could two different programing languages use it (not simultaneously, just in general)?

How you create DLLs and libs depend on the compiler you use. Each compiler does it differently.

I'm using VC++ 2008 Express.

CoolGamer48 65 Posting Pro in Training

Hey,

So, three questions:

1. What is a DLL and what is a .lib file?

2. (might have been answered w/ #1) What is the purpose of .lib/.dll files?

3. How do I create a .lib file with C++, and (again, may have been answered above) what exactly will this do?

Thanks for any clarifications.

CoolGamer48 65 Posting Pro in Training

you have to have tools and a license from microsoft to make a game for 360. HOW DARE YOU DEFILE THE XBOX, GREATEST CONSOLE EVER DEVISED?

Err... were you talking to me, or the OP? Either way what exactly do you mean by defiling the Xbox?

And you must pay Microsoft (big shock) to use XNA to develop games for the 360 (I'm assuming that's what you were referring to).

CoolGamer48 65 Posting Pro in Training

EDIT: Ahhh.. nvm, I found it: die("Error with database".); should be die("Error with database."); Might anyone know why the following php script produces no results? I.e., when I ctrl+u in Firefox, a blank screen comes up.

<html>
	<head>
		<title>Create Base</title>
	</head>
	<body>
		<h1>Create Base</h1>
		<form action="bases.php" method="post">
			<table>
			    <tr><td>Name:</td><td><input type="text" name="name" /></td></tr>
			</table>
			<input type="submit" value="Create Base" />
		</form>
		<?php
			$con = mysql_connect("localhost","user","pass");
			if($con == NULL)
			{
				die("Error with database".);
			}
			mysql_select_db("alecbenz_rpgProj",$con);
			if(isset($_POST["name"]) && $_POST["name"] != "")
			{	
				$sql = "SELECT money FROM users WHERE username = \"".$_COOKIE["user"]."\"";
				$result = mysql_query($sql,$con);
				$row = mysql_fetch_array($result);
				$current_money = $row["money"];
				if($current_money >= $cost)
				{
					$sql = "INSERT INTO bases (name,usr_name) VALUES (\"".$_POST["name"]."\",\"".$_COOKIE["user"]."\")";
					mysql_query($sql,$con);
					$sql = "UPDATE users SET money = ".($current_money-$cost)." WHERE username = \"".$_COOKIE["user"]."\"";
					if(!mysql_query($sql,$con))
					{
						echo "Error: ".mysql_error();
					}
				}
				else
				{
					echo "You do not have enough money to create a new base. Current money: $current_money.";
				}
			}
			
			$sql = "SELECT name FROM bases WHERE usr_name = \"".$_COOKIE["user"]."\"";
			$result = mysql_query($sql,$con);
			if(mysql_num_rows($result) == 0)
			{
				$cost = 100;
			}
			elseif(mysql_num_rows($result) == 1)
			{
				$cost = 150;
			}
			elseif(mysql_num_rows($result) == 2)
			{
				$cost = 200;
			}
			elseif(mysql_num_rows($result) >= 3)
			{
				$cost = 300;
			}
			echo "New bases will cost you ".$cost.".<br /><br />";
			
			$sql = "SELECT name,id FROM bases WHERE usr_name = \"".$_COOKIE["user"]."\"";
			$result = mysql_query($sql,$con);
			if(mysql_num_rows($result) == 0)
			{
				echo "No bases currently established.";
			}
			else
			{
				echo "<div style=\"text-decoration: underline;\">Current bases:</div><br />";
				$counter = 1;
				while($row = mysql_fetch_array($result))
				{
					echo $counter.". ".$row["name"]."   <a href=\"delete_base.php?base=".$row["id"]."\">Delete</a><br />";
					$counter++;
				}
			}
		?> …
CoolGamer48 65 Posting Pro in Training

Hey, im trying to use the mail() function, but its not working. This is the script:

<html>
<head>
</head>
<body>
	<?php
		if(mail("coolgamer48@gmail.com","Test","Test","From:coolgamer48@gmail.com"))
		{
			echo "Success";
		}
		else
		{
			echo "Failure";
		}
	?>
</body>
</html>

I keep getting "Failure". Is there an issue with my syntax, or is it some other problem?

I'm running Ubuntu, and I've done nothing other than installing PHP to use the mail functions.

CoolGamer48 65 Posting Pro in Training

people disagree and say Java or even VB is the way to go.

Isn't Java pretty much EXACTLY like C++, except without pointers (and some other, less significant differences). That is, from a programmer's perspective. I suppose the JVM and bytecode are also differences. If so, why wouldn't you want pointers? I find it hard to imagine programming a game without pointer-based structures like Linked lists.

CoolGamer48 65 Posting Pro in Training

Cliffy B is not a programmer. Cliffy B is a project manager (or something along those lines). He would have more to do with ensuring that the entire project is going as planned.

As for what OS professional game programmers use, I am not sure exactly, though if by PC you mean Windows-based PC, then I would assume that they program on a Windows platform.

CoolGamer48 65 Posting Pro in Training

The buffer next_room_script[] lives in the scope of the containing if() block. Your problem will go away if you change the m_nextRoomScript to be a std::string because the string will copy and hold the data you have read from the file. The pointer version just points to the temporary buffer and gets garbled.

Right... I thought it might be something like that....

So basically when I pass a char array to a function that takes a pointer, I'm taking the address of the array, which goes out of scope at the end of the if block. If I were to use a string, I would be copying the actual data to a new memory location, not just copying the memory location, right? Now, if I did that, would I need to change the data type of m_nextRoomScript to string, or would there be a way to still keep that as a char*?

CoolGamer48 65 Posting Pro in Training

Ah, you have a 'C' mind, not a C++ ;)

What's the C++ mindset concerning overloading operators? That you shouldn't worry about the operator originally does with primitive data types? That it might as well be a new symbol, but C++ doesn't let you invent new operators?


Ehh... I guess I'll learn to use strings and the << >> operators for file I/O.

CoolGamer48 65 Posting Pro in Training

Ehh... I just don't really like std::strings for some reason... I also don't like the idea of using << >> operators to for I/O, because shifting left and right have nothing to do with I/O.

But if that will solve my problem I guess I'd give it a go, but why exactly would it solve my problem?

CoolGamer48 65 Posting Pro in Training

Hey, I'm having a problem with my RPG. I'm trying to get a player to move from one room to another. All the coordinates (and other properties) of all the objects inside a given room are contained inside a text file, and this includes the properties of an exit to a different room. The exit has a position, sprite, and most importantly, a char* that holds the name of the script to look at to "build" the next room (obviously it isn't a char* inside the text file, my game just interprets it and stores it as a char*, which is a member of an Exit class). However, when it comes time to load the next room, the member that held the new room's filename is corrupt (not sure if that's the correct word - it basically no longer has the right data). I think there's an issue with how I store the filename.

else if(strcmp(buffer,"#exitNextRoomScript") == 0)
				{
					char next_room_script[MAX_PATH];
					fscanf(file,"%s",next_room_script);
					exit->SetNextRoomScript(next_room_script);
				}

This is the code the reads the string from the text file and stores in into an instance of the Exit class by calling Exit:: SetNextRoomScript(), defined here:

void Exit::SetNextRoomScript(char* filename)
{
	m_nextRoomScript = filename;
}

m_nextRoomScript is declared: char* m_nextRoomScript; , as a private member of the Exit class.

It is retrived with the Exit::GetNextRoomScript() method, defined as:

char* Exit:: GetNextRoomScript()
{
	return m_nextRoomScript;
}

Is there something wrong with the way I am letting the compiler convert a char array …

CoolGamer48 65 Posting Pro in Training

I always thought C/C++ meant C or C++...

CoolGamer48 65 Posting Pro in Training

@ hughv

Dell Inspiron and XPS are a good place to start

I thought Dell's quality was a bit bad..

@ jbennet

I think [Alienware is] owned by dell now actually....

were you implying that?

CoolGamer48 65 Posting Pro in Training

Also: for the desktop, what brand do you recommend? I was leaning towards the Alienware Aurora, but I read some reviews on cnet saying that Alienware was pretty bad with customer service and has shipping issues.

CoolGamer48 65 Posting Pro in Training

yeah, and if you have got a LAn (particuarly a wireless one) then its dead easy

Err... do you mean a wireless network at home, or at school?

CoolGamer48 65 Posting Pro in Training

Hey, sorry if this is the wrong place for this, but...

A while ago I was thinking of getting a new laptop. At first I was going to focus on battery life, but as time went by I saw myself caring less about that and more about a quality machine. Now, if I were to get laptop, I would most likely make it a desktop replacement.

A friend of mine recommended that instead, I get a really good desktop with all the things I want, and then a laptop to use for more basic word-processing, and that sounded like an ok idea. He said that the price wouldn't be too high(price range: desired: $2000, might go for: $3000, absolute max: $4000, pushing it)

I'm just looking for input on which choice would be better, and for what reasons. The only time I go out of the house with my laptop is at school, where having the power to program or run graphics intensive applications would be nice, but not all that important. A machine that's capable of handling some basic things would work. I guess. Then again, I would need to transfer things between my laptop and my desktop, and that might be a hassle.

So just looking for input...

CoolGamer48 65 Posting Pro in Training

>>when coming from C background
I actually don't come from a C background. C++ was actually the very first programming language I learned (took me a while to understand all of it though, i.e. classes, pointers). I just think the whole idea of using the shift operators to get input, because left and right shifting have nothing to do with getting input or putting output to a stream.

Also, is there a way to check if the end of a file has been reached with ifstream? Because I'm using feof() in my program.

CoolGamer48 65 Posting Pro in Training

Why so much C code in a C++ program?

FILE is used for C? What's the C++ way to do file I/O? fstream? If so, I guess I just don't like using the overloaded >> operator, but I suppose I could call the function directly if I wanted to.

CoolGamer48 65 Posting Pro in Training

>>Oh but yes you are. file is supposted to be a pointer to an open FILE object.
I am writing to file? Aren't I just reading from it? file is declared as FILE* in another part of the code. And I double-check, the address with the issue is indeed sprite_filename.

I'll try the dynamic allocation with new. Thanks.

CoolGamer48 65 Posting Pro in Training

Hey, when I run this code:

else if(strcmp(buffer,"#itemSprite") == 0)
{
    char* sprite_filename = "";
    int trans_r;
    int trans_g;
    int trans_b;
    int width;
    int height;
    int numFrames;
    int numCols;
    int frameChangeDelay;
    fscanf(file,"%s",sprite_filename);
    fscanf(file,"%d",&trans_r);
    fscanf(file,"%d",&trans_g);
    fscanf(file,"%d",&trans_b);
    fscanf(file,"%d",&width);
    fscanf(file,"%d",&height);
    fscanf(file,"%d",&numFrames);
    fscanf(file,"%d",&numCols);
    fscanf(file,"%d",&frameChangeDelay);
    item->SetSprite(sprite_filename,D3DCOLOR_XRGB
             (trans_r,trans_g,trans_b),width,height,numFrames,numCols,frameChangeDelay);
}

I get an error on this line: fscanf(file,"%s",sprite_filename); that I don't have access to write to 0x0041ed5b. I'm guessing that's the address of sprite_filename, since the only other variable on that line is file, and we're not writing to it. Why am I getting this error? If I declare char* sprite_filename = ""; , shouldn't I have access to it within the same set of code brackets?

CoolGamer48 65 Posting Pro in Training

I used to use GameMaker. There used to be tutorials on the site, but GameMaker got bought by YoYo games, so I'm not sure if they're anywhere anymore. Ill see if I have any saved on my computer somewhere if I have the time.

A nice thing about GMaker is that you learn programming concepts without actually writing code. But GameMaker isn't THAT easy to use (it is from a knowing/not knowing how to code perspective, but not really from other perspectives). I tried to make an RPG in GameMaker once and it wasn't pretty (of course I was younger, but still...).

CoolGamer48 65 Posting Pro in Training

Hey,

I'm doing a school project on how math and physics are used in video games, and I'm trying to find things that I could talk about. The main idea I have right now is how trig is used to calculate the changes in x and y values of an object based on its speed and direction to get full circular movement, but I can't really think of much else worth talking about that I really understand. I thought of gravity/friction, but that's a bit simple (just adding or subtracting a value to the x or y values of a velocity). I suppose I could also talk about collision detection, but that's also a bit simple (at least simple 2D collision detection to the degree that I understand it).

So I was jsut wondering if anyone had any ideas for things I could talk about. Try and keep them from being too complex if possible.

Thanks to anyone that helps! :)

CoolGamer48 65 Posting Pro in Training

Hey,

I'm a C++ programmer, but I'm beginning to learn Java, and from what I see so far the two languages are very similar. The main difference I hear is that C++ has pointers and Java doesn't, but from my understanding Java does have pointers in a sense, the user is just not aware of it.

From what I've read in my book so far, I am under the impression that when you declare a variable of a complex data type (not sure if that's the right word, I mean like a self-defined class vs. an int) it is automatically a pointer. You cannot make it so that it is not a pointer. And when you declare a variable with a simple data type, it is not a pointer, and nothing you can do will make it a pointer? Is this assumption correct?

Like, this java code (sorry if there are minor syntax errors, as I'm used to C++):

Student bill;
bill = new Student();
bill.GPA = 4.0;

is equivalent to this C++ code:

Student* bill;
bill = new Student;
bill->GPA = 4.0;

Is that a correct "translation"?

CoolGamer48 65 Posting Pro in Training

hey, is this code:

if(m_velocity.x == 0)
		return 0;
	return ToDegrees(atan(m_velocity.y/m_velocity.x));

any more efficient than this code:

if(m_velocity.x == 0)
		return 0;
else
	return ToDegrees(atan(m_velocity.y/m_velocity.x));

I.e., are we saving any time by omitting the else statement?

CoolGamer48 65 Posting Pro in Training

Ehh, I ran into yet another problem. I really think I don't understand something (or things) that are very fundamental in using header files that's causing me to get all these errors every time I try to do something that I think is very simple.

I have this code in a header file Graphics.h:

extern IDirect3D9* d3d;
extern IDirect3DDevice9* d3ddev;
extern IDirect3DSurface9* back_buffer;
extern ID3DXSprite* sprite_handler;

At first I didn't have the extern keyword, and then I had issues with the linker. It told me I was trying to redefine these and other variables in another header file (Input.h). I tried adding the static keyword to them (not because I understood the problem and I thought that would help, but because I looked at MSDN and some other sources and I had a hunch that making them static might help. I did that and the project compiled, but then I had issues with code that worked fine when it was all in one file. The window would appear but it wouldn't accept input (the only thing I had it set up to do was to exit the program when the user pressed escape). I isolated the problem and found that d3ddev was evaluating to NULL, which resulted in the game loop function not running. I thought that this had something to do with the static keyword, so I replaced it with extern (which, again, seemed like a good idea based on examples from sites and a book of …

CoolGamer48 65 Posting Pro in Training

<< Block.obj : error LNK2001: unresolved external symbol "protected: static class Texture *
<< Block::m_img4" (?m_img4@Block@@1PAVTexture@@A)

class Block : public Object
{
public:
	Block();
	~Block();
<snip>
protected:
	static Texture* m_img1;
	static Texture* m_img2;
	static Texture* m_img3;
	static Texture* m_img4;
};

// outside your class initialize the static member variables ...
Texture* Block::m_img1 = 0;
Texture* Block::m_img2 = 0;
Texture* Block::m_img3 = 0;
Texture* Block::m_img4 = 0;

I added both this:

Texture* Block::m_img1 = 0;
Texture* Block::m_img2 = 0;
Texture* Block::m_img3 = 0;
Texture* Block::m_img4 = 0;

and this:

Block::m_img1 = 0;
Block::m_img2 = 0;
Block::m_img3 = 0;
Block::m_img4 = 0;

Right after the declaration of the Block class in Block.h, and neither worked (the first complained about redefinitions, and the second complained about missing variable types).

I also tried replacing the code in the Block constructor from

m_img1 = new Texture;
m_img2 = new Texture;
m_img3 = new Texture;
m_img4 = new Texture;

To:

m_img1 = 0;
m_img2 = 0;
m_img3 = 0;
m_img4 = 0;

and allocated the memory elsewhere, but that also didn't work.

Any else know what could be wrong?

CoolGamer48 65 Posting Pro in Training

If you want to make good money then I recommend getting yourself a PC and then to learn C++ --> Win32/MFC(or both) --> DirectX/OpenGL(or both which would be better).

Note that DirectX and OpenGL are not game engines (neither are Win32 or MFC). They are APIs. Game aren't really too big on Macs (or Linux). Most commercial games come out for PCs (if for no reason other than more people have them).

From my knowledge of what a game engine really is, there really wouldn't be an engine for a generic game. There's the Unreal engine for shooters (just an example), but you wouldn't use that to make an RPG.

CoolGamer48 65 Posting Pro in Training

When you put implementation code in a header file, then include the header file in two or more *.cpp files the compiler will attempt to copy the function into each of the *.cpp files, and the linker will produce duplicate definition errors

Then what is the purpose of surrounding the code in header files with #ifndef? I thought that prevents the code from being executed twice or something.

Also, is #define old functionality left over from C, and you should usually use const variables and inline functions?

CoolGamer48 65 Posting Pro in Training

I'm away from my home computer right now, but I'll try that when I get home.

But wouldn't code like that be placed in a constructor? And aren't you redifining the type of the variable as Texture*? Why is that redefinition neccesary? I'm a little confused as to what exactly is causing the errors.

CoolGamer48 65 Posting Pro in Training

It would be very difficult to write a game with C++ without the use of a graphics API like Direct3D or OpenGL. The only real function you have with Win32 programming is DrawPixel() (or is it SetPixel()...something like that). Loading bitmaps like that would be VERY difficult.

CoolGamer48 65 Posting Pro in Training

Would it work if I separated the implementation into a different .cpp file (ie, MyMath.cpp)? Because I'd rather not put MyMath. in front of every one of my math functions.

Also, what is an executable function? Are there non-executable functions? And why would putting them in a class fix whatever the problem is?

EDIT: I tried separating the definitions and that worked, but I have another problem.

Block.obj : error LNK2001: unresolved external symbol "protected: static class Texture * Block::m_img4" (?m_img4@Block@@1PAVTexture@@A)
Block.obj : error LNK2001: unresolved external symbol "protected: static class Texture * Block::m_img3" (?m_img3@Block@@1PAVTexture@@A)
Block.obj : error LNK2001: unresolved external symbol "protected: static class Texture * Block::m_img2" (?m_img2@Block@@1PAVTexture@@A)
Block.obj : error LNK2001: unresolved external symbol "protected: static class Texture * Block::m_img1" (?m_img1@Block@@1PAVTexture@@A)

I get these errors. the m_img... variables are members of a Block class (declared in Block.h and implemented in Block.cpp), and Texture is a wrapper class for the IDirect3DTexture9 struct (declared and implemented in Texture.h and Texture.cpp)

Block.h:

#ifndef BLOCK_H
#define BLOCK_H

#include "Object.h"
#include "Texture.h"
#include "MyMath.h"
#include <d3d9.h>

class Block : public Object
{
public:
	Block();
	~Block();
	static int SetBlockImages(IDirect3DDevice9* d3ddev,char* img1,D3DCOLOR transcolor1,char* img2,D3DCOLOR transcolor2,char* img3,D3DCOLOR transcolor3,char* img4,D3DCOLOR transcolor4);
	int SetImage();
protected:
	static Texture* m_img1;
	static Texture* m_img2;
	static Texture* m_img3;
	static Texture* m_img4;
};

#endif

Texture.h:

#ifndef TEXTURE_H
#define TEXTURE_H

#include <d3d9.h>
#include <d3dx9.h>

class Texture
{
public:
	Texture();
	~Texture();
	int InitTexture(char* filename,D3DCOLOR transcolor,IDirect3DDevice9* d3ddev);
	int Draw(float x,float y,float rotation,ID3DXSprite* sprite_handler);
	IDirect3DTexture9* GetTexture();
	D3DXIMAGE_INFO …
CoolGamer48 65 Posting Pro in Training

Hey, so I have a file I use to store my own math functions called MyMath.h. I included MyMath.h in my main.cpp file and it worked fine. But then I tried including it to another file, and I get this error:

Block.obj : error LNK2005: "int __cdecl Random(int,int,bool)" (?Random@@YAHHH_N@Z) already defined in main.obj

Why is that happening? I have the code in the header surrounded by an #ifndef, if that might be it.

Here's MyMath.h:

#ifndef MY_MATH_H
#define MY_MATH_H

int Random(int my_min = 0,int my_max = RAND_MAX,bool use_complex = false);
int Complement(int angle);
int Suplement(int angle);
double Angle(double in_angle,bool use_degrees = true);

#define PI 3.14

int Random(int my_min, int my_max,bool use_complex)
{
	int result = 0;
	if(use_complex == false)
	{
		int range = my_max-my_min;
		result = rand()%(range+1) + my_min;
	}
	else if(use_complex == true && my_min < my_max)
	{
		do
		{
			result = rand();
		}
		while(result < my_min || result > my_max);
	}
	return result;
}

double Angle(double in_angle,bool use_degrees)
{
	double max_angle = use_degrees ? 360.0 : 2.0*PI;

	while(in_angle >= max_angle)
		in_angle -= max_angle;
	while(in_angle < 0)
		in_angle += max_angle;

	return in_angle;
}

int Complement(int angle)
{
	angle = Angle(angle);
	while(angle > 90)
		angle -= 90;
	return 90-angle;
}

int Suplement(int angle)
{
	angle = Angle(angle);
	if(angle > 180)
		angle -= 180;
	return 180-angle;
}

#endif

The line #include "MyMath.h" is found in the top of both main.cpp and Block.h. Block.cpp is what was complaining.

CoolGamer48 65 Posting Pro in Training

The first language I learned was actually C++ (even before HTML), and I didn't find it too hard. Sure, I went sort of slow, but it worked out. You may have to come back to some of the more complicated things though (i.e., pointers, polymorphism). It took me a while and couple of readings of the pointers section of my book to understand why they (pointers) were useful.

CoolGamer48 65 Posting Pro in Training

Wthe ball hits the side of the paddle, it ussualy just goes through the paddle and starts spazing, and then comes out when I move the paddle away. Bouncing on the top side works well, but I have some issues with bottom bouncing as well (when the ball moves below the paddle it starts moving straight until it moves out from under the paddle).

CoolGamer48 65 Posting Pro in Training

Hey,

I have some code for bouncing. It works well most of the time but there are some issues at times. Does this look good?

if(m_position.y+m_height >= paddle->GetY() && m_position.y <= paddle->GetY() + paddle->GetHeight() && m_position.x+m_width/2 > paddle->GetX() && m_position.x+m_width/2 < paddle->GetX() + paddle->GetWidth())
	{
		m_velocity.x += paddle->GetMoveX()*(0.25);
		m_velocity.y *= (-1);
	}
	else if(m_position.x+m_width >= paddle->GetX() && m_position.x <= paddle->GetX() + paddle->GetWidth() && m_position.y+m_height/2 > paddle->GetY() && m_position.y+m_height/2 < paddle->GetY() + paddle->GetWidth())
	{
		m_velocity.x *= (-1);
		m_velocity.y -= paddle->GetSpeed()*(0.15);
	}

The code's in C++, and the scope is within the ball class. So things like m_position and m_width refer to the ball, and paddle->GetX() and paddle->GetWidth() refer to the paddle. if you'd like me to give it in more basic pseudo code let me know.

CoolGamer48 65 Posting Pro in Training

Yes, the second interpretation is correct.
the same exists for rotation, except velocity = angular momentum, and acceleration = torque. But err.. don't worry about rotation, it's evil.

Uhh... I think I'll stick to degrees for rotation.

CoolGamer48 65 Posting Pro in Training

So, wait - what exactly is a velocity vector? A point that the object will move to every frame, and then is updated? Or is it always relative to the current position of the object (I'm guessing its this one). So if you were moving to the left at 5 pixels per frame, the velocity would be (-5,0)?

CoolGamer48 65 Posting Pro in Training

Yes, I like this:

velocity2[x] = velocity1[x] + ( paddle_velocity[x] * some_constant );
velocity2[y] = velocity1[y] * -1;

solution a lot. I had thought of something like that before, but I thought that the code was just affecting the speed of the ball (which I didn't want to worry about yet). I didn't think of that fact that changing the x movement while not changing the y movement will result in a change of angle. I especially like this solution because it avoids trig (which I hear really taxes the proccesor) as well as keeping track of the angle of movement.

Now, the one thing I'm thinking about is that there should be some sort of gradule friction, as well as a maximum ball speed, otherwise the ball speed would get out of hand. I'm thinking that figuring out the maximum ball speed might require some inverse trig functions. Is there another way to figure out the ball's speed w/o trig?

Edit: O, well I just thought of simply putting upper and lower limits (and friction) on the x and y velocities seperately. This would avoid trig, but the friction would be a bit unrealistic. But, hey, games are supposed to be fun, not realistic.

CoolGamer48 65 Posting Pro in Training

I didn't have time to read through that yet, but I've heard that distance from center thing before, and I don't necessarily get it. If the paddle isn't moving, the distance from the center of the paddle shouldn't affect the angle of the ball's path of motion (correct me if I'm wrong). And if the paddle is moving, I don't see the distance from the center playing as big a role in the change of direction as I do the direction the paddle is moving relative to the horizontal direction of the ball.