Tutorial #5 My code is broken as shit

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Austiculus
Posts: 2
Joined: January 29th, 2021, 1:00 am

Tutorial #5 My code is broken as shit

Post by Austiculus » January 29th, 2021, 1:10 am

So I am tying to use the gfx.ScreenWidth and gfx.ScreenHeight to make it to where the reticle stops when it hits the edge of the screen. When I try to run it I get an error saying:
Assertion failed!

Expression: x < int(Graphics::ScreenWidth)

Ill attach the file that the debugger is stopping at (Graphics.cpp) and also the game.cpp and game.h.
Attachments
Graphics.cpp
(11.8 KiB) Downloaded 157 times
Game.h
(2.19 KiB) Downloaded 149 times
Game.cpp
(4.18 KiB) Downloaded 169 times

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Tutorial #5 My code is broken as shit

Post by albinopapa » February 1st, 2021, 5:09 am

Here's the problem I believe:

Code: Select all

	if (x + 5 >= gfx.ScreenWidth)
	{
		x = gfx.ScreenWidth - 6;
	}
	if (x - 5 <= gfx.ScreenWidth)
	{
		x = gfx.ScreenWidth + 6;
	}
Assuming Graphics::ScreenWidth is 800
If x + 5 is greater than or equal to 800, then x equals 794
if x - 5 is less than or equal to 800, then equals 806

So if x is 0 to 799 it automatically gets set to 806.

I think the second one is suppose to be:
if( x - 5 < 0 ) x = 5;
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Austiculus
Posts: 2
Joined: January 29th, 2021, 1:00 am

Re: Tutorial #5 My code is broken as shit

Post by Austiculus » February 17th, 2021, 6:16 am

I did that and now it runs but everytime it hits a wall I got another error screen instead of the reticle just sitting at the edge of the screen. Now it says "Assertation failed!.... Expression:x >=0"

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Tutorial #5 My code is broken as shit

Post by albinopapa » February 17th, 2021, 5:05 pm

The original issue you were having means that the pixels were trying to be drawn beyond the Graphics::ScreenWidth boundary ( >= 800 ). This issue means that the pixels are trying to be drawn beyond the left side of the window ( < 0 ). You'll have to determine where the failure is in your logic.

If the reticle is drawn from the center and is 5 pixels in either direction, then the center needs to be at least 5 pixels away from all edges or go from ( 5, 5 ) to ( ScreenWidth - 6, ScreenHeight - 6 ).

If you still can't find the error, post the code and someone will take a look.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply