fps.py

Created by aidanplews2013

Created on November 25, 2020

7.39 KB

this is a simple raycasting engine. to use it right now you need a modded firmware but I’ve been told key presses will work in the next official update


import turtle
from math import *


import kandinsky

draw=False
loc=turtle
px=float(5.5)
py=float(5.5)
pa=float(0)



fd=float(10)
tx=0
fl=False
hit=False
ex1=[-0.0375, -0.6678, -0.6643, -0.6608, -0.6572, -0.6537, -0.6502, -0.6466, -0.643, -0.6394, -0.6358, -0.6322, -0.6285, -0.6249, -0.6212, -0.6175, -0.6138, -0.6101, -0.6064, -0.6027, -0.5989, -0.5952, -0.5914, -0.5876, -0.5838, -0.58, -0.5762, -0.5723, -0.5685, -0.5646, -0.5607, -0.5569, -0.553, -0.549, -0.5451, -0.5412, -0.5372, -0.5333, -0.5293, -0.5253, -0.5213, -0.5173, -0.5133, -0.5093, -0.5052, -0.5012, -0.4971, -0.4931,-0.0375, 0.7448, 0.7479, 0.751, 0.7541, 0.7572, 0.7602, 0.7632, 0.7663, 0.7693, 0.7723, 0.7752, 0.7782, 0.7811, 0.784, 0.7869, 0.7898, 0.7927, 0.7955, 0.7984, 0.8012, 0.804, 0.8068, 0.8095, 0.8123, 0.815, 0.8177, 0.8204, 0.8231, 0.8257, 0.8283, 0.831, 0.8336, 0.8361, 0.8387, 0.8412, 0.8438, 0.8463, 0.8488, 0.8512, 0.8537, 0.8561, 0.8585, 0.8609, 0.8633, 0.8657, 0.868, 0.8703,-0.0375, 0.6668, 0.6633, 0.6598, 0.6563, 0.6528, 0.6492, 0.6456, 0.642, 0.6384, 0.6348, 0.6312, 0.6275, 0.6239, 0.6202, 0.6165, 0.6128, 0.6091, 0.6054, 0.6017, 0.5979, 0.5942, 0.5904, 0.5866, 0.5828, 0.579, 0.5751, 0.5713, 0.5674, 0.5636, 0.5597, 0.5558, 0.5519, 0.548, 0.5441, 0.5401, 0.5362, 0.5322, 0.5282, 0.5243, 0.5203, 0.5162, 0.5122, 0.5082, 0.5042, 0.5001, 0.496, 0.492,-0.0375, -0.7456, -0.7487, -0.7518, -0.7549, -0.758, -0.761, -0.7641, -0.7671, -0.7701, -0.7731, -0.776, -0.779, -0.7819, -0.7848, -0.7877, -0.7906, -0.7935, -0.7963, -0.7991, -0.8019, -0.8047, -0.8075, -0.8103, -0.813, -0.8157, -0.8184, -0.8211, -0.8238, -0.8264, -0.829, -0.8317, -0.8343, -0.8368, -0.8394, -0.8419, -0.8444, -0.8469, -0.8494, -0.8519, -0.8543, -0.8568, -0.8592, -0.8616, -0.8639, -0.8663, -0.8686, -0.8709]

