Created
June 20, 2023 15:01
-
-
Save horstjens/983b18532c1dc238820ba40d89fd74ad to your computer and use it in GitHub Desktop.
rogue2_brothers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#rogue2.py | |
import PySimpleGUI as sg | |
import random | |
herox = 20 | |
heroy = 10 | |
level_1 = """ | |
######################################## | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
#......................................# | |
########################################""" | |
level = [list(line.strip()) for line in level_1.splitlines() if len(line.strip()) > 0] | |
layout = [ | |
[sg.Button("Start"), sg.Button("Quit"), sg.Button("Inventory")], | |
[sg.Text("Hitpoints:"), sg.Text("\u2665"*20, key="hptext", size=(50,1))], | |
[sg.Text("Mana :"), sg.Text("\u2605"*20, key="mptext", size=(50,1))], | |
[sg.Graph(canvas_size=(1000,600), | |
graph_bottom_left=(0,30), | |
graph_top_right=(40,0), | |
key="canvas", | |
background_color="#4d4d4d")], | |
] | |
window = sg.Window("Rogue Game", layout, return_keyboard_events=True) | |
window.finalize() | |
c = window["canvas"] | |
# draw dungeon | |
walls = [] | |
for y, row in enumerate(level): | |
for x, char in enumerate(row): | |
#if char == "#": | |
walls.append( | |
c.draw_rectangle( | |
top_left=(x-0.5,y-0.5), | |
bottom_right=(x+0.5, y+0.5), | |
fill_color = "#00ff33" if char == "#" else None, | |
line_color = "#ff3300", | |
line_width=2)) | |
hero = c.draw_text("\U0001f47e", | |
(herox,heroy), | |
color = "black", | |
font = (None,32), | |
angle = 0, | |
text_location = "center") | |
# block \u2588 | |
while True: | |
event, values = window.read() | |
if event in ("Quit", sg.WIN_CLOSED): | |
break | |
print(event) | |
if event in ("w:25","a:38","s:39","d:40"): | |
# keycodes for windows: "w", "s", ... etc. | |
# below are linux keycodes | |
if event == "w:25": | |
heroy -= 1 | |
if event == "s:39": | |
heroy += 1 | |
if event == "a:38": | |
herox -= 1 | |
if event == "d:40": | |
herox += 1 | |
window["canvas"].relocate_figure(hero, herox, heroy) | |
window.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment