Share your repls and programming experiences

← Back to all posts
Ray Casting Game
TurtleAndrew

I've spent the last day and a half working on this game that uses ray casting. Ray casting is a method of rendering a 2D level as if it was 3D. It was originally used in Wolfenstein 3D. Also note that it is very slow. I was getting much higher fps running it on my desktop and have spent hours trying to optimize it. Also, sorry for the low render distance, it was the only way for it to run fast enough. I have gotten floors working but they are even to slow to run on my desktop while still looking like more than random pixels. You can also find the python file "PyVectors.py" and an overview/documentation of it on my git hub: github.com

What it looks like running on my desktop (Its also using floors):

Controls:

space to toggle between textured and flat color
wasd to move
shift and wasd to sprint
left and right arrows to change view direction
up and down arrows to change resolution (lower res gives better performance)
shift space to toggle the map on and off
e to open/break doors (darker brown when using flat colors)
e to open yellow doors (flat yellow when using flat colors) and advance to the next level

There's a timer at the bottom of the texts ("TIME: ") so have fun speed running if you want to! Just comment a screenshot of your time.
Hope you enjoy!

Voters
Andy_4sberg
ANDREWVOSS
GamerM
Baconman321
Soccer135246
programmeruser
ch1ck3n
JacobMcPherson1
Luchadordragon
Wilke000
Comments
hotnewtop
[deleted]

not often you see python games in 3d, not complaining though.

TurtleAndrew

@tickedoffsquid Thanks! It's probably because python is so slow. Even this was really hard to get running in real time.

tussiez

This is amazing! Deserves an upvote

TurtleAndrew

@tussiez Thanks!

LegendaryWolf

wwwwwwwwwwwwwwwwwwwwwwwoooooooooooooooooooooowwwwwwwwwww!!!!!!!!!!!!!!!

TurtleAndrew
JohnHunter5

incredible! i gotta learn pygame lol

TurtleAndrew

@JohnHunter5 Thanks! also, if you need i can help you learn pygame.

LukeWright

i dunno if theres something wrong with my computer but res 1 gives me 2 fps avg and 5 gives me 10 fps avg

TurtleAndrew

@LukeWright Nothing wrong with your computer, i dont know why but on repl the frame rate is all over the place, i will get 60fps then 5fps on like 8 res no textures.

BananaJellyfish

i managed to get to level 2! through the yellow stripy door

TurtleAndrew
BananaJellyfish

This is really cool!

TurtleAndrew
BananaJellyfish

nice, the lighting has really improved!

TurtleAndrew

@BananaJellyfish ya, its four directional. Also, i made a game for the ScoreSpace #12 game jam, the files for it are here: https://github.com/AndrewDMorgan/Switch-em-up/blob/main/README.md you might enjoy it if you can run python3 on your computer. The issu is replit cant play sounds.

BananaJellyfish

Wow, its really cool! Can replit really not play sounds? I thought it could @TurtleAndrew

TurtleAndrew

@BananaJellyfish I've seen multiple posts saying replit can't. I don't think it's changed. Also, i don't have the hacker plan and it would take up a lot of space.

BananaJellyfish
TurtleAndrew

@BananaJellyfish How well do you know python3 and c++? Im wondering because im working on a python3 to c++ compiler but its really hard and im trying to find some people to work with on the project. Here's the post i put up abount it replit.com

TurtleAndrew

@BananaJellyfish Well, the sound situation on replit has changed, i saw the new news letter thingy in my email and it said replit now supports sound and references pygame for sound implementation, thats what im using for sounds. but the issu of space will still be an issu. Also, replit runs pygame SUPER slowly.

BananaJellyfish

Yeah, i've tried pygame and it was very laggy @TurtleAndrew

Coding4Lizz

mine doesn't have the mini map at the top:(

TurtleAndrew

@Coding4Lizz Press shift and space. It's also under the controls which are in the projects description (at the bottom)

IsmailHansia

I WON

IsmailHansia

TurtleAndrew

@IsmailHansia good job!

ch1ck3n

doom eternal 1993 lol

Luchadordragon

rip cpu but cool

TurtleAndrew

@Luchadordragon Thanks! I don't think my cpu likes me much. I constantly abuse it.

Luchadordragon

@TurtleAndrew me looking at minecraft w/ shaders: oooOOOHHHHhhhh fancy
my cpu and gpu: loud fan noises

TurtleAndrew

@Luchadordragon My computer is a newer one and i guess it cools in a different way so theres no loud fans (no fans at all). Before it i had to listen to vrrrrrrrr for so long. I think my cpu wants to light on fire. I'm currently running a program and I'm using 100 threads. i think my cpu is crying right now.

TurtleAndrew

@TurtleAndrew Should i add multi-threading to the ray caster?

Luchadordragon

@TurtleAndrew idk probably not because I have a low end pc and it cant handle anything above tetris smoothly

TurtleAndrew

@Luchadordragon lol, my old computer was like that.

TurtleAndrew

@Luchadordragon lol, i think my cpu is mad at me. Heres the cpu usage over all the cores on my computer:

Luchadordragon

