4 thoughts on “I’ll show you how to create life!”

  1. Hey there Jx9! I saw your video and followed along with it and I though it was really well done. I am using your source code but also trying to implement the functionality that when a cell hits the end of the screen to have it wrap around and appear at the other side. So for example if ScreenWidth = 160, and ScreenHeight = 100, once the cell hits 159 in the x direction have it appear at x = 1 while keeping y the same. Do you have any advice about this? Thank you.

  2. Hi Inceptix,
    Firstly thanks and congrats for being the first person to register on the website!

    There would need to be two main modifications to the code to implement wrap around boundary conditions. Firstly, you may have already notice that I cheat needing to check boundaries in the “cell()” lambda function because my x/y loop starts at one and goes to ScreenXXX -1. This is to keep the code clearer for viewers. So you’ll need to change the loop to operate on all cells.

    Secondly, you will need to change the cell() lambda to be more sophisticated, so when it receives an x that is larger than ScreenWidth it wraps around. The easiest way to do this is just checking with if, so for example:
    if(x >= ScreenWidth()) x = x - ScreenWidth()
    if(x < 0) x=x + ScreenWidth()

    Hope that helps,

    1. Thanks for the reply. It seems as though that wrapping around the x value is somehow implemented on it’s own. It might be because of the ConsoleGameEngine.h. Either way the y doesn’t work on it’s own but the example code you provided works for both. At first I was trying to insert the code in the nested for loop but realized that it doesn’t really do anything there then I put inside the lambda function and the wrapping works perfectly on both the x and the y axis. 😀

      1. The X-axis “kind of works” on its own because the screen is just an array of incrementing memory addresses. Consider a 5×5 Screen

        00, 01, 02, 03, 04
        05, 06, 07, 08, 09
        10, 11, 12, 13, 14
        15, 16, 17, 18, 19
        20, 21, 22, 23, 24

        Anything going off the right hand side, wraps round, but moves one line down. The opposite is also true. Y-Axis can’t do that, so you’ll be reading in random memory values. You may have probably already observed activity along the bottom and top edges that does not go away. It’s reasonably safe as you never write to addresses outside of the screen buffer.

Leave a Reply