Beginner C++ Game Programming DirectX [Snake Game] Tutorial 14b -

Beginner C++ Game Programming DirectX [Snake Game] Tutorial 14b

Views: 41398
Like: 1189
A tutorial for making a the snake game in C++. This is part two of two parts (2/2).

Tutorial 14 wiki page:

Check out my Patreon!


End slate theme: Arpanauts by Eric Skiff


  1. You know, not having the code available to download after each lesson really discourages people to try to do it themselves since nobody wants to have to redo all their code to match yours for the next lesson (esp since I know I would have done it differently .. not as fancy as yours since i am just learning) ;-( I can only seem to get the advanced version on Git Hub BTW…. but other than that, great job!

  2. Hey Chilli, why is it that when define the function like :
    void Goal::respawn(std::mt19937 & rng, const Snake& snek, const Board& brd)
    and when i call a function from the object like:
    loc.x = xDist(rng);
    loc.y = yDist(rng);
    } while (snek.IsInTile(loc));
    i get a error in the 'Snek' which reads: cannot convert 'this' pointer from 'const Snake' to 'Snake &),
    And also, do we always have to use a const when initializing a constructor? like i have noticed that when i initialize the data members by just using the function: Snake::Snake(int x_in); i get a error. Thank you!!

  3. Hey Chili, I did run into another problem. Any help with this would be appreciated, so I'm at about 6:40 in the video where you start testing out the growth of the Snek. My problem is that when I press Control, the program just crashes; The debugger tells me its because of this Assert code "assert(abs(delta_loc.x) + abs(delta_loc.y) == 1);" and I see that loc's y value is some crazy high number which is what I'm assuming is the problem (the x value is about 50 or so which doesn't seem to be somewhat reasonable.)

    I triple checked all the code from the last video and everything looks fine to me, so any help with this would be appreciated.

  4. Great job Chili! I laugh so much during the videos that its hard to convince the others that im actually studying!!

    Aside from that, I noticed a bug in your code… If the snek has one or two segments(including the head), when you go the opposite direction it doesn't die because of the function IsInTileExceptEnd() which allows collisions with the last segment.

  5. I love the weird videos and pictures you splice in. Takes away from the tedium of just looking at line after line of code. The memes are always dank and they make me chuckle.

  6. If I was a Chick, I'd totally be a Chilli groupie.

  7. First I want to thank you for doing these great tutorials!
    Just have some questions regarding the architecture of the game. This game design that you employed on the snek is common in other games too?
    1) Mapping / DrawMap
    2) An object manager that will deal with this map object iteration
    3) The object itself and so on….

  8. There might be a problem with youtube but, where are the other three zeros after the number 11,039 before the word "views"?

  9. I just have 1 question – why do you fucking draw image filling pixel by pixel instead of loading it to texture from a file and then initializing a sprite using that texture? That is literally 4 lines of code 😂

  10. I think game logic is more comlicated than data structures and algorithms…You have to take a lot of factors into account.

  11. When the snake went off the screen or collided with itself, I made a function to only draw the snake body with the game over screen like " Snake just got his mofooking head split "

  12. Fuck yeah now I'm ready for 3D!
    opens empty project
    cracks fingers
    #include <windows.h>

  13. another feature to add, prevent user from making the snek turn directly back on itself. Currently, if snek is moving right and you press left arrow, snek dies.

  14. Thank you for teaching me how to live my life to the fullest

  15. I have to admit SNEK game wasn't that easy.. but regardless c++ still chills with CHILI.. keep going with the good stuffs bro and extra thanks for you

  16. i remember the snake game from my old nokia 3210 where the snake wraps around the screen/board instead of colliding with the wall. good to see there is a definitive difference between snake and snek xD

  17. Hay Chili. How is everything? Love your videos man. When I will be able to support you I definitely will.

  18. Can anybody HELP? I made an Item(same as Goal) class and later made an ObstacleManager class which manages obstacle segments. But this got me caught up in a circular dependency where the item needs to know about the obstacles before respawning and a new Obstacle object needs to know about the currently spawned item and not spawn on top of it. How do I get around this? please help!! I keep getting a "missing type specifier error – int assumed" kind of thingy!

  19. hi, why can't we just use the current head location for collision detection for the body?

  20. Chilli help, ive made my own system of respawning goals (array of 1000 of them when next is showing up when previous is eaten) but i thought its kinda primal and i wanted to copy yours smart one. BUT. when i made everything just right (exept const's cus i dont fully understand them ) error "unknown override specifier" appeared and i have no idea whats wrong and even what does it mean, i searched it on internet but i still dont understand it 🙁 (i dont expect you to tell me what shold i change cus you cant see my code ofc but at least tell me what that error is)

  21. I don't understand at 28:24 why'd you call location by reference in goal. You didn't do that at 11:39 when u created a getLocation for the segments

    Edit: just wanted to say this. Amazing totorial, chilli. This was a difficult topic but I've grasped all of it. Thanks for these videos

  22. Chili, I must have watched your beginning tutorials a number of times. Each time, I'm always amazed how accessible and entertaining you make the subject matter. Unfortunately, I haven't progressed further than the beginning series — because 'life'?! This time, though, I'm going to onward march, steadily, throughout the lot. I don't know how long it will take, but I think taking your time really pays off. Mad props to you for putting this whole thing together. Can't commend you enough.

  23. I actually used your way, things like random_device mt19937 to create my own Random class. When using I just need #include “Random.h” and int number = Random::Next(min, max); similar to C# (but not even needed to instance an instance like C#). It’s super convenient and easy to breathe. I’m typing on my phone so if anyone interested I will upload the source code for Random class so. Sorry if my English annoyed you.

  24. Nice one again, including excellent advice at the end. I made the snake defy gravity and jump over stuff!!

  25. Why does "GetNextHead" have to return by value, and not reference? It looks like by reference wouldn't change anything?

  26. I just realized that in minute 6:21, if you move snek first and then make it grow in case ctrl is pressed, a green square appears at the top left corner of the screen and I can't figure out why. Can someone explain me?
    By the way Chili I'm lovin' this series so far!

  27. This got hard quickly 😛 I was following along nicely up until the snake game. Gonna keep grinding though and I expect I'll get it quicker than I think!

  28. Something is fucking me over .. When I do –> snek ( {2,2}
    it fails to build and says –> Snake::Snake(Snake &&) cannot convert argument 1 from 'initializer list' to 'Location &'

    Fine I made Location startingLocation = {2,2} just as we did deltaLocation. Initialized perfectly, and built.

    Now it freaking crashes before I do anything and throws that assert ( x >= 0 ), Ok..
    I used the debugger as best as I could and there's something wrong with initializing loc member variable in segment, it gets a weird negative number like memory garbage you find if you don't initialize a variable!!

    I'm doing my best to figure out wtf is wrong but I'm struggling af -_-

    EDIT: I didn't wanna delete my comment if ever someone does the same stupid shit as I did … You talked about the order in which stuff gets initialized is the same order as they were declared in the class as member variables right?!

    I created a Snake snek THEN made the Location startingLocation = {2,2} so it had that trash value and initialized snek with then it initialized itself with my values, which is weird since that's not what I meant 😀

  29. Those texts are useful for further understanding. Thanks chili.

  30. That Metal Gear Solid Ocelot Action at the end… OMG you are an idol.
    Thanks for all of this madness you give to us, please never stop, it's really good shit.
    I will watch every single playlist you made, it's so good!

  31. my snake game doesn't work…even with your Version i downloaded from the wiki…

  32. Please share the source code ASAP.
    thank you

  33. wel fuck my life i couldnt find the error with Drawcell and i downloaded the proyect and now it seems to be way over coed for what i wanted lol, time to try this shit solo boyz, wish me luck or i might end up in xtube

  34. I can't wait to make my first danger noodle, i mean Snake

  35. Hey chili I've been following along with the tutorials and I love what you're doing but I do have one question with this snake game, I know you probably won't see this but when I try to define the constructor in goal.cpp I get an error that says Goal::Goal(blah blah blah) provides no initializer for reference member Goal::loc. I did what you did in the video to see if I missed something but it doesn't look like I did, do you know why this would be? It seems like for the goal constructor we're not even using loc. I tried setting the loc equal to newloc and putting the constructor after all the other function definitions but that didn't help. If you have any insight it would be much appreciated, could it be because of an error I made in another file?

  36. im watching this in 2021 and the memes catch up xD im getting old

  37. I absolutely love learning from you. Thank you for all the time and effort you put in!

  38. i have to say,this game was quite difficult to make. I am not a pro programmer, i gotta watch ur video multiple times to get an idea of what to do in my code.But , in time i think will get easier. IDk,man i just hope .I kinda like pain, so yeah programmin is a thing for me xd

  39. this shit took me way more than a month to get a grasp on it , I cant say ill be able to apply all that information in different project but I'm glad I've finally come to understand what's going on, I hope that doesn't count as a problem though since I'm total new born when it comes to programming.

Leave a Reply

Your email address will not be published.