Snake Game Tutorial 14a

The Partridge Family were neither partridges nor a family. Discuss.
Adagio
Posts: 5
Joined: April 13th, 2017, 11:07 am

Re: Snake Game Tutorial 14a

Post by Adagio » April 13th, 2017, 3:46 pm

chili wrote:You're missing the default constructor for the segment

You want like Segment() = default;
Where do i put the default constructor for the segment? I wrote it as Segment() = default; under the segment class and it still has the same error of trying to reference a deleted function.

1>c:\users\Adagio\desktop\t14-snek-start\engine\snake.cpp(5): error C2280: 'Snake::Segment::Segment(void)': attempting to reference a deleted function
1>c:\users\Adagio\desktop\t14-snek-start\engine\snake.h(12): note: see declaration of 'Snake::Segment::Segment'

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

Re: Snake Game Tutorial 14a

Post by albinopapa » April 13th, 2017, 5:45 pm

Adagio wrote:
chili wrote:You're missing the default constructor for the segment

You want like Segment() = default;
Where do i put the default constructor for the segment? I wrote it as Segment() = default; under the segment class and it still has the same error of trying to reference a deleted function.

1>c:\users\Adagio\desktop\t14-snek-start\engine\snake.cpp(5): error C2280: 'Snake::Segment::Segment(void)': attempting to reference a deleted function
1>c:\users\Adagio\desktop\t14-snek-start\engine\snake.h(12): note: see declaration of 'Snake::Segment::Segment'
I'm going to say that this is the culprit
note: 'Snake::Segment::Segment(void)': function was implicitly deleted because a data member 'Snake::Segment::loc' has either no appropriate default constructor or overload resolution was ambiguous
You probably did the same as someone else in the forum and make a constructor for the Location struct. Remove any Location::Location constructors, and you should be ok.
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

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

Re: Snake Game Tutorial 14a

Post by albinopapa » April 13th, 2017, 5:51 pm

Here's a link to the previous persons experience with same issue
http://planetchili.net/forum/viewtopic. ... 7&start=10
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

User avatar
chili
Site Admin
Posts: 3939
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Snake Game Tutorial 14a

Post by chili » April 14th, 2017, 2:31 am

Ah right, I was looking for that! Thanks for posting the link. ;)
Chili

Adagio
Posts: 5
Joined: April 13th, 2017, 11:07 am

Re: Snake Game Tutorial 14a

Post by Adagio » April 14th, 2017, 3:26 am

Right I removed the constructor i made for the location struct and it built successfully. Thanks for the help guys!

Adagio
Posts: 5
Joined: April 13th, 2017, 11:07 am

Re: Snake Game Tutorial 14a

Post by Adagio » April 14th, 2017, 2:22 pm

Hello again my friends!
I've finished tutorial 14b and was trying out the homework section and I have a question regarding the spawning of the obstacle.
I looked through the github file Chili put up in the wiki and there's several areas I'm unclear on.
First, what happens when u set a boolean statement to an array ( e.g. bool hasObstacle[width * height] = { false }; )? does it set up a boolean for each cell in the grid?

Secondly, the boolean function you have set up in board.cpp :
bool Board::CheckForObstacle( const Location & loc ) const
{
return hasObstacle[loc.y * width + loc.x];
}


why do you take loc.y * width + loc.x inside the array number an what does that statement return exactly?

I'm guessing you are checking each cell in the grid to see if there is an obstacle in the grid and to draw 1 if there isn't according to the draw obstacle function. I just don't get what this line in particular: "return hasObstacle[loc.y * width + loc.x];" mean. :?

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

Re: Snake Game Tutorial 14a

Post by albinopapa » April 14th, 2017, 9:59 pm

First, what happens when u set a boolean statement to an array ( e.g. bool hasObstacle[width * height] = { false }; )? does it set up a boolean for each cell in the grid?
Kind of, it makes an array with the same number of bool elements as the grid.
Secondly, the boolean function you have set up in board.cpp :
bool Board::CheckForObstacle( const Location & loc ) const
{
return hasObstacle[loc.y * width + loc.x];
}

why do you take loc.y * width + loc.x inside the array number an what does that statement return exactly?
If you have made it this far in the tutorials, you would have covered functions. Look at the function declaration and it tells you want it returns.
As far as ( loc.y * width + loc.x ) goes, this is covered in one of the tutorials, but I don't remember if chili covered it at that point or not. Each row is width wide, so loc.y being the vertical axis ( row number ), when you multiply the row number by the number of columns, you get an offset to the beginning of that row. When you add loc.x to it, you get the location of the cell in the array.

Imagine you have a 10x10 grid
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
...

If you want to know the index of the cell in the array you want, you multiply row number by the width of the grid.
Example ( x = 3, y = 2, width = 10 )
row_offset = y * width // 2 * 10 = 20
index = x + row_offset // 20 + 3 = 23
So now
return hasObstacle[loc.y * width + loc.x];
would return a bool from the array hasObstacle at index 23.
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

Adagio
Posts: 5
Joined: April 13th, 2017, 11:07 am

Re: Snake Game Tutorial 14a

Post by Adagio » April 15th, 2017, 3:29 am

I see. So ( loc.y * width + loc.x ) is the input of the individual coordinates of the cell in the grid. I was having trouble visualising what it meant but now i understand. Thanks for the explanation @albinopapa!
So bool CheckForObstacle(const Location& loc) const; just returns the bool element of a specific coordinate { x, y } in the grid!

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

Re: Snake Game Tutorial 14a

Post by albinopapa » April 15th, 2017, 6:09 am

@Adagio
Yes, it returns the bool element at the index of hasObstacle specified by the Location loc object with the values stored at members x and y.
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

Geezer
Posts: 1
Joined: August 13th, 2017, 12:12 pm

Re: Snake Game Tutorial 14a

Post by Geezer » August 31st, 2017, 12:08 am

I got thus same error. Even with the default constructor added. I ended up taking off the = default and created a body for the constructor where I just set the value of c = Colors::Cyan;
The error moved to Location has no default and I added one.
Location() = default;

I'm still a little confused why a couple of us got these errors and not everyone. But in the end, if it compiles ok, I'll live with it.

Geezer.

Aaaaaand Now I just found all the other posts on here. I do have a Location constructor, so there's the problem. Thanks.

Post Reply