ey1=[0.9993, 0.7444, 0.7475, 0.7506, 0.7537, 0.7567, 0.7598, 0.7628, 0.7659, 0.7689, 0.7719, 0.7748, 0.7778, 0.7807, 0.7836, 0.7865, 0.7894, 0.7923, 0.7952, 0.798, 0.8008, 0.8036, 0.8064, 0.8091, 0.8119, 0.8146, 0.8173, 0.82, 0.8227, 0.8253, 0.828, 0.8306, 0.8332, 0.8358, 0.8384, 0.8409, 0.8434, 0.8459, 0.8484, 0.8509, 0.8534, 0.8558, 0.8582, 0.8606, 0.863, 0.8653, 0.8677, 0.87, 0.8723, 0.8746, 0.8768, 0.8791,0.9993, 0.6673, 0.6638, 0.6603, 0.6568, 0.6532, 0.6497, 0.6461, 0.6425, 0.6389, 0.6353, 0.6317, 0.628, 0.6244, 0.6207, 0.617, 0.6133, 0.6096, 0.6059, 0.6022, 0.5984, 0.5947, 0.5909, 0.5871, 0.5833, 0.5795, 0.5757, 0.5718, 0.568, 0.5641, 0.5602, 0.5563, 0.5524, 0.5485, 0.5446, 0.5407, 0.5367, 0.5327, 0.5288, 0.5248, 0.5208, 0.5168, 0.5128, 0.5087, 0.5047, 0.5006, 0.4966, 0.4925, 0.4884, 0.4843, 0.4802, 0.4761,0.9993, -0.7452, -0.7483, -0.7514, -0.7545, -0.7576, -0.7606, -0.7637, -0.7667, -0.7697, -0.7727, -0.7756, -0.7786, -0.7815, -0.7844, -0.7873, -0.7902, -0.7931, -0.7959, -0.7987, -0.8016, -0.8044, -0.8071, -0.8099, -0.8126, -0.8154, -0.8181, -0.8207, -0.8234, -0.8261, -0.8287, -0.8313, -0.8339, -0.8365, -0.839, -0.8416, -0.8441, -0.8466, -0.8491, -0.8516, -0.854, -0.8564, -0.8589, -0.8612, -0.8636, -0.866, -0.8683, -0.8706, -0.8729, -0.8752, -0.8775, -0.8797,0.9993, -0.6664, -0.6629, -0.6593, -0.6558, -0.6523, -0.6487, -0.6451, -0.6415, -0.6379, -0.6343, -0.6307, -0.6271, -0.6234, -0.6197, -0.616, -0.6123, -0.6086, -0.6049, -0.6012, -0.5974, -0.5936, -0.5899, -0.5861, -0.5823, -0.5785, -0.5746, -0.5708, -0.5669, -0.5631, -0.5592, -0.5553, -0.5514, -0.5475, -0.5435, -0.5396, -0.5356, -0.5317, -0.5277, -0.5237, -0.5197, -0.5157, -0.5117, -0.5076, -0.5036, -0.4995, -0.4955, -0.4914, -0.4873, -0.4832, -0.4791, -0.475]





ty=0


h=float(0)
loc.goto(5.5,5.5)
loc.penup()
loc.ht()

pi=22/7



ma1 = ['x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x',

      'x','.','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','x','x','x','x','x','x',

      'x','.','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','x','x','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','x','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','x','.','.','.','x','x',

      'x','.','.','.','.','.','.','.','.','.','x','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','x','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','.','.','.','.','.','.','.','.','.','.','.','.','.','.','x',

      'x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x']






   

while True:

    for i in range (int(sw)):
       















                
        ex=0       
                    
        if pa==4.015873015873016:
            ex=ex4[i]
            ey=ey4[i]
        if pa==2.4444444444444446:
            ex=ex3[i]
            ey=ey3[i]
        if pa==0.873015873015873:
            ex=ex2[i]
            ey=ey2[i]
        if pa==-0.6984126984126984:
            ex=ex1[i]
            ey=ey1[i]           
        
        
        
        
        
        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:
            
                if(ma1[(tx*mx+ty)]=="x"):
                    hit=True
        if dis>= fd:
            hit=True
                    
        
        if hit:
          
            
                
            
              kandinsky.wait_vblank
              h=40-(dis*4)
                
                   
                   
              
                   
              kandinsky.fill_rect((i*3),0,3,int(240-(((40-h)/2)*5)),((255-(int(dis*1.2*12.75))),0,0))
              draw=True
                
                  
              kandinsky.fill_rect(i*3,0,3,int(((((40-h)/2)*5))),(0,0,0))
              fl=True
                  
                
                    
              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)]=="x"):
                  loc.fd(-0.1)
                kandinsky.fill_rect(0,0,320,240,(0,0,0))
              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)]=="x"):
                  loc.fd(0.1)
                kandinsky.fill_rect(0,0,320,240,(0,0,0))
              if "left" in k and i==(sw-1):
                loc.lt(-90)
                  
                  
                radian = (loc.heading()-40)*(pi/180)
                pa=radian                 
                kandinsky.fill_rect(0,0,320,240,(0,0,0))
              if "right" in k and i==(sw-1):
                loc.lt(90)
                  
                  
                radian = (loc.heading()-40)*(pi/180)
                pa=radian                 
                kandinsky.fill_rect(0,0,320,240,(0,0,0))
              hit=False
                
                  
                

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.