Help with raycaster

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
loz_bl2_mario
Posts: 8
Joined: May 16th, 2020, 12:03 pm

Help with raycaster

Post by loz_bl2_mario » July 7th, 2020, 1:35 am

I'm trying to get the rectangles that the player is looking at to turn cyan, and I feel like this should be working.


My code:


Code: Select all

void update(Graphics& gfx)
{
for (int x = 0; x < 7; x++)
	{
		for (int y = 0; y < 6; y++)
		{
			gfx.DrawRectDim(p1.potX, p1.potY, 5, 5, Colors::Red);
			if (map[x][y] == 1)
			{
				

				if (p1.potX >= x * 50 && p1.potX <= ((x * 50) + 50))
				{
					if (p1.potY >= y * 50 && p1.potY <= ((y * 50) + 50))
					{
						gfx.DrawRectDim(x * 50, y * 50, 50, 50, Colors::Cyan);
					}
				}
				else
				{
					gfx.DrawRectDim(x * 50, y * 50, 50, 50, Colors::Magenta);
					p1.update();
				}
			}
			else
			{
				gfx.DrawRectDim(x * 50, y * 50, 50, 50, Colors::Green);
			}
		}
	}
}
Player.cpp

Code: Select all

#include "Player.h"

void Player::update(bool canUpdate)
{

	
	if (rayPos > 500.0f)
	{
		rayPos = 0.0f;
	}
	if (angle > 180.0f)
	{
		angle = -180.0f;
	}
	if (canUpdate)
	{
		potX = x + cos(angle) * rayPos;
		potY = y + sin(angle) * rayPos;
		rayPos += 50.0f;
	}

Here is the solution if you want be get fucky:
Attachments
Chili DirectX Framework.zip
(106.37 KiB) Downloaded 42 times
I'm better than you, F*ck Off!


Formerly know as goldengamesTM

loz_bl2_mario
Posts: 8
Joined: May 16th, 2020, 12:03 pm

Re: Help with raycaster

Post by loz_bl2_mario » July 7th, 2020, 6:54 am

I figured it out
I'm better than you, F*ck Off!


Formerly know as goldengamesTM

Post Reply