CoolGamer48 65 Posting Pro in Training

Hey, so I'm making a Breakout game in C++ w/ DirectX, and I'm having some trouble thinking of the ball bouncing physics. The way I've made breakout games before was to have the ball only move at 45 degree angles. This was fairly simple. Just reverse the x or y movement everytime you hit something. But now I want to make a game where the ball moves not just at 45 degree angles. The way I see it, bouncing against non-moving blocks will not change the direction that the ball is moving (that is angle-wise, obviously it will bounce off, but the angle that the ball is moving won't ever change to anything other than 45, 135, 225, or 315 degrees. So I came to the conclusion that the only way to change the angle is when the ball collides with a moving object, i.e., the paddle. But I'm not sure how this works exactly. How do I calculate the change in angle based on the movement of the paddle, the place the ball hits the paddle, and the angle the ball is currently traveling at. I look online for some tips but I couldn't find much that gave an algorithm and explained it. So anyone have what I'm looking for. How do I use the factors I just mentioned along with any others I might need to take into consideration to write the code for this?

Any and all help is appreciated. :)

CoolGamer48 65 Posting Pro in Training

Hey, am I correct in assuming that when you declare a function virtual in a prototype, it is illegal to use the virtual keyword again when you define the function?

CoolGamer48 65 Posting Pro in Training

Ive tried to install it and it has an error when installing, guess ill go with Dev-C++.

Eh.. well I guess that's pretty sad for Microsoft.

