http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_7&feed=atom&action=historyRoguelike Tutorial, using python3+tdl, part 7 - Revision history2024-03-28T16:41:21ZRevision history for this page on the wikiMediaWiki 1.36.0http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_7&diff=45424&oldid=prevWeilian: Updated version to 3.1.0. No changes in code.2017-05-30T08:55:19Z<p>Updated version to 3.1.0. No changes in code.</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 08:55, 30 May 2017</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l2">Line 2:</td>
<td colspan="2" class="diff-lineno">Line 2:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This is part of a series of tutorials; the main page can be found [[Roguelike Tutorial, using python3+tdl|here]].</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This is part of a series of tutorials; the main page can be found [[Roguelike Tutorial, using python3+tdl|here]].</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The tutorial uses tdl version 3.0<del style="font-weight: bold; text-decoration: none;">.2 </del>and Python 3.5</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>The tutorial uses tdl version 3<ins style="font-weight: bold; text-decoration: none;">.1</ins>.0 and Python 3.5</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></center></td></tr></table></center></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></center></td></tr></table></center></div></td></tr>
</table>Weilianhttp://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_7&diff=45360&oldid=prevWeilian: Updated version to 3.0.2. No changes in code.2017-05-28T04:35:27Z<p>Updated version to 3.0.2. No changes in code.</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 04:35, 28 May 2017</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l2">Line 2:</td>
<td colspan="2" class="diff-lineno">Line 2:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This is part of a series of tutorials; the main page can be found [[Roguelike Tutorial, using python3+tdl|here]].</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This is part of a series of tutorials; the main page can be found [[Roguelike Tutorial, using python3+tdl|here]].</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The tutorial uses tdl version <del style="font-weight: bold; text-decoration: none;">1</del>.<del style="font-weight: bold; text-decoration: none;">6</del>.<del style="font-weight: bold; text-decoration: none;">0 </del>and Python 3.5</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>The tutorial uses tdl version <ins style="font-weight: bold; text-decoration: none;">3</ins>.<ins style="font-weight: bold; text-decoration: none;">0</ins>.<ins style="font-weight: bold; text-decoration: none;">2 </ins>and Python 3.5</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></center></td></tr></table></center></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></center></td></tr></table></center></div></td></tr>
</table>Weilianhttp://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_7&diff=43910&oldid=prevWeilian at 11:49, 21 November 20162016-11-21T11:49:40Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:49, 21 November 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l2">Line 2:</td>
<td colspan="2" class="diff-lineno">Line 2:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This is part of a series of tutorials; the main page can be found [[Roguelike Tutorial, using python3+tdl|here]].</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This is part of a series of tutorials; the main page can be found [[Roguelike Tutorial, using python3+tdl|here]].</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The tutorial uses tdl version 1.<del style="font-weight: bold; text-decoration: none;">5</del>.<del style="font-weight: bold; text-decoration: none;">3 </del>and Python 3.5</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>The tutorial uses tdl version 1.<ins style="font-weight: bold; text-decoration: none;">6</ins>.<ins style="font-weight: bold; text-decoration: none;">0 </ins>and Python 3.5</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></center></td></tr></table></center></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></center></td></tr></table></center></div></td></tr>
</table>Weilianhttp://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_7&diff=43878&oldid=prevWeilian: Several minor edits2016-11-17T13:20:19Z<p>Several minor edits</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 13:20, 17 November 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l133">Line 133:</td>
<td colspan="2" class="diff-lineno">Line 133:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The long message allows us to test the word-wrap. You can now replace all the calls to the standard ''print'' with calls to our own ''message'' function (all 4 of them). I made the player death message red (''colors.red''), and the monster death message orange (''colors.orange''), others are the default. By the way, [http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/color.html?c=false&cpp=false&cs=false&py=true&lua=false here's the list of <del style="font-weight: bold; text-decoration: none;">standard libtcod </del>colors]. It's very handy, if you don't mind using a pre-defined palette of colors! As mentioned ealier, don't forget that our colors.py file uses underscores ('''light_red''') rather than camel case ('''lightRed''').</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>The long message allows us to test the word-wrap. You can now replace all the calls to the standard ''print'' with calls to our own ''message'' function (all 4 of them). I made the player death message red (''colors.red''), and the monster death message orange (''colors.orange''), others are the default. By the way, [http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/color.html?c=false&cpp=false&cs=false&py=true&lua=false here's the list of colors]. It's very handy, if you don't mind using a pre-defined palette of colors! As mentioned ealier, don't forget that our colors.py file uses underscores ('''light_red''') rather than camel case ('''lightRed''').</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This is just the kind of polish that our game needed, it's much more attractive, even for casual players. Don't let the die-hard roguelike players fool you, everyone likes a little bit of eye candy!</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This is just the kind of polish that our game needed, it's much more attractive, even for casual players. Don't let the die-hard roguelike players fool you, everyone likes a little bit of eye candy!</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l141">Line 141:</td>
<td colspan="2" class="diff-lineno">Line 141:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>We'll now work some interactivity into our GUI. Roguelikes have a long tradition of using strict keyboard interfaces, and that's nice; but for a couple of tasks, like selecting a tile, a mouse interface is much easier. So we'll implement something like a "look" command, by automatically showing the name of any object the player hovers the mouse with! You could also use it for selecting targets of spells and ranged combat. Of course this is only a tutorial, showing you what you ''can'' do, and you may decide to replace this with a traditional "look" command!</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>We'll now work some interactivity into our GUI. Roguelikes have a long tradition of using strict keyboard interfaces, and that's nice; but for a couple of tasks, like selecting a tile, a mouse interface is much easier. So we'll implement something like a "look" command, by automatically showing the name of any object the player hovers the mouse with! You could also use it for selecting targets of spells and ranged combat. Of course this is only a tutorial, showing you what you ''can'' do, and you may decide to replace this with a traditional "look" command!</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Using tdl it's very easy to know the position of the mouse, and if there were any clicks: the ''tdl.event.get'' method returns information on both keyboard and mouse activity<del style="font-weight: bold; text-decoration: none;">: (</del>[<del style="font-weight: bold; text-decoration: none;">http</del>://<del style="font-weight: bold; text-decoration: none;">roguecentral</del>.org/<del style="font-weight: bold; text-decoration: none;">doryen/data/libtcod/doc</del>/<del style="font-weight: bold; text-decoration: none;">1</del>.<del style="font-weight: bold; text-decoration: none;">5</del>.<del style="font-weight: bold; text-decoration: none;">1/html2/console_non_blocking_input</del>.html<del style="font-weight: bold; text-decoration: none;">?c=false&cpp=false&cs=false&py=true&lua=false see the docs</del>] for more details, and [<del style="font-weight: bold; text-decoration: none;">http</del>://<del style="font-weight: bold; text-decoration: none;">roguecentral</del>.org/<del style="font-weight: bold; text-decoration: none;">doryen/data/libtcod/doc</del>/<del style="font-weight: bold; text-decoration: none;">1</del>.<del style="font-weight: bold; text-decoration: none;">5</del>.<del style="font-weight: bold; text-decoration: none;">1/html2/mouse</del>.html<del style="font-weight: bold; text-decoration: none;">?c=false&cpp=false&cs=false&py=true&lua=false </del>here] for the mouse <del style="font-weight: bold; text-decoration: none;">structure)</del>. </div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Using tdl it's very easy to know the position of the mouse, and if there were any clicks: the ''tdl.event.get'' method returns information on both keyboard and mouse activity<ins style="font-weight: bold; text-decoration: none;">. See </ins>[<ins style="font-weight: bold; text-decoration: none;">https</ins>://<ins style="font-weight: bold; text-decoration: none;">pythonhosted</ins>.org/<ins style="font-weight: bold; text-decoration: none;">tdl</ins>/<ins style="font-weight: bold; text-decoration: none;">tdl</ins>.<ins style="font-weight: bold; text-decoration: none;">event</ins>.<ins style="font-weight: bold; text-decoration: none;">MouseMotion-class</ins>.html <ins style="font-weight: bold; text-decoration: none;">here</ins>] for more details <ins style="font-weight: bold; text-decoration: none;">about mouse motion events</ins>, and [<ins style="font-weight: bold; text-decoration: none;">https</ins>://<ins style="font-weight: bold; text-decoration: none;">pythonhosted</ins>.org/<ins style="font-weight: bold; text-decoration: none;">tdl</ins>/<ins style="font-weight: bold; text-decoration: none;">tdl</ins>.<ins style="font-weight: bold; text-decoration: none;">event</ins>.<ins style="font-weight: bold; text-decoration: none;">MouseButtonEvent-class</ins>.html here] for the mouse <ins style="font-weight: bold; text-decoration: none;">button events</ins>. </div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>We need to restructure the program a little bit to use this combined mouse and keyboard detection. Just before the main loop, add:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>We need to restructure the program a little bit to use this combined mouse and keyboard detection. Just before the main loop, add:</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l149">Line 149:</td>
<td colspan="2" class="diff-lineno">Line 149:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>As our turn-based game gets more complex, we'll have to remove the <del style="font-weight: bold; text-decoration: none;">optionc '</del>''REALTIME = False<del style="font-weight: bold; text-decoration: none;">'</del>''. In the extras at the end of the tutorial, we'll discuss how to re-implement a real-time game.</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>As our turn-based game gets more complex, we'll have to remove the <ins style="font-weight: bold; text-decoration: none;">option </ins>''REALTIME = False''. In the extras at the end of the tutorial, we'll discuss how to re-implement a real-time game.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>For now, lets's take this whole block of code</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>For now, lets's take this whole block of code</div></td></tr>
</table>Weilianhttp://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_7&diff=43876&oldid=prevWeilian: var string --> var text2016-11-17T13:12:23Z<p>var string --> var text</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 13:12, 17 November 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l45">Line 45:</td>
<td colspan="2" class="diff-lineno">Line 45:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"> #finally, some centered text with the values</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"> #finally, some centered text with the values</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;">string </del>= name + ': ' + str(value) + '/' + str(maximum)</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">text </ins>= name + ': ' + str(value) + '/' + str(maximum)</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> x_centered = x + (total_width-len(<del style="font-weight: bold; text-decoration: none;">string</del>))//2</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> x_centered = x + (total_width-len(<ins style="font-weight: bold; text-decoration: none;">text</ins>))//2</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> panel.draw_str(x_centered, y, <del style="font-weight: bold; text-decoration: none;">string</del>, fg=colors.white, bg=None)</syntaxhighlight></div></div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> panel.draw_str(x_centered, y, <ins style="font-weight: bold; text-decoration: none;">text</ins>, fg=colors.white, bg=None)</syntaxhighlight></div></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
</table>Weilianhttp://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_7&diff=43874&oldid=prevWeilian: Created page with "<center><table border="0" cellpadding="10" cellspacing="0" style="background:#F0E68C"><tr><td><center> This is part of a series of tutorials; the main page can be found [[Rogu..."2016-11-17T13:06:20Z<p>Created page with "<center><table border="0" cellpadding="10" cellspacing="0" style="background:#F0E68C"><tr><td><center> This is part of a series of tutorials; the main page can be found [[Rogu..."</p>
<p><b>New page</b></p><div><center><table border="0" cellpadding="10" cellspacing="0" style="background:#F0E68C"><tr><td><center><br />
This is part of a series of tutorials; the main page can be found [[Roguelike Tutorial, using python3+tdl|here]].<br />
<br />
The tutorial uses tdl version 1.5.3 and Python 3.5<br />
<br />
</center></td></tr></table></center><br />
<br />
<br />
__TOC__<br />
<br />
<center><h1>'''The GUI'''</h1></center><br />
<br />
<br />
== Status bars ==<br />
<br />
Lots of stuff happens under the hood of a game that players don't really appreciate, like the combat mechanics detailed in the last couple of sections. We'll now work on something much more flashy -- the Graphical User Interface! Using the full power of libtcod's true-color consoles, and a bit of creativity, you can make some truly amazing graphics. You may argue that the limitations of a console actually make it easier to create a polished game, rather than if you had the freedom to position per-pixel graphics like most other games.<br />
<br />
We'll start by creating a GUI panel at the bottom of the screen. Of course, you're welcome to change this to suit your taste. For now, it will hold the player's health bar and a colored message log.<br />
<br />
It's easier to manage GUI windows and panels with an off-screen console for each one, created before the main loop:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">panel = tdl.Console(SCREEN_WIDTH, PANEL_HEIGHT)</syntaxhighlight></div><br />
<br />
<br />
The constant ''PANEL_HEIGHT'' is defined later, along with others. Let's jump right to the "status bar" rendering code! This is fully generic and can be used for experience bars, mana bars, recharge times, dungeon level, you name it.<br />
<br />
The bar has two parts, one rectangle that changes size according to the proportion between the value and the maximum value, and a background rectangle. It just takes a simple formula to calculate that size, and a few calls to tdl's ''Console.draw_rect'' function for the rectangles.<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):<br />
#render a bar (HP, experience, etc). first calculate the width of the bar<br />
bar_width = int(float(value) / maximum * total_width)<br />
<br />
#render the background first<br />
panel.draw_rect(x, y, total_width, 1, None, bg=back_color)<br />
<br />
#now render the bar on top<br />
if bar_width > 0:<br />
panel.draw_rect(x, y, bar_width, 1, None, bg=bar_color)</syntaxhighlight></div><br />
<br />
<br />
For extra clarity, the actual value and maximum are displayed as text over the bar, along with a caption ('Health', 'Mana', etc).<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"> #finally, some centered text with the values<br />
string = name + ': ' + str(value) + '/' + str(maximum)<br />
x_centered = x + (total_width-len(string))//2<br />
panel.draw_str(x_centered, y, string, fg=colors.white, bg=None)</syntaxhighlight></div><br />
<br />
<br />
Now we'll modify the main rendering function to use this. First, define a few constants: the height of the panel, its position on the screen (it's a bottom panel so only the Y is needed) and the size of the health bar.<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">#sizes and coordinates relevant for the GUI<br />
BAR_WIDTH = 20<br />
PANEL_HEIGHT = 7<br />
PANEL_Y = SCREEN_HEIGHT - PANEL_HEIGHT</syntaxhighlight></div><br />
<br />
<br />
I also changed ''MAP_HEIGHT'' to 43 to give the panel more room. At the end of ''render_all'', replace the code that shows the player's stats as text with the following code. It re-initializes the panel to black, calls our ''render_bar'' function to display the player's health, then shows the panel on the root console.<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"> #prepare to render the GUI panel<br />
panel.clear(fg=colors.white, bg=colors.black)<br />
<br />
#show the player's stats<br />
render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,<br />
colors.light_red, colors.darker_red)<br />
<br />
#blit the contents of "panel" to the root console<br />
root.blit(panel, 0, PANEL_Y, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0)</syntaxhighlight></div><br />
<br />
<br />
Time to test it -- that health bar looks pretty sweet! And you can easily make more like it with different colors and all.<br />
<br />
A small detail, the console where the map is rendered (''con'') should be the size of the map, not the size of the screen. This is more noticeable now that the panel takes up quite a bit of space. Change ''SCREEN_WIDTH'' and ''SCREEN_HEIGHT'' to ''MAP_WIDTH'' and ''MAP_HEIGHT'' when creating this console and blitting it. It's the ''con = tdl.Console(...)'' line before the main loop, and the first ''root.blit'' in ''render_all''.<br />
<br />
<br />
== The message log ==<br />
<br />
Until now the combat messages were dumped in the standard console -- not very user-friendly. We'll make a nice scrolling message log embedded in the GUI panel, and use colored messages so the player can know what happened with a single glance. It will also feature word-wrap!<br />
<br />
The constants that define the message bar's position and size are:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">MSG_X = BAR_WIDTH + 2<br />
MSG_WIDTH = SCREEN_WIDTH - BAR_WIDTH - 2<br />
MSG_HEIGHT = PANEL_HEIGHT - 1</syntaxhighlight></div><br />
<br />
<br />
This is so it appears to the right of the health bar, and fills up the rest of the space. The messages will be stored in a list so they can be easily manipulated. Each message is a tuple with 2 fields: the message string, and its color.<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">#create the list of game messages and their colors, starts empty<br />
game_msgs = []</syntaxhighlight></div><br />
<br />
<br />
A simple-to-use function will handle adding messages to the list. It will use Python's textwrap module to split a message into several lines if it's too long! For that, put ''import textwrap'' at the top of the file, and create the function:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">def message(new_msg, color = colors.white):<br />
#split the message if necessary, among multiple lines<br />
new_msg_lines = textwrap.wrap(new_msg, MSG_WIDTH)<br />
<br />
for line in new_msg_lines:<br />
#if the buffer is full, remove the first line to make room for the new one<br />
if len(game_msgs) == MSG_HEIGHT:<br />
del game_msgs[0]<br />
<br />
#add the new line as a tuple, with the text and the color<br />
game_msgs.append((line, color))</syntaxhighlight></div><br />
<br />
<br />
After obtaining the broken up message as a list of strings, it adds them one at a time to the actual message log. This is so that, when the log gets full, the first line is removed to make space for the new line. Dealing with one line at a time makes it easy to ensure that the message log never has more than a maximum height.<br />
<br />
The code to show the message log is simpler. Just loop through the lines and print them with the appropriate colors (right before rendering the health bar). Notice how we get the values of the tuple right in the for loop; this sort of feature in Python (called ''unpacking'') allows you to write very concise code.<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"><br />
#print the game messages, one line at a time<br />
y = 1<br />
for (line, color) in game_msgs:<br />
panel.draw_str(MSG_X, y, line, bg=None, fg=color)<br />
y += 1</syntaxhighlight></div><br />
<br />
<br />
Ready to test! Let's print a friendly message before the main loop to welcome the player to our dungeon of doom:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">#a warm welcoming message!<br />
message('Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', colors.red)</syntaxhighlight></div><br />
<br />
<br />
The long message allows us to test the word-wrap. You can now replace all the calls to the standard ''print'' with calls to our own ''message'' function (all 4 of them). I made the player death message red (''colors.red''), and the monster death message orange (''colors.orange''), others are the default. By the way, [http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/color.html?c=false&cpp=false&cs=false&py=true&lua=false here's the list of standard libtcod colors]. It's very handy, if you don't mind using a pre-defined palette of colors! As mentioned ealier, don't forget that our colors.py file uses underscores ('''light_red''') rather than camel case ('''lightRed''').<br />
<br />
This is just the kind of polish that our game needed, it's much more attractive, even for casual players. Don't let the die-hard roguelike players fool you, everyone likes a little bit of eye candy!<br />
<br />
== Mouse-look ==<br />
<br />
We'll now work some interactivity into our GUI. Roguelikes have a long tradition of using strict keyboard interfaces, and that's nice; but for a couple of tasks, like selecting a tile, a mouse interface is much easier. So we'll implement something like a "look" command, by automatically showing the name of any object the player hovers the mouse with! You could also use it for selecting targets of spells and ranged combat. Of course this is only a tutorial, showing you what you ''can'' do, and you may decide to replace this with a traditional "look" command!<br />
<br />
Using tdl it's very easy to know the position of the mouse, and if there were any clicks: the ''tdl.event.get'' method returns information on both keyboard and mouse activity: ([http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/console_non_blocking_input.html?c=false&cpp=false&cs=false&py=true&lua=false see the docs] for more details, and [http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/mouse.html?c=false&cpp=false&cs=false&py=true&lua=false here] for the mouse structure). <br />
<br />
We need to restructure the program a little bit to use this combined mouse and keyboard detection. Just before the main loop, add:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">mouse_coord = (0, 0)</syntaxhighlight></div><br />
<br />
<br />
As our turn-based game gets more complex, we'll have to remove the optionc '''REALTIME = False'''. In the extras at the end of the tutorial, we'll discuss how to re-implement a real-time game.<br />
<br />
For now, lets's take this whole block of code<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #FDECEC"><syntaxhighlight lang="python"> if REALTIME:<br />
keypress = False<br />
for event in tdl.event.get():<br />
if event.type == 'KEYDOWN':<br />
user_input = event<br />
keypress = True<br />
if not keypress:<br />
return<br />
<br />
else: #turn-based<br />
user_input = tdl.event.key_wait()</syntaxhighlight></div><br />
<br />
<br />
and chage it to:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"> keypress = False<br />
for event in tdl.event.get():<br />
if event.type == 'KEYDOWN':<br />
user_input = event<br />
keypress = True<br />
if event.type == 'MOUSEMOTION':<br />
mouse_coord = event.cell<br />
<br />
if not keypress:<br />
return 'didnt-take-turn'</syntaxhighlight></div><br />
<br />
<br />
We now have a ''mouse_coord'' global variable that lets use know which tile the mouse pointer is on. This will be used by a new function that returns a string with the names of objects under the mouse:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python">def get_names_under_mouse():<br />
global visible_tiles<br />
<br />
#return a string with the names of all objects under the mouse<br />
(x, y) = mouse_coord</syntaxhighlight></div><br />
<br />
<br />
Now we need to gather a list of names of objects that satisfy a few conditions: they're under the mouse, and inside the player's FOV. (Otherwise he or she would be able to detect enemies through walls!) This can be done with list comprehensions, [http://docs.python.org/tutorial/datastructures.html#list-comprehensions using the "if" variant].<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"> #create a list with the names of all objects at the mouse's coordinates and in FOV<br />
names = [obj.name for obj in objects<br />
if obj.x == x and obj.y == y and (obj.x, obj.y) in visible_tiles]</syntaxhighlight></div><br />
<br />
<br />
After that mouthful, it's a simple matter of joining the names into a single string, using commas. Python has neat functions for this and capitalizing the first letter:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"> names = ', '.join(names) #join the names, separated by commas<br />
return names.capitalize()</syntaxhighlight></div><br />
<br />
<br />
The function ''render_all'' can call this to get the string that depends on the mouse's position, after rendering the health bar:<br />
<br />
<br />
<div style="padding: 5px; border: solid 1px #C0C0C0; background-color: #F0F0F0"><syntaxhighlight lang="python"> #display names of objects under the mouse<br />
panel.draw_str(1, 0, get_names_under_mouse(), bg=None, fg=colors.light_gray)<br />
</syntaxhighlight></div><br />
<br />
<br />
But wait! If you recall, in a turn-based game, the rendering is done only once per turn; the rest of the time, the game is blocked on ''tdl.event.key_wait''. During this time (which is ''most'' of the time) the code we wrote above would simply not be processed! We switched to real-time rendering by replacing the ''tdl.event.key_wait'' call in ''handle_keys'' with the ''tdl.event.get'' in the main loop.<br />
<br />
<br />
Won't our game stop being turn-based then? It's funny, but surprisingly it won't! Before you question logic itself, let me tell you that we did some changes earlier that had the side-effect of enabling this.<br />
<br />
When the player doesn't take a turn (doesn't press a movement/attack key), ''handle_keys'' returns a special string ('' 'didnt-take-turn' ''). You'll notice that the main loop only allows enemies to take their turns if the value returned from ''handle_keys'' is not '' 'didnt-take-turn' ''! The main loop goes on, but the monsters don't move. The only real distinction between a real-time game and a turn-based game is that, in a turn-based game, the monsters wait until the player moves to make their move. Makes sense!<br />
<br />
If you hadn't before, you now need to call ''tdl.setFPS(LIMIT_FPS)'' before the main loop to limit the game's speed. <br />
<br />
That's it! You can move the mouse around to quickly know the names of every object in sight.<br />
<br />
<br />
The whole code is available [[Roguelike Tutorial, using python3+tdl, part 7 code|here]].<br />
<br />
[[Roguelike Tutorial, using python3+tdl, part 8|Go on to the next part]].<br />
<br />
[[Category:Developing]]</div>Weilian