Created
January 5, 2022 04:28
-
-
Save foone/e2ae1cc22c3db56d2bd547ba57e4df9c to your computer and use it in GitHub Desktop.
Hall of Tortured Souls
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
#!/usr/bin/python | |
import pygame | |
from pygame.constants import * | |
import sys,re | |
lines=[] | |
dots=[] | |
offset=[0,0] | |
def build_re(start,args): | |
return re.compile('^({})'.format(start) + (r'(?:[\s,]+)([-.\d]+)'*args)) | |
def anymatch(line,regexes): | |
for regex in regexes: | |
m=regex.search(line) | |
if m: | |
return m | |
XSCALE=-10.0 | |
YSCALE=10.0 | |
REGEXES=[ | |
build_re('b',2), | |
build_re('w',5), | |
build_re('z',4), | |
build_re('e',4), | |
build_re('s',4), | |
] | |
with open('map.txt','r') as f: | |
for line in f: | |
line=line.rstrip() | |
m=anymatch(line.rstrip(),REGEXES) | |
if not m: | |
continue # skip line | |
m_type=m.group(1) | |
if m_type=='b': | |
offset[0]=XSCALE*float(m.group(2)) | |
offset[1]=YSCALE*float(m.group(3)) | |
elif m_type in 'wz': | |
xoff,yoff=offset | |
x1,y1=xoff+XSCALE*float(m.group(2)),yoff+YSCALE*float(m.group(3)) | |
x2,y2=xoff+XSCALE*float(m.group(4)),yoff+YSCALE*float(m.group(5)) | |
if m_type=='w': | |
tex=int(m.group(6)) | |
else: | |
tex=0 | |
lines.append((x1,y1,x2,y2,tex,m_type)) | |
elif m_type in 'es': | |
x,y=XSCALE*float(m.group(3)),YSCALE*float(m.group(2)) | |
dots.append((x,y,m_type)) | |
print dots[-1] | |
COLORS={ | |
'w':(0,0,0), | |
'z':(192,192,192), | |
'e':(255,0,0), | |
's':(0,255,0) | |
} | |
AFTERSCALE=0.5 | |
MOVESPEED=10.0 | |
drawpos=[0.0,0.0] | |
def translate_xy(x,y): | |
xoff,yoff=drawpos | |
return (int((xoff+x)*AFTERSCALE),int((yoff+y)*AFTERSCALE)) | |
def draw(): | |
screen.fill((255,255,255)) | |
for (x1,y1,x2,y2,tex,line_type) in lines: | |
p1=translate_xy(x1,y1) | |
p2=translate_xy(x2,y2) | |
pygame.draw.line(screen,COLORS[line_type],p1,p2) | |
for (x,y,dot_type) in dots: | |
pygame.draw.circle(screen,COLORS[dot_type],translate_xy(x,y),5) | |
pygame.display.flip() | |
def update(): | |
pass | |
def init(): | |
global screen,screen_size | |
screen_size=(800,800) | |
pygame.init() | |
pygame.display.set_caption('Hall of Tortured Souls') | |
flags=0 | |
if '-f' in sys.argv or '--fullscreen' in sys.argv: | |
flags|=FULLSCREEN | |
screen=pygame.display.set_mode(screen_size,flags) | |
pygame.key.set_repeat(25,200) | |
def main(): | |
global running,AFTERSCALE | |
init() | |
running=True | |
while running: | |
update() | |
draw() | |
for event in pygame.event.get(): | |
if event.type==QUIT: | |
running=False | |
elif event.type==KEYUP: | |
if event.key==K_ESCAPE: | |
running=False | |
elif event.type==KEYDOWN: | |
if event.key==K_w: | |
drawpos[1]+=MOVESPEED/AFTERSCALE | |
elif event.key==K_s: | |
drawpos[1]-=MOVESPEED/AFTERSCALE | |
elif event.key==K_a: | |
drawpos[0]+=MOVESPEED/AFTERSCALE | |
elif event.key==K_d: | |
drawpos[0]-=MOVESPEED/AFTERSCALE | |
elif event.key==K_q: | |
AFTERSCALE*=0.5 | |
elif event.key==K_e: | |
AFTERSCALE*=2.0 | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment