<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Help With C++ Objects</title>
		<link>http://www.allegro.cc/forums/view/574968</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 03 Apr 2006 13:36:11 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I recently started using C++ OO, and I&#39;m a complete n00b.<br />I can&#39;t quite figure out where the code goes for loading and drawing sprites. Everywhere  I put it, it doesn&#39;t work. Does it go inside the class, or in with the initializations?</p><p>Oh, and also, is there a way to get one tile or sprite from a sprite sheet or tileset? Because right now, i have the sprites in spritesheets, and I&#39;m not sure how to just get a small section of it. Is there some sort of cropping code?</p><p>Thanks,<br />Genius314
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Genius314)</author>
		<pubDate>Sat, 25 Mar 2006 20:57:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I can&#39;t quite figure out where the code goes for loading and drawing sprites.
</p></div></div><p>
Anywhere you want.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Everywhere I put it,
</p></div></div><p>
Define <i>everywhere</i>.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
it doesn&#39;t work
</p></div></div><p>
Define <i>doesn&#39;t work</i>.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Does it go inside the class, or in with the initializations?
</p></div></div><p>
Inside the what?
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Oh, and also, is there a way to get one tile or sprite from a sprite sheet or tileset? Because right now, i have the sprites in spritesheets, and I&#39;m not sure how to just get a small section of it. Is there some sort of cropping code?
</p></div></div><p><span class="source-code"><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/create_sub_bitmap" target="_blank"><span class="a">create_sub_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>parent, <span class="k1">int</span> x, y, width, height<span class="k2">)</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Sat, 25 Mar 2006 21:01:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Actually Genius314 you should read a C++ tutorial and complete its assignments before you start making games. I think you will find that it&#39;s well invested time, and you&#39;ve got to learn this stuff anyway if you want to create games using C++.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kentl)</author>
		<pubDate>Sat, 25 Mar 2006 21:13:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">2</td><td>    <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">3</td><td>    <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">4</td><td>    <a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span><span class="n">16</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">5</td><td>    <a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT_WINDOWED, <span class="n">640</span>, <span class="n">480</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>&#160;</td></tr><tr><td class="number">7</td><td>    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>buffer <span class="k3">=</span> creat_bitmap<span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>    <span class="c">//  Load stuff</span></td></tr><tr><td class="number">10</td><td>    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>sprite <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"some.bmp"</span>, NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td>    <span class="k1">bool</span> done <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>    <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span>done<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">14</td><td>        <span class="c">// do logic and input</span></td></tr><tr><td class="number">15</td><td>        <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">16</td><td>            done <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>        <span class="k2">}</span></td></tr><tr><td class="number">18</td><td>&#160;</td></tr><tr><td class="number">19</td><td>        <span class="c">// Draw stuff</span></td></tr><tr><td class="number">20</td><td>        <a href="http://www.allegro.cc/manual/clear_to_color" target="_blank"><span class="a">clear_to_color</span></a><span class="k2">(</span>buffer, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">255</span>, <span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>        <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span>buffer, sprite, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>        <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>buffer, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">24</td><td>&#160;</td></tr><tr><td class="number">25</td><td>    <span class="c">// Cleanup</span></td></tr><tr><td class="number">26</td><td>    <a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>buffer<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td><span class="k2">}</span></td></tr><tr><td class="number">29</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span></td></tr></tbody></table></div></div><p>

Something like that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonny Cook)</author>
		<pubDate>Sat, 25 Mar 2006 21:23:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Normally, you don&#39;t want to load or toy with bitmaps within an object. It&#39;s a bad idea. You should maybe load a datafile full of all your sprites at the beginning of your program as a global datafile, then in your objects constructor do something like