Personally, I like Dev-C++ for simple console apps (which is what you'll most likely be starting with), but once you get into writing more complex programs, I think Visual is better. Its source editor is a lot more helpful (it tells you what the parameters are for functions as you type them, gives you a list of members of a class when you need them, among other things)

CoolGamer48 65 Posting Pro in Training

If Microsoft Visual C++ 2008 doesn't work on Microsoft Vista, that's pretty sad for Microsoft.

CoolGamer48 65 Posting Pro in Training

First, some stuff on cleaning up your code. Skip to the bottom for the solution I think you're looking for.

second = (number-dig1) / 100;
dig2 = second % 10;

looks like it should be just dig2 = (number-dig1*1000) / 100; So if your number is 3255, digit one would be 3, then 3255-3*1000 = 255, and then that divided by 100 equals 2 (with int truncation).

Then, for the third number, you have

third = number / 10;
dig3 = third % 10;

The variables second, third, and fourth seem unneccesary to me. Just do dig3 = ((number-dig1*1000)-dig2*100)/10 . That way, with the 3255 example, dig1 = 3, number-dig1*1000 = 255, and that minus dig2*100 = 55. 55/10 is 5, your third digit.

And a simmilar thing with dig4: dig4 = (((number-dig1*1000)-dig2*100)-dig3*10) .

The code you have may have worked too, but this seems less messy. There may be better ways still to do this, but w/e.

The reason that your program is only doing it once, is that you have return 0; at the end of your loop (in the loop, not after it). This means that after one iteration of the loop the program will terminate. Move return 0; to outside the loop, but still inside the main() function.

CoolGamer48 65 Posting Pro in Training

First off, for(;conditional;) is the same as while(conditional) . So you can fix that. Also, initial_loan_amount is being declared but not initialized (i.e., its filled with nonsense). Fix that.

CoolGamer48 65 Posting Pro in Training

Ehh... I may switch to another API if I can't figure this out.

I do believe the sample uses the file I was referring to. Does anyone know of any tutorials for DirectSound? I'm curious to see how they will do it. I may trying to switch to more open APIs like OpenGL, because the only real thing I use DirectX for is Direct3D. I do use DirectInput, but I can get key presses with GetAsyncKeyState() and I'm sure there's a way to get mouse input. DirectPlay is deprecated, and I can't really get DirectSound to work.

So anyway, any DirectSound tutorials appreciated.

CoolGamer48 65 Posting Pro in Training

Right after p2hp -= p1attack; , add:

if(p2hp < 0)
    p2hp = 0;

You may also try making the health values unsigned, though the above method should work well enough

CoolGamer48 65 Posting Pro in Training

You could get the whole thing into a string or an array and then convert it into Int.

Yes, that approach would be effective. However the OP said something about using modulus to find the answer, which you wouldn't need if you took the data in as a string.

So it would be good if the OP could post the exact promt.

CoolGamer48 65 Posting Pro in Training

There are a whole bunch of posts like this below somewhere, but basically - try to learn C++ if you don't already. You're going to have to spend some time on just console applications, and that might get boring if you've got games in mind, but have patience. Then, once you've got C++ down pretty well, learn to use a graphics API like Direct3D (part of DirectX) or OpenGL along with C++.

CoolGamer48 65 Posting Pro in Training

Hey,

So, I'm trying to learn DirectSound, and imagine my delight to learn that DirectSound doesn't have any interface for loading wave files! So MSDN refers me to the DXUT.h file that can be used to load .wav files and even to take care of some DirectSound stuff for you. Neato! Unfortunately, it requires a unicode build instead of multi-byte. Now I'm not exactly sure what that means, but all I know is I don't want to have to cast every string I have with (LPCWSTR).

So, is there some other interface that I can use with DirectSound to load .wav files (or some other sound file format), or some other API I can use all together (would prefer it if I didn't need to switch to a whole other API)? Basically just looking for advice on what's best for playing sounds.

CoolGamer48 65 Posting Pro in Training

No it doesn't. He had the basic code for it somewhere above. You take in the number as one value using cin, and you yourself take it apart and figure out the different digits. If the number is four digits long, we can obtain the thousands place with floor(number/1000), the hundreds place with floor((number%1000)/100), the tens with floor(((number%1000)%100)/10), and the ones with floor(((number%1000)%100)%10).

CoolGamer48 65 Posting Pro in Training

I believe every four digit number had to be taken in at once, not each digit separately (otherwise your approach works). But I'm not sure exactly, so I'm waiting for him to try and clarify exactly what the program needs to do.

CoolGamer48 65 Posting Pro in Training

If you'd like to being learning C++ (I'm guessing you do seeing this is the C++ forum). cplusplus.com is a good online resource. If you're looking for a book I learned C++ from C++ for Dummies, and I'd recommend that or other books by Stephen Randy Davis. Dev-C++ is a nice compiler for basic console apps, and Microsoft Visual C++ is a nice compiler I like using for slightly larger projects (I love it's code editor).

CoolGamer48 65 Posting Pro in Training

Do you have the exact prompt with you? Could you post it, because I doubt that all six of the inputs would be put in at once without any breaks. I think they might mean that the digits within each of the six numbers need to be taken it at once, but not all the numbers together.

CoolGamer48 65 Posting Pro in Training

Er... at first you said

the given integers will all consist of four digits

. But you just mentioned six digits. And then you gave 325510671393289211112020, which is a 24 digit number, and then broke it up into six sections of four digits, treating each one like a "digit". Then you performed the digit operations that you mentioned (first*3 + second*third - fourth) on the first four of those "digits", and just ignored the last two. What exactly is the program supposed to do? Give an example of input, output, and an explanation, because what you just said contradicts what you said originally.

CoolGamer48 65 Posting Pro in Training

There is no need to use floor() as int truncates any decimal place as it is.

Is that method of truncation considered "safe"? I thought it wasn't a good idea to let C++ take care of the truncation for you when you pass a non-integral number to an int.

CoolGamer48 65 Posting Pro in Training

Well i am sorry .. MAde a bad comment on that one. I respond with DEEP apologies.

And edit my post as well

No need to apologize - just pointing it out. Everybody makes mistakes.

CoolGamer48 65 Posting Pro in Training

As for the floor() thing, I think you are getting floor() confused with a rounding function. floor() always rounds down, so floor(3.812) would be 3, not 4. conversely, ceil() always rounds up. so ceil(3.224) would be 4, not 3.

if you used abs() to truncate the non-integral part of the number, you would just be doing the same thing that he's currently doing, only doing indirectly through the abs() function, and not on your own.

CoolGamer48 65 Posting Pro in Training

I skimmed the article, but is the only problem with rand() that RAND_MAX may not be one less than a multiple of your maximum? Like if you do rand()%3, and RAND_MAX+1 is a multiple of 3, will that be truly random?

CoolGamer48 65 Posting Pro in Training

I actually put the code in 47 Keeping in mind that there is an option for an attacker not to attack also. right

For example if the user enters something other than "A".

Hmm.... yes you're very correct. In fact, the same thing should be done to the player1 code, because if p2hp -= p1attack; is called and p1attack hasn't been initialized, you'll get not so optimal results.

So either change it, or in the beginning of the loop set p1attack and p2attack to 0.

CoolGamer48 65 Posting Pro in Training

Or, if you'd like to keep in consistent with the code for player 1's attack, you could simply put it outside of the switch statement but inside the while loop (like line 57 or 58 in Sky Diploma's program). If you do do that though, remember to take away that same code from line 47.

CoolGamer48 65 Posting Pro in Training

You might want to repost your program (using code tags) to see if it really was fixed.

Also, you may want to change something like

first = number/1000;

to

first = floor(number/1000);

floor() is declared in math.h (so add #include<cmath> or #include<math.h> to the top of your source). i think it would be better than simply relying on the integer round down, but it won't really change your program's results.

CoolGamer48 65 Posting Pro in Training

As long as the number of people lured into the industry by the idea of fame and fortune is enough to make up for the people leaving it for normal work weeks, life outside the office, and preventing burnout at 30 there will continue to be enough people to churn out games.

And yes, then there are the people who don't know anything else and can't adept to other work.

Just curious - were you actually a game programmer somewhere? Or do you know people that have been and then left? Or do you have another source?

CoolGamer48 65 Posting Pro in Training

If all the people who program games hate it, why do they stay there? I mean games still come out - there have to be some people who don't leave for different jobs (or die).

CoolGamer48 65 Posting Pro in Training

Im not exactly sure if this would work, but couldn't you just use srand() to ensure that results of same names come out the same. Like use the length of both strings combined instead of time(NULL). not sure if this will work though.

CoolGamer48 65 Posting Pro in Training

Ehh.... nevermind. It turns out it's cause my video card is old and weak. :(

CoolGamer48 65 Posting Pro in Training

start with this

bool discr(double array2[3], double &result)

do you know how to use c++ references?

Are references less or more efficient than using pointers? Also, if I were to call this function, would the second parameter be simple of type double? or would it be double*?

CoolGamer48 65 Posting Pro in Training

first u asked me to go for c++...u said u urself started with c++ ...then why now diretx?????

C++ is a programming language that you should learn. DirectX is NOT a programming language. It is an API (application programming interface). Basically, it's a whole bunch of functions and classes and structures that you can use with C++ (or other languages) to help the user(programmer) make graphical games more easily.

Put simply, you are not using DirectX instead of C++ - you are using it with C++.

this c++ or directx or opengl...or somthing else???

i dont want..that..first i do one language and then switch to another..n then another.....

As i've said, DirectX is an API that is used with programming languages, and so is OpenGL. You should learn how to make basic applications with C++, then learn how to use either DirectX OR OpenGL to make games.

To be a bit technical: DirectX isn't used just for graphics. DirectX is made up of several different APIs, like Direct3D(3D graphics), DirectSound (playing sounds), DirectInput (getting input from the keyboard and mouse), DirectPlay (used for making online or networked games), and some others. OpenGL is not a set of APIs like DirectX, it is ONE API that's used for 2D and 3D graphics.

A side note: I really hope that you actually are new to forum culture, and that you actually don't know English perfectly. I've got absolutely no problem with people who are new to things (forums …

CoolGamer48 65 Posting Pro in Training

in that case you didn't learn it properly. You learned a few tricks maybe, but nothing in depth and no proper introduction in the philosophy behind the language, paradigms, etc. etc.

Syntax is easy to learn, but it's not programming.

So what is programming? Why was the way I learned it improper? What's an example of something you doubt I learned from the book?

CoolGamer48 65 Posting Pro in Training

Um, seeing as I have around 50 views and no replies (other than myself), I'm thinking this would be better off in the game dev forum. Is is possible for a mod to move it?

CoolGamer48 65 Posting Pro in Training

and don't buy any book calling itself "for dummies".

I don't know about that.... The first real language I learned was C++ and it was from a "for dummies" book.

CoolGamer48 65 Posting Pro in Training

DirectX and OpenGL are not programming languages. They are APIs (application programming interfaces, wiki it if you want) that can be used with other programming languages (like C++).
As far as which one is better, don't know if I can help you too much there.

The only real programming language I know is C++, and I'm currently learning to use DirectX with it. If you're a fan of things be open-source and multi-platform (or a Microsoft hater), then you might want to go with OpenGL. DirectX is strictly Microsoft. As far as how good the actual APIs are, I don't think that DirectX is really that much better or worse than OpenGL (but that's just from what I've heard - I've never actually used OpenGL).

As far as what language to use, C++ is probably the way to go, though as I've said, I haven't had too much experience with other real programming languages.

CoolGamer48 65 Posting Pro in Training

Would that mean i'd have to get the time from user twice. Once for hour and once for minutes? Right now it's just accepting the time as a whole (in military)

time as a whole in what format? as a string? separated by a colon?(e.g., 13:49) you don't need to ask the user for input twice (that might make things easier though) but you do need to somehow separate the hours and minutes values (either before our after you ask for the input)

CoolGamer48 65 Posting Pro in Training

graphics is not part of either c or c++ languages.

I think he meant that he has not learned how to create programs that use 3D or advanced 2D graphics (like those used by a game) in C++ yet. Obviously what you said was correct, but someone who hasn't made a graphics program yet might misinterpret that to mean that you can't make graphics programs in C++.

As a beginner/intermediate at programming, I've found that books are usually a much better learning resource that web tutorials (except maybe for w3schools.com, but that's web development only). So go buy books. You say you know C++. How well exactly? Are you up to speed with classes and pointers? If not, I started learning C++ from C++ for Dummies, by Stephen Randy Davis, though if you have some basic knowledge of C++, you may be able to skip that and learn as you go. I began basic game development from Beginning Game Programming, by John S. Harbour. That introduces you to some basic windows programming and then delves into DirectX. I'm currently making my way through Programming a Multiplayer FPS in DirectX, by Vaughn Young (btw, none of these authors have paid me anything). It covers a lot of ground but doesn't (and probably couldn't) delve in to every detail of what's going on. btw, if anyone knows a thing or two about DirectX - help please?

A lot of those resources should help you. That's pretty …

CoolGamer48 65 Posting Pro in Training

Um, anyone? Would this get better results in the GameDev forum?

CoolGamer48 65 Posting Pro in Training

Um, do you mean something like:

if(minutes > 59)
{
//whatever error you want to come up, ex:
cout << "Error: minutes entered was over 59";
}

where minutes is already defined as the number of minutes you got from the user.

CoolGamer48 65 Posting Pro in Training

Ok. Just so you know - initialize does absolutely nothing (well it, does ask for and store a number, but then it does nothing with that number and no other part of your program can access the number since it goes out of scope).

CoolGamer48 65 Posting Pro in Training

Um, ok, first of all, what exactly is z for?

Second - look at this:

void initialize (int& x,int& y,char& z)
{
int num;
cout<<"Enter Integer"<<endl;
cin>>num;
}

This function takes in three parameters but does nothing with them. Try to fix that... I'm not entirely sure what you're trying to do here anyway

CoolGamer48 65 Posting Pro in Training

The amount went to 500. I need it to be 460 though. I feel we are almost there though.

Sorry - it's

amount = (40*rate) + (( hours - 40 ) * ( rate * perhour));

That's should do it.

And just fyi, on line 34 you have

else if (hours >= 40)

. This won't affect your program at all, but it should be:

else if (hours > 40)

, since if amount == 40, you would want the first if block to handle the code

CoolGamer48 65 Posting Pro in Training

I had already started it and used friend function to calculate the total toll fee,static member function to calculate the total no. of vehicles that passed the tollstation but my codes ain't right.

What isn't right exactly? Show us a sample of what you have and why/where it's not working to the best of your knowledge.

CoolGamer48 65 Posting Pro in Training

Allright, so as I understand it: the fact that perhour = 1.5 means that for any hours worked over 40 hours, you receive 1.5 times your regular rate (perhour seems like a weird name for that). If that's the case, then this line (35):

amount = (( hours - 40 ) * ( rate * perhour));

is only calculating the EXTRA money earned. Not the total money earned. To get the total, you would replace the line above with:

amount = (hours*rate) + (( hours - 40 ) * ( rate * perhour));
CoolGamer48 65 Posting Pro in Training

If you didn't get it from the above post:

on line 14, you declare amount as a double, but don't initialize it to anything. then, in the getHoursRate() function, you declare a SECOND double called amount, which will go out of scope as soon as the function ends. you're saving the value you want for amount in getHoursRate()'s version of amount, and then, on line 16, your using main()'s version of amount, which is still uninitialized, and that's why you get some really weird number for your output.

getHoursRate() either needs to take a third reference to amount, or it needs to return the amount, which you would then store in main()'s version of amount.

Edit: you've got a simmilar situation with initialize. you've got three parameters, but you're not doing anything with them

CoolGamer48 65 Posting Pro in Training

I keep getting D3DERR_INVALIDCALL from my CreateDevice() call. Here it is:

long dev_result = d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,m_window,D3DCREATE_MIXED_VERTEXPROCESSING,
&d3dpp,&m_device);

I think the problem is with m_window. Here's its creation:

if((m_window = CreateWindow("WindowClass",m_setup->name,g_deviceEnumeration->IsWindowed() ? WS_OVERLAPPED : WS_POPUP,0,0,800,600,NULL,NULL,m_setup->instance,NULL)) == NULL)
	{
		MessageBox(NULL,"Error creating the window","CreateWindow()",MB_OK | MB_ICONERROR);
		return;
	}

It's really weird. I put breakpoints in the code, and somtimes m_window appears to be fine (CreateDevice() still fails) and other times it seems like it wasn't initialized. On both occasions I've never gotten the "Error creating the window" message box I set up. Could something be corrupting the window between the the two functions? This is all the code I have in between those two calls:

D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS));
	d3dpp.BackBufferWidth = g_deviceEnumeration->GetSelectedDisplayMode()->Width;
	d3dpp.BackBufferHeight = g_deviceEnumeration->GetSelectedDisplayMode()->Height;
	d3dpp.BackBufferFormat = g_deviceEnumeration->GetSelectedDisplayMode()->Format;
	d3dpp.BackBufferCount = m_setup->totalBackBuffers;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = m_window;
	d3dpp.Windowed = g_deviceEnumeration->IsWindowed();
	d3dpp.EnableAutoDepthStencil = true;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
	d3dpp.FullScreen_RefreshRateInHz = g_deviceEnumeration->GetSelectedDisplayMode()->RefreshRate;
	if(g_deviceEnumeration->IsVSynced() == true)
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
	else
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

	SAFE_DELETE(g_deviceEnumeration);

basically setting up the presentation parameters. I don't see anything that would cause m_window to become corrupt if it wasn't already. Anyone have any ideas? This is the second day I've been at this.

Thanks a bunch to anyone that helps! :)

