Log In  

Cart #zenhewum-5 | 2024-01-31 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
12

Try to solve the maze >:)

Arrow keys to look around
ESDF/up and down arrow keys to move

--Comments in code explain how everything works, so feel free to take it apart, but ill explain here again:
the player has "raycasts" which are lines that can hit certain objects and return data, sent in front of them at different angles. When these rays hit a wall, they draw a line at a height of the reciprocal of the distance to the point that was hit. The reciprocal is used so it creates perspective (far stuff is small close stuff is big).

--IMPORTANT NOTE--
This engine is not the most effective way of doing it, as it does not store map data in strings. It is, however, easier to create maps with this one as you can simply use the built in map editor. If you are willing to lose some efficiency for an easier time, this engine is perfect for you.

--Ps. you can use this in whatever you want, just credit me (also if you don't read any of the other notes in the code at least read the last tab, that one is important)

--Version history
--1.0
--Old version with reverse fisheye effect and sprite overlapping
--Thanks to @freds72 for pointing these bugs out
--2.0 reverse fisheye fixed and sprite overlapping fixed
--2.1 minor optimizations

P#140742 2024-01-28 09:04 ( Edited 2024-01-31 04:44)

1

Very nice! You may be interested in the methods for improved accuracy of trig functions laid out by @samhocevar in this post

It's looking good! I will have to dig more into the code later

P#140775 2024-01-28 23:25
1

the fisheye effect has nothing to do with sin/cos precision.
this engine is missing a bit of code to correct the effect (see lodev tuto on raycasting or Mot raycaster).

P#140787 2024-01-29 07:49

@freds72 i believe i added the fix to the fisheye if you're referring to multiplying distance by cos(looking angle), I don't see a fisheye effect while I'm playing it? Unless you're referring to a different type of visual distortion (also I love demi daggers :) )

P#140788 2024-01-29 08:12 ( Edited 2024-01-29 08:15)
1

thanks 😊
looks like something is off in your raycasting - you have a sort of inverted fisheye effect (not to mention texture blocks overlapping each other’s).

and really suggest to look at sspr usage - I bet that the 1000/d loop is the root cause for bad perf + distortion.

P#140794 2024-01-29 10:08 ( Edited 2024-01-29 10:12)

@freds72 i didn't think about that but I can definitely see how that would cause bugs! I'll look into that right away, thank you 😊

P#140831 2024-01-29 17:34

@freds72 I figured out the reason I have the inverted fisheye effect! And the reason textures overlap (with much less difficulty LOL) I went on a wild goose chase trying to figure out why it was broken when in fact it was something else entirely! I just needed to increase the precision of my raycasting. EX: in the old version I was increasing each ray by one, which would be off by anywhere from 0-1, so obviously it looked weird. I'm still increasing by the same amount but am making a separate function to increase the precision much! (I also optimized the code a lot more LOL)

P#140905 2024-01-31 02:30
1

I won too ;)

P#140918 2024-01-31 12:57
1

definitely an improvement but still running at 15fps (eg you are over cpu budget!).

If you can/will, suggest to refactor your code to match what this tutorial is doing: https://lodev.org/cgtutor/raycasting.html

P#140944 2024-01-31 18:52

[Please log in to post a comment]