Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 30 Jun 2009
Offline Last Active Dec 05 2014 10:12 PM

Topics I've Started

Function "Overload" Question

17 June 2012 - 05:00 PM

This is a long shot, but is there any way, in C++, to overload a function such that it takes an arbitrary number of parameters (without explicitly overloading it a thousand times) and can evaluate various control structures and/or output the "parameter number" (ie foo(a, b, c), where "a" is parameter 0, "b" is parameter 1 etc? Obviously each of the arbitrary number of parameters would have to be the same type. An example of my ideal solution...:

[source lang="cpp"]foo(any number of std::strings){ std::string str; cin >> str; if (str == any of the input strings){ return parameter_number_of_the_string_it's_equal_to; } // if} // foo[/source]

Struct Initialization Within Struct

17 June 2012 - 01:11 PM


Is it possible to call a constructor with parameters for a struct within another struct? (Something like this, though VC++ is highlighting the "2" in myA and saying it wants a type specifier, so this is obviously wrong).

[source lang="cpp"]struct A{ int iSize; A(int x = 10) { iSize = x; }}; // Astruct B{ A myA(2);}; // B[/source]

Essentially I want a struct that has a standardized initial Size member, but I also want to be able to specify a different Size member for it when it is itself a member of other structs.

Determining and Displaying All Feasible Movements (Tile Based "Pathing")

20 February 2012 - 08:16 PM

I've poked around the forum a bit and saw some similar topics but most of them are about finding the shortest/most efficient path between two points, whereas I'm looking for ALL of the paths between ALL points that a character can reach

I have a square tile-based map in a Fire Emblem-esque TBS game and I'm trying to figure out the quickest way to determine and highlight all of the squares a given unit can move to when I click on the square it occupies. Each unit has a predetermined number of spaces it can move to in a turn (potentially being affected by terrain, but that's an issue for another time), and movement is to adjacent squares only (not diagonally). Obstacles such as allied units, enemy units and permanent fixtures on the map need to be navigated around (I'll decide later whether or not allied units can be moved through later - it shouldn't add too much work to modify later I hope).

I've got a basic algorithm that looks at every potential path a unit could follow and highlights the tiles along the way, but it's wildly inefficient (to code as well as to run), and it gets progressively messier as the movement range of a unit increases.

The biggest problem I've been seeing over and over is the fact that many tiles can be reached from more than one tile, so progressively expanding the known "reachable area" by looking at each tile only once or twice doesn't seem to work (at least not with any method I've thought of).

Thanks in advance,


Basic Line Drawing

31 May 2011 - 08:11 AM

I'm starting small with Win32 and doing a basic battle type system to get used to displaying things.

void draw_opp_health(HDC hdc)
	HPEN hPenOld;

	HPEN hLinePen;
	COLORREF bar_colour;
	if (opponent.current_hp / opponent.max_hp > 0.5) // Green > 50% health
		bar_colour = RGB(55, 220, 30);
	else if (opponent.current_hp / opponent.max_hp > 0.1) // Yellow > 10% health
		bar_colour = RGB(225, 225, 0);
	else // Red < 10% health
		bar_colour = RGB(225, 0, 0);
	hLinePen = CreatePen(PS_SOLID, 7, bar_colour);
	hPenOld = (HPEN)SelectObject(hdc, hLinePen);

	health_bar = ((opponent.current_hp / opponent.max_hp) * 150) + 110;
	// int			    // int starts at 100	    // const int 100	   	   //positioning the health bar

	// Opponents health
	MoveToEx(hdc, 110, 113, NULL);
	LineTo(hdc, health_bar, 113);

	SelectObject(hdc, hPenOld);

I'm trying to redraw the health bar to a percentage of its maximum amount (changing colours as health decreases).
So (as of this testing phase) when I click the left mouse button, opponent.current_hp decreases by 20 and i redraw the window.
Initially, when it's all drawn, current_hp is 100 and max_hp is 100 so health_bar evaluates to 260 and the line is drawn properly. Then on my first click the line is redrawn red and short (essentially a circle... I'm pretty sure it's a line of length 0 but the computer can't do that... Either way, not important right now).
Can anyone tell me why the line isn't being redrawn 20% shorter each time?

Iterating though a vector: Pointers?

05 May 2011 - 10:38 AM

Hi, I'm new to game programming so this might just be completely the wrong way to go about this. I'm trying to read from two files, names.txt and scores.txt which record the names of the people on the high-scores table and their scores respectively and insert the new name and score so the scores are increasing on the high-score table

char broke = 'n';
		for (int i = 0; i < score_string.size(); i++)
			vector::iterator it = score_string.begin() + i;
			if (atoi(score_string[i].c_str()) <= new_score)
				name_string.insert(it, player);
				score_string.insert(it, convert_int(new_score));
				broke = 'y';

Where 'broke' just records the fact that the loop was exited early for use later on, name_string and score_string are vectors containing the names and scores respectively and new_score is the integer value representing the score of the current player. Both name_string and score_string are the same length by default and whenever I modify one, I modify the other, but for some reason I keep getting an error saying the vector iterator is outside of the range.

The rest of my code seems to work fine, it's just trying to insert the new score that causes problems. Am I supposed to use pointers with the iterator? If so could you explain how?