I need help making my raycaster faster as it takes time to render the image after
input. I have tried doing the turtle.tracer(0, 0) thing but it is still slow.
P.S. I don't know how to do python keyboard detection so you have to press enter every time you press a letter.
input. I have tried doing the turtle.tracer(0, 0) thing but it is still slow.
P.S. I don't know how to do python keyboard detection so you have to press enter every time you press a letter.
import turtle import math # Instructions: # You can only type in one letter at a time and return # w = forward # A = left # d = right # s = backwards # Do not run into the walls partly because I haven't coded the collision # detection and also partly because it displays an error right after screen = turtle.Screen() screen.bgcolor("Black") turt = turtle.Turtle() turt.speed(0) turt.penup() plr = turtle.Turtle() plr.penup() plr.sety(-30) plr.setx(-30) plr.setheading(45) draw = turtle.Turtle() draw.penup() draw.pensize(6) draw.speed(0) user = "" angle = -48 distance = 0 lis = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] lis2 = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] def fwd(): plr.forward(20) def bck(): plr.forward(-20) def lft(): plr.right(20) def rgt(): plr.left(20) while True: while True: user = str(input("use the W A S D keys to move around:")) if (user == "w"): plr.forward(5) break if (user == "s"): plr.forward(-5) break if (user == "d"): plr.left(15) break if (user == "a"): plr.right(15) break angle = -48 for i in range(96): turt.tracer(0, 0) turt.setx(plr.xcor()) turt.sety(plr.ycor()) turt.setheading(plr.heading() + angle) distance = 0 while distance != 200: turt.tracer(0, 0) lis2[i] = 0 # bounderies if (turt.xcor() > 50): turt.setx(50) lis2[i] = 1 break if (turt.ycor() < -50): turt.sety(-50) lis2[i] = 2 break if (turt.ycor() > 50): turt.sety(50) lis2[i] = 2 break if (turt.xcor() < -50): turt.setx(-50) lis2[i] = 1 break # block if (turt.xcor() > 30 and turt.xcor() < 31.5 and turt.ycor() > -20 and turt.ycor() < 20): lis2[i] = 3 break if (turt.xcor() > 37 and turt.xcor() < 38.5 and turt.ycor() > -20 and turt.ycor() < 20): lis2[i] = 3 break if (turt.ycor() > 20 and turt.ycor() < 21 and turt.xcor() > 30 and turt.xcor() < 38.5): lis2[i] = 4 break if (turt.ycor() < -20 and turt.ycor() > -21 and turt.xcor() > 30 and turt.xcor() < 38.5): lis2[i] = 4 break # block 2 if (turt.xcor() > 10 and turt.xcor() < 11.5 and turt.ycor() > -20 and turt.ycor() < 20): lis2[i] = 3 break if (turt.xcor() > 17 and turt.xcor() < 18.5 and turt.ycor() > -20 and turt.ycor() < 20): lis2[i] = 3 break if (turt.ycor() > 20 and turt.ycor() < 21 and turt.xcor() > 10 and turt.xcor() < 18.5): lis2[i] = 4 break if (turt.ycor() < -20 and turt.ycor() > -21 and turt.xcor() > 10 and turt.xcor() < 18.5): lis2[i] = 4 break turt.forward(1) distance = distance + 1 lis[i] = distance * math.sin(math.radians(90 - angle)) angle += 1 draw.setx(-200) draw.clear() for i in range(96): if (lis2[i] == 2): draw.color("Mediumblue") elif (lis2[i] == 1): draw.color("Blue") elif (lis2[i] == 3): draw.color("Red") elif (lis2[i] == 4): draw.color("Crimson") draw.sety(200) draw.sety(-1500 / lis[i]) draw.pendown() draw.sety(1500 / lis[i]) draw.setx(draw.xcor() + 5) draw.penup() draw.color("Black") draw.update()