CoolGamer48 65 Posting Pro in Training

Nvm - I had forgotten to define some prototypes having to do with the device. I'm not sure why that caused a linker error, but it works fine now.

CoolGamer48 65 Posting Pro in Training

Hey,

I keep getting this error:
error LNK2019: unresolved external symbol "public: struct IDirect3DDevice9 * __thiscall Engine::GetDevice(void)"

when I try to compile my project. MSDN says that IDirect3DDevice9 uses d3d9.lib, but it still won't work even with that lib in additional dependencies. (using VC++ 2008) I tried linking to a whole bunch of other libraries that sounded like they might have something to do with the Direct3D device, but nothing worked. Anyone know what I can do? thanks.

Edit: just fyi, I also got an error that Direct3DCreate9 was an unresolved external symbol, but when I add d3d9.lib, that goes away, but IDirect3DDevice9 stays.

CoolGamer48 65 Posting Pro in Training

Hey,

I'm having problems with my OS. At random times - right after I press Ctrl + 'S', the system just restarts (which is annoying because whatever I just tried to save is lost). It's happened around 4 or 5 times so far, but they've all been spread apart. But just today it happened twice in a row - which really ticked me off. My first thought was that some key combo near ctrl + 'S' is causing the computer to restart - but whenever I log in I get a message saying that the system has recovered from a serious error, so I'm guessing it's not that.

