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.
Tutorial #5 My code is broken as shit
-
- Posts: 2
- Joined: January 29th, 2021, 1:00 am
Tutorial #5 My code is broken as shit
- Attachments
-
- Graphics.cpp
- (11.8 KiB) Downloaded 158 times
-
- Game.h
- (2.19 KiB) Downloaded 151 times
-
- Game.cpp
- (4.18 KiB) Downloaded 170 times
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Tutorial #5 My code is broken as shit
Here's the problem I believe:
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;
Code: Select all
if (x + 5 >= gfx.ScreenWidth)
{
x = gfx.ScreenWidth - 6;
}
if (x - 5 <= gfx.ScreenWidth)
{
x = gfx.ScreenWidth + 6;
}
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
-
- Posts: 2
- Joined: January 29th, 2021, 1:00 am
Re: Tutorial #5 My code is broken as shit
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"
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Tutorial #5 My code is broken as shit
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 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