A downloadable game

Download NowName your own price

raycasting was a very used 3D rendering technique in the 90's when computers had not enough power to display  real time polygonal 3D as today's, it is also called 2.5D or pseudo 3D.
one of the most popular games that used this technique was Wolfenstein 3D and Doom (id software), 
back then games were mostly all written in C programming language 
and assembly (machine language) for speed and optimization purpose, 
one famous programmer who optimized this technique was John Carmack (Doom, Wolfenstein 3D).
there is also floorcasting  a well known technique to render 3D perspective view, 
also known as mode 7 in the Super NES video game console (SNES), the SNES was hardware accelerated to do mode 7, 
and one famous exemple was Super Mario Kart and F-Zero, even rpg like Final Fantasy VI  used it.
I used this tutorial:
https://permadi.com/1996/05/ray-casting-tutorial-table-of-contents/
so it is recommended to follow it step by step to understand the math behind raycasting and floorcasting.

Download

Download NowName your own price

Click download now to get access to the following files:

raycasting+floorcasting.rar 42 kB

Comments

Log in with itch.io to leave a comment.

(1 edit) (+1)

First of all, thank you... I have been struggling with finding a simple raycast sample to help me figure it out, and so far yours has been ideal for what I am trying to do. I have already tweaked the code in a couple places to achieve what I was hoping for. I do have some questions I would like to ask, and was wondering what the best way to go about that is?

(1 edit) (+1)

you're welcome... one thing you can do to deal with performance issue in pygame when it come to pixel manipulation or blitting so many things at once is as follow:

create a small display surface like (320, 240), blit everything on it (sprites must be tiny) then scal it to the screen size like (640, 420) then blit it on screen. that should resolve performance problems in raycasting and pseudo 3D engines, and  I think this is how programmers dealed with it in the past when they have limited hardware resources.

(+1)

Performance really isn't the issue... Here are the changes I have made:

1) I added the ability to have different "wall" types
2) I added a ceiling
3) I allowed for the floor and ceiling to have a different tile than the walls
4) I checked for collision with the wall before allowing you to move (kinda important!)
5) I added a soundtrack. The one I am using is Stones, from Ultima IX

The issue is that, now with different images, I see some "bleeding" on the wall images. For instance, if you look at the following image:

http://www.tidmadt.com/images/new_images/errors.jpg

you can see (where I circle in red) where slices from the wrong image are being rendered. This isn't a problem where ALL the images are the same, but I can't see where the line of sight is failing. As you can see in the code, what I do wherever you check to see if there is a wall (if grid[y][x]==1:) I set "wall_type" to what that wall is (a 1 or 2... wall_type = grid[y][x]) so it SHOULD be the same result for the entire segment of the wall... for some reason, some bands seem to be wrong.

Also, while the walls (resolution wise) seem to be fine, the ceiling and floors don't look right. 

I created a GitHub fork of your code (giving you full credit for the original) here:

https://github.com/TIDMADT-SYS/simle-raycast

I have 2 versions there, the FPS (with free movement) and the crawler mode (which locks you into 90 degree turns, and one full grid space in movement)

Hopefully it is something minor... just not knowing that aspect of it as well as you, I can't see where in it the problem rests

Thank you in advance for taking time to look

(2 edits) (+1)

sorry, I really don't have the time nor the will to delve in raycasting project right now. but I can point you to some useful resources that may help you in your project:

here is a good raycasting engine with floor and ceiling that work very well, there's even shadow implemented and it is derived from the permadi tutorial I believe, it is written in java script but  you can easily port it to python:

https://github.com/permadi-com/ray-cast/tree/master/

here is other good raycasting tutorials with code and explanation:

https://dev.opera.com/articles/3d-games-with-canvas-and-raycasting-part-1/

https://www.playfuljs.com/a-first-person-engine-in-265-lines/

hope it help.

(+1)

It is something to look at... I will let you know how it goes! Thanks

(1 edit) (+1)

I just remembered to tell you that for the ceiling and the floors to be correct, change the value of the resolution variable to 1, you will have a clear image but unfortunately the performances will drop considerably, that's why I gave you some suggestions on how to improve performance in the first place.