@TurtleAndrew lol you would think they would all be used equaly but nope. what cpu do you have, i have like a intel i3 or i4

TurtleAndrew

@Luchadordragon they wouldnt be equally used because each of the windows are running on a different core. Also, the operating system dosent equalize the processing over multiple cores. I have the new apple m1 chip.

TurtleAndrew

@TurtleAndrew you can equalize the processing over multiple cores within the code but the operating system dosent do it for you. I was running python on 4 terminals and each of the terminals was running on a different core.

Luchadordragon

@TurtleAndrew yeah I know a whole prosses per core so some are used more than others. also what os are you on?

TurtleAndrew

@Luchadordragon My computer uses OS X

Luchadordragon

@TurtleAndrew I dont know many people using macs to do coding and FYI your computer has watercooling

TurtleAndrew

@Luchadordragon I dont think so, i cant find it anywhere that the new mac has water cooling. I have the mac book air and its way to small to have a water cooler.

Luchadordragon

@TurtleAndrew well thermal paste is another thing

TurtleAndrew

@Luchadordragon yes i think it has that. It also has no fan.

Wilke000

Before I turned on the map: Hmm... How do you play agian? Where in the ****n world do I go?
After I turned on the map: Oh.................. So that's what you do

TurtleAndrew
KENNETHTRIPP

WOW

TurtleAndrew
EMERSONSCHNIPKE

Will it work better if I copy it onto a local python file?

TurtleAndrew

@EMERSONSCHNIPKE If your referring to running it outside of a web browser/repl then yes it will run much quicker. When i run it on my desktop i get like a 2x-4x speed up and the frame rate is much more stable.

PSIPowerhouse

nvm

PSIPowerhouse

how do i get the minimap

TurtleAndrew

@Devgod23 Hold shift and press space. The controls are in the description to.

elburg

something interesting: at the last level(the end level), there is no yellow door. if one was placed in the level and interacted with, the game will crash.

TurtleAndrew

@elburg Yes it would crash and there is no door. Good observations. I could add a if statement stating if level < 4 then level += 1 else pass but theres no way to get a door so I'm not worried.

elburg

@TurtleAndrew The game uses a database to load levels, when the play interacts with a door, the value in the database goes up by one and loads the level with that value. since there is no level with the value that it returns, the game throws an error and halts itself.

maxina

Cool!

TurtleAndrew

@maxina Thanks!

PXY

I'm unable to load the project it seems. Is it supposed to take several minutes to run?

TurtleAndrew

@PXY no, try reloading. It's been working for me.

TurtleAndrew

@PXY It just loaded in for me so try reloading and if that doesn't work then idk.

PXY

works for me now. my browser was just running slow.

Looking at it now, this is an extremely impressive work and I'm amazed that you could pull it off without using a huge built-in framework. This is [email protected]

TurtleAndrew

@PXY Thanks!

JBloves27

Really cool!

TurtleAndrew

@JBloves27 Thanks!

JBloves27
AeneidVI

Oh, THAT'S what it's called! It's surprisingly hard to find information on if you don't know what it's called. Great program!

TurtleAndrew

@AeneidVI Thanks!

proryan

Epic!

TurtleAndrew

@proryan Thanks!

Bookie0

OUch

I bumped into wall :(

Lol really cool job! :D

TurtleAndrew

@Bookie0 Thanks! hope that didn't hurt to much.

Bookie0

@TurtleAndrew it did
lol np! :)

TurtleAndrew

@Bookie0 Just be careful and don't hit any more walls. But your not the only one, I've hit plenty myself.

Bookie0

@TurtleAndrew Yea, I'll try. Comforting to know I'm not the only one! xD

MikeJMS8910

I wanna see someone speed run this

TurtleAndrew

@MikeJMS8910 Here, ill add a timer that ends on the final level.

TurtleAndrew

@TurtleAndrew I added a timer and got this time (the timmer is bellow the "MAP: " text)

edit:

I got a better time (was done on my desktop for better performance):

MikeJMS8910

@TurtleAndrew cool thanks

TurtleAndrew

@MikeJMS8910 Speed run away!

BananaJellyfish

i won!

TurtleAndrew
MrDumbGuy

I have low fps, but that's a me thing, pretty cool otherwise.

TurtleAndrew

@MrDumbGuy Thanks! It's not a you thing, browser environments are slow, on my desktop i can run res 2 with textures and not dip bellow 20 but on repl i have to be on no textures res 6 to get ok performance. It also varys from 60fps to 5fps to 25fps. Basically when running it on a browser, it's slower and the fps isn't as stable.

BananaJellyfish

can you recommend a python raycasting tutorial?

TurtleAndrew
BananaJellyfish
BananaJellyfish

there's one thing i have never understood about raycasting. how is it 2D? i know you can't look up or down, but apart from that it seems pretty 3D to me.

TurtleAndrew

@BananaJellyfish The map is 2D, go to the "ray_casting_map.map" file and you can see all the levels and how to maps are 2D. You also only cast rays horizontally not vertically and use math to find the height of the wall.

BananaJellyfish

@TurtleAndrew ohh thanks