</p><div class="source-code snippet"><div class="inner"><pre>MyObject::MyObject<span class="k2">(</span><span class="k2">)</span>
<span class="k2">{</span> <span class="c">// MyObject's constructor</span>
  mysprite <span class="k3">=</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>graphics_dat<span class="k2">[</span>MYSPRITE<span class="k2">]</span>.dat<span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

Then, make your object have a draw function that draws onto the specified bitmap.
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> MyObject::draw<span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>dest<span class="k2">)</span>
<span class="k2">{</span>
  <a href="http://www.allegro.cc/manual/masked_blit" target="_blank"><span class="a">masked_blit</span></a><span class="k2">(</span>mysprite, dest, <span class="n">0</span>, <span class="n">0</span>, x, y, mysprite-&gt;w, mysprite-&gt;h<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

Of course, you could get a little bit more fancy and make an array of BITMAP * for use in multiple frames using create_sub_bitmap. I&#39;ll leave that up to you to toy around with. Remember to unload your datafile at the end of the program.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elverion)</author>
		<pubDate>Sat, 25 Mar 2006 23:50:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>i think you should check out my game it will be a great help to you <a href="http://www.allegro.cc/depot/Thegame/">http://www.allegro.cc/depot/Thegame/</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (piccolo)</author>
		<pubDate>Sun, 26 Mar 2006 04:47:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I recently started using C++ OO, and I&#39;m a complete n00b.
</p></div></div><p>
Good to hear you are aware of that.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I can&#39;t quite figure out where the code goes for loading and drawing sprites. Everywhere I put it, it doesn&#39;t work.
</p></div></div><p>
That&#39;s probably because you lack essential coding skills.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Does it go inside the class, or in with the initializations?
</p></div></div><p>
<i>The</i> class? There can be more than one class, you know. And if by &quot;initialization&quot;, you mean &quot;constructor&quot;, I&#39;d say rather not. But the question in itself is void, unless you tell us what else it needs to do.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Oh, and also, is there a way to get one tile or sprite from a sprite sheet or tileset? Because right now, i have the sprites in spritesheets, and I&#39;m not sure how to just get a small section of it. Is there some sort of cropping code?
</p></div></div><p>
blit() and create_sub_bitmap() can help a lot, although they are not fully-fledged miracle tools that do all of your dirty work for you. They can&#39;t be, because they don&#39;t know how your sprite sheet is laid out. I&#39;m afraid you need to do this yourself.</p><p>Anyway, considering your very first sentence, I&#39;d say - <br />1. Get a decent C++ book. An actual book (one of those paper thingies, you know) is a lot better than any online tutorial. Work through the book, and finish the assignments - or at least be sure that you can, and that you grasp the concepts covered.<br />2. Code your own &quot;Hello world&quot;-program, using allegro.<br />3. Guess-the-number, tic-tac-toe, pong, that kind of things - stuff an experienced programmer hacks together in 30 minutes.<br />4. In case of doubt, RTFM.<br />5. If still in doubt, come back.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Thu, 30 Mar 2006 06:20:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, now i feel really stupid.<br />Apparently the only problem is that i can&#39;t name classes as &quot;player.&quot; Any other name works.<br /><img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Genius314)</author>
		<pubDate>Sat, 01 Apr 2006 08:14:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Apparently the only problem is that i can&#39;t name classes as &quot;player.&quot; Any other name works.
</p></div></div><p>

try using <a href="http://www.cplusplus.com/doc/tutorial/namespaces.html">namespaces</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sat, 01 Apr 2006 09:31:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or else, use one of the common style conventions that prevent things like this to happen. The most common one would be this:<br />&quot;All classes are prefixed with a &#39;c&#39;, and each word in the identifier starts with a capital: class cPlayer { ... };&quot;</p><p>A more allegro-ish way would be to use UPPER_CASE_WITH_UNDERSCORES for all type names, macros and constants, and lower_case_with_underscores() for variables and function names.</p><p>It&#39;s not important which convention you use, as long as you choose one and stick to it. It helps to be able to see what kind of indentifier you&#39;re looking at when you see it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Sun, 02 Apr 2006 16:31:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
i think you should check out my game it will be a great help to you
</p></div></div><p>
Always.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Apparently the only problem is that i can&#39;t name classes as &quot;player.&quot; Any other name works.
</p></div></div><p>
That&#39;s weird, I name a class &#39;player&#39; in just about every single one of my games. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ceagon Xylas)</author>
		<pubDate>Mon, 03 Apr 2006 13:36:11 +0000</pubDate>
	</item>
</rss>
