Hello! For reasons unknown to me I've seem to have created a bug in the drawing of the boxes in the game. It can't be the DrawBox method, since if that didn't work, the Player couldn't be drawn.
Github Link: https://github.com/Battlefrog/AssaultCube
Thanks in advance!
AssaultCube issue
- Battlefrog
- Posts: 69
- Joined: March 31st, 2015, 10:10 pm
- Location: Florida, United States of America
AssaultCube issue
Broc W.
Sole Member of Sledgehog Software, trademark and LLC status pending.
Sole Member of Sledgehog Software, trademark and LLC status pending.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: AssaultCube issue
Not sure what problem you were having, but here's what I see:
In C++ and other languages, the first element in an array is 0 as you show:
blocks[0].InitBlock(250, 250, 50, 50);
blocks[1].InitBlock(145, 145, 12, 12);
So if you want to create two blocks you need to allocate for two blocks
static constexpr int amountOfBlocks = 2;
Block blocks[amountOfBlocks];
Since you start from 0, the number of loops needs to reflect that, so iteration 1 would be the 0 index and iteration 2 would be the 1 index, and since those are the only two, you need to stop at the 1 index.
The error I was getting was 'Stack corrupted around the varaible Game theGame'
Code: Select all
// You have amountOfBlocks = 1, so you are only allowed 1 block
static constexpr int amountOfBlocks = 1;
Block blocks[amountOfBlocks];
// You initialize two blocks
blocks[0].InitBlock(250, 250, 50, 50);
blocks[1].InitBlock(145, 145, 12, 12);
// You go from 0 to i = amountOfBlocks, so 0 and 1 but you only allocated 1
for (int i = 0; i <= amountOfBlocks; ++i)
{
if (blocks[i].IsNotCollidingWithPlayer(player))
{
player.UpdateInput(wnd.kbd);
player.IsOutsideBoundries();
}
else
{
isGameOver = true;
// TODO: Do something when the game is over
}
}
// Same goes for this loop
for (int i = 0; i <= amountOfBlocks; ++i)
{
blocks[i].DrawBlock(gfx);
}
blocks[0].InitBlock(250, 250, 50, 50);
blocks[1].InitBlock(145, 145, 12, 12);
So if you want to create two blocks you need to allocate for two blocks
static constexpr int amountOfBlocks = 2;
Block blocks[amountOfBlocks];
Since you start from 0, the number of loops needs to reflect that, so iteration 1 would be the 0 index and iteration 2 would be the 1 index, and since those are the only two, you need to stop at the 1 index.
Code: Select all
for (int i = 0; i < amountOfBlocks; ++i)
{
blocks[i].DrawBlock(gfx);
}
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
- Battlefrog
- Posts: 69
- Joined: March 31st, 2015, 10:10 pm
- Location: Florida, United States of America
Re: AssaultCube issue
Thank you so much.
Broc W.
Sole Member of Sledgehog Software, trademark and LLC status pending.
Sole Member of Sledgehog Software, trademark and LLC status pending.
Re: AssaultCube issue
FROGMAN! ARE YOU MESSING UP YOUR ARRAYS+LOOPS AGAIN!!?? BAD FROGGY!
But seriously, you should like write this on your fridge or above the toilet where you will see it multiple times a day:
for( int i = 0; i < count; i++ )
It is super important.
Love,
Chili
P.S.
When you get to T20, I'm gonna show you something sweet that will let you iterate over all the elements in an array without worrying about their indices. Stay tuned!
But seriously, you should like write this on your fridge or above the toilet where you will see it multiple times a day:
for( int i = 0; i < count; i++ )
It is super important.
Love,
Chili
P.S.
When you get to T20, I'm gonna show you something sweet that will let you iterate over all the elements in an array without worrying about their indices. Stay tuned!
Chili
- Battlefrog
- Posts: 69
- Joined: March 31st, 2015, 10:10 pm
- Location: Florida, United States of America
Re: AssaultCube issue
Can't wait.chili wrote: P.S.
When you get to T20, I'm gonna show you something sweet that will let you iterate over all the elements in an array without worrying about their indices. Stay tuned!
Broc W.
Sole Member of Sledgehog Software, trademark and LLC status pending.
Sole Member of Sledgehog Software, trademark and LLC status pending.