First we need to clean up the raylib code and draw a blue background
in main after the close window lets make a dark blue color and assign it to a new variable
|
|
You could also use one of the predefined colors that RayLib offers.
- lets remove the old text
- and instead of clearing the screen with white, we will use our new background color
|
|
One more thing. We will rename our window to ‘Tetris’
|
|
run it to view your changes and also see if you have errors.
The next thing we do is to draw the grid with code very similar to the print grid we already have. We wont be print a line at a time either, we will draw each cell as a rectangle with a COLOR in it.
Just below the Grid definition we need to define a color for each number ‘value’ we use.
|
|
And below the Background color definition
|
|
A function to GET a value at a position
|
|
and then the draw code.
|
|
And finally call our new draw function just below the clear-background-color and before end-drawing
|
|
Run the code and you should now see
Thoughts
Functions are used to keep the main function ‘clean’. I find that if there is too much code in one area then I start having difficulty figuring out what is going on. the same can be said for indirection and ‘clever’ programming.
Go is faster than Java and definitely way faster that JavaScript. If you need the extra performance then I suggest you have a ‘clean’ master/main branch in your git and keep your performance ‘patches’ for the version branches. This keeps Adding new code simple.
Note: I do not advocate low performance, nor do I advocate ‘Messy Code’. High performance AND Bug free makes a huge difference to your client base.
I suggest you find a balance that best suits you.
Keep in mind messy code:
- slows the work down
- is difficult to add new code
- no Developer wants to touch it
- encourages hacking (to add new code)
- encourages bugs