import turtle from math import * cor=0 import kandinsky turtle.speed(0) draw=False loc=turtle px=float(8) py=float(14) sw=int(64) sh=int(64) fov=float(0.22) fd=float(10) tx=0 fl=False hit=False ty=0 h=float(0) loc.goto(5.5,5.5) loc.penup() loc.hideturtle() loc.goto(3,3) loc.rt(180) pa=(loc.heading()-13)*((22/7)/180) pi=22/7 px=loc.position()[1] py=loc.position()[0] cal=mx*fov # use multiline string define to make the map easier to # see/adjust map = ''' x64\nx.62x\nx.62x\nx.62x\nx.62x\nx.62x\nx.28b10.24x\nx.4g6.18b.8b.24x\nx.4g.4g.7g11b.8b5.20x\nx.4g.4g.7g.10b.8b.3b.20x\nx.4g.5g.6g.23b.20x\nx.4g.5g.6g.10b.8b.3b.20x\nx.4g5.g6.g.3g7b.8b5.20x\nx.4g.10g.g.3g.6b.8b.24x\nx.4g.10g3.3g3.5b3.b5.24x\nx.4g.10g.7g.6b.3b.27x\nx.4g.18g.6b.3b.27x\nx.4g.10g.7g.6b.3b.27x\nxg5.10g9.6b.3b.27x\nx.3g2.10g.14b.3b.27x\nx.3g7.g4.10b6.3b3.25x\nx.3g.4g.3g.12b.10b.25x\ng2.g2.4g.3g.12b.2b3.3b3.25x\nx.3g6.3g.12b.2b3.3b.27x\nx.3g.4g.3g.12b.2b3.3b.27x\nx.8g.3g.12b6.3b.27x\nx.3g.4g.3g.17b.3b.27x\nx.3g7.g4.15b2.b2.16x10.x\nx.3g2.9g.9g6.5g7.9x.8x.x\nx.3g2.9g.9g.15g2.9x.8x.x\nx.3g2.9g.9g.15gx11.8x.x\nx.4g.9g.9g.16x.9x.8x.x\nx.14g.9g.35x.x\nx.4g.9g.9g.16x.9x.8x.x\nx.3g2.9g.9g.15gx3.4x4.8x.x\nx.3g2.9g.9g.15g2.x2.2x.3x.8x.x\nx.3g2.9g.9g6x2.x2g6.3x.2x.3x.8x.x\nx.3g6.g5.15x.3x.9x.2x.3x3.x2.x3.x\nx.3g5.3g.18x.3x.9x.2x.6x.2x.4x\nx.3g5.3g.18x.3x.9x.2x.14x\nx.3g.3g.3g.18x.3x.9x.2x.14x\nx.7g.3g.18x.3x.9x.2x.2x.x.x.x.5x\nx.3g.3g.3g.18x.3x.9x.2x3.x.x.x.x2.3x\nx.3g5.3g.18x.3x.9x.3x.9x.3x\nx.3g5.3g12.7x.3x.9x.13x.3x\nx.15g.6g3.5x.3x.9x.3x.9x.3x\nx.24g.5x.3x.9x6.x.x.x.x2.3x\nx.15g.6g3.5x.3x.15x.x.x.x.5x\ng24.7x.3x.27x\nx.25x7.2x6.22x\nx.25x.4x.3x.4x.22x\nx.25x.13x.22x\nx.25x.4x.3x.4x.22x\nx.25x.4x.3x.4x.22x\nx.25x6.3x6.22x\nx.25x.4x.3x.4x.22x\nx.25x.13x.22x\nx.25x.4x.3x.4x.22x\nx.25x6.3x6.22x\nx.25x.13x.22x\nx.25x.13x.22x\nx.25x.13x.22x\nx.25x.13x.22x\nx64 '''.strip() # strip just removes any whitespace at the beginning and end # generate ma1, note this could easily be extended # to auto-detect width and height. ma1 = [] for row in map.splitlines(): ma1.extend(row) # strip the neewline from the map mx = my = int(sqrt(len(ma1))) # autodetect map square print(ma1) print(mx) print(my) def do_color(c, dis): shade = int(255-(dis*1.2*12.75)) if c == "b": return shade,shade,0 if c == "g": return shade,shade,shade if c=="x": return 0,0,shade while True: for i in range (int(sw)): ra=float(((pa-0.11)+(i)/(mx)*fov)) spot = 'r' ey=float(cos(ra)) ex=float (sin(ra)) dis=float (0) while hit ==False and dis< fd: dis=dis+0.5 tx=int(px+ex*dis) ty=int(py+ey*dis) if tx<0 or tx>=mx or ty<0 or ty>= my: hit=True else: cor=0 spot =(tx*mx+ty) for ci in range (len(ma1)): cor=cor+int(ma1[ci-1][1]) if cor>=spot: spot=(ma1[ci-1][0]) break if(spot!='o'): hit=True if dis>= fd: spot='o' hit=True if hit: h=40-(dis*4) kandinsky.fill_rect(17+(i*7),0,7,int(240-(((40-h)/2)*5)),(do_color(int(spot),dis))) kandinsky.fill_rect(17+(i*7),0,7,int((((40-h)/2)*5)),(50,50,50)) if i==sw-1: kandinsky.draw_string(str(turtle.position()),10,200) k = kandinsky.get_keys() if "up" in k and i==(sw-1): loc.fd(0.1) px=loc.pos()[1] py=loc.pos()[0] #if(ma1[int(px-0.1)*mx+int(py-0.1)]!="."): #loc.fd(-0.1) kandinsky.fill_rect(0,0,320,240,(50,50,50)) if "down" in k and i==(sw-1): loc.fd(-0.1) px=loc.pos()[1] py=loc.pos()[0] #if(ma1[int(px-0.1)*mx+int(py-0.1)]!="."): #loc.fd(0.1) kandinsky.fill_rect(0,0,320,240,(50,50,50)) if "left" in k and i==(sw-1): loc.lt(-3) radian = (loc.heading()-13.33)*(pi/180) pa=radian kandinsky.fill_rect(0,0,320,240,(50,50,50)) if "right" in k and i==(sw-1): loc.lt(3) radian = (loc.heading()-13.333)*(pi/180) pa=radian kandinsky.fill_rect(0,0,320,240,(50,50,50)) hit=False# Type your text here