http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&feed=atom&action=history
Roguelike Tutorial, using python3+tdl, part 3 code - Revision history
2024-03-28T12:34:28Z
Revision history for this page on the wiki
MediaWiki 1.36.0
http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&diff=45431&oldid=prev
Weilian: Updated version to 3.1.0. No changes in code.
2017-05-30T08:59:25Z
<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:59, 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>
Weilian
http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&diff=45383&oldid=prev
Weilian: Fixed fullscreen toggle
2017-05-29T14:18:10Z
<p>Fixed fullscreen toggle</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 14:18, 29 May 2017</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l150">Line 150:</td>
<td colspan="2" class="diff-lineno">Line 150:</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> if user_input.key == 'ENTER' and user_input.alt:</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> if user_input.key == 'ENTER' and user_input.alt:</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;"><div> #Alt+Enter: toggle fullscreen</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> #Alt+Enter: toggle fullscreen</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> tdl.set_fullscreen(<del style="font-weight: bold; text-decoration: none;">True</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> tdl.set_fullscreen(<ins style="font-weight: bold; text-decoration: none;">not tdl.get_fullscreen()</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;"><div> </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></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> elif user_input.key == 'ESCAPE':</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> elif user_input.key == 'ESCAPE':</div></td></tr>
</table>
Weilian
http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&diff=45368&oldid=prev
Weilian: object --> obj
2017-05-28T05:45:29Z
<p>object --> obj</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 05:45, 28 May 2017</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l199">Line 199:</td>
<td colspan="2" class="diff-lineno">Line 199:</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> #erase all objects at their old locations, before they move</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> #erase all objects at their old locations, before they move</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> for <del style="font-weight: bold; text-decoration: none;">object </del>in objects:</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> for <ins style="font-weight: bold; text-decoration: none;">obj </ins>in objects:</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;">object</del>.clear()</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;">obj</ins>.clear()</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> #handle keys and exit game if needed</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> #handle keys and exit game if needed</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l459">Line 459:</td>
<td colspan="2" class="diff-lineno">Line 459:</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> #erase all objects at their old locations, before they move</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> #erase all objects at their old locations, before they move</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> for <del style="font-weight: bold; text-decoration: none;">object </del>in objects:</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> for <ins style="font-weight: bold; text-decoration: none;">obj </ins>in objects:</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;">object</del>.clear()</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;">obj</ins>.clear()</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> #handle keys and exit game if needed</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> #handle keys and exit game if needed</div></td></tr>
</table>
Weilian
http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&diff=45346&oldid=prev
Weilian at 03:55, 28 May 2017
2017-05-28T03:55:57Z
<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 03:55, 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;">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 <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>
Weilian
http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&diff=43865&oldid=prev
Weilian: Screen height
2016-11-17T08:39:50Z
<p>Screen height</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:39, 17 November 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l16">Line 16:</td>
<td colspan="2" class="diff-lineno">Line 16:</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>#actual size of the window</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>#actual size of the window</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;"><div>SCREEN_WIDTH = 80</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>SCREEN_WIDTH = 80</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>SCREEN_HEIGHT = <del style="font-weight: bold; text-decoration: none;">65</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>SCREEN_HEIGHT = <ins style="font-weight: bold; text-decoration: none;">50</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>#size of the map</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>#size of the map</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l218">Line 218:</td>
<td colspan="2" class="diff-lineno">Line 218:</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>#actual size of the window</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>#actual size of the window</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;"><div>SCREEN_WIDTH = 80</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>SCREEN_WIDTH = 80</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>SCREEN_HEIGHT = <del style="font-weight: bold; text-decoration: none;">65</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>SCREEN_HEIGHT = <ins style="font-weight: bold; text-decoration: none;">50</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>#size of the map</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>#size of the map</div></td></tr>
</table>
Weilian
http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&diff=43801&oldid=prev
Weilian at 11:33, 13 November 2016
2016-11-13T11:33:20Z
<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:33, 13 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 <del style="font-weight: bold; text-decoration: none;">tld </del>version 1.5.3 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 <ins style="font-weight: bold; text-decoration: none;">tdl </ins>version 1.5.3 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>
Weilian
http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&diff=43798&oldid=prev
Weilian: /* Dungeon building blocks */
2016-11-13T11:25:17Z
<p><span dir="auto"><span class="autocomment">Dungeon building blocks</span></span></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:25, 13 November 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l11">Line 11:</td>
<td colspan="2" class="diff-lineno">Line 11:</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="background-color: #EEEEEE; border-style: dotted"><syntaxhighlight lang="python"></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="background-color: #EEEEEE; border-style: dotted"><syntaxhighlight lang="python"></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;"><div>#!/usr/bin/env python3</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>#!/usr/bin/env python3</div></td></tr>
<tr><td colspan="2"></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;"></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;"><div>import tdl</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>import tdl</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 colspan="2" class="diff-lineno" id="mw-diff-left-l206">Line 206:</td>
<td colspan="2" class="diff-lineno">Line 207:</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> break</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> break</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;"><div></syntaxhighlight></div></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></syntaxhighlight></div></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;"></del></div></td><td colspan="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;"><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>== Dungeon generator ==</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>== Dungeon generator ==</div></td></tr>
</table>
Weilian
http://roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl,_part_3_code&diff=43797&oldid=prev
Weilian: 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-13T11:24:36Z
<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 tld version 1.5.3 and Python 3.5<br />
<br />
</center></td></tr></table></center><br />
<br />
<br />
== Dungeon building blocks ==<br />
<br />
<div style="background-color: #EEEEEE; border-style: dotted"><syntaxhighlight lang="python"><br />
#!/usr/bin/env python3<br />
import tdl<br />
<br />
#actual size of the window<br />
SCREEN_WIDTH = 80<br />
SCREEN_HEIGHT = 65<br />
<br />
#size of the map<br />
MAP_WIDTH = 80<br />
MAP_HEIGHT = 45<br />
<br />
REALTIME = False<br />
LIMIT_FPS = 20 #20 frames-per-second maximum<br />
<br />
color_dark_wall = (0, 0, 100)<br />
color_dark_ground = (50, 50, 150)<br />
<br />
<br />
class Tile:<br />
#a tile of the map and its properties<br />
def __init__(self, blocked, block_sight=None):<br />
self.blocked = blocked<br />
<br />
#by default, if a tile is blocked, it also blocks sight<br />
if block_sight is None: <br />
block_sight = blocked<br />
self.block_sight = block_sight<br />
<br />
class Rect:<br />
#a rectangle on the map. used to characterize a room.<br />
def __init__(self, x, y, w, h):<br />
self.x1 = x<br />
self.y1 = y<br />
self.x2 = x + w<br />
self.y2 = y + h<br />
<br />
<br />
class GameObject:<br />
#this is a generic object: the player, a monster, an item, the stairs...<br />
#it's always represented by a character on screen.<br />
def __init__(self, x, y, char, color):<br />
self.x = x<br />
self.y = y<br />
self.char = char<br />
self.color = color<br />
<br />
def move(self, dx, dy):<br />
#move by the given amount, if the destination is not blocked<br />
if not my_map[self.x + dx][self.y + dy].blocked:<br />
self.x += dx<br />
self.y += dy<br />
<br />
def draw(self):<br />
#draw the character that represents this object at its position<br />
con.draw_char(self.x, self.y, self.char, self.color, bg=None)<br />
<br />
def clear(self):<br />
#erase the character that represents this object<br />
con.draw_char(self.x, self.y, ' ', self.color, bg=None)<br />
<br />
<br />
def create_room(room):<br />
global my_map<br />
#go through the tiles in the rectangle and make them passable<br />
for x in range(room.x1 + 1, room.x2):<br />
for y in range(room.y1 + 1, room.y2):<br />
my_map[x][y].blocked = False<br />
my_map[x][y].block_sight = False<br />
<br />
def create_h_tunnel(x1, x2, y):<br />
global my_map<br />
for x in range(min(x1, x2), max(x1, x2) + 1):<br />
my_map[x][y].blocked = False<br />
my_map[x][y].block_sight = False<br />
<br />
def create_v_tunnel(y1, y2, x):<br />
global my_map<br />
#vertical tunnel<br />
for y in range(min(y1, y2), max(y1, y2) + 1):<br />
my_map[x][y].blocked = False<br />
my_map[x][y].block_sight = False<br />
<br />
def make_map():<br />
global my_map<br />
<br />
#fill map with "blocked" tiles<br />
my_map = [[ Tile(True)<br />
for y in range(MAP_HEIGHT) ]<br />
for x in range(MAP_WIDTH) ]<br />
<br />
#create two rooms<br />
room1 = Rect(20, 15, 10, 15)<br />
room2 = Rect(50, 15, 10, 15)<br />
create_room(room1)<br />
create_room(room2)<br />
<br />
<br />
#connect them with a tunnel<br />
create_h_tunnel(25, 55, 23)<br />
<br />
#place the player inside the first room<br />
player.x = 25<br />
player.y = 23<br />
<br />
def render_all():<br />
<br />
#go through all tiles, and set their background color<br />
for y in range(MAP_HEIGHT):<br />
for x in range(MAP_WIDTH):<br />
wall = my_map[x][y].block_sight<br />
if wall:<br />
con.draw_char(x, y, None, fg=None, bg=color_dark_wall)<br />
else:<br />
con.draw_char(x, y, None, fg=None, bg=color_dark_ground)<br />
<br />
#draw all objects in the list<br />
for obj in objects:<br />
obj.draw()<br />
<br />
#blit the contents of "con" to the root console and present it<br />
root.blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0)<br />
<br />
def handle_keys(realtime):<br />
global playerx, playery<br />
<br />
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()<br />
<br />
if user_input.key == 'ENTER' and user_input.alt:<br />
#Alt+Enter: toggle fullscreen<br />
tdl.set_fullscreen(True)<br />
<br />
elif user_input.key == 'ESCAPE':<br />
return True #exit game<br />
<br />
#movement keys<br />
if user_input.key == 'UP':<br />
player.move(0, -1)<br />
<br />
elif user_input.key == 'DOWN':<br />
player.move(0, 1)<br />
<br />
elif user_input.key == 'LEFT':<br />
player.move(-1, 0)<br />
<br />
elif user_input.key == 'RIGHT':<br />
player.move(1, 0)<br />
<br />
<br />
#############################################<br />
# Initialization & Main Loop #<br />
#############################################<br />
<br />
tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)<br />
root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Roguelike", fullscreen=False)<br />
tdl.setFPS(LIMIT_FPS)<br />
con = tdl.Console(SCREEN_WIDTH, SCREEN_HEIGHT)<br />
<br />
#create object representing the player<br />
player = GameObject(SCREEN_WIDTH//2, SCREEN_HEIGHT//2, '@', (255,255,255))<br />
<br />
#create an NPC<br />
npc = GameObject(SCREEN_WIDTH//2 - 5, SCREEN_HEIGHT//2, '@', (255,255,0))<br />
<br />
#the list of objects with those two<br />
objects = [npc, player]<br />
<br />
#generate map (at this point it's not drawn to the screen)<br />
make_map()<br />
<br />
<br />
while not tdl.event.is_window_closed():<br />
<br />
#draw all objects in the list<br />
render_all()<br />
<br />
tdl.flush()<br />
<br />
#erase all objects at their old locations, before they move<br />
for object in objects:<br />
object.clear()<br />
<br />
#handle keys and exit game if needed<br />
exit_game = handle_keys(REALTIME)<br />
if exit_game:<br />
break<br />
</syntaxhighlight></div><br />
<br />
<br />
== Dungeon generator ==<br />
<br />
<div style="background-color: #EEEEEE; border-style: dotted"><syntaxhighlight lang="python"><br />
#!/usr/bin/env python3<br />
<br />
import tdl<br />
from random import randint<br />
<br />
#actual size of the window<br />
SCREEN_WIDTH = 80<br />
SCREEN_HEIGHT = 65<br />
<br />
#size of the map<br />
MAP_WIDTH = 80<br />
MAP_HEIGHT = 45<br />
<br />
#parameters for dungeon generator<br />
ROOM_MAX_SIZE = 10<br />
ROOM_MIN_SIZE = 6<br />
MAX_ROOMS = 30<br />
<br />
REALTIME = False<br />
LIMIT_FPS = 20 #20 frames-per-second maximum<br />
<br />
<br />
color_dark_wall = (0, 0, 100)<br />
color_dark_ground = (50, 50, 150)<br />
<br />
<br />
class Tile:<br />
#a tile of the map and its properties<br />
def __init__(self, blocked, block_sight=None):<br />
self.blocked = blocked<br />
<br />
#by default, if a tile is blocked, it also blocks sight<br />
if block_sight is None: <br />
block_sight = blocked<br />
self.block_sight = block_sight<br />
<br />
class Rect:<br />
#a rectangle on the map. used to characterize a room.<br />
def __init__(self, x, y, w, h):<br />
self.x1 = x<br />
self.y1 = y<br />
self.x2 = x + w<br />
self.y2 = y + h<br />
<br />
def center(self):<br />
center_x = (self.x1 + self.x2) // 2<br />
center_y = (self.y1 + self.y2) // 2<br />
return (center_x, center_y)<br />
<br />
def intersect(self, other):<br />
#returns true if this rectangle intersects with another one<br />
return (self.x1 <= other.x2 and self.x2 >= other.x1 and<br />
self.y1 <= other.y2 and self.y2 >= other.y1)<br />
<br />
class GameObject:<br />
#this is a generic object: the player, a monster, an item, the stairs...<br />
#it's always represented by a character on screen.<br />
def __init__(self, x, y, char, color):<br />
self.x = x<br />
self.y = y<br />
self.char = char<br />
self.color = color<br />
<br />
def move(self, dx, dy):<br />
#move by the given amount, if the destination is not blocked<br />
if not my_map[self.x + dx][self.y + dy].blocked:<br />
self.x += dx<br />
self.y += dy<br />
<br />
def draw(self):<br />
#draw the character that represents this object at its position<br />
con.draw_char(self.x, self.y, self.char, self.color, bg=None)<br />
<br />
def clear(self):<br />
#erase the character that represents this object<br />
con.draw_char(self.x, self.y, ' ', self.color, bg=None)<br />
<br />
<br />
def create_room(room):<br />
global my_map<br />
#go through the tiles in the rectangle and make them passable<br />
for x in range(room.x1 + 1, room.x2):<br />
for y in range(room.y1 + 1, room.y2):<br />
my_map[x][y].blocked = False<br />
my_map[x][y].block_sight = False<br />
<br />
def create_h_tunnel(x1, x2, y):<br />
global my_map<br />
for x in range(min(x1, x2), max(x1, x2) + 1):<br />
my_map[x][y].blocked = False<br />
my_map[x][y].block_sight = False<br />
<br />
def create_v_tunnel(y1, y2, x):<br />
global my_map<br />
#vertical tunnel<br />
for y in range(min(y1, y2), max(y1, y2) + 1):<br />
my_map[x][y].blocked = False<br />
my_map[x][y].block_sight = False<br />
<br />
def make_map():<br />
global my_map<br />
<br />
#fill map with "blocked" tiles<br />
my_map = [[ Tile(True)<br />
for y in range(MAP_HEIGHT) ]<br />
for x in range(MAP_WIDTH) ]<br />
<br />
rooms = []<br />
num_rooms = 0<br />
<br />
for r in range(MAX_ROOMS):<br />
#random width and height<br />
w = randint(ROOM_MIN_SIZE, ROOM_MAX_SIZE)<br />
h = randint(ROOM_MIN_SIZE, ROOM_MAX_SIZE)<br />
#random position without going out of the boundaries of the map<br />
x = randint(0, MAP_WIDTH-w-1)<br />
y = randint(0, MAP_HEIGHT-h-1)<br />
<br />
#"Rect" class makes rectangles easier to work with<br />
new_room = Rect(x, y, w, h)<br />
<br />
#run through the other rooms and see if they intersect with this one<br />
failed = False<br />
for other_room in rooms:<br />
if new_room.intersect(other_room):<br />
failed = True<br />
break<br />
<br />
if not failed:<br />
#this means there are no intersections, so this room is valid<br />
<br />
#"paint" it to the map's tiles<br />
create_room(new_room)<br />
<br />
#center coordinates of new room, will be useful later<br />
(new_x, new_y) = new_room.center()<br />
<br />
if num_rooms == 0:<br />
#this is the first room, where the player starts at<br />
player.x = new_x<br />
player.y = new_y<br />
<br />
else:<br />
#all rooms after the first:<br />
#connect it to the previous room with a tunnel<br />
<br />
#center coordinates of previous room<br />
(prev_x, prev_y) = rooms[num_rooms-1].center()<br />
<br />
#draw a coin (random number that is either 0 or 1)<br />
if randint(0, 1):<br />
#first move horizontally, then vertically<br />
create_h_tunnel(prev_x, new_x, prev_y)<br />
create_v_tunnel(prev_y, new_y, new_x)<br />
else:<br />
#first move vertically, then horizontally<br />
create_v_tunnel(prev_y, new_y, prev_x)<br />
create_h_tunnel(prev_x, new_x, new_y)<br />
<br />
#finally, append the new room to the list<br />
rooms.append(new_room)<br />
num_rooms += 1<br />
<br />
<br />
def render_all():<br />
<br />
#go through all tiles, and set their background color<br />
for y in range(MAP_HEIGHT):<br />
for x in range(MAP_WIDTH):<br />
wall = my_map[x][y].block_sight<br />
if wall:<br />
con.draw_char(x, y, None, fg=None, bg=color_dark_wall)<br />
else:<br />
con.draw_char(x, y, None, fg=None, bg=color_dark_ground)<br />
<br />
#draw all objects in the list<br />
for obj in objects:<br />
obj.draw()<br />
<br />
#blit the contents of "con" to the root console and present it<br />
root.blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0)<br />
<br />
def handle_keys(realtime):<br />
global playerx, playery<br />
<br />
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()<br />
<br />
if user_input.key == 'ENTER' and user_input.alt:<br />
#Alt+Enter: toggle fullscreen<br />
tdl.set_fullscreen(True)<br />
<br />
elif user_input.key == 'ESCAPE':<br />
return True #exit game<br />
<br />
#movement keys<br />
if user_input.key == 'UP':<br />
player.move(0, -1)<br />
<br />
elif user_input.key == 'DOWN':<br />
player.move(0, 1)<br />
<br />
elif user_input.key == 'LEFT':<br />
player.move(-1, 0)<br />
<br />
elif user_input.key == 'RIGHT':<br />
player.move(1, 0)<br />
<br />
<br />
#############################################<br />
# Initialization & Main Loop #<br />
#############################################<br />
<br />
tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)<br />
root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Roguelike", fullscreen=False)<br />
tdl.setFPS(LIMIT_FPS)<br />
con = tdl.Console(SCREEN_WIDTH, SCREEN_HEIGHT)<br />
<br />
#create object representing the player<br />
player = GameObject(SCREEN_WIDTH//2, SCREEN_HEIGHT//2, '@', (255,255,255))<br />
<br />
#create an NPC<br />
npc = GameObject(SCREEN_WIDTH//2 - 5, SCREEN_HEIGHT//2, '@', (255,255,0))<br />
<br />
#the list of objects with those two<br />
objects = [npc, player]<br />
<br />
#generate map (at this point it's not drawn to the screen)<br />
make_map()<br />
<br />
<br />
while not tdl.event.is_window_closed():<br />
<br />
#draw all objects in the list<br />
render_all()<br />
<br />
tdl.flush()<br />
<br />
#erase all objects at their old locations, before they move<br />
for object in objects:<br />
object.clear()<br />
<br />
#handle keys and exit game if needed<br />
exit_game = handle_keys(REALTIME)<br />
if exit_game:<br />
break<br />
</syntaxhighlight></div><br />
<br />
[[Category:Developing]]</div>
Weilian