Skip to content
Sign upLog in
← Back to Community
Ray Casting Game
Profile icon
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):
screenshot-ray_casting

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
Profile icon
RishiMohanty
Profile icon
Andy_4sberg
Profile icon
ANDREWVOSS
Profile icon
GamerM
Profile icon
Baconman321
Profile icon
Soccer135246
Profile icon
programmeruser
Profile icon
ch1ck3n
Profile icon
JacobMcPherson1
Profile icon
Luchie
Comments
hotnewtop
Profile icon
[deleted]

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

Profile icon
TurtleAndrew

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

Profile icon
tussiez

This is amazing! Deserves an upvote

Profile icon
TurtleAndrew

@tussiez
Thanks!

Profile icon
LegendaryWolf

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

Profile icon
TurtleAndrew
Profile icon
JohnHunter5

incredible! i gotta learn pygame lol

Profile icon
TurtleAndrew

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

Profile icon
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

Profile icon
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.

Profile icon
BananaJellyfish

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

Profile icon
TurtleAndrew
Profile icon
BananaJellyfish

This is really cool!

Profile icon
TurtleAndrew
Profile icon
BananaJellyfish

nice, the lighting has really improved!

Profile icon
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.

Profile icon
BananaJellyfish

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

@TurtleAndrew

Profile icon
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.

Profile icon
BananaJellyfish
Profile icon
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

Profile icon
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.

Profile icon
BananaJellyfish

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

@TurtleAndrew

Profile icon
Coding4Lizz

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

Profile icon
TurtleAndrew

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

Profile icon
IsmailHansia

I WON

Profile icon
IsmailHansia

Screenshot 2021-03-08 at 6.03.04 PM

Profile icon
TurtleAndrew

@IsmailHansia
good job!

Profile icon
ch1ck3n

doom eternal 1993 lol

Profile icon
Luchie

rip cpu but cool

Profile icon
TurtleAndrew

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

Profile icon
Luchie

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

Profile icon
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.

Profile icon
TurtleAndrew

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

Profile icon
Luchie

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

Profile icon
TurtleAndrew

@Luchadordragon
lol, my old computer was like that.

Profile icon
TurtleAndrew

@Luchadordragon
lol, i think my cpu is mad at me. Heres the cpu usage over all the cores on my computer:
Screen Shot 2021-03-05 at 8.57.43 PM

Profile icon
Luchie

@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

Profile icon
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.

Profile icon
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.

Profile icon
Luchie

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

Profile icon
TurtleAndrew

@Luchadordragon
My computer uses OS X

Profile icon
Luchie

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

Profile icon
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.

Profile icon
Luchie

@TurtleAndrew
well thermal paste is another thing

Profile icon
TurtleAndrew

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

Profile icon
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
image

Profile icon
TurtleAndrew
Profile icon
KENNETHTRIPP

WOW

Profile icon
TurtleAndrew
Profile icon
EMERSONSCHNIPKE

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

Profile icon
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.

Profile icon
PSIPowerhouse

nvm

Profile icon
PSIPowerhouse

how do i get the minimap

Profile icon
TurtleAndrew

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

Profile icon
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.

Profile icon
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.

Profile icon
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.

Profile icon
maxina

Cool!

Profile icon
TurtleAndrew

@maxina
Thanks!

Profile icon
PXY

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

Profile icon
TurtleAndrew

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

Profile icon
TurtleAndrew

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

Screen Shot 2021-02-25 at 1.53.57 PM

Profile icon
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]

Profile icon
TurtleAndrew

@PXY
Thanks!

Profile icon
JBloves27

Really cool!

Profile icon
TurtleAndrew

@JBloves27
Thanks!

Profile icon
JBloves27
Profile icon
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!

Profile icon
TurtleAndrew

@AeneidVI
Thanks!

Profile icon
proryan

Epic!

Profile icon
TurtleAndrew

@proryan
Thanks!

Profile icon
Bookie0

Screen Shot 2021-02-25 at 10.18.01 AM