Skip to content

thewongwaae/cub3d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CUB3D

This project was made by Wong Hong You | hwong and Nur Almas | nnorazma

Current Workflow:

Map Parsing

  • Start with square/rectangular maps. Prioritise raycasting.
  • Filename check (.cub)
  • Check that all walls are closed off (1 for wall, 0 for space)
  • Store map in 2d array

Top-down player movement

  • Initialise whatever needs to be initialised for mlx. (Window, etc)
  • Print a marker to represent the player.
  • Handle key press, and map them to players movement.
  • Print out a top-down view of the map, preferably with gridlines. (To act as reference for raycast)
  • Later on we could maybe minimise this on screen to become the minimap.
  • Handle player rotation (I don't have brain to make notes on this atm)

Raycasting

* Refer to that one video I shared

* Horizontal and vertical lines (on the grid) handled somewhat separately. Start with a single ray first.

* Horizontal check (up or down on the grid):

* Check if the nearest cell that the ray is facing on the horizontal line is a wall.

* else, add the x and y offset to check the next horizontal line.

* Draw a ray, just so we can see whats going on lol

* Vertical check (left or right):

* Pretty much the same as above.

We scrapped the method above for multiple reasons:

  • The 3D display had very jagged walls.
  • The algorithm often miscalculated the distance. Resulting in said jaggedness.
  • It could definitely be fixed, with reduced step-size, or with extra work. But extra steps == laggy. And extra work to fix this method used meant more time spent. I don't have enough BH days for that.

Instead we referred to this, Raycasting by Lodev.

Textures

  • Initialise and store textures.
  • Set current ray texture based on direction.
  • Determine top and bottom coordinate of ray.
  • Calculate the point at where the ray hits the texture.
  • Calculate the exact position of the texture pixel.
  • Get the colour of the pixel. Set the pixel to draw as that colour.
  • Draw texture on screen. :thumbs_up:

Audio

  • Figure out how to do it.
  • seele
  • Wall collision sounds.

Door Animation

  • This is about to be the most scuffed animation you've ever seen.
  • [ ] Figure out the frames. (Actual video has 118 frames. Thats 118 XPM FILES)
  • Went with amogus x the rock.

ISSUES

  • Pure raycast render is rough and jagged, anti-aliasing? later on need take vertex coordinates and map to an mlx image.
    • Fixed: Completely changed the method. Smoother lines and display.

  • Different wall faces have same color, difficult to make out edges. find out direction of each wall rays hit and map to right color.
    • Mapping textures to different wall directions done.

  • At certain distances, only the top pixels of the walls seem to be from another texture. :'>
    • Fixed: pix(x, y) were swapped in get_wall_hit calculations lol.

  • Textures appear to be scrolling.
    • Fixed: See above.

  • At certain angles, some walls seem to I guess.. crop? It just gets cut off. When walking past the wall, everything beyond that seems to disappear.
    • Fixed: Forgot to update the new position in the map. The variable was already declared.

  • Audio forking is wrecking my imac bro.
    • Fixed: exit(0)

  • Doors are making the game laggy.
    • Fixed: remove fsanitize ???

  • Seele ani crashes game.
    • Not so fixed: Scrapped the idea and went with something else.