The error signature is as follows:
BCCode : 1000008e BCP1 : C0000005 BCP2 : 804DC033 BCP3 : EF775C80
BCP4 : 00000000 OSVer : 5_1_2600 SP : 2_0 Product : 256_1

When I tell windows to send an error report to Microsoft, it says the error was due to a problem with a device driver. This is the page I got:


Problem caused by Device Driver

You received this message because a device driver installed on your computer caused Windows to stop unexpectedly. This type of error is referred to as a "stop error." A stop error requires you to restart your computer.

More information

--------------------------------------------------------------------------------

Problem report summary


Problem type
Windows stop error (a message appears on a blue screen with error code information)

Solution …

CoolGamer48 65 Posting Pro in Training

Hey - so I'm writing this game engine with help from a book. I'm encountering some difficulties with DirectInput. I keep having problems when I try to poll the keyboard.

When I first try to poll the keyboard - i get DIERR_NOTACQUIRED - which I found out means that the device is not acquired. now, i believe that I am calling the Acquire() method of the IDirectInput8Device for the keyboard (I have tested this and it says I'm successfully acquiring the device), but I still atempt to reaqcuire the device. this works successfully, again, and the game once again tries to poll the keyboard. this time, I get DIERR_INPUTLOST - which means the input device was lost and I need to reacquire it. so i do, successfully a third time, and it still throws a DIERR_INPUTLOST error when I try to poll the mouse. anyone know what's going on?

here's the part of the code that polls the mouse:

void Input::Update()
{
	MessageBox(NULL,"Input::Update() invoked","Test",MB_OK);
	static HRESULT result;

	//poll the keyboard
	while(1)
	{
		MessageBox(NULL,"Entered the keyboard polling loop","Test",MB_OK);
		m_keyboard->Poll();

		if(SUCCEEDED(result = m_keyboard->GetDeviceState(256,(LPVOID)&m_keyState)))
		{
			MessageBox(NULL,"Keyboard updated, breaking loop...","Test",MB_OK);
			break;//we succeeded in updating the keyboard, break out of the loop
		}

		if(result == DIERR_INPUTLOST)
			MessageBox(NULL,"Error: DIERR_INPUTLOST","test",MB_OK);

		if(result == DIERR_NOTACQUIRED)
			MessageBox(NULL,"Error: DIERR_NOTACQUIRED","test",MB_OK);

		if(result != DIERR_INPUTLOST && result != DIERR_NOTACQUIRED)
		{
			MessageBox(NULL,"Unknown error encountered, aborting...","Test",MB_OK);
			return;//we don't know what to do with the error returned to us, abort the function
		}

		MessageBox(NULL,"Atempting to reacquire keyboard to solve known error","Test",MB_OK);
		if(FAILED(m_keyboard->Acquire()))//try to reaquire the …
CoolGamer48 65 Posting Pro in Training

So, say I wanted someone to provide a function that performs a mathematical function on two integers that returns an integer, I would define the "variable" to hold the function as

int (*MathematicalFunction) (int num1, int num2);

Then I could make a function called add:

int Add(int addEnd1, int addEnd2)
{
return addEnd1 + addEnd2;
}

then you do

MathematicalFunction = Add;

and so

MathematicalFunction(5,6)

would return 11?

but, if I had defined Subtract:

int Subtract(int myNum1, int myNum2)
{
return myNum1 - myNum2;
}

and set that as Mathematicl function - then

MathematicalFunction(3,4)

would return -1?

CoolGamer48 65 Posting Pro in Training
ResourceManager(void (*CreateResourceFunction) (Type** resource, char* name, char* path) = NULL)
	{
		m_list = new LinkedList<Type>;
		CreateResource = CreateResourceFunction;
	}

hey - this is code for a contructer for a class (taking the code from a book I bought). What exactly is the parameter of the function? Is the parameter like a refrence to another function? CreateResource is defined as:

void (*CreateResource)(Type** resource, char* name, char* path);

as a private member.