Classic Snake finished!

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
YoMomIsANiceLady
Posts: 33
Joined: February 2nd, 2017, 8:20 am

Classic Snake finished!

Post by YoMomIsANiceLady » February 18th, 2017, 9:41 pm

So the game has all the basic functionality finally. Took me a good few weeks. I will now start documenting everything properly. I am still not sure about the speed levels, if they feel similar enough to the original game cause i have no way of playing it to test it out but I did whatever felt natural. So here is the .exe: https://drive.google.com/open?id=0B-IrF ... XgzTjEzYUU

Here is the git repo:
https://github.com/BenjaminKorady/Classic-Snake-1-1997-

BUT the code and the documentation is not that well written in terms of readability and consistency, so I will update that soon enough hopefully.
"Life is like death, but completely different"
- Ivan Gašparovič

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

Re: Classic Snake finished!

Post by chili » February 19th, 2017, 9:28 am

Haha, looks super legit man. Good work!

I took a look at your code, it looks good too. Decent style. One thing that seemed strange to me:

Code: Select all

void Board::clearPixelRectangle(const PixelLocation & locIn, const int width, const int height, int pixelSpacing)
{
    PixelLocation locCopy = locIn;
    for (int j = 0; j < height; ++j) {
        for (int i = 0; i < width; ++i) {
            clearPixel({ locCopy.x, locCopy.y }, pixelSpacing);
            ++locCopy.x;
        }
        locCopy.x = locIn.x;
        ++locCopy.y;
    }
}
Why do you construct a new PixelLocation from locCopy.x,locCopy.y instead of just passing locCopy directly into the clearPixel function here??
Chili

User avatar
YoMomIsANiceLady
Posts: 33
Joined: February 2nd, 2017, 8:20 am

Re: Classic Snake finished!

Post by YoMomIsANiceLady » February 19th, 2017, 5:15 pm

Yeah I was doing proper documentation with all block comments and stuff but then I added more functionality and didn't do it for those new functions. I actually noticed that by commenting and documenting my code I found a ton of imperfections. I was trying to explain why I did something there and realize it's done poorly, or that it doesn't need to be done at all... Or JESUS the amount of magic numbers I found while commenting. So now I'm looking at this and I have no idea. My guess is, I was trying to do some operations with it at first, that's why I started with { , }. Maybe passing it {locCopy.x++, locCopy.y} or something. I'll fix that. Thanks for pointing it out!
"Life is like death, but completely different"
- Ivan Gašparovič

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

Re: Classic Snake finished!

Post by chili » February 20th, 2017, 2:00 pm

Yeah, seems like one of those things where it doesn't make sense until you consider that maybe the code was doing something else before but got changed... I got ya now :P
Chili

User avatar
YoMomIsANiceLady
Posts: 33
Joined: February 2nd, 2017, 8:20 am

Re: Classic Snake finished!

Post by YoMomIsANiceLady » February 21st, 2017, 2:41 am

Hey, I need some help! I tried the homework from Tutorial 17 to make Snake move based on timer instead of frames. I'm solely using <chrono>, no "FrameTime.h".

Everything seems to be working fine, I would just like some ideas for a formula for determining the snake speed.

The speed levels are 1-9

Here's a preview of max speed level from the original game:
Level 9:
https://youtu.be/hb9Zdlra-GI?t=49s

Later on he changes it to lower
Level 3:
https://youtu.be/hb9Zdlra-GI?t=1m40s

Now I need to figure out a formula to make the snake's speed scale appropriately. Basically the snake moves every x seconds, stored in the variable movePeriod. Current formula is this:

Code: Select all

void Snake::updateSpeed()
{
    const float base = 1.0f;
    movePeriod = base / speedLevel;
}
where speedLevel ranges between 1-9. This doesn't feel right though. So let me know if you have any ideas. Feel free to play around with my code!

https://github.com/BenjaminKorady/Classic-Snake-1-1997-

The movement code is in Snake.cpp class on line 100
"Life is like death, but completely different"
- Ivan Gašparovič

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

Re: Classic Snake finished!

Post by chili » February 22nd, 2017, 2:58 pm

that will give you an inverse function relationship curve. You can try for a linear relationship with base -= k * level. Just make sure you dont let it get to a negative number! There are other relationships you might wanna try too, sqrt or log might be interesting

or you could just hardcode movement period numbers for each of the 9 levels :P
Chili

Post Reply