<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Health Bar Drawing Question</title>
		<link>http://www.allegro.cc/forums/view/606543</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 01 Mar 2011 21:08:52 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So for my game, I am attempting to draw a health bar on the screen. The health bar is a gray capsule on the side of the screen that contains blue squares separated by black space. Each time the player is hurt, I want one of the blue squares to go away.</p><p>I am trying to determine the most efficient way to go about redrawing my health bar after the player is hurt.</p><p>If I have a total of 10 squares, I wouldn&#39;t want to draw 11 different health bars (1 for empty) in paint (currently my sprite-creation program) and load a new image each time the player is hurt. That is dumb. And I considered making a small bitmap the size of a square that is black, which would be drawn over a blue square every time the player is hurt.</p><p>I also considered creating one blue square bitmap, and drawing that to certain locations within the health bar to make it fill up. Once the player is hurt, that draw_sprite() function corresponding to that square could be skipped over.</p><p>But again, this procedure seems... not right. I don&#39;t know why.</p><p>Any suggestions?</p><p>Thank you,<br />opiaboy
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (opiaboy)</author>
		<pubDate>Sun, 27 Feb 2011 03:35:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> x <span class="k3">=</span> health_x<span class="k2">;</span>
<span class="k1">int</span> y <span class="k3">=</span> health_y<span class="k2">;</span>
<span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span> <span class="k2">;</span> i <span class="k3">&lt;</span> health <span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span> <span class="k2">{</span>
   <a href="http://www.allegro.cc/manual/rectfill"><span class="a">rectfill</span></a><span class="k2">(</span>buffer , x , y , x <span class="k3">+</span> <span class="n">5</span> , y <span class="k3">+</span> <span class="n">5</span> , <a href="http://www.allegro.cc/manual/makecol"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
   x <span class="k3">+</span><span class="k3">=</span> <span class="n">10</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
<img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 27 Feb 2011 03:59:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606543/905422#target">opiaboy</a> said:</div><div class="quote"><p>But again, this procedure seems... not right. I don&#39;t know why.</p></div></div><p>I&#39;d either go with that last option, or using <span class="source-code"><a href="http://www.allegro.cc/manual/rectfill"><span class="a">rectfill</span></a><span class="k2">(</span><span class="k2">)</span></span> instead to draw the health blocks.</p><p>Also if you&#39;re double buffering, you&#39;re probably going to be redrawing the entire screen each frame, so you won&#39;t need to draw <i>over</i> other colors, just draw blue bitmaps or rects for each health square the player still has, and none or black for ones the player doesn&#39;t have.</p><p>In fact, you could draw a translucent black rectangle that covers the entire health meter, then for the area that the player still has, draw a solid colored rectangle over top of that. That should look a little fancier. If you get fancy with drawing a couple rectangles for the colored part, you can even make it look shiny or glassy.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 27 Feb 2011 04:01:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This method would work perfectly! I mean, I was thinking about something like this (I forgot a about the rectfill function though). But the reason I didn&#39;t do so was because I was worried that it wasn&#39;t the most straightforward or efficient method. Is there anything else that would be more efficient? If there is I have no clue what it would be.</p><p>Thank you for your help!</p><p>EDIT: Oooh, making it look glassy would be neat!</p><p>When the game is COMPLETELY finished (meaning, I have no clue when I would get to this) I want to only redraw sections of the screen that need to be redrawn. So... would that change anything?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (opiaboy)</author>
		<pubDate>Sun, 27 Feb 2011 04:06:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s too early to really worry about how efficient your program is. Get your program working first, and then profile it to see if/where you need to optimize it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 27 Feb 2011 04:10:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Let&#39;s say that you have 10 health bar &#39;boxes&#39; to indicate health.</p><p>If the player gets hit once, does an entire health &#39;box&#39; disappear, or does it only fill part of the way?
</p><div class="source-code snippet"><div class="inner"><pre><span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="c">// full health</span>
<span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span> <span class="k2">]</span> <span class="c">// hit once (last one is empty)</span>

...or...
<span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span>x<span class="k2">]</span> <span class="k2">[</span><span class="k3">/</span><span class="k2">]</span> <span class="c">// hit once, only 1/2 of last bar is filled</span>
</pre></div></div><p>

If these will simply be &quot;10 hits&quot; and the player is dead, you can simply loop from <span class="source-code"><span class="n">0</span>..<span class="n">9</span></span> and print the health &#39;box&#39; next to each other (with a small offset for the gap between then).</p><p>Otherwise, you will want to use <span class="source-code"><a href="http://www.allegro.cc/manual/rectfill"><span class="a">rectfill</span></a><span class="k2">(</span><span class="k2">)</span></span> or similar, like Thomas suggested, and fill up the each &#39;box&#39; the appropriate amount (1/2 per box, or even 1/10th so 10 boxes of 10 gives a total of 100% health).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Sun, 27 Feb 2011 04:10:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you all for your help!</p><p>That is the reason I love using Allegro; not only are there about a billion examples and tutorials floating around the internet, but the forums here are filled with people who respond promptly and are willing to help aspiring programmers.</p><p>Thank you again... and Edgar, what do you mean by &quot;profile&quot;?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (opiaboy)</author>
		<pubDate>Sun, 27 Feb 2011 04:15:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A profiler is a special tool that measures the time each of your function takes. If you&#39;re using MinGW then you compile your sources with the -pg flag, run your program and then use gprof to analyze the profiling log produced by your program (when a program compiled with -pg is run, it produces a file called a.out, which contains the profiling information).
</p><pre class="terminal">&gt;mingw32-g++ -Wall -O2 -pg -o main.exe main.cpp -Wl,--subsystem,windows
&gt;main.exe
&gt;gprof a.out &gt; main_profile.txt
&gt;type main_profile.txt</pre><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 27 Feb 2011 04:21:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Aaaah, got it. I&#39;m using Visual Studio C++ 2008 Express Edition... if that helps? <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=";D" border="0" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (opiaboy)</author>
		<pubDate>Sun, 27 Feb 2011 04:24:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Express doesn&#39;t include a profiler. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 27 Feb 2011 04:31:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Give Very Sleepy <a href="http://www.codersnotes.com/sleepy">http://www.codersnotes.com/sleepy</a> a try, it is my favorite profiler.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Sun, 27 Feb 2011 10:09:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you like a good IDE, that is free and has a profile, I recommend netbeans.</p><p>Netbeans and MS visual Studio are the best IDEs that I have used as far as interpreting the source code goes (such as correctly colouring and fading pasts based on macro definitions in conditional compilation blocks and the like). I use Visual Stuodio 2010 Express wit the win7 sdk 7.2 for 64bit pe compilation support on windows 7, and netbeans on archlinux (I do profiling and debugging mostly on linux but I further develop the same code on both platforms interchangeably because the IDEs are of the same high tier AFAIC).</p><p>Either that or +1 to trying very sleepy</p><p>But seriously I slightly prefer netbeans&#39; interface and it has a heap usage profiler visible by default while it is running your program. Just create a makefile project with it and write your own Makefiles, that&#39;s what I do. The only project configuration I do in netbeans beyond telling it to call my makefile is telling it which preprocessor defines I have as active by default so I can see my code as it will usually compile.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (m c)</author>
		<pubDate>Tue, 01 Mar 2011 05:53:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For Intellisense on Visual Studio I use Visual Assist
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Tue, 01 Mar 2011 06:12:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You GOTTA have Visual Assist X for Visual Studio. Otherwise, you shouldn&#39;t be using Visual Studio <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />. Really; it makes that much of a difference.</p><p>I&#39;ve been doing all of my programming in a regular text editor that at least supports regular expression Search And Replace. Then, I&#39;ve just compiled my projects from the command line. I know that it isn&#39;t very efficient, but it makes more sense to me. Then when I really need to work in an IDE that builds for me, I actually know what&#39;s going on &quot;behind the scenes&quot; and I can troubleshoot any errors that surface.</p><p>Netbeans IS awesome, although it&#39;s a bit slower. But it&#39;s almost the top performer for context-sensitive code completion.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Tue, 01 Mar 2011 07:45:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606543/905430#target">opiaboy</a> said:</div><div class="quote"><p>When the game is COMPLETELY finished (meaning, I have no clue when I would get to this) I want to only redraw sections of the screen that need to be redrawn.</p></div></div><p>
In the 90s, this was a valuable technique and was called &#39;dirty rectangles&#39;. These days, computers are powerful enough that most people just render the whole screen from scratch every frame. It&#39;s good because it enables you to move things around more flexibly (e.g. for parallax, camera shake and the like) without worrying about losing any efficiency. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Tue, 01 Mar 2011 09:39:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606543/905432#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>It&#39;s too early to really worry about how efficient your program is.</p></div></div><p>I just wanted to say that I disagree with this 100%.  Always write code with efficiency in mind.</p><p>Have you ever complained about Flash sucking?  It&#39;s because the programmer who wrote that particular applet was not thinking about efficiency.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (StevenVI)</author>
		<pubDate>Tue, 01 Mar 2011 09:57:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not saying write inefficient code just so you can get your project done, I&#39;m saying that it&#39;s more important to get things working first and not worry about how uber efficient your code is. If you spend all your time perfecting and optimizing your code, that&#39;s time taken away from actually finishing a project. Most optimization won&#39;t actually have a visible effect on your program execution, because only small sections of code are actually time critical and are potential bottlenecks.</p><p>I say, get a prototype working first, and then go back over it to see what you could do better. Once you have more experience, your initial code will be more efficient and effective in the first place anyway.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 01 Mar 2011 10:36:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My gut feeling is you&#39;re doing OK and you&#39;re not going to have too many problems with efficiency, so don&#39;t worry. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>When it comes to Flash, I think there are plenty of things Macromedia could have done to encourage people to write efficient code. If you design an editor for artists and then expect them to have the approach that an experienced old-school programmer would have, you&#39;re doing it wrong.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Tue, 01 Mar 2011 11:25:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606543/905808#target">StevenVI</a> said:</div><div class="quote"><p> I just wanted to say that I disagree with this 100%. Always write code with efficiency in mind.</p></div></div><p>Efficient, sure. But don&#39;t spend hours thinking about a micro-optimization problem for a function that will probably not use up more than 0.5% of the total render time per frame, regardless of how poorly written it is.</p><p>The road to madness is paved with premature optimization <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Tue, 01 Mar 2011 20:46:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>filling a rectangle is a bit ugly. Why not create yourself a decent image in a paint program then crop the image based on the health level onto the target buffer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Tue, 01 Mar 2011 21:08:52 +0000</pubDate>
	</item>
